ZhenlongDai/ACPR huggingface dataset:
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1
print(r,g,b)

ans=r*g*b

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


Failing test case input:
39
RRRBGRBGGBBRBGGBRGBBGBBRBRBRBGBBBBBGBRR

Expected output:
1803


Actual output:
11 9 19
1803


Fixed submission (verdict: Accepted):
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1

ans=r*g*b
for i in range(n):
  for j in range(i+1,n):
    k_ = j+(j-i)
    if(k_ >=n):
      break
    ans -= int(s[i]!= s[j] and s[i] != s[k_] and s[j] != s[k_])

print(ans)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
s = input()

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

ret = r*g*b

for i in range(1,int(n/2)):
	for j in range(0,n-2*i):
		if(s[j] != s[j+i]) and (s[j+i] != s[j+2*i]) and (s[j+2*i] != s[j]):
			ret -= 1




print(ret)

Failing test case input:
39
GBBGBBBBBGBRBGBRBGRBBRRBBGRRBBGGBRGBRRR

Expected output:
1809


Actual output:
1810


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

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

ret = r*g*b

for i in range(1,int((n+1)/2)):
	for j in range(0,n-2*i):
		if(s[j] != s[j+i]) and (s[j+i] != s[j+2*i]) and (s[j+2*i] != s[j]):
			ret -= 1




print(ret)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
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)


Failing test case input:
39
RRRRGRBGGBBRRGBBRBBBGGBBRGBRBGBRBBBGBBB

Expected output:
1814


Actual output:
Counter({'B': 19, 'R': 11, 'G': 9}) 1881
1814


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

from collections import Counter

a = [None] * n
for i in range(n):
    if s[i] == "R":
        a[i] = 0
    if s[i] == "G":
        a[i] = 1
    if s[i] == "B":
        a[i] = 2

c = [0] * 3
for v in a:
    c[v] += 1

ans = 1
for v in c:
    ans *= v

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)
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] == str[j] or str[i] == str[k] or str[j] == str[k] :
        sum -= 1
    
print(sum)

Failing test case input:
39
RBRBGRBRGBBRBGBBRRRBGGBRBGBRBGBRBBBGGBB

Expected output:
1799


Actual output:
1602


Fixed submission (verdict: Accepted):
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
S = list(input())

res = 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:
                continue
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                res += 1


Failing test case input:
39
RBBGBBBBBGBRBRBRBBGBBGRBGGRRBBGGBRGBRRR

Expected output:
1808


Actual output:

Fixed submission (verdict: Accepted):
N = int(input())
S = list(input())

r = len([s for s in S if s == "R"])
g = len([s for s in S if s == "G"])
b = len([s for s in S if s == "B"])

res = r * g * b

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            res -= 1

print(res)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()
ans = s.count('B') + s.count('G') + s.count('R')
for i in range(n):
  for j in range(i, n-1):
    k = 2*j - i
    if k >= n:
      continue
    if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
      ans -= 1

print(ans)

Failing test case input:
39
RRBBGRRGGBBRRGBBRGBBGGBRBRBRBGBBBBBGBBR

Expected output:
1803


Actual output:
-39


Fixed submission (verdict: Accepted):
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, n-1):
    k = 2*j - i
    if k >= n:
      continue
    if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
      ans -= 1

print(ans)
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

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)
    
count = 0

for r in R:
  for g in G:
    for b in B:
      S = sorted([r,g,b])
      if S[0]+S[2]!=2*S[1]:
        count += 1

Failing test case input:
39
RRRRGRBGGBBRRGBBRGBBGGRBBRBBBGBBBBBGBBR

Expected output:
1810


Actual output:

Fixed submission (verdict: Accepted):

N = int(input())
S = 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
    
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    if 2*j-i>=N:
      break
    if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
      count += 1

print(R*G*B-count)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
S = list(input())

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

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

Failing test case input:
39
RRRBGRBGGBBRRGBBRRBBRGBRBGBRBGBBBBBGBBG

Expected output:
1809


Actual output:
1810


Fixed submission (verdict: Accepted):
N = int(input())
S = input()

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

for i in range(N-2):
    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]:
            ans -= 1
print(ans)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = list(input())

