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 collections

n=int(input())
S=input()
s=collections.Counter(S)
print(s)
ans=s['R']*s['G']*s['B']
for i in range(n):
    for d in range(n):
        j=i+d
        k=j+d
        if k>n-1:
            break
        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()

alphabet_dict = {}
for i in range(N):
    alphabet = S[i]
    if alphabet in  alphabet_dict.keys():
        alphabet_dict[alphabet].append(i)
    else:
        alphabet_dict[alphabet] = [i]

# 全集合
result = 1
for key in alphabet_dict.keys():
    result*=len(alphabet_dict[key])

# rgb三色揃っている
if len(alphabet_dict.keys())==3:
    for i in range(N):
        for j in range(i, N):
            k = 2*j-i
            keys = []
            for key in alphabet_dict.keys():
                if i in alphabet_dict[key]:
                    keys.append(key)
                if j in alphabet_dict[key]:
                    keys.append(key)
                if k in alphabet_dict[key]:
                    keys.append(key)
            if len(set(keys))==3:
                result-=1
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
s = input()
cnt = Counter(s)

ans = cnt['R'] * cnt['G'] * cnt['B']
for i in range(n):
    for j in range(n):
        k = 2 * j - i
        if k > n-1:
            break
        if 1 < j < k and s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
R = []
G = []
B = []
ans = {}
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)

for r in R:
    for g in G:
        for b in B:
            a = [r, g, b]
            a.sort(reverse=True)
            if a[0]-a[1] != a[1]-a[2]:
                ans[str(a[0])+str(a[1])+str(a[2])] = True

print(len(ans))

Submission status: Wrong Answer

Solution code:
import statistics

n = int(input());
s = str(input());
rlist = [0]
glist = [0]
blist = [0]
for i in range(n):
    if s[i] == 'R':
        rlist.append(i+1);
    elif s[i] == 'G':
        glist.append(i+1);
    elif s[i] == 'B':
        blist.append(i+1);
print(rlist);
print(glist);
print(blist);

rr = len(rlist)
gg = len(glist)
bb = len(blist)
if rr==1 or gg==1 or bb==1:
    print(0);
else:
    con = 0;
    for r in range(1,rr):
        x = rlist[r]
        for g in range(1,gg):
            y = glist[g]
            for b in range(1,bb):
                z = blist[b]
                sol = [0]*3
                sol[0] =x
                sol[1] =y
                sol[2] = z
                if (max(x,y,z)-statistics.median(sol))!=(statistics.median(sol)-min(x,y,z)):
                    con+=1
    print(con);

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
R = [0]*N
G = [0]*N
B = [0]*N
for i in range(N):
    if S[i]=="R":
        R[i] += 1
    elif S[i] == "G":
        G[i] += 1
    else:
        B[i] += 1

ans = sum(R)*sum(G)*sum(B)

