Problem:


Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800



Sample input:
4
RRGB


Sample output:
1

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
N = int(input())
#A = list(map(int,input().split()))
S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
R = []
G = []
B = []
for i in range(N):
    a = S[i]
    if a == "R":
        R.append(i)
    elif a == "G":
        G.append(i)
    else:
        B.append(i)
s = len(R) * len(G) * len(B)
nr = len(R)
nb = len(B)
ng = len(G)
nn = max(nr,nb,ng)
def binary_search(S,key):  #昇順リストSからkeyを探す。
    n = len(S)             #存在したらindex,なかったら-1を返す
    left  = 0
    right = n
    while left < right:
        mid = (left+right) // 2
        if S[mid] == key:
            return mid
        elif S[mid] > key:
            right = mid
        else:
            left = mid + 1
    return -1
if nn == nb:
    for r in R:
        for g in G:
            Min = min(r,g)
            Max = max(r,g)
            if 2 * Min - Max > 0:
                c1 = 2 * Min - Max
            else:
                c1 = -1
            if (Min + Max ) % 2 == 0:
                c2 = (Min + Max) / 2
            else:
                c2 = -1
            if 2 * Max - Min < N:
                c3 = 2 * Max - Min
            else:
                c3 = -1
            if c1 != -1:
                if binary_search(B,c1) != -1:
                    s -= 1
            if c2 != -1:
                if binary_search(B,c2) != -1:
                    s -= 1
            if c3 != -1:
                if binary_search(B,c3) != -1:
                    s -= 1
elif nn == ng:
    for r in R:
        for b in B:
            Min = min(r,b)
            Max = max(r,b)
            if 2 * Min - Max > 0:
                c1 = 2 * Min - Max
            else:
                c1 = -1
            if (Min + Max ) % 2 == 0:
                c2 = (Min + Max) / 2
            else:
                c2 = -1
            if 2 * Max - Min < N:
                c3 = 2 * Max - Min
            else:
                c3 = -1
            if c1 != -1:
                if binary_search(B,c1) != -1:
                    s -= 1
            if c2 != -1:
                if binary_search(B,c2) != -1:
                    s -= 1
            if c3 != -1:
                if binary_search(B,c3) != -1:
                    s -= 1
else:
    for b in B:
        for g in G:
            Min = min(b,g)
            Max = max(b,g)
            if 2 * Min - Max > 0:
                c1 = 2 * Min - Max
            else:
                c1 = -1
            if (Min + Max ) % 2 == 0:
                c2 = (Min + Max) / 2
            else:
                c2 = -1
            if 2 * Max - Min < N:
                c3 = 2 * Max - Min
            else:
                c3 = -1
            if c1 != -1:
                if binary_search(B,c1) != -1:
                    s -= 1
            if c2 != -1:
                if binary_search(B,c2) != -1:
                    s -= 1
            if c3 != -1:
                if binary_search(B,c3) != -1:
                    s -= 1
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
memo = {key:[] for key in ("R","G","B")}
ans = 0
for i in range(N):
    memo[S[i]].append(i)
    for space in range(1,N//2):
        j = space + i
        k = space + j
        if(k<N):
            if(S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]):
                ans -= 1

ans += len(memo["R"])*len(memo["G"])*len(memo["B"])
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

def runLength(string):
    """文字列strをランレングス圧縮して返す関数
    ex: "0000111101" => [(0,4), (1,4), (0,1), (1,1)]
    """
    res = []
    data, count = string[0], 1
    for i in range(1, len(string)):
        if string[i] == data:
            count += 1
        else:
            res.append((data, count, i))
            data, count = string[i], 1
    res.append((data, count, i))
    return res