arr = []
R = len(list(filter(lambda x:x == 'R', s)))
G = len(list(filter(lambda x:x == 'G', s)))
B = len(list(filter(lambda x:x == 'B', s)))
tot = R*G*B
print(tot)

for i in range(n):
  for j in range(i+1, n):
    k = 2*j-i
    if k < n:
      if (s[i] != s[j]) & (s[i] != s[k]) & (s[j] != s[k]):
        tot -= 1

print(tot)

Failing test case input:
39
RBBGBBBBBGBRBRBRBGGBBGRBBGRRBBGGRRGBBRR

Expected output:
1803


Actual output:
1881
1803


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

arr = []
R = len(list(filter(lambda x:x == 'R', s)))
G = len(list(filter(lambda x:x == 'G', s)))
B = len(list(filter(lambda x:x == 'B', s)))
tot = R*G*B

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

print(tot)
Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
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)


Failing test case input:
4
GRRB

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ret = 0
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:
            ret += 1
ans = r*g*b - ret
print(ans)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N - 2):
        for j in range(i, N - 1):
            for k in range(j, N):
                if j - i != k - j:
                    if S[j] != S[i] and S[i] != S[k]:
                        ans += 1                                        
    print(ans)

if __name__ == "__main__":
    main()

Failing test case input:
39
RBRBRRBGGBBRRGGBRGBRGBBRGRBBBGBBBBBGBBR

Expected output:
1805


Actual output:
4436


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k >= N:
                continue
            if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)

if __name__ == "__main__":
    main()

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
39
RRGRRRBGGBBRRBBBRRBBRGBBBBBRBGBGGBBGBBG

Expected output:
1827


Actual output:
1828


Fixed submission (verdict: Accepted):
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,n):
        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)
Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from sys import stdin
import sys





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)



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]*2 != temp[0]+temp[1]:
                cnt+=1
print(cnt)


Failing test case input:
39
RRRBGRBGGBBRRGBBRBRBGGBRBGBRBGBBBBBGBBR

Expected output:
1813


Actual output:
1881


Fixed submission (verdict: Accepted):
from sys import stdin
import sys





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)



cnt = len(r)*len(g)*len(b)
for i in range(N):
    for j in range(i+1, N):
        k = 2*j-i
        if k < N and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            cnt -= 1
print(cnt)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools
N = int(input())
S = input()

out = S.count('R') * S.count('G') * S.count('B')
print(out)

RGBs = list(itertools.permutations(['R', 'G', 'B'], 3))

for i in range(1, N):
  for j in range(N-i*2):
    
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      out -= 1
print(out)

Failing test case input:
39
RRRBGRBGGBBRBGGBRGBBGBBRBRBRBGBBBBBGBRR

Expected output:
1803


Actual output:
1881
1803


Fixed submission (verdict: Accepted):
import itertools
N = int(input())
S = input()

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

RGBs = list(itertools.permutations(['R', 'G', 'B'], 3))

for i in range(1, N):
  for j in range(N-i*2):
    
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      out -= 1
print(out)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
    N = int(input())
    S = list(str(input()))
    sum = 0
    for i in range(0, N-2):
        si = S[i]
        for j in range(i+1, N-1):
            sj = S[j]
            k = 2*j -i  
            if k < N:
                sk = S[k]
                
                if si != sj and si != sk and sj != sk:
                    sum += 1
    print(sum)


main()

Failing test case input:
39
RRRBGRBGGBRRRGBRBBBBGGBRBGBRBGBBBBBGBBR

Expected output:
1817


Actual output:
64


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    S = list(str(input()))
    sum = S.count("R") * S.count("G") * S.count("B")
    for i in range(0, N-2):
        si = S[i]
        for j in range(i+1, N-1):
            sj = S[j]
            k = 2*j -i  
            if k < N:
                sk = S[k]
                
                if si != sj and si != sk and sj != sk:
                    sum -= 1
    print(sum)

    


main()
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()

count = 0

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

print(count)


Failing test case input:
39
RBBGBBBBBGBRBBBRBGGBRGRBBGRRBBGGBRGBRRR

Expected output:
1809


Actual output:
1642


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

nr = s.count("R")
ng = s.count("G")
nb = s.count("B")

count = nr * ng * nb

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

print(count)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()

r_num = s.count("R")
g_num = s.count("G")
b_num = s.count("B")