for i in range(N):
    for j in range(i+1,min((N+3)//2,N)):
        k = 2*j-i
        if  k<N:
            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()
n=4000
s="RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBG"*100
r=[[0,0,0] for _ in range(n)]
c=0
l={"GB":0,"BG":0,"RB":1,"BR":1,"RG":2,"GR":2}
for i in range(n):
  if s[i] =="R":
    r[i][0]=r[i-1][0]+1
    r[i][1]=r[i-1][1]
    r[i][2]=r[i-1][2]
  elif s[i]=="G":
    r[i][1]=r[i-1][1]+1
    r[i][0]=r[i-1][0]
    r[i][2]=r[i-1][2]
  elif s[i]=="B":
    r[i][2]=r[i-1][2]+1
    r[i][0]=r[i-1][0]
    r[i][1]=r[i-1][1]

for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i]==s[j]:
      continue
    else:
      c+=r[n-1][l[s[i]+s[j]]]-r[j][l[s[i]+s[j]]]
     # print("p",i,j,c)
      
      if 2*j-i<n:
        if s[2*j-i]!= s[i] and s[2*j-i]!=s[j]:
          c-=1
      #   print("m",i,j,c)
  
print(c)

Submission status: Wrong Answer

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

lr = list()
lg = list()
lb = list()

for i in range(n):
    if s[i] == "R":
        lr.append(i)
    if s[i] == "G":
        lg.append(i)
    if s[i] == "B":
        lb.append(i)

r = len(lr)
g = len(lg)
b = len(lb)
dic = {r:lr, g:lg, b:lb}

l3 = sorted([r, g, b])

ans = r*g*b

for i in dic[l3[0]]:
    for j in dic[l3[1]]:
        d1 = abs(i-j)
        if max(i,j) + d1 in dic[l3[2]]:
            ans -= 1
        if min(i,j) - d1 in dic[l3[2]]:
            ans -= 1
        if min(i,j) + d1/2 in dic[l3[2]]:
            ans -= 1
print(ans)

Submission status: Wrong Answer

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

rinds, ginds, binds = [], [], set()

for i in range(n):
    if s[i] == 'R': rinds.append(i)
    elif s[i] == 'G': ginds.append(i)
    else: binds.add(i)

rlen, glen, blen = len(rinds), len(ginds), len(binds)


ans = 0

for i in rinds:
    for j in ginds:
        dist = abs(i-j)
        i_ = min(i, j)
        j_ = max(i, j)
        ans += blen
        # i' < j' < k
        if j_ + dist in binds:
            ans -= 1
        if i_ + dist//2 in binds:
            ans -= 1
        if i_ - dist in binds:
            ans -= 1

        # if binsearch_same(binds, blen, dist, j_):
        #     ans -= 1
        # # i'< k < j' 
        # if dist%2==0 and binsearch_same(binds, blen, dist//2, i_):
        #     ans -= 1
        # # # k < i' < j'
        # if binsearch_same(binds, blen, -dist, i_):
        #     ans -= 1

print(ans)















# n = input()
# print('Yes' if '7' in n else 'No')

# n = int(input())
# ans = 0
# for i in range(1, n+1):
#     if i%3 == 0 or i%5==0:
#         pass
#     else:
#         ans += i
# print(ans)


# k = int(input())
# def gcd(a, b):
#     if b == 0:
#         return a
#     return gcd(b, a%b)

# 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:
n = int(input())
s = input()

R=[]
G=[]
B=[]

for i in range(n):
    if s[i] == "R":
        R.append(i)
    elif s[i] == "G":
        G.append(i)
    else:
        B.append(i)

ans = len(R)*len(G)*len(B)
for i in range(n-2):
    for j in range(i+1,n-1):
        k  = 2*j-i
        if k<n:
            if (s[i]==s[j]) and (s[i]==s[k]) and (s[j]==s[k]):
                ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
r = 0
g = 0
b = 0
for i in range(n):
    if s[i] == "R":
        r += 1
    elif s[i] == "G":
        g += 1
    else:
        b += 1
p = r*g*b
for i in range(n-2):
    for j in range(int(n/2)):
        if i + 2*j >n-1:
            break
        if s[i] != s[i+j] and s[i] != s[i+2*j] and s[i+2*j] != s[i+j]:
            p -= 1
print(p)

Submission status: Wrong Answer

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

from collections import Counter

ctr = Counter(s)

ans = 1
for val in ctr.values():
    ans *= val

cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = 2 * j - i
        if j < k and k < n:
            if s[i] == s[j]:
                continue
            if s[i] == s[k]:
                continue
            if s[j] == s[k]:
                continue
            cnt += 1

ans -= cnt

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

ctr = Counter(s)

ans = 1
for val in ctr.values():
    ans *= val

cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = 2 * j - i
        if j < k < n:
            if s[i] == s[j]:
                continue
            if s[i] == s[k]:
                continue
            if s[j] == s[k]:
                continue
            cnt += 1

ans -= cnt

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

ctr = Counter(s)

ans = 1
for val in ctr.values():
    ans *= val

cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = 2 * j - i
        if k < n:
            if s[i] == s[j]:
                continue
            if s[i] == s[k]:
                continue
            if s[j] == s[k]:
                continue
            cnt += 1

ans -= cnt

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

ctr = Counter(s)

ans = 1
for val in ctr.values():
    ans *= val
print(ctr, ans)
cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = 2 * j - i
        if k < n:
            if s[i] == s[j]:
                continue
            if s[i] == s[k]:
                continue
            if s[j] == s[k]:
                continue
            cnt += 1

ans -= cnt

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

ctr = Counter(s)

ans = 1
for val in ctr.values():
    ans *= val

cnt = 0
for i in range(n - 1):
    for j in range(i + 1, n - 1):
        k = 2 * j - i
        if k < n:
            if s[i] == s[j]:
                continue
            if s[i] == s[k]:
                continue
            if s[j] == s[k]:
                continue
            cnt += 1

ans -= cnt

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

ctr = Counter(s)

ans = 1
for val in ctr.values():
    ans *= val

cnt = 0
for i in range(n - 1):
    for j in range(i + 1, n - 1):
        k = 2 * j - i
        if k > n - 1:
            continue
        if s[i] == s[j]:
            continue
        if s[i] == s[k]:
            continue
        if s[j] == s[k]:
            continue
        cnt += 1

ans -= cnt

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

ctr = Counter(s)

ans = 1
for val in ctr.values():
    ans *= val

cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        if k > n - 1:
            continue
        if s[i] == s[j]:
            continue
        if s[i] == s[k]:
            continue
        if s[j] == s[k]:
            continue
        cnt += 1

ans -= cnt

print(ans)

Submission status: Wrong Answer

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

ruisekiR = [0]*(n+1)
ruisekiG = [0]*(n+1)
ruisekiB = [0]*(n+1)

for i, c in enumerate(s):
  ruisekiR[i+1] = ruisekiR[i] + (1 if c == 'R' else 0)
  ruisekiG[i+1] = ruisekiG[i] + (1 if c == 'G' else 0)
  ruisekiB[i+1] = ruisekiB[i] + (1 if c == 'B' else 0)
  
for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i] == s[j]:
      continue
    c = 'R'
    if 'R' in (s[i],s[j]):
      c = 'G'
    if 'G' in (s[i],s[j]):
      c = 'B'
    
    if c == 'R':
      ans += ruisekiR[n]-ruisekiR[j]
    if c == 'G':
      ans += ruisekiG[n]-ruisekiG[j]
    if c == 'B':
      ans += ruisekiB[n]-ruisekiB[j]
    
    if j+(j-i) < n and s[j+(j-i)] == c:
      ans -= 1
      
