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:
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 a in r:
  for k in g:
    for l in b:
      if a > k:
        break
      elif k > l:
        break
      if k - a == l - k :
        ans -= 1
      elif k - a < l - k:
        break        
  else:
    continue
  break
  
  
for a in b:
  for k in g:
    for l in r:
      if a > k:
        break
      elif k > l:
        break
      if k - a == l - k :
        ans -= 1
      elif k - a < l - k:
        break        
  else:
    continue
  break

for a in b:
  for k in r:
    for l in g:
      if a > k:
        break
      elif k > l:
        break
      if k - a == l - k :
        ans -= 1
      elif k - a < l - k:
        break        
  else:
    continue
  break
  
for a in g:
  for k in r:
    for l in b:
      if a > k:
        break
      elif k > l:
        break
      if k - a == l - k :
        ans -= 1
      elif k - a < l - k:
        break        
  else:
    continue
  break
  
for a in r:
  for k in b:
    for l in g:
      if a > k:
        break
      elif k > l:
        break
      if k - a == l - k :
        ans -= 1
      elif k - a < l - k:
        break        
  else:
    continue
  break
  
for a in g:
  for k in b:
    for l in r:
      if a > k:
        break
      elif k > l:
        break
      if k - a == l - k :
        ans -= 1
      elif k - a < l - k:
        break        
  else:
    continue
  break

print(ans)

Submission status: Wrong Answer

Solution code:
"""
39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

"""
#n = int(input())
#s = input()

n = 300
s = "RGB" * 100
out = 0

def rgb (tmpstr, j, i, s):
    if s[j] != s[i]:
        tmpstr = s[j + 1 :  n]
        remain = "RGB".replace(s[j],"").replace(s[i],"")
        num = tmpstr.count(remain) 
        if (j + (j - i)) < len(s):
            if  s[j + (j - i)]  == remain:
                num = num - 1
        return num
    else:
        return 0
    
    
out = sum([sum([rgb(s[j + 1 :  n], j, i, s) for j in range(i+1, n-1)]) for i in range(n-2)])
#for i in range(n-2):
#    out += sum([rgb(s[j + 1 :  n], j, i, s) for j in range(i+1, n-1)])
print(out)

Submission status: Wrong Answer

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

R = [i for i, x in enumerate(S) if x == 'R']
G = [j for j, y in enumerate(S) if y == 'G']
B = [k for k, z in enumerate(S) if z == 'B']
print(R, G, B)

cnt=0
for r in R:
    for g in G:
        for b in B:
            if abs(g-r) != abs(b-g) and \
                abs(b-r) != abs(g-b) and \
                abs(r-b) != abs(g-r):
                cnt+=1

print(cnt)

Submission status: Wrong Answer

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

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

# リストを作成
for i in range(0,N):
  if S[i]=="R":
    R += [i]
  elif S[i]=="G":
    G += [i]
  else:
    B += [i]

def search(ind, col):
  n=0
  useable_col = ["R","G","B"]
  useable_col.remove(col)
  for i,j in [[0,1],[1,0]]:
    l_col=useable_col[i]
    r_col=useable_col[j]
    if l_col=="R":
      l_col=R
    elif l_col=="G":
      l_col=G
    else:
      l_col=B
    if r_col=="R":
      r_col=R
    elif r_col=="G":
      r_col=G
    else:
      r_col=B
        
    l_useable = [ii for ii in l_col if ii<ind]
    r_useable = [ii for ii in r_col if ii>ind]

    if l_useable == [] or r_useable == []:
      return 0
      
    # print(l_useable)
    # print(r_useable)
    l = min(ind, N-1-ind)
    for m in range(1,l+1):
      if ind-m in l_useable and ind+m in r_useable:
        n -= 1
    n += len(l_useable) * len(r_useable)
  return n

n=0
for pivot in range(1,N-1):
  if S[pivot] =="R":
    n += search(pivot, "R")
  elif S[pivot] =="G":
    n += search(pivot, "G")
  else:
    n += search(pivot, "B")

print(n)

Submission status: Wrong Answer

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

Rlist = list()
Blist = list()
Glist = list()

for i in range(0, len(S)):
    if S[i] == "R":
        Rlist.append(i)
    elif S[i] == "G":
        Glist.append(i)
    else:
        Blist.append(i)

for i in range(len(Rlist)):
    for j in range(len(Blist)):
        for k in range(len(Glist)):
            if j - i != k - j:
                count += 1