ans = r_num * b_num * g_num

for i in range(n):
    for j in range(i+1, n):
        k = 2 * j - i
        if k >= n:
            break

        if (s[i] == s[j] or 
            s[j] == s[k] or
            s[i] == s[k]):
            ans += -1
 
print(ans)

Failing test case input:
4
GRRB

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

r_num = s.count("R")
g_num = s.count("G")
b_num = s.count("B")

ans = r_num * b_num * g_num

for i in range(n):
    for j in range(i+1, n):
        k = 2 * j - i
        if k >= n:
            break

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

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
if ans==0:
    print(ans)
else:
    for i in range(n):
        for j in range(i+1, n):
            k=2*j-i
            if k<n and s[i]!=s[j] and s[j]!=s[k]:
                ans -= 1
    print(ans)

Failing test case input:
39
GBRBRRBGGBBRRRBBGRRBGGBRBGBRBGBRBBBGBBB

Expected output:
1791


Actual output:
1713


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
if ans==0:
    print(ans)
else:
    for i in range(n):
        for j in range(i+1, n):
            k=2*j-i
            if k<n:
                if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
                    ans -= 1
    print(ans)
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
39
RBBGBBBBBGBRBRBRBGGBBGRBBGRRBBGGRRGBBRR

Expected output:
1803


Actual output:
1785


Fixed submission (verdict: Accepted):
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
        k = int(2 * i - j)
        if(0 <= 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)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
    N = int(input())
    S = list(str(input()))
    print()
    sum = 0
    for i in range(0, N-2):
        si = S[i]
        for j in range(i, N-1):
            sj = S[j]
            for k in range(j, N):
                sk = S[k]
                
                if si != sj and sj != sk and sj != sk:
                    if j - i != k -j:
                        sum += 1
    print(sum)



main()

Failing test case input:
39
RBBGBBBBBGBBBBBBBGGBBGRBBGRRRBGGRRGRRRR

Expected output:
1829


Actual output:

2909


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    S = list(str(input()))
    sum = S.count("R") * S.count("G") * S.count("B")
    for i in range(0, N-2):
        si = S[i]
        for j in range(i+1, N-1):
            sj = S[j]
            k = 2*j -i  
            if k < N:
                sk = S[k]
                
                if si != sj and si != sk and sj != sk:
                    sum -= 1
    print(sum)

    


main()
Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
S = input()

R = []
G = []
B = []
ans = 0
for i in range(len(S)):    
    if S[i] == "R":
        R.append(i)
    if S[i] == "G":
        G.append(i)
    if S[i] == "B":
        B.append(i)











rem = 0 
for r in R:
    for g in G:
        
        
        
        if g - abs(r - g) in B or r - abs(g - r) in B or  g + abs( r- g) in B or r +abs( g- r) in B:
            rem += 1
        if (r >= g):
            if (g + r) / 2 in B :
                rem += 1
        if (g >= r):
            if (g + r) / 2 in B :
                rem += 1
            
print(len(R)*len(G)*len(B) - rem )
    

Failing test case input:
39
RRBBGRBGGBBRRGBBRGRBGGBRBBRBBGBRBBBGBBR

Expected output:
1811


Actual output:
1822


Fixed submission (verdict: Accepted):
N = int(input())
S = input()

R = []
G = []
B = []
ans = 0
for i in range(len(S)):
    if S[i] == "R":
        R.append(i)
    if S[i] == "G":
        G.append(i)
    if S[i] == "B":
        B.append(i)
rem = 0
setB = set(B)

for r in R:
    for g in G:
        if g - abs(r - g) in setB:
            rem += 1
        if r - abs(g - r) in setB:
            rem += 1
        if (g + r) / 2 in setB:
            rem += 1
        if g + abs(r - g) in setB:
            rem += 1
        if r + abs(g - r) in setB:
            rem += 1


print(len(R)*len(G)*len(B) - rem)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools

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

r = len(list(filter(lambda x: x == "R", S)))
g = len(list(filter(lambda x: x == "G", S)))
b = len(list(filter(lambda x: x == "B", S)))



ans = r * g * b
RGB = itertools.permutations(["R", "G", "B"], 3)
for i in range(1, N):
    for j in range(1, N-i*2):
        if (S[j], S[j+i], S[j+2*i]) in RGB:
            ans -= 1