print(ans)

Submission status: Wrong Answer

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

r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r*g*b

for i in range(n):
    for a in range(i, n):
        j = i + a
        k = i +j
        if k >= n or j>= n:
            break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
s = list(input())
n = int(n)
ans = 0

for i in range(n-2):
    for j in range(i,n-1):
        for k in range(j, n):
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k] and j - i != k -j:
                print(i,j,k)
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
r = s.count('R')
g = s.count('G')
b = s.count('B')
cnt = r * g * b
for i in range(n // 2 - 1):
    for j in range(n - (i + 1) * 2):
        if s[j] != s[j+i+1] and s[j+i+1] != s[j+2*(i+1)] and s[j] != s[j+2*(i+1)]:
            cnt -= 1
print(cnt)

Submission status: Wrong Answer

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

nr = len([r for r in S if r == 'R'])
nb = len([b for b in S if b == 'B'])
ng = len([g for g in S if g == 'G'])

ALL = nr * nb * ng
count = 0

for i in range(N-2):
  for k in range(2,N):
    j = (i + k) // 2
    if 1 <= j and j <= N:
      count += 1
      
print(ALL - count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
rgb={"R":0,"G":0,"B":0}
for s in S:
  rgb[s]+=1
ans=rgb["R"]*rgb["G"]*rgb["B"]
for dist in range(N//2):
  left=0
  while left+dist*2<N:
    if len(set([S[left],S[left+dist],S[left+dist*2]]))==3:
      ans-=1
    left+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r*g*b

for i in range(n - 2):
    for j in range(int(n//2)):
        if i + j*2 < n:
            if s[i] != s[i + j]:
                if s[i] != s[i + j*2]:
                    if s[i + j] != s[i + j*2]:
                        ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s_=input()
s=Counter(s_)
rgb = s['R'] * s['G'] * s['B']
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<len(s_)-1:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s_=input()

s=Counter(s_).values()
rgb=1
for i in s:
  rgb*=i
  
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<=len(s_)-1:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)

Submission status: Wrong Answer

Solution code:
def main():
    rc = S.count("R")
    gc = S.count("G")
    bc = S.count("B")
    ns = 0
    for i in range(N-2):
        for k in range(i+2, N):
            if (i+k)%2 == 0:
                j = (i+k)//2
                ns += 1 if S[j] != S[i] and S[j] != S[k] else 0
    print(rc*gc*bc - ns)


if __name__ == "__main__":
    N = int(input())
    S = input()
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
 
r_cnt = S.count('R')
g_cnt = S.count('G')
b_cnt = S.count('B')

ans = r_cnt * g_cnt * b_cnt
 
for i in range(N):
    for j in range(i,N):
        k = 2*j - i
        if k >= N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans -= 1
        print(i,j,k)
print(ans)

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)
    elif(s[i] == 'G'):
        G.append(i)
    else:
        B.append(i)

samu = len(R) * len(G) * len(B)

for i in R:
    for j in G:
        k = int(2 * j - i)
        if(0 <= k < n):
            if(s[k] == 'B'):
                samu -= 1
                print(i,j,k)
        k = int(2 * i - j)
        if(0 <= k < n):
            if(s[k] == 'B'):
                samu -= 1
                print(i,j,k)
        if(i % 2 == j % 2):
            k = int((i + j) / 2)
            if(s[k] == 'B'):
                samu -= 1
                print(i,j,k)

print(samu)

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)
    elif(s[i] == 'G'):
        G.append(i)
    else:
        B.append(i)

samu = len(R) * len(G) * len(B)

for i in R:
    for j in G:
        k = int(2 * j - i)
        if(k < n):
            if(s[k] == 'B'):
                samu -= 1
        k = int(2 * i - j)
        if(k < n):
            if(s[k] == 'B'):
                samu -= 1
        if(i % 2 == j % 2):
            k = int((i + j) / 2)
            if(s[k] == 'B'):
                samu -= 1

print(samu)

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)
    elif(s[i] == 'G'):
        G.append(i)
    else:
        B.append(i)

samu = len(R) * len(G) * len(B)

for i in R:
    for j in G:
        k = int(2 * j - i)
        if(k < n):
            if(s[k] == 'B'):
                samu -= 1
        if(i % 2 == j % 2):
            k = int((i + j) / 2)
            if(s[k] == 'B'):
                samu -= 1

print(samu)

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)
    elif(s[i] == 'G'):
        G.append(i)
    else:
        B.append(i)