N = int(input())
S = input()
rl = runLength(S)
keys = [rli[2] for rli in rl]
nrl = len(rl)

ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        elif set([S[i], S[j]]) == {"R", "G"}:
            if 2*j - i < N and S[2*j - i] == "B":
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "B"]) - 1
            else:
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "B"])
        elif set([S[i], S[j]]) == {"B", "G"}:
            if 2*j - i < N and S[2*j - i] == "R":
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "R"]) - 1
            else:
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "R"])
        else:
            if 2*j - i < N and S[2*j - i] == "G":
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "G"]) - 1
            else:
                ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "G"])

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	S = input()
	S = S[:-1]

	R = []
	G = []
	B = []
	for i,val in enumerate(S):
		if val == "R":
			R.append(i)
		elif val == "G":
			G.append(i)
		else:
			B.append(i)

	ans = 0
	for i,val in enumerate(R):
		tmp = bisect_right(G, val)
		if len(G) == tmp:
			break

		for j in range(tmp,len(G)):
			tmptmp = bisect_right(B, G[j])
			if len(B) == tmptmp:
				break

			aaa = G[j] - val
			ans += len(G)-tmptmp

		tmp = bisect_right(B, val)
		if len(B) == tmp:
			break

		for j in range(tmp,len(B)):
			tmptmp = bisect_right(G, B[j])
			if len(G) == tmptmp:
				break

			ans += len(B)-tmptmp

	for i,val in enumerate(B):
		tmp = bisect_right(G, val)
		if len(G) == tmp:
			break

		for j in range(tmp,len(G)):
			tmptmp = bisect_right(R, G[j])
			if len(R) == tmptmp:
				break

			ans += len(G)-tmptmp

		tmp = bisect_right(R, val)
		if len(R) == tmp:
			break

		for j in range(tmp,len(R)):
			tmptmp = bisect_right(G, R[j])
			if len(G) == tmptmp:
				break

			ans += len(R)-tmptmp

	for i,val in enumerate(G):
		tmp = bisect_right(B, val)
		if len(B) == tmp:
			break

		for j in range(tmp,len(B)):
			tmptmp = bisect_right(R, B[j])
			if len(R) == tmptmp:
				break

			ans += len(B)-tmptmp

		tmp = bisect_right(R, val)
		if len(R) == tmp:
			break

		for j in range(tmp,len(R)):
			tmptmp = bisect_right(B, R[j])
			if len(B) == tmptmp:
				break

			ans += len(R)-tmptmp

	print(ans)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

def int_sqrt2(n):
    def f(prev):
        while True:
            m = (prev + n / prev) / 2
            if m >= prev:
                return prev
            prev = m

    return f(int(math.sqrt(n) * (1 + 1e-10)))

# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
from math import gcd
k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(gcd(a, b), c)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(sys.stdin.readline())
s = sys.stdin.readline()
r = []
g = []
b = []
cnt = 0
i = 0
while i < n:
  if s[i] == "R":
    r.append(i)
  elif s[i] == "G":
    g.append(i)
  else:
    b.append(i)
  i += 1
for j in r:
  for k in g:
    for l in b:
      if l - k != k - j:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
S = list(s[i] for i in range(n))
T = set(S)
x = 0
if len(T)<=2:
  print(0)
else:
  for i in range(n-2):
    for j in range(i+1, n-1):
      for k in range(j+1, n):
        if {s[i], s[j], s[k]}=={"R", "G", "B"} and i+k != 2*j:
          x += 1
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

import collections
C = collections.Counter(S)



count = 0

for i in range(N):
    j = 1
    while i - j >= 0 and i + j < N:
        if S[i-j] != S[i] and S[i+j] != S[i] and S[i-j] != S[i+j]:
            count += 1
        j += 1

ans = 1
for k, v in C.items():
    ans *= v