print(ans)


Failing test case input:
39
RRRGGRBGGBRRRRBBRGBBGGBBBBBBBGBBBBRGBBR

Expected output:
1824


Actual output:
1881


Fixed submission (verdict: Accepted):
import itertools

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

r = len(list(filter(lambda x: x == "R", S)))
g = len(list(filter(lambda x: x == "G", S)))
b = len(list(filter(lambda x: x == "B", S)))



ans = r * g * b
RGB = list(itertools.permutations(["R", "G", "B"], 3))



for i in range(1, N):
    for j in range(N-i*2):
        if (S[j], S[j+i], S[j+2*i]) in RGB:
            ans -= 1

print(ans)
Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
X = input()
ans = 0
r=0
g=0
b=0
G = []
R = []
B = []
for i in range(0,N):
    if(X[i] == 'G'):
        G.append(i)
        g+=1
for k in range(0,N):
    if(X[k] == 'R'):
        R.append(k)
        r+=1
for j in range(0,N):
    if(X[j] == 'B'):
        B.append(j)
        b+=1
ans = r*b*g
for i in range(0,N-2):
    for j in range(i+1,N-2):
        if(2*j-i < N) and X[i] != X[j]:
            if(X[2*j-i] != X[i]) and (X[2*j-i] != X[j]):
                ans -= 1
print(ans)

Failing test case input:
4
RBRG

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
X = input()
ans = 0
r=0
g=0
b=0
G = []
R = []
B = []
for i in range(0,N):
    if(X[i] == 'G'):
        G.append(i)
        g+=1
for k in range(0,N):
    if(X[k] == 'R'):
        R.append(k)
        r+=1
for j in range(0,N):
    if(X[j] == 'B'):
        B.append(j)
        b+=1
ans = r*b*g
for i in range(0,N):
    for j in range(i+1,N):
        if(2*j-i < N) and X[i] != X[j]:
            if(X[2*j-i] != X[i]) and (X[2*j-i] != X[j]):
                ans -= 1
print(ans)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
S =input()

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

print(count)


Failing test case input:
39
RGBGBBBBBRBBBRBRBGGBBGRBBGRRBBGGRRGBBRR

Expected output:
1810


Actual output:
3651


Fixed submission (verdict: Accepted):
N = int(input())
S =input()
r = S.count('R')
b = S.count('B')
g = S.count('G')
x = r*b*g

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

print(x-count)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
s = str(input())
ans = s.count("R")*s.count("G")*s.count("B")

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

print(ans)

Failing test case input:
39
RBBGBBBBBGBRBRBRBGGBBGRBBGRRBBGGBRGBRRR

Expected output:
1806


Actual output:
1731


Fixed submission (verdict: Accepted):
n = int(input())
s = str(input())
ans = s.count("R")*s.count("G")*s.count("B")

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

print(ans)
Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
s = str(input())
r, g, b = map(s.count, "RGB")
ans = r*g*b
for i in range(n-2):
    for j in range(i, n-1):
        k = 2*j - i
        if k < n and s[i] != s[j] != s[k]:
            ans -= 1
print(ans)

Failing test case input:
39
RRRRGRBGGBBRRGBBRBBBGGBBRGBRBGBRBBBGBBB

Expected output:
1814


Actual output:
1738


Fixed submission (verdict: Accepted):
n = int(input())
s = str(input())
r, g, b = map(s.count, "RGB")
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k<n and len(set([s[i], s[j], s[k]])) == 3:
            ans -= 1
print(ans)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from copy import deepcopy

def main():
    n = int(input())
    s = list(input())
    sr = [0] * n
    sg = [0] * n
    sb = [0] * n
    for i1 in range(n):
        ts = s[i1]
        if ts == 'R':
            sr[i1] = 1
        elif ts == 'G':
            sg[i1] = 1
        else:
            sb[i1] = 1
    if n <= 3:
        print(0)
        exit()
    r = 0
    for ia in range(0,n-3):
        ta = s[ia]
        if ta == 'R':
            r += sum(sg[ia+1:]) * sum(sb[ia+1:])

        elif ta == 'G':
            r += sum(sr[ia+1:]) * sum(sb[ia+1:])
        else:
            r += sum(sg[ia + 1:]) * sum(sr[ia + 1:])
    print(r-1)