print(count)

Submission status: Wrong Answer

Solution code:
k=int(input())
ans=0
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
sumlis={}
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            lis=sorted([a,b,c])
            if lis in sumlis.values(): 
                ans+=sumlis[lis]
            elif 1 in lis:
                ans+=1
            elif sum(lis)==a*3:
                ans+=a
            else:
                x=gcdlist(lis)
                sumlis[x]=sumlis
                ans+=x
                
print(ans)

Submission status: Wrong Answer

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

r = [i for i, c in enumerate(S) if c == 'R']
g = [i for i, c in enumerate(S) if c == 'G']
b = [i for i, c in enumerate(S) if c == 'B']

result = 0
if N <= 3:
    print(0)
else:
    for r_i in r:
        for g_i in g:
            for b_i in b:
                ci = sorted([r_i, g_i, b_i])
                if ci[1] - ci[0] != ci[2] - ci[1]:
                    result += 1

print(result)

Submission status: Wrong Answer

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

    d = 0
    for k,sk in enumerate(S[2:N]):
        for j in range(k):
            sj = S[j]
            if sk != sj:
                for i in range(j):
                    si = S[i]
                    if (si != sj) & (si != sk) & (j-i != k-j):
        
                        d += 1

    print(d)


main()

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
S = input()
r_list = [i for i, x in enumerate(S) if x == 'R']
g_list = [i for i, x in enumerate(S) if x == 'G']
b_list = [i for i, x in enumerate(S) if x == 'B']


rg_list = itertools.product(r_list, g_list)
rb_list = itertools.product(r_list, b_list)
gb_list = itertools.product(g_list, b_list)
gr_list = itertools.product(g_list, r_list)
br_list = itertools.product(b_list, r_list)
bg_list = itertools.product(b_list, g_list)

count = 0
# RGB
for r, g1 in rg_list:
    if r > g1:
        continue
    for g2, b in gb_list:
        if g2 > b:
            continue
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# RBG
for r, g1 in rb_list:
    if r > g1:
        continue
    for g2, b in bg_list:
        if g2 > b:
            continue
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# BGR
for r, g1 in bg_list:
    if r > g1:
        continue
    for g2, b in gr_list:
        if g2 > b:
            continue
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# BRG
for r, g1 in br_list:
    if r > g1:
        continue
    for g2, b in rg_list:
        if g2 > b:
            continue
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# GBR
for r, g1 in gb_list:
    if r > g1:
        continue
    for g2, b in br_list:
        if g2 > b:
            continue
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# GRB
for r, g1 in gr_list:
    if r > g1:
        continue
    for g2, b in rb_list:
        if g2 > b:
            continue
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import itertools as it

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

s = [int(i) for i in s.replace('R', '0').replace('G', '1').replace('B', '2')]
r_indeces = [i for i in range(n) if s[i] == 0]
g_indeces = [i for i in range(n) if s[i] == 1]
b_indeces = [i for i in range(n) if s[i] == 2]

indeces = [i for i in it.product(r_indeces, g_indeces, b_indeces)
           if (max(i) + min(i)) / 2 in i]
print(len(indeces))

Submission status: Wrong Answer