samu = len(R) * len(G) * len(B)

for i in R:
    for j in G:
        k = 2 * j - i
        if(k in B):
            samu -= 1
        k = (i + j) / 2
        if(k in B):
            samu -= 1

print(samu)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    from collections import Counter
    c = Counter(S)
    result = 1
    if len(list(c.values())) < 3:
        return 0
    for v in c.values():
        result *= v
    piyo = (N-3) // 2
    for p in range(piyo+1):
        for i in range(N-1 - 2*p -2 + 1):
            a, b, c = S[i] , S[i+p+1] , S[i + (p+1)*2]
            if a != b and a != c and b != c:
                result -= 1
    print(result)
main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    from collections import Counter
    c = Counter(S)
    result = 1
    if len(list(c.values())) < 3:
        return 0
    for v in c.values():
        result *= v
    piyo = (N-3) // 2
    for p in range(piyo+1):
        for i in range(N-1 - 2*p -1):
            hoge = S[i] + S[i+p+1] + S[i + (p+1)*2]
            if len(set(hoge)) == 3:
                result -= 1
    print(result)
main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,int(n/2)):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)

Submission status: Wrong Answer

Solution code:
_input = input
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

#ここに書きたいコードを書く
#データ読み込み

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

RGB_num=[0]*3

for c in S:
	if c=='R':
		RGB_num[0] += 1
	elif c=='G':
		RGB_num[1] += 1
	else:
		RGB_num[2] += 1