if __name__ == '__main__':
    main()


Failing test case input:
39
RBRBGRBRGBBRGGBBRRRBGGBRBGBRBGBRBBBGBBB

Expected output:
1794


Actual output:
1880


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    s = list(input())
    sr = [0] * n
    sg = [0] * n
    sb = [0] * n
    for i1 in range(n):
        ts = s[i1]
        if ts == 'R':
            sr[i1] = 1
        elif ts == 'G':
            sg[i1] = 1
        else:
            sb[i1] = 1
    if n <= 3:
        print(0)
        exit()
    r = 0
    for ia in range(0,n-3):
        ta = s[ia]
        if ta == 'R':
            r += sum(sg[ia+1:]) * sum(sb[ia+1:])
        elif ta == 'G':
            r += sum(sr[ia+1:]) * sum(sb[ia+1:])
        else:
            r += sum(sg[ia + 1:]) * sum(sr[ia + 1:])
        for ib in range((n - ia)
            if ia + ib * 2 < n:
                if ta != s[ia + ib] and ta != s[ia + ib + ib] and s[ia+ib]!= s[ia + ib + ib]:
                    r -= 1
    print(r)

if __name__ == '__main__':
    main()
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
S = list(input())

sum_R = 0
sum_B = 0
sum_G = 0

for i in range(N):
    if S[i] == "R":
        sum_R = sum_R +1
    if S[i] == "G":
        sum_G = sum_G+1
    if S[i] == "B":
        sum_B = sum_B +1
     
sum_A = sum_R*sum_G*sum_B

M = int((N-1)/2)

for j in range(1,M+1):
    for i in range(j):
        if S[i]!=S[j] and S[j]!=S[j+(j-i)] and S[i]!=S[j+(j-i)]:
            sum_A -=1

if N % 2 == 0:
    for i in range(1,M+1):
        if S[i] != S[M+1] and S[M+1] != S[2*(M+1)-(i)] and S[i] != S[2*(M+1)-(i)]:
            sum_A -= 1
    
print(sum_A)

Failing test case input:
39
RBRBGRBRGBBRBGBBRRRBGGBRBGBRBGBRBBBGGBB

Expected output:
1799


Actual output:
1836


Fixed submission (verdict: Accepted):
N = int(input())
S = list(input())

sum_R = 0
sum_B = 0
sum_G = 0
sum_A = 0

for i in range(N):
    if S[i] == "R":
        sum_R = sum_R +1
    if S[i] == "G":
        sum_G = sum_G+1
    if S[i] == "B":
        sum_B = sum_B +1
     
sum_A = sum_R*sum_G*sum_B

M = int((N-1)/2)

for j in range(1,M+1):
    for i in range(j):
        if S[i]!=S[j] and S[j]!=S[j+(j-i)] and S[i]!=S[j+(j-i)]:
            sum_A = sum_A -1

for j in range(M+1,N):
    for i in range(j+1,N):
        if S[i]!=S[j] and S[j]!=S[j+(j-i)] and S[i]!=S[j+(j-i)]:
            sum_A = sum_A -1
    
print(sum_A)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()

rc = s.count('R')
gc = s.count('G')
bc = s.count('B')

ans = rc*gc*bc

for i in range(n):
    if s[i] == 'R':
        for j in range(1,min(n-i-1, i-1)+1):
            if s[i-j] != s[i+j] and s[i-j] != 'R' and s[i+j] != 'R':
                ans -= 1
        for j in range(1,int((n-i-1)/2)+1):
            if s[i+2*j] != s[i+j] and s[i+2*j] != 'R' and s[i+j] != 'R':
                ans -= 1
        for j in range(1,int((i-1)/2)+1):
            if s[i-j] != s[i-2*j] and s[i-j] != 'R' and s[i-2*j] != 'R':
                ans -= 1

print(ans)

Failing test case input:
39
BBBGRBBBBGBRBGBRBGGBRRRBBGRRBBGGBRGBRBR

Expected output:
1804


Actual output:
1807


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

rc = s.count('R')
gc = s.count('G')
bc = s.count('B')

ans = rc*gc*bc

for i in range(n):
    if s[i] == 'R':
        for j in range(1,min(n-i-1, i)+1):
            if s[i-j] != s[i+j] and s[i-j] != 'R' and s[i+j] != 'R':
                ans -= 1
        for j in range(1,int((n-i-1)/2)+1):
            if s[i+2*j] != s[i+j] and s[i+2*j] != 'R' and s[i+j] != 'R':
                ans -= 1
        for j in range(1,int(i/2)+1):
            if s[i-j] != s[i-2*j] and s[i-j] != 'R' and s[i-2*j] != 'R':
                ans -= 1

print(ans)
Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N=int(input())
S=input()
c=0
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if S[i]!=S[j] and S[j]!=S[k] and j-i!=k-j:
        c+=1
print(c)   

Failing test case input:
39
BBBGBBBRBGBRBGBRBGGBRRGBBGRRBBGGBRRBRBR

Expected output:
1796


Actual output:
3771


Fixed submission (verdict: Accepted):
N=int(input())
S=input()
s=0
s+=S.count('R')*S.count('G')*S.count('B')
for i in range(N):
  for j in range(i+1,N):
    k=2*j-i
    if k<N and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
      s-=1
print(s)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    n=int(input())
    s=list(input())
    if len(set(s)) < 3:
      print(0)
      return 0
    from collections import Counter
    c=Counter(s)
    res=c['R']*c['G']*c['B']

    for j in range(2,n):
      for w in range(1,2001):
        i=j-w
        k=j+w

        if i>=0 and k<n:
          if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
            res-=1
    print(res)
    return 0

if __name__ == '__main__':
    main()



Failing test case input:
39
GBRBRRBGGBBRRRBBGRRBGGBRBGBRBGBRBBBGBBB

Expected output:
1791


Actual output:
1792


Fixed submission (verdict: Accepted):
def main():
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    n=int(input())
    s=list(input())
    if len(set(s)) < 3:
      print(0)
      return 0
    from collections import Counter
    c=Counter(s)
    res=c['R']*c['G']*c['B']

    for j in range(1,n):
      for w in range(0,n+1):
        i=j-w
        k=j+w

        if i<0 or k>=n:
          continue
        if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
          res-=1
    print(res)
    return 0

if __name__ == '__main__':
    main()

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
S=input()
c = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    if S[i] != S[j]:
      RGB = 'RGB'.strip(S[i]).strip(S[j])
      S_ = S[j+1:]
      d = j - i - 1
      S_ = S_[:d]+S_[d+1:]
      c += S_.count(RGB)
print(c)

Failing test case input:
39
RBBGBBRBBGBRBGBRBGGBBRRBGBRRBBGGBRGBRBR

Expected output:
1815


Actual output:
1418


Fixed submission (verdict: Accepted):
N=int(input())
S=input()
c = 0
rgb = S.count('R')*S.count('G')*S.count('B')
for i in range(N-2):
  for j in range(i+1, N-1):
    if 2*j - i < N:
      if (S[i] != S[j] and S[i] != S[2*j-i] and S[j] != S[2*j-i]):
        c+=1
print(rgb-c)
Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
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 or n<3:
    ans = 0
elif r == 1 or g == 1 or b == 1:
    ans = 1
print(ans)


Failing test case input:
4
GRRB

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ret = 0
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:
            ret += 1
ans = r*g*b - ret
print(ans)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
s=input()

ans=s.count("R")*s.count("B")*s.count("G")
print(ans)
for i in range(n):
    for j in range(n):
        k=(j-i)*2
        if k<n:break
        if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
            ans -=1

print(ans-1)

Failing test case input:
39
RBBGBBBBBGBRRBBRBGGBRGRBBGRRBBGGBRGBBRR

Expected output:
1808


Actual output:
1881
1880


Fixed submission (verdict: Accepted):
n=int(input())
s=input()

ans=s.count("R")*s.count("B")*s.count("G")
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[i]!=s[k]:
            ans -=1

print(ans)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
s = input()
R = s.count('R')
G = s.count('G')
B = s.count('B')

count = R*G*B
print(count)
cnt = 0
for i in range(len(s)):
    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]:
            count -= 1