Solution code:
import re
N=int(input())
S=input()
all=S.count('R')*S.count('G')*S.count('B')
a=0
for i in range(int(N//2)):
  string='R'+'.'*i+'G'+'.'*i+'B'
  a += len(re.findall(string,S))
  
  string='R'+'.'*i+'B'+'.'*i+'G'
  a += len(re.findall(string,S))
  
  string='B'+'.'*i+'G'+'.'*i+'R'
  a += len(re.findall(string,S))
  
  string='B'+'.'*i+'R'+'.'*i+'G'
  a += len(re.findall(string,S))
  
  string='G'+'.'*i+'R'+'.'*i+'B'
  a += len(re.findall(string,S))
  
  string='G'+'.'*i+'B'+'.'*i+'R'
  a += len(re.findall(string,S))
  
print(all-a)

Submission status: Wrong Answer

Solution code:
import numpy
import sys
import statistics

num=int(input())
txt=input()
count=0
ri=[]
gi=[]
bi=[]
for i in range(len(txt)):
  if txt[i]=='R':
    ri.append(i)
  elif txt[i]=='G':
    gi.append(i)
  else:
    bi.append(i)
for i in ri:
  for j in gi:
    add=len(bi)
    if j>i:
      diff=j-i
      if j+diff in bi:
        add-=1
      if i-diff in bi:
        add-=1
    else:
      diff=i-j
      if i+diff in bi:
        add-=1
      if i-diff in bi:
        add-=1
    if (j+i)%2==0 and (j+i)//2 in bi:
      add-=1
    count+=add
print(count)

Submission status: Wrong Answer

Solution code:
from itertools import product as pro

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

r = [i for i in range(n) if s[i] == 'R']
g = [i for i in range(n) if s[i] == 'G']
b = [i for i in range(n) if s[i] == 'B']
cnt = len(r) * len(g) * len(b)

length = max(len(r), len(g), len(b))
for i, j, k in [(r, g, b), (g, b, r), (b, r, g)]:
    if length == len(i):
        max1 = set(i)
        min1, min2 = j, k

for i, j in pro(min1, min2):
    if ((2*j-i) or (2*i-j) or ((i+j)/2)) in max1:
        cnt -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
R = S.count("R")
G = S.count("G")
B = S.count("B")
# print(R,G,B)
RGB = [R,G,B]
RGB.sort()
ans = min(RGB) * (max(RGB)+1) * (RGB[1]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
n = int(input())
s = input()
count = 0
list1 = []
list = []
list2= []
for i in range(1, len(s)+1):
    list.append(i)
for c in combinations(list, 3):
    list1.append(c)
print(list1)
for item in list1:

    if (item[1]-item[0]) != (item[2]-item[1]):
        list2.append(item)
for k in list2:
    if s[k[0]-1]!=s[k[1]-1] and s[k[0]-1]!=s[k[2]-1] and s[k[1]-1]!=s[k[2]-1]:
        count= 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 = 0
ans = r*g*b
for i in range(1,n-1):
    m = min(i,n-i-1)
    for j in range(1,m+1):
        A,B,C = s[i],s[i-j],s[i+j]
        if A != B and A != C and B != C:
            ans -= 1
if r == 0 or g == 0 or b == 0:
    ans = 0
elif r == 1 or g == 1 or b == 1:
    ans = 1
print(ans)

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
bb=b.count(1)
ans=0
for i in range(n):
    if r[i]==1:
        for j in range(n):
            if g[j]==1:
                ans+=bb
                if 2*i-j<n and 2*i-j>=0:
                    ans-=b[2*i-j]
                if 2*j-i<n and 2*j-i>=0:
                    ans-=b[2*j-i]
                
print(ans)

Submission status: Wrong Answer

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

counta = 0
i = 0

while i < N:
    if S[i] == 'R':
        r = i
        j = i + 1
        while j < N:
            if S[j] == 'G':
                g = j
                k = j + 1
                while k < N:
                    if S[k] == 'B':
                        b = k
                        if b - g != g - r:
                            counta += 1
                            print(r, g, b)
                    k += 1
            j += 1
    # if i < j and j < k:
    i += 1
    # else:
    #     break

print(counta)

Submission status: Wrong Answer

Solution code:
import bisect


def main():
    N = int(input())
    S = input()
    dict = {"R": [], "G": [], "B": []}
    ans = 0
    for i in range(N):
        dict[S[i]].append(i)
    l = {"R": len(dict["R"]), "G": len(dict["G"]), "B": len(dict["B"])}
    name = [["R", "G", "B"], ["R", "B", "G"], ["G", "R", "B"], ["G", "B", "R"], ["B", "R", "G"], ["B", "G", "R"]]
    for n in name:
        a, b, c = n
        for i in dict[a]:
            p = bisect.bisect_left(dict[b], i + 1)
            if p >= l[b]:
                continue
            for j in dict[b][p:]:
                q = bisect.bisect_left(dict[c], j + 1)
                if bisect.bisect_left(dict[c], 2 * j - i) + 2 == bisect.bisect_right(dict[c], 2 * j - i):
                    ans -= 1
                ans += (l[c] - q)

    print(ans - 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy
import sys
import statistics

num=int(input())
txt=input()
count=0
ri=[]
gi=[]
bi=[]
for i in range(len(txt)):
  if txt[i]=='R':
    ri.append(i)
  elif txt[i]=='G':
    gi.append(i)
  else:
    bi.append(i)
for i in ri:
  for j in gi:
    add=len(bi)
    if j>i:
      diff=j-i
      if j+diff in bi:
        add-=1
      if i-diff in bi:
        add-=1
    else:
      diff=i-j
      if i+diff in bi:
        add-=1
      if i-diff in bi:
        add-=1
    if (j+i)/2. in bi:
      add-=1
    count+=add
print(count)

Submission status: Wrong Answer

Solution code:
import itertools

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

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

RGBs = list(itertools.permutations(['R', 'G', 'B'], 3))
for i, s in enumerate(S):
  if s == 'R': R.append(i)
  if s == 'G': G.append(i)
  if s == 'B': B.append(i)
out = len(R) * len(G) * len(B)
for i in range(1, N//3+6):
  for j in range(N-i*2):
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      out -= 1
print(out)

Submission status: Wrong Answer

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

A  = []
for i in range(n):
    if S[i] == "R":
        A.append(1)
    if S[i] == "G":
        A.append(2)
    if S[i] == "B":
        A.append(3)

cnt = 0
for i in range(0, n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if A[i]+A[j]+A[k]== 6:
                if (j - i) != (k - j):
                    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = input()
    # Positions for each character.
    r = []
    g = []
    b = []
    for ind, c in enumerate(s):
        if c == 'R':
            r.append(ind)
        elif c == 'G':
            g.append(ind)
        else:
            b.append(ind)
    ans = 0
    print(r, g, b)

    for i in r:
        for j in g:
            for k in b:
                o, p, q = sorted((i, j, k))
                if p - o != q - p:
                    ans += 1
    return ans


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
s = '_' + input().strip()
s += ''.join(['_'] * 10 ** 5)
r = []
g = []
b = []
for i in range(1, n + 1):
    if s[i] == 'R':
        r.append(i)
    elif s[i] == 'G':
        g.append(i)
    elif s[i] == 'B':
        b.append(i)

le = len(b)
ans = len(r) * len(g) * le
for x in r:
    for y in g:
        if (x + y) % 2 == 0 and s[(x + y) // 2] == 'B':
            ans -= 1
        if (1 <= (2 * x - y) and s[2 * x - y] == 'B') or (1 <= (2 * y - x) and s[2 * y - x] == 'B'):
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
R_list = [0]*(N+1)
R_list_ = []
R_cnt = 0
G_list = [0]*(N+1)
G_list_ = []
G_cnt = 0
B_list = [0]*10000
B_list_ = []
B_cnt = 0
ans = 0
for i, j in enumerate(S):
    i += 1
    if j == "R":
        R_list[i] = 1
        R_list_.append(i)
        R_cnt += 1
    elif j == "G":
        G_list[i] = 1
        G_list_.append(i)
        G_cnt += 1
    else:
        B_list[i] = 1
        B_list_.append(i)
        B_cnt += 1
for i in R_list_:
    for j in G_list_:
        if B_list[2*j-i] != 1:
            ans += B_cnt
        else:
            ans += (B_cnt - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for z in range(j+1, n):
            if s[i] != s[j] != s[z]:
                if (z-j)!=(j-i):
                    cnt = cnt+1
                else:
                    pass
            else:
                pass
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
S = input()
r_list = [i for i, x in enumerate(S) if x == 'R']
g_list = [i for i, x in enumerate(S) if x == 'G']
b_list = [i for i, x in enumerate(S) if x == 'B']


rg_list = itertools.product(r_list, g_list)
rb_list = itertools.product(r_list, b_list)
gb_list = itertools.product(g_list, b_list)
gr_list = itertools.product(g_list, r_list)
br_list = itertools.product(b_list, r_list)
bg_list = itertools.product(b_list, g_list)

count = 0
# RGB
for r, g1 in rg_list:
    for g2, b in gb_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# RBG
for r, g1 in rb_list:
    for g2, b in bg_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# BGR
for r, g1 in bg_list:
    for g2, b in gr_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# BRG
for r, g1 in br_list:
    for g2, b in rg_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# GBR
for r, g1 in gb_list:
    for g2, b in br_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# GRB
for r, g1 in gr_list:
    for g2, b in rb_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
def resolve():
        n = int(input())
        s = 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 = 0
        a = [r, g, b]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])
        a = [r, b, g]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])
        a = [g, r, b]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])
        a = [g, b, r]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])

        a = [b, r, g]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])

        a = [b, g, r]
        for i in range(n):
            if a[0][i] == 1:
                for j in range(i + 1, n):
                    if a[1][j] == 1:
                        ans += sum(a[2][j + 1:n])

        for i in range(1, n // 2):
            j = 0
            while j + 2 * i <= n - 1:
                if {s[j], s[j + i], s[j + 2 * i]} == {"R", "G", "B"}:
                    ans -= 1
                j += 1
        print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
from itertools import product as pro

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

r = [i for i in range(n) if s[i] == 'R']
g = [i for i in range(n) if s[i] == 'G']
b = [i for i in range(n) if s[i] == 'B']
cnt = len(r) * len(g) * len(b)

length = max(len(r), len(g), len(b))
for i, j, k in [(r, g, b), (g, b, r), (b, r, g)]:
    if length == len(i):
        max1 = set(i)
        min1, min2 = j, k

for i, j in pro(min1, min2):
    if (2*j-i) or (2*i-j) or ((i+j)/2) in max1:
        cnt -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
dict = {}
tmp = input()
for i in range(n):
    dict[i] = tmp[i]
tmli = []
for i in range(n):
    tmli.append(tmp[i])
tmli.sort()
tmp = ""
for i in range(n):
    tmp += tmli[i]
dict2 = sorted(dict.items(), key=lambda x: x[1])
r = len(tmp) - tmp.find("R")
g = tmp.find("R") - tmp.find("G")
b = tmp.find("G")
ans = r * g * b

def sol(i, j, k):
    if j - i != k - j:
        return False
    return True


cnt = 0
for i in range(b):
    for j in range(g):
        for k in range(r):
            x = dict2[i][0] + 1
            y = dict2[b + j][0] + 1
            z = dict2[b + g + k][0] + 1
            if sol(x, z, y):
                cnt += 1
            if sol(x, y, z):
                cnt += 1
            if sol(y, x, z):
                cnt += 1
print(ans - cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# A,B = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
# A, B = [str(x) for x in stdin.readline().rstrip().split()]
N = int(input())
S = list(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)
print(r)
print(g)
print(b)
cnt = 0
for i in range(len(r)):
    for j in range(len(g)):
        for k in range(len(b)):
            temp = [r[i], g[j], b[k]]
            temp.sort()

            if temp[1]-temp[0] != temp[2]-temp[1]:
                cnt += 1
                if temp[2] == b[k] and temp[1]-temp[0] < temp[2]-temp[1]:
                    cnt = cnt+len(b)-1-k
                    break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

S = input()

r = S.count("R")
g = S.count("G")
b = N-r-g

result = r*g*b

if N!=3:
    for interval in range(1,N//2):
        for i in range(1,N-interval*2+1):
            Si = S[i-1]
            Sj = S[i+interval-1]
            if Si != Sj:
                Sk = S[i+interval*2-1]
                if Sk != Si and Sk != Sj:
                    result -= 1
else:
    result=0

print(result)

Submission status: Wrong Answer

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

for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if (j-i)==(k-j):
                break
            else:
                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:
import itertools

N = int(input())
S = input()
r_list = [i for i, x in enumerate(S) if x == 'R']
g_list = [i for i, x in enumerate(S) if x == 'G']
b_list = [i for i, x in enumerate(S) if x == 'B']


rg_list = itertools.product(r_list, g_list)
rb_list = itertools.product(r_list, b_list)
gb_list = itertools.product(g_list, b_list)
gr_list = itertools.product(g_list, r_list)
br_list = itertools.product(b_list, r_list)
bg_list = itertools.product(b_list, g_list)

count = 0
# RGB
for r, g1 in rg_list:
    for g2, b in gb_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# RBG
for r, g1 in rg_list:
    for g2, b in bg_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# BGR
for r, g1 in bg_list:
    for g2, b in gr_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# BRG
for r, g1 in br_list:
    for g2, b in rg_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# GBR
for r, g1 in gb_list:
    for g2, b in br_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1
# GRB
for r, g1 in gr_list:
    for g2, b in rb_list:
        if g1 != g2:
            continue
        if (g1-r) != (b-g2):
                count += 1

print(count)

Submission status: Wrong Answer

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

R, G, B = [], [], []
for i, c in enumerate(s):
  if c == 'R': R.append(i)
  elif c == 'G': G.append(i)
  else: B.append(i)

ans = len(R) * len(G) * len(B) - (min(len(R), len(G), len(B)) ** 2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import re
n = int(sys.stdin.readline())
s = sys.stdin.readline()
res = len(re.findall("R.*G.*B", s))
i = 0
while i <= n//2:
  res -= len(re.findall("R.{i}G.{i}B", s))
  i += 1
print(res)

Submission status: Wrong Answer

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

ans = 0

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


print(ans)

Submission status: Wrong Answer

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

for i in range(N-2):
  for j in range(N-1):
    for k in range(N):
      if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i] and not j-i == k-j:
        count = count + 1
      else:
        pass

print(count)

Submission status: Wrong Answer

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

for i in range(N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        else:
            RGB = 'RGB'
            RGB = RGB.strip(S[i])
            RGB = RGB.strip(S[j])
            x = 2*j - i
            if x > N-1:
                ans += S[j+1:].count(RGB)
            elif x == N-1:
                ans += S[j+1:x].count(RGB)
            else:
                ans += S[j+1:x].count(RGB)
                ans += S[x+1:].count(RGB)
print(ans)

Submission status: Wrong Answer

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

index = dict()
for color in ['R', 'G', 'B']:
    index[color] = [i for i, v in enumerate(s) if v == color]

result = 0
for i in index['R']:
    for j in index['G']:
        for k in index['B']:
            if j - i != k - j:
                result += 1

print(result)

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)
    elif s[i]=="B":
        b.append(i)
    else:
        pass
# print(r,g,b)
count = 0
for i in range(n):
    x = s[i]
    for sa in range(n-2):
        j = i + sa
        k = j + sa
        if j<n:
            y = s[j]
        else:
            break
        if k<n:
            z = s[k]
        else:
            break
        if x!=y and y!=z and z!=x:
            count += 1
# print(count)
ans = len(r) * len(g) * len(b) - count
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import re
n = int(sys.stdin.readline())
s = sys.stdin.readline()
res = len(re.findall("R.*G.*B", s))
i = 0
while i < n//2:
  res -= len(re.findall("R.{i}G.{i}B", s))
  i += 1
print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np
 
def solve(N: int, S: str):
    r = []
    g = []
    b = []
 
    for i, x in enumerate(S):
        if x ==  "R":r.append(i)
        elif x =="G":g.append(i)
        elif x =="B":b.append(i)
 
    r = np.array(r)
    g = np.array(g)
    b = np.array(b)
 
 
    def rgb(r, g, b):
        sb = set(b)
        ans = 0
        for r_ in r:
            # rg
            for g_ in g[g>r_]:
                # rgb
                if (g_ + (g_ - r_)) in sb:
                    ans -= 1
                ans += len(b[b>g_])
                # brg
                if (r_ - (g_ - r_)) in sb:
                    ans -= 1
                ans += len(b[b<r_])

                # rbg
                if ((r_ + g_)/2) in sb:
                    ans -= 1
                ans += len(b[(r_<b)&(b<g_)])

            # gr
            for g_ in g[g<r_]:
                # grb
                if (r_ + (r_ - g_)) in sb:
                    ans -= 1
                ans += len(b[b>r_])
                # bgr
                if (g_ - (r_ - g_)) in sb:
                    ans -= 1
                ans += len(b[b<g_])
                # gbr
                if ((r_ + g_)/2) in sb:
                    ans -= 1
                ans += len(b[(g_<b)&(b<r_)])

        print(ans)
        return ans
 
    k = rgb(r,g,b)
    print(k)
 
 
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [0 if i=="R" else 1 if i=="G" else 2 for i in input()]
s.sort()

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

      
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=0
if n<=2:
    print(0)
    quit()
import itertools           
for i,j,k in itertools.combinations_with_replacement(range(0,n), 3):
    if j-i!=k-j and s[i]!=s[j]!=s[k]:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
s = input()
r_cnt = 0
g_cnt = 0
b_cnt = 0
for i in s:
    if i == 'R':
        r_cnt += 1
    elif i == 'G':
        g_cnt += 1
    elif i == 'B':
        b_cnt += 1
        
total = r_cnt*g_cnt*b_cnt

if n < 4:
    print(total)

elif n == 4:
    for j in range(2):
        tmp = s[j]+s[j+1]+s[j+2]
        if (tmp == 'RGB') or (tmp == 'RBG') or (tmp == 'GBR') or (tmp == 'GRB') or (tmp == 'BRG') or (tmp == 'BGR'):
            total -= 1
            
    print(total)
else:
    for i in range(1,math.floor((len(s)-2)/2)+10):
        for j in range(n-2*i):
            tmp = s[j]+s[j+i]+s[j+2*i]
            if (tmp == 'RGB') or (tmp == 'RBG') or (tmp == 'GBR') or (tmp == 'GRB') or (tmp == 'BRG') or (tmp == 'BGR'):
                total -= 1
    print(total)