print(ans - count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
r = []
g = []
b = []


for x in range(n):
    if s[x] == 'R':
        r.append(x+1)
        continue
    if s[x] == 'G':
        g.append(x+1)
        continue
    if s[x] == 'B':
        b.append(x+1)
        continue

print(r)
print(g)
print(b)
def count(x,y,z):
    c = 0
    for i in x:
        for j in y:
            if i > j: continue 
            for k in z:
                if j > k: continue 
                if j - i != k - j:
                    c += 1
    return c

ans = 0
ans += count(r,g,b)
ans += count(r,b,g)
ans += count(b,r,g)
ans += count(b,g,r)
ans += count(g,r,b)
ans += count(g,b,r)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
s = str(input())
ans = 1

s_l = collections.Counter(s)
s_value = s_l.values()  # +1*
for k in s_value:
    ans *= k


cnt = 0
for i in range(1, n-1):
    for j in range(1, min(i, n - i - 1) + 1):
        if s[i] != s[i - j] and s[i] != s[i + j] and s[i - j] != s[i + j]:
            cnt += 1

print(ans - cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())

S=input()
LEN=len(S)
END='EEEEEEEEEEEEEEEEEEEEEEEEEEEEEE'
S += END

R=S.count('R')
G=S.count('G')
B=S.count('B')


cnt=0
for j in range(1, int((LEN-1)/2)):
    for i in range(LEN):
        if S[i+j+j]=='E':
            break
        if (S[i] != S[i+j]) and (S[i+j] != S[i+j+j]) and (S[i] != S[i+j+j]):
            cnt+=1

print(R*G*B-cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

rs = []
gs = []
bs = []
for i, e in enumerate(s):
  if e == 'R':
    rs.append(i)
  if e == 'G':
    gs.append(i)
  if e == 'B':
    bs.append(i)
      
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  if len(rs) <= len(bs) and len(gs) <= len(bs):
    for i in rs:
      for j in gs:
        mi = i if i < j else j
        ma = j if i < j else i
        p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
        for e in p:
          if e in bs:
            saidai -= 1
    print(int(saidai))
  elif len(rs) <= len(gs) and len(bs) <= len(gs):
    for i in rs:
      for j in bs:
        mi = i if i < j else j
        ma = j if i < j else i
        p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
        for e in p:
          if e in gs:
            saidai -= 1
  elif len(gs) <= len(rs) and len(bs) <= len(rs):
    for i in gs:
      for j in bs:
        mi = i if i < j else j
        ma = j if i < j else i
        p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
        for e in p:
          if e in rs:
            saidai -= 1
    print(int(saidai))

Submission status: Wrong Answer

Solution code:
N =int(input())
S = str(input())
A = 0
R = []
G = []
B = []
for i in range(len(S)):
  if S[i] == "R":
    R.append(i+1)
  elif S[i] == "G":
    G.append(i+1)
  else:
    B.append(i+1)
rl = len(R)
gl = len(G)
bl = len(B)
D = sorted([rl,gl,bl])
if D[0] == rl:
  O = R
elif D[0] == gl:
  O = G
else:
  O = B
if D[1] == rl:
  T = R
elif D[1] == gl:
  T = G
else:
  T = B

if D[2] == rl:
  F = R
elif D[2] == gl:
  F = G
else:
  F = B

for r in O:
  for g in T:
    for b in F:
      C = sorted([r,g,b])
      if C[1] - C[0] != C[2] - C[1]:
        A += 1
print(A)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
counter=[[0 for i in range(N)] for _ in range(3)]#i+1より右側にあるR(0),G(1),B(2)の数
if S[N-1]=="R":
  counter[0][N-1]=1
elif S[N-1]=="G":
  counter[1][N-1]=1
else:
  counter[2][N-1]=1
for i in range(1,N):
  if S[N-1-i]=="R":
    counter[0][N-1-i]=counter[0][N-i]+1
  elif S[N-1-i]=="G":
    counter[1][N-1-i]=counter[1][N-i]+1
  else:
    counter[2][N-1-i]=counter[2][N-i]+1
  counter[0][N-1-i]=max(counter[0][N-i],counter[0][N-1-i])
  counter[1][N-1-i]=max(counter[1][N-i],counter[1][N-1-i])
  counter[2][N-1-i]=max(counter[2][N-i],counter[2][N-1-i])
print(counter[0])
ans=0
for i in range(N-1):
  if S[i]=="R":
    for j in range(i+1,N):
      if S[j]=="G":
        ans+=counter[2][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="B":
            ans-=1
      elif S[j]=="B":
        ans+=counter[1][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="G":
            ans-=1
for i in range(N-1):
  if S[i]=="G":
    for j in range(i+1,N):
      if S[j]=="R":
        ans+=counter[2][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="B":
            ans-=1
      elif S[j]=="B":
        ans+=counter[0][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="R":
            ans-=1
for i in range(N-1):
  if S[i]=="B":
    for j in range(i+1,N):
      if S[j]=="R":
        ans+=counter[1][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="G":
            ans-=1
      elif S[j]=="G":
        ans+=counter[0][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="R":
            ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = input()
Ans = 0
for i in range(1, 1 + N):
    for j in range(1, 1 + N):
        for k in range(1, 1 + N):
            if i < j and j < k:
                if S[i-1] != S[j-1] and S[j-1] != S[k-1]:
                    if (j-i) != (k-j):
                        Ans += 1
print(Ans)

Submission status: Wrong Answer

Solution code:
S=str(input())
R=S.count('R')
B=S.count('B')
G=S.count('G')
ans=R*B*G-min(R,B,G)**2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

rs = []
gs = []
bs = []
for i, e in enumerate(s):
  if e == 'R':
    rs.append(i)
  if e == 'G':
    gs.append(i)
  if e == 'B':
    bs.append(i)
      
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  if len(rs) <= len(bs) and len(gs) <= len(bs):
    for i in rs:
      for j in gs:
        mi = i if i < j else j
        ma = j if i < j else i
        p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
        for e in p:
          if e in bs:
            saidai -= 1
    print(int(saidai))
  elif len(rs) <= len(gs) and len(bs) <= len(gs):
    for i in rs:
      for j in bs:
        mi = i if i < j else j
        ma = j if i < j else i
        p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
        for e in p:
          if e in bs:
            saidai -= 1
  elif len(gs) <= len(rs) and len(bs) <= len(rs):
    for i in gs:
      for j in bs:
        mi = i if i < j else j
        ma = j if i < j else i
        p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
        for e in p:
          if e in bs:
            saidai -= 1
    print(int(saidai))

Submission status: Wrong Answer

Solution code:
n = int(input())
s=input()
r=[]
g=[]
b=[]
for i,c in enumerate(s):
    if 'R' == c:
        r.append(i+1)
    elif 'G' == c:
        g.append(i+1)
    elif 'B' == c:
        b.append(i+1)
print(len([(i,j,k) for i in r for j in g for k in b if j*2-i-k]))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
print(S)
a=0
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i] and j-i!=k-j:
                a+=1
            else:
                pass
print(a)

Submission status: Wrong Answer

Solution code:
import sys
# sys.stdin = open('input.txt')

from math import gcd


n = int(input())
s = input()
i_indices = []
j_indices = []
k_indices = []

for i in range(n):
    if s[i] == 'R':
        i_indices.append(i+1)
    elif s[i] == 'G':
        j_indices.append(i+1)
    else:
        k_indices.append(i+1)

# print(i_indices, len(i_indices))
# print(j_indices, len(j_indices))
# print(k_indices, len(k_indices))

ans = 0
tot = 0

for i in i_indices:
    for j in j_indices:
        for k in k_indices:
            if j - i != k - j and 1 <= i < j < k <= n:
                ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()


Slist = list(S)

print(Slist)

count = 0
for i in range(len(Slist)+1):
    for j in range(i, len(Slist)):
        for k in range(j, len(Slist)):
            notEqualColor = Slist[i] != Slist[j] and Slist[j] != Slist[k] and Slist[k] != Slist[i]
            notEqualDistance = (j - i != k - j)

            if(notEqualColor and notEqualDistance):
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# D - RGB Triplets
# 標準入力の取得
N = int(input())
S = input()

# 求解処理
result = 0
size = len(S)
for i in range(size):
    S_i = S[i]
    S_k = "RGB".replace(S_i, "")
    for j in range(i+1, size):
        S_j = S[j]
        if S_i == S_j:
            continue
        S_k = S_k.replace(S_j, "")
        result += S[j+1:].count(S_k)
        if (2*j - i < size) and (S[2*j-i] == S_k):
            result -= 1

# 結果出力
print(result)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    s = 0
    Rl = [i for i in range(N) if S[i] == "R"]
    Gl = [i for i in range(N) if S[i] == "G"]
    Bl = [i for i in range(N) if S[i] == "B"]
    for i in range(N):
        if S[i] == "R":
            for j in Gl:
                if j > i:
                    for k in Bl:
                        if k > j:
                            if k-j != j-i:
                                s += 1
            for j in Bl:
                if j > i:
                    for k in Gl:
                        if k > j:
                            if k-j != j-i:
                                s += 1

        elif S[i] == "G":
            for j in Bl:
                if j > i:
                    for k in Rl:
                        if k > j:
                            if k-j != j-i:
                                s += 1
            for j in Rl:
                if j > i:
                    for k in Bl:
                        if k > j:
                            if k-j != j-i:
                                s += 1
        elif S[i] == "B":
            for j in Rl:
                if j > i:
                    for k in Gl:
                        if k > j:
                            if k-j != j-i:
                                s += 1
            for j in Gl:
                if j > i:
                    for k in Rl:
                        if k > j:
                            if k-j != j-i:
                                s += 1
    print(s)

Submission status: Wrong Answer

Solution code:
import collections
import functools
import operator



n=int(input())
s=input()
c=collections.Counter(s)

# l=r*g*b
l = functools.reduce(operator.mul, c.values())
for i in range(0,n-1):
    for j in range(i+1,n):
        k=j-i+j
        if k>=n:
            continue
        if s[i]!=s[j] and s[k]!=s[j] and s[i]!=s[k]:
            l-=1
print(l)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

rlist, glist, blist = [], [], []
for i in range(N):
    if S[i] == "R":
        rlist.append(i)
    if S[i] == "G":
        glist.append(i)
    else:
        blist.append(i)
#print(rlist)

rnumber = len(rlist)
gnumber = len(glist)
bnumber = N - rnumber - gnumber
total = rnumber * gnumber * bnumber
#print(total)

overcount = 0
for r in rlist:
    for g in glist:
        for b in blist:
            options = sorted([r,g,b])
            if options[0]+options[2] == 2*options[1]:
                overcount += 1
    
print(total - overcount)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

count = 0

for i in range(0, N-2):
    for j in range(i +1, N-1):
        if S[i] == S[j]:
            continue
        else:
            for k in range(j+1, N):
                if S[i]!=S[k] and 2*j != k+i:
                    count = count + 1
                else:
                    continue
                    
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

n_R = S.count('R')
n_G = S.count('G')
n_B = S.count('B')
ans = n_R * n_G * n_B

for a in range(N - 2):
    # a = 2
    for b in range(1, N // 2):
        # b = 3
        i = a
        j = a + b
        k = a + 2 * b

        if k > N - 1:
            continue

        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

S=input()
LEN=len(S)
END='EEEEEEEEEEEEEEE'
S += END

R=S.count('R')
G=S.count('G')
B=S.count('B')


cnt=0
for j in range(1, int(LEN/2)):
    for i in range(LEN):
        if S[i+j+j]=='E':
            break
        if (S[i] != S[i+j]) and (S[i+j] != S[i+j+j]) and (S[i] != S[i+j+j]):
            cnt+=1

print(R*G*B-cnt)

Submission status: Wrong Answer

Solution code:
n= int(input())
ss=input()
rs = set()
gs = set()
bs = set()

for i, s in enumerate(ss):
    if s == "R":
        rs.add(i)
    elif s == "G":
        gs.add(i)
    else:
        bs.add(i)
ans = 0
if len(gs) > len(bs) and len(gs) > len(rs):
    tmp = gs
    gs = bs
    bs = tmp
elif len(rs) > len(bs) and len(rs) > len(gs):
    tmp =rs
    rs = bs
    bs = rs
    
for r in rs:
    for g in gs:
        c = 0
        if r+r-g in bs:
            c+=1
        if g+g-r in bs:
            c+=1
        if (g+r)/2 in bs:
            c+=1
        ans += len(bs) -c
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
for i in range(1,N-1):
    for j in range(i+1, N):
        if S[i-1] == S[j-1]:
            pass
        else:
            if (S[i-1] == "R" and S[j-1] == "G" )or (S[i-1] == "G" and S[j-1] == "R"):
                k = "B"
            elif (S[i-1] == "R" and S[j-1] == "B") or (S[i-1] == "B" and S[j-1] == "R"):
                k = "G"
            elif (S[i-1] == "G" and S[j-1] == "B") or (S[i-1] == "B" and S[j-1] == "G"):
                k = "R"
            S_cp = S[j:N]
            count += S_cp.count(k)
            print(i,j,2*j-i-1)
            if 2*j-i <= N :
                if S[2*j-i-1] == k:
                    count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
S = input()

col_lis = [0 if c == "R" else 1 if c == "G" else 2 for c in S]
col_lis = np.asarray(col_lis)

ans = 0

r_count = 0
g_count = 0
b_count = 0

color_table = []

for color in col_lis:
    if color == 0:
        r_count += 1
    elif color == 1:
        g_count += 1
    else:
        b_count += 1
    color_table.append([r_count, g_count, b_count])

ans = 0

for center in range(1, N - 1):
    if col_lis[center] == 0:
        ans += color_table[center - 1][1] * (color_table[N - 1][2] - color_table[center][2])
        ans += color_table[center - 1][2] * (color_table[N - 1][1] - color_table[center][1])
    elif col_lis[center] == 1:
        ans += color_table[center - 1][0] * (color_table[N - 1][2] - color_table[center][2])
        ans += color_table[center - 1][2] * (color_table[N - 1][0] - color_table[center][0])
    else:
        ans += color_table[center - 1][0] * (color_table[N - 1][1] - color_table[center][1])
        ans += color_table[center - 1][1] * (color_table[N - 1][0] - color_table[center][0])
    for width in range(1, center):
        if center - width < 0 or center + width >= N:
            break
        if col_lis[center] + col_lis[center - width] + col_lis[center + width] == 3:
            ans -= 1


print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
from collections import Counter
def MI():return map(int,input().split())
def LI():return list(MI())

n=int(input())
s=input()
c=Counter(s).values()
ans=1
for i in c:ans*=i


for j in range(n):
    jj=s[j]
    for i in range(j):
        k=2*j-i
        if not j<=k<=n-1:
            continue
        ii=s[i]
        kk=s[k]
        if jj!=ii and jj!=kk and ii!=kk:
            ans-=1

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
#from sys import stdin
#import math
#from functools import reduce
    
#A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
N = int(input())
S = input()
 
counter = 0
 
for k in range(N):
    sk = S[k]
    for j in range(k):
        sj = S[j]
        #print(sk, sj)
        if (sk == sj):
            print('ok')
            continue
        for i in range(j):
            if (j-i)==(k-j):
                continue
            si = S[i]
            if (si==sj):
                continue
            elif (si==sk):
                continue
            else:
                counter = counter + 1
 
print(counter)

Submission status: Wrong Answer

Solution code:

n=int(input())
s=input()

r=[]
g=[]
b=[]

for i in range(n):
    if s[i]=="R":
        r.append(i+1)
    elif s[i]=="G":
        g.append(i+1)
    else:
        b.append(i+1)

isum=0
for ir in range(len(r)):
    for ig in range(len(g)):
        for ib in range(len(b)):
            imin=min(ir,ig,ib)
            imax=max(ir,ig,ib)
            imid=ir+ig+ib-imin-imax
            if (imid-imin)!=(imax-imid):
                isum=isum+1
                
print(isum)