#print(RGB_num)
joken2=0

print(S[0])
for i in range(N-2):
	#print("i",i,S[i+1])
	for j in range(min(i+1,N-i-2)):
		if S[i+1] != S[i-j] and S[i+1] != S[i+j+2] and S[i-j] != S[i+j+2]:
			joken2 += 1
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2],"j2")
		#else:
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2])

joken1=RGB_num[0]*RGB_num[1]*RGB_num[2]

print(joken1-joken2)

input = _input

Submission status: Wrong Answer

Solution code:
_input = input
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

#ここに書きたいコードを書く
#データ読み込み

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

RGB_num=[0]*3

for c in S:
	if c=='R':
		RGB_num[0] += 1
	elif c=='G':
		RGB_num[1] += 1
	else:
		RGB_num[2] += 1

#print(RGB_num)
joken2=0

print(S[0])
for i in range(N-2):
	#print("i",i,S[i+1])
	for j in range(min(i+1,N-i-2)):
		if S[i+1] != S[i-j] and S[i+1] != S[i+j+2] and S[i-j] != S[i+j+2]:
			joken2 += 1
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2],"j2")
		#else:
			#print(i,j,S[i-j]+S[i+1]+S[i+j+2])

joken1=RGB_num[0]*RGB_num[1]*RGB_num[2]

print(joken1-joken2)

input = _input

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
dict={}
dict["R"]=[]
dict["G"]=[]
dict["B"]=[]
res=0
for i in range(n):
  if s[i]=="R":
    dict["R"].append(i)
  elif s[i]=="G":
    dict["G"].append(i)
  elif s[i]=="B":
    dict["B"].append(i)
  else:
    raise Exception
for r in dict["R"]:
  for g in dict["G"]:
    if r<g:
      for b in dict["B"]:
        if g<b:
          if 2*r!=g+b and 2*g!=r+b and 2*b!=r+g:
            res+=1           
print(res)

Submission status: Wrong Answer

Solution code:
FizzBizz = int(input())

Sum = []
for i in range(1, FizzBizz+1):
    if i % 3 != 0 and i % 5 != 0:
        Sum.append(i)
    else:
        Sum.append(0)
print(sum(Sum))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
R = []
G = []
B = []
cnt = 0

for i in range(n):
    if s[i] == 'R':
        R.append(i)
    elif s[i] == 'G':
        G.append(i)
    else:
        B.append(i)

ans = len(R) * len(G) * len(B)

for i in range(1,n-2):
    for j in range(i,n-1):
        k = 2 * j - i
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            cnt += 1 

print(ans - cnt)

Submission status: Wrong Answer

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

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

if R==0 or G==0 or B==0:
    print(0)

ans=R*G*B
for i in range(N-2):
    for j in range(i+1,N-1):
        if S[i]==S[j]:continue
        n=2*j-i
        if n>=N:continue
        if S[i]!=S[n] and S[j]!=S[n]:
            ans-=1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
print(S.count("RGB"))

Submission status: Wrong Answer

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

R = [i+1 for i, x in enumerate(S) if x == 'R']
G = [i+1 for i, x in enumerate(S) if x == 'G']
B = [i+1 for i, x in enumerate(S) if x == 'B']