print(count)

Failing test case input:
39
RRBBGRRGGBBRRGBBRGBBGGBRBRBBBRBBBBBGBGR

Expected output:
1810


Actual output:
1881
1810


Fixed submission (verdict: Accepted):
N = int(input())
s = input()
R = s.count('R')
G = s.count('G')
B = s.count('B')

count = R*G*B
cnt = 0
for i in range(len(s)):
    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]:
            count -= 1
print(count)
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
4
RBGR

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
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(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)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

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)

Failing test case input:
39
RRRRGRBGGBRRRGBBRGBBGGBBBBBBBGBBBBRGBBR

Expected output:
1823


Actual output:
1703


Fixed submission (verdict: Accepted):
n=int(input())
s=input()

r=set()
g=set()
b=set()

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

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in r:
    for ig in g:
        if (ir+ig)/2 in b: 
            isum=isum+1
for ir in r:
    for ib in b:
        if (ir+ib)/2  in g: 
            isum=isum+1
for ig in g:
    for ib in b:
        if (ig+ib)/2  in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
S = input()
nR = 0
nG = 0
nB = 0
cnt = 0
for i in range(N-1):
  if S[i] == 'R':
    nR += 1
  elif S[i] == 'G':
    nG += 1
  else:
    nB += 1
  for j in range(i+1, N):
    k = j - i + j
    if k < N:
      L = [S[i], S[j], S[k]]
      if 'R' in L and 'G' in L and 'B' in L:
        cnt += 1
    else:
      break