print(R)
print(G)
print(B)
ans = len(R) * len(G) * len(B)

count = 0

for r in R:
    for g in G:
        if (r+g)/2 in B:
            count += 1

for r in R:
    for b in B:
        if (r+b)/2 in G:
            count += 1

for g in G:
    for b in B:
        if (g+b)/2 in R:
            count += 1

print(ans - count)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(input())
b = collections.Counter(a)
ans =b['R']*b['G']*b['B']
print(b,ans)
for i in range(n-2):
    for j in range(i+1,n-1):
        if a[i] == a[j]:
            continue
        c = j*2 -i
        if c < n:
            if a[i] != a[j] and a[i] != a[c] and a[j] != a[c]:
                ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
#組み合わせ4000C3=10,658,668,000なので全探索は無理

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

r = s.count("R")
g = s.count("G")
b = s.count("B")

paircount_without_regulation = r*g*b

#j−i ≠ k−jの条件に引っかかるペア数を数える。
i = 0
j = 1
k = 2
between_counter = 1
regulation_counter = 0

while k <= n-1:
    while k <= n-1:
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            regulation_counter += 1
        i += 1
        j += 1
        k += 1

    i = 0
    j = 1
    k = 2
    between_counter += 1
    i += between_counter
    j += between_counter
    k += between_counter
    #print(between_counter)

result = paircount_without_regulation - regulation_counter

print(result)

Submission status: Wrong Answer

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

R = 0
G = 0
B = 0

for i in range(N):
    if S[i] == "R":
        R += 1
    if S[i] == "G":
        G += 1
    if S[i] == "B":
        B += 1
        

ans = R * G * B