print(nR*nG*nB-cnt)


Failing test case input:
4
RGBR

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
nR = 0
nG = 0
nB = 0
cnt = 0
for i in range(N):
  if S[i] == 'R':
    nR += 1
  elif S[i] == 'G':
    nG += 1
  else:
    nB += 1
  for j in range(i+1, N):
    k = j - i + j
    if k < N:
      L = [S[i], S[j], S[k]]
      if 'R' in L and 'G' in L and 'B' in L:
        cnt += 1
    else:
      break
print(nR*nG*nB-cnt)
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
string = input()

result = string.count('R')*string.count('G')*string.count('B')

for i in range(N-2):
  for j in range(i+1, N):
    k = 2*j-1
    if k>=N:
      break
    if string[i] != string[j] != string[k]:
      result -= 1
print(result)

Failing test case input:
39
RRRBGRBGGBBBRGBRRBRBGGBRBGBRBGBRBBBGBBB

Expected output:
1798


Actual output:
1833


Fixed submission (verdict: Accepted):
N = int(input())
string = input()
 
result = string.count('R')*string.count('G')*string.count('B')
 
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j-i
    if k>=N:
      break
    if string[i] != string[j] and string[j] != string[k] and string[i] != string[k]:
      result -= 1
print(result)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1
print(r,g,b)

ans=r*g*b

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


Failing test case input:
39
RBBGBBBBBGBBBBBBBGGBBGRBBGRRRBGGRRGRRRR

Expected output:
1829


Actual output:
11 9 19
1831


Fixed submission (verdict: Accepted):
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1

ans=r*g*b
for i in range(n):
  for j in range(i+1,n):
    k_ = j+(j-i)
    if(k_ >=n):
      break
    ans -= int(s[i]!= s[j] and s[i] != s[k_] and s[j] != s[k_])

print(ans)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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) 
    if 1 <= j and j <= N:
      count += 1
      
print(ALL - count)

Failing test case input:
39
RRBBGRRGGBBRRGBBRGBBGGBRBRBBBRBBBBBGBGR

Expected output:
1810


Actual output:
1142


Fixed submission (verdict: Accepted):
import itertools
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

RGBs = list(itertools.permutations(['R', 'G', 'B'], 3))

for i in range(N):
  for j in range(N-i*2):
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      count += 1
      
print(ALL - count)
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()
ans = 0
ans_list = []

R_index = []
G_index = []
B_index = []

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

ans = len(R_index) * len(G_index) * len(B_index)

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


print(ans)


Failing test case input:
39
RRBBGRBGGBBRRGBBRGRBGGBRBBRRBGBBBBBGBBR

Expected output:
1808


Actual output:
1814


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
ans = 0
ans_list = []

R_index = []
G_index = []
B_index = []

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

ans = len(R_index) * len(G_index) * len(B_index)

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

print(ans)

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
4
RRGB

Expected output:
1

Actual output:
Counter({'R': 2, 'G': 1, 'B': 1}) 2
1


Fixed submission (verdict: Accepted):
import collections
n = int(input())
a = input()
a = a.replace('R','1')
a = a.replace('G','2')
a = a.replace('B','3')
a = tuple(map(int,list(a)))
b = collections.Counter(a)
ans =b[3]*b[1]*b[2]
for i in range(n-2):
    for j in range(i+1,n):
        if a[i] == a[j]:
            continue
        c = j*2 -i
        if c < n:
            if a[i]+a[j]+a[c]==6:
                ans -= 1
        else:
            break
print(ans)
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    n = int(input())
    s = input()
    res = 0
    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)
    
    cnt = 0
    for i in r:
        for j in g:
            diff = abs(j-i)
            for k in b:
                if abs(i-k) != diff and abs(j-k) != diff:
                    cnt += 1
    print(cnt)
                    


if __name__ == '__main__':
    main()



Failing test case input:
39
RRRRGRBGGBBRRGBBRBBBGGBBRGBRBGBRBBBGBBB

Expected output:
1814


Actual output:
1840


Fixed submission (verdict: Accepted):
from itertools import permutations

def main():
    n = int(input())
    s = input()
    res = 0
    r = 0
    g = 0
    b = 0
    for i, c in enumerate(s):
        if c == 'R':
            r += 1
        elif c == 'G':
            g += 1
        else:
            b += 1
    
    rgb = []
    for t in permutations('RGB'):
        rgb.append(''.join(t))

    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            k = 2*j - i 
            if k >= n:
                break
            if (s[i] + s[j] + s[k]) in rgb:
                cnt += 1
    print(r*g*b - cnt)


if __name__ == '__main__':
    main()

Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


N = int(input())
S = input()
S = S[::-1]

cnt = 0






for i in range(1,N-1):
    for j in range(i+1,N):
        k = 2*j-i
        if k>j and k<=N:
            if S[i-1]==S[j-1] or S[i-1]==S[k-1] or S[j-1]==S[k-1] :
                cnt += 1


print(N-cnt)

Failing test case input:
39
RRBBGRRBGBBRRGBBRGBBGGBRBRBRBGBBBBGGBBR

Expected output:
1807


Actual output:
-248


Fixed submission (verdict: Accepted):


N = int(input())
S = input()
S = S[::-1]

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

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


print(cnt)
Problem: p02714
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
39
RRRRGRBGGBBRRGBBRGBBGGRBBRBBBGBBBBBGBBR

Expected output:
1810


Actual output:
0 7 14
0 13 26
0 17 34
0 20 10
1 8 15
1 17 33
1 17 9
1 29 15
1 35 18
2 4 6
2 8 14
2 13 24
2 17 32
3 13 23
3 17 31
3 17 10
3 20 37
3 35 19
5 4 6
5 7 9
5 7 6
5 13 9
5 21 37
11 4 18
11 7 15
11 7 9
11 8 14
11 13 15
11 13 9
11 17 23
11 17 14
11 21 31
11 35 23
12 8 10
12 13 14
12 20 28
12 21 30
16 4 28
16 4 10
16 8 24
16 13 10
16 13 19
16 17 18
16 17 15
16 20 24
16 20 18
16 21 26
22 7 37
22 8 36
22 8 15
22 13 31
22 17 27
22 20 18
22 20 24
22 21 23
22 29 36
22 29 15
22 35 9
25 13 37
25 13 19
25 17 9
25 17 33
25 20 15
25 20 30
25 21 23
25 29 33
25 29 27
25 35 15
25 35 30
38 8 23
38 35 32
1810


Fixed submission (verdict: Accepted):
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
        k = int(2 * i - j)
        if(0 <= 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)

Problem: p02714
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
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-3):
  for j in range(i+1,n-1):
    k = 2*j-i
    if k < n:
      if  s[i] != s[j] and s[j]!= s[k] and s[i] != s[k]:
        ans -= 1
print(ans)

Failing test case input:
39
RRBBGRRGGBBRRGBBRGBBGGBRBRBBBRBBBBBGBGR

Expected output:
1810


Actual output:
1811


Fixed submission (verdict: Accepted):
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):
  for j in range(i+1,n):
    k = 2*j-i
    if k < n:
      if  s[i] != s[j] and s[j]!= s[k] and s[i] != s[k]:
        ans -= 1
print(ans)