for i in range(N - 2):
    for d in range(1, N // 2):
        j = i + d
        k = j + d
        try:
            if len(set([S[i],S[j],S[k]])) == 3:
                ans -= 1
        except:
            pass
            
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import functools

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

total = functools.reduce(lambda x, y : x * y , (collections.Counter(s).values()))

minus = 0
for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            if (s[i] != s[j] and s[j] != s[k] and s[i] != s[k]) and j - i == k - j:
                minus += 1
print(total - minus)

Submission status: Wrong Answer

Solution code:
import collections
import functools

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

total = functools.reduce(lambda x, y : x * y , (collections.Counter(s).values()))

minus = 0
for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            if (s[i] != s[j] and s[j] != s[k] and s[i] != s[k]) and j - i == k - j:
                print(i, j , k)
                minus += 1
print(total - minus)

Submission status: Wrong Answer

Solution code:
n=int(input())
S=input()
dictR=[]
dictG=[]
dictB=[]
for i in range(len(S)):
    if S[i]=="R":
        dictR.append(i)
    elif S[i]=="G":
        dictG.append(i)
    else:
        dictB.append(i)
sum=len(dictR)*len(dictG)*len(dictB)
for i in dictR:
    for j in dictG:
        for k in dictB:
            if j-i==k-j:
                sum-=1
print(sum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed May  6 02:13:01 2020

@author: shinba
"""

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)

ans = len(R)*len(G)*len(B)
print(R)
print(G)
print(B)

for i in R:
    for j in G:
        if 2*j - i in B:
            ans -= 1
        if (i+j)%2 == 0:
            if (i+j)//2 in B:
                ans -= 1
        if 2*i - j in B:
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
import bisect, collections, copy, itertools, math, string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int, input().split()))
def LS(): return list(input().split())

def solve():
	N = I()
	s = S()

	def listExcludedIndices(data, indices=[]):
  		return [x for i, x in enumerate(data) if i not in indices]

	data = ['R', 'G', 'B']
	junretu = []
	for i in range(len(data)):
		for j in range(len(data) - 1):
			for k in range(len(data) - 2):
				jData = listExcludedIndices(data, [i])
				kData = listExcludedIndices(jData, [j])
				junretu.append([data[i], jData[j], kData[k]])

	print(S)
	cnt = 0
	for _orderRGB in junretu:
		for i in range(0, N):
			if s[i]==_orderRGB[0]:
				for j in range(i+1, N):
					if s[j]==_orderRGB[1]:
						for k in range(j+1, N):
							if s[k]==_orderRGB[2]:
								if not j-i == k-j:
									cnt += 1
	print(cnt)

if __name__ == '__main__':
	solve()

Submission status: Wrong Answer

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

ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N):
    for j in range(i+1,N):
        k = j-i+j
        if k<N and S[k]!=S[j] and S[k]!=S[j] and S[i]!=S[j]:
            ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
A = S.count("R") * S.count("G") * S.count("B")

for i in range(N):
  for j in range(N):
    k = j-i+j
    if k<N and S[k] != S[j] and S[k] != S[i] and S[i] !=S[j]:
      A -= 1    

print(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
A = S.count("R") * S.count("G") * S.count("B")

for i in range(N-3):
  for j in range(i+1, N-1):
    k = j-i+j
    if k<N and S[k] != S[j] and S[k] != S[i] and S[i] !=S[j]:
      A -= 1

print(A)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
r,g,b = S.count('R'),S.count('G'),S.count('B')
total = r*g*b

count = 0
for d in range(1,N//2):
  for i in range(N-2*d):
    if S[i]!=S[i+d] and S[i+d]!=S[i+2*d] and S[i+2*d] != S[i]:
      count+=1

print(total-count)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
S = list(input())
num = [i for i in range(0,N)]
C = list(itertools.combinations(num,3))
ans = 0
for c in C:
    if c[1]-c[0] == c[2]-c[1]:
        continue
    if S[c[0]] != S[c[1]] and S[c[1]] != S[c[2]]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
S = list(input())
num = [i for i in range(0,N)]
C = list(itertools.combinations(num,3))
ans = 0
print(C)
for c in C:
    if c[1]-c[0] == c[2]-c[1]:
        continue
    if S[c[0]] != S[c[1]] and S[c[1]] != S[c[2]]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
num = r*g*b
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >=n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            n

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
import collections
c=collections.Counter(S)
u=1
for i in c.values():
  u=u*i  
for i in range(N-2):
  for j in range(i+1,N-1):
    if 2*j-i<=N-1:
      
      if set([S[i],S[j],S[2*j-i]])=={'B','R','G'} :
        u=u-1
print(u)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(str,input()))
ans = 0
b = 0
for i in range(N):
  for j in range(i,N):
    if S[i] != S[j]:
      b = j-i
      if j+b <= N:
        for k in range(3,2):
          if S[i] != S[k] and S[j] != S[k]:
            ans += 1
        for k in range(3,2):
          if S[i] != S[k] and S[j] != S[k]:
            ans += 1
      else:
        for k in range(j,N):
          if S[i] != S[k] and S[j] != S[k]:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(str,input()))
ans = 0
b = 0
for i in range(N):
  for j in range(i,N):
    b = j - i
    if S[i] != S[j]:
      if j + b >= N:
        for k in range(j,N):
          if S[i] != S[k] and S[j] != S[k]:
            ans += 1
      else:
        for k in range(j,j+b):
          if S[i] != S[k] and S[j] != S[k]:
            ans += 1
        for k in range(j+b,N):
          if S[i] != S[k] and S[j] != S[k]:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

R = []
G = []
B = []

ans = 0

for i in range(n):
    if s[i] == "R":
        R.append(i)
    elif s[i] == "G":
        G.append(i)
    else:
        B.append(i)

if len(R) > len(G):
    R, G = G, R
if len(G) > len(B):
    G, B = B, G


for r in R:
    for g in G:
        ans += len(B)
        if (g + r) / 2 in B:
            ans -= 1
        elif (2 * g - r) in B:
            ans -= 1
        elif (2 * r - g) in B:
            ans -= 1
print(ans)