qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n=int(input())
s=list(input())
for i in range(n):
    if s[i]=='R':
        s[i]=1
    elif s[i]=='G':
        s[i]=2
    elif s[i]=='B':
        s[i]=4
ans=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:
        continue
      if s[i]+s[j]+s[k]==7:
          ans-=1
print(ans)

Fixed code:
n=int(input())
s=list(input())
ans=s.count('R')*s.count('G')*s.count('B')
for i in range(n):
    if s[i]=='R':
        s[i]=1
    elif s[i]=='G':
        s[i]=2
    elif s[i]=='B':
        s[i]=4
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]+s[k]==7:
          ans-=1
print(ans)
Buggy code:
def calc():
  n=int(input())
  s=list(input())
  cnt1=0
  cnt2=0
  cnt3=0
  for i in range(n):
      if s[i]=='R':
          cnt1+=1
          s[i]=1
      elif s[i]=='G':
          cnt2+=1
          s[i]=2
      elif s[i]=='B':
          cnt3+=1
          s[i]=4
  ans=cnt1*cnt2*cnt3
  for i in range(n):
      for j in range(i+1,n):
        k=1*j-i
          if k>=n:
            continue
          if s[i]+s[j]+s[k]==7:
            ans-=1
  print(ans)
calc()

Fixed code:
def calc():
  n=int(input())
  s=list(input())
  cnt1=0
  cnt2=0
  cnt3=0
  for i in range(n):
      if s[i]=='R':
          cnt1+=1
          s[i]=1
      elif s[i]=='G':
          cnt2+=1
          s[i]=2
      elif s[i]=='B':
          cnt3+=1
          s[i]=4
  ans=cnt1*cnt2*cnt3
  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]+s[k]==7:
            ans-=1
  print(ans)
calc()
Buggy code:
n=int(input())
str=input()
count=str.count("R")*str.count("G")*str.count("B")
count0=0
for i in range(0,n-2):
    for j in range(i+1,(n+i)/2):
        k=2*j-i
        if str[k]!=str[i] and str[k]!=str[j] and str[i]!=str[j]:
            count0=count0+1
print(count-count0)

Fixed code:
n=int(input())
str=input()
count=str.count("R")*str.count("G")*str.count("B")
count0=0
for i in range(0,n-2):
    for j in range(i+1,int((n+i-1)/2)+1):
        k=2*j-i
        if str[k]!=str[i] and str[k]!=str[j] and str[i]!=str[j]:
            count0=count0+1
print(count-count0)
Buggy code:
n = int(input())
s = input()
S = list(s)
r = S.count('R')
g = S.count('G')
b = S.count('B')
ans = r * g * b
for k in range(n):
        for j in range(k):
            i = 2*j - k
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
print(ans)

Fixed code:
n = int(input())
s = input()
S = list(s)
r = S.count('R')
g = S.count('G')
b = S.count('B')
ans = r * g * b
for k in range(n):
        for j in range(k):
            i = 2*j - k
            if i >= 0 and i < j and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
print(ans)
Buggy code:
from collections import Counter

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

c = Counter(s)
print(c)
ans = c['R'] * c['G'] * c['B']

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

print(ans)


Fixed code:
from collections import Counter

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

c = Counter(s)
ans = c['R'] * c['G'] * c['B']

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

print(ans)
Buggy code:
n = int(input())
s = input()

if n < 2:
    print(0)
    exit(0)

cum_r = [0] * (n + 1)
cum_g = [0] * (n + 1)
cum_b = [0] * (n + 1)

for i in range(n):
    cum_r[i + 1] = cum_r[i]
    cum_g[i + 1] = cum_g[i]
    cum_b[i + 1] = cum_b[i]
    if s[i] == "R":
        cum_r[i + 1] += 1
    elif s[i] == "G":
        cum_g[i + 1] += 1
    else:  # s[i] == "b":
        cum_b[i + 1] += 1

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

        # check "b"
        if (s[i] == "R" and s[k] == "G") or (s[i] == "G" and s[k] == "R"):
            sum += cum_b[k] - cum_b[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "B":
                sum -= 1
        elif (s[i] == "R" and s[k] == "B") or (s[k] == "B" and s[k] == "R"):
            sum += cum_g[k] - cum_g[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "G":
                sum -= 1
        else:
            sum += cum_r[k] - cum_r[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "R":
                sum -= 1

print(sum)


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

if n < 2:
    print(0)
    exit(0)

cum_r = [0] * (n + 1)
cum_g = [0] * (n + 1)
cum_b = [0] * (n + 1)

for i in range(n):
    cum_r[i + 1] = cum_r[i]
    cum_g[i + 1] = cum_g[i]
    cum_b[i + 1] = cum_b[i]
    if s[i] == "R":
        cum_r[i + 1] += 1
    elif s[i] == "G":
        cum_g[i + 1] += 1
    else:  # s[i] == "b":
        cum_b[i + 1] += 1

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

        # check "b"
        if (s[i] == "R" and s[k] == "G") or (s[i] == "G" and s[k] == "R"):
            sum += cum_b[k] - cum_b[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "B":
                sum -= 1
        elif (s[i] == "R" and s[k] == "B") or (s[i] == "B" and s[k] == "R"):
            sum += cum_g[k] - cum_g[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "G":
                sum -= 1
        else:
            sum += cum_r[k] - cum_r[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "R":
                sum -= 1

print(sum)
Buggy code:
def main():
    n, s = int(input()), input()
    r, g, b = 0, 0, 0
    for i in s:
        if i == 'R':
            r += 1
        if i == 'G':
            g += 1
        if i == 'b':
            b += 1

    ans = r * g * b
    s = tuple(s)
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed code:
def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()
Buggy code:
import sys
input = sys.stdin.readline
def main():
    n= int(input())
    s = str(input().rstrip())
    r= s.count('R')
    g=s.count('G')
    b = s.count('B')
    ans = 0
    for i in range(2):
        for j in range(i+1, (n+i+1)//2):
            k = 2*j-i
            t = {s[i], s[j], s[k]}
            if len(t) ==3:
                ans +=1
    print(r*g*b-ans)
if __name__ == '__main__':
    main()

Fixed code:
import sys
input = sys.stdin.readline
def main():
    n= int(input())
    s = str(input().rstrip())
    r= s.count('R')
    g=s.count('G')
    b = s.count('B')
    ans = 0
    for i in range(n-2):
        for j in range(i+1, (n+i+1)//2):
            k = 2*j-i
            t = {s[i], s[j], s[k]}
            if len(t) ==3:
                ans +=1
    print(r*g*b-ans)
if __name__ == '__main__':
    main()
Buggy code:
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)

Fixed code:
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)
Buggy 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)

Fixed 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(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)
Buggy 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)

Fixed 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
        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)
Buggy code:
def main():
    N = int(input())
    S = list(input())
    R = []
    G = []
    B = []
    Reval = {}
    Geval = {}
    Beval = {}
    for i in range(N):
        if S[i] == "R":
            R.append(i)
            Reval[i] = i
        elif S[i] == "G":
            G.append(i)
            Geval[i] = i
        elif S[i] == "B":
            B.append(i)
            Beval[i] = i
            #if i / 2 in R or i / 2 in G or i / 2 in B
    count = len(R)*len(G)*len(B)

    for a in R:
        for b in G:
            if (a + b)//2 in Beval:
                count -= 1
    for a in G:
        for b in B:
            if (a + b)//2 in Reval:
                count -= 1
    for a in B:
        for b in G:
            if (a + b)//2 in Geval:
                count -= 1
    print(count)

if __name__ == "__main__":
    main()


Fixed code:
def main():
    N = int(input())
    S = list(input())
    R = []
    G = []
    B = []
    Reval = {}
    Geval = {}
    Beval = {}
    for i in range(N):
        if S[i] == "R":
            R.append(i)
            Reval[2*i] = 2*i
        elif S[i] == "G":
            G.append(i)
            Geval[2*i] = 2*i
        elif S[i] == "B":
            B.append(i)
            Beval[2*i] = 2*i
    count = len(R)*len(G)*len(B)

    for a in R:
        for b in G:
            if (a + b) in Beval:
                count -= 1
    for a in G:
        for b in B:
            if (a + b) in Reval:
                count -= 1
    for a in B:
        for b in R:
            if (a + b) in Geval:
                count -= 1
    print(count)

if __name__ == "__main__":
    main()
Buggy code:
n = int(input())
s = list(input())
ans = s.count('R')*s.count('G')*s.count('B')

for i in range(n):
  if s[i] == 'R':
    s[i] = 1
  elif s[i] == 'G':
    s[i]
  elif s[i] = 4
  
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]+s[k]==7:
      ans-=1

print(ans)

Fixed code:
n = int(input())
s = list(input())
ans = s.count('R')*s.count('G')*s.count('B')

for i in range(n):
  if s[i] == 'R':
    s[i] = 1
  elif s[i] == 'G':
    s[i] = 2
  elif s[i] == 'B':
    s[i] = 4
  
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]+s[k]==7:
      ans-=1

print(ans)
Buggy code:
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-3):
    for j in range(i+1, n-1):
        if s[i] == s[j]:continue
        else:
            k = 2*j - i # k - j = j - i
            if k > n - 1:continue
            if s[i] == s[k]:continue
            if s[j] == s[k]:continue
            count -= 1

print(count)


Fixed code:
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)//2):
        if s[i] == s[j]:continue
        else:
            k = 2*j - i # k - j = j - i
            if s[i] == s[k]:continue
            if s[j] == s[k]:continue
            count -= 1

print(count)
Buggy code:
N=input()
S=input()
Sn=[]
R=0
G=0
B=0
for i in range(len(S)):
    if S[i]=='R':
        R+=1
        Sn.append(1)
    elif S[i]=='G':
        G+=1
        Sn.append(2)
    else:
        B+=1
        Sn.append(3)

count=0
for start in range(len(S)):
        for diff in range(1,int((len(S)-start+1)/2)):
            print(start,diff)
            if (Sn[start]-Sn[start+diff])*(Sn[start+diff]-Sn[start+(2*diff)])*(Sn[start]-Sn[start+(2*diff)])!=0: 
                count+=1
                
print(str((R*G*B)-count))

Fixed code:
N=input()
S=input()
Sn=[]
R=0
G=0
B=0
for i in range(len(S)):
    if S[i]=='R':
        R+=1
        Sn.append(1)
    elif S[i]=='G':
        G+=1
        Sn.append(2)
    else:
        B+=1
        Sn.append(3)

count=0
for start in range(len(S)):
        for diff in range(1,int((len(S)-start+1)/2)):
            #int(start,diff)
            if (Sn[start]-Sn[start+diff])*(Sn[start+diff]-Sn[start+(2*diff)])*(Sn[start]-Sn[start+(2*diff)])!=0: 
                count+=1
                
print(str((R*G*B)-count))
Buggy code:
def calc(i, j, B1, len_b):
    extra = 0
    d = j - i

    # i < j < k
    k1 = d + j
    if k1 < len_b:
        extra += B1[k1]

    # k < i < j
    k2 = i - d
    if 0 <= k2 and k2 < len_b:
        extra += B1[k2]

    # i < k < j
    s = i + j
    if s % 2 == 0:
        k3 = s // 2
        if k3 < len_b:
            extra += B1[k3]
    return extra

def main():
    N = int(input())
    S = input()
    R, G, B = [], [], []
    RGB = {'R': R, 'G': G, 'B': B}
    for i in range(N):
        RGB[S[i]].append(i)
    num_r, num_g, num_b = len(R), len(G), len(B)
    ans = num_r * num_g * num_b
    if ans == 0:
        print(0)
        return

    len_b = (B[-1] + 1)
    B1 = [0]*len_b
    for b in B:
        B1[b] = 1
    # print(R, G, B)
    for i in R:
        for j in G:
            if i > j:
                i, j = j, i
            ans -= calc(i, j, B1, len_b)
    print(ans)

if __name__ == '__main__':
    main()


Fixed code:
def calc(i, j, B1, len_b):
    extra = 0
    d = j - i

    # i < j < k
    k1 = d + j
    if k1 < len_b:
        extra += B1[k1]

    # k < i < j
    k2 = i - d
    if 0 <= k2 and k2 < len_b:
        extra += B1[k2]

    # i < k < j
    s = i + j
    if s % 2 == 0:
        k3 = s // 2
        if k3 < len_b:
            extra += B1[k3]
    return extra

def main():
    N = int(input())
    S = input()
    RGB = {'R': [], 'G': [], 'B': []}
    for i in range(N):
        RGB[S[i]].append(i)
    num_r = len(RGB['R'])
    num_g = len(RGB['G'])
    num_b = len(RGB['B'])
    if num_r == 0 or num_g == 0 or num_b == 0:
        print(0)
        return

    len_b = (RGB['B'][-1] + 1)
    B1 = [0]*len_b
    for b in RGB['B']:
        B1[b] = 1
    # print(R, G, B)
    ans = num_r * num_g * num_b
    for i in RGB['R']:
        for j in RGB['G']:
            ans -= calc(min(i, j), max(i, j), B1, len_b)
    print(ans)

if __name__ == '__main__':
    main()
Buggy code:
a=int(input())
b=str(input())
sum=0

riron_sum=b.count('R')*sum=b.count('G')*sum=b.count('B')
for i in range(1,a):
    for n in range(1,i):
        if i+n>N:
            j = i+d
            k = j+d
            if b[i]!=b[j] and b[j]!=b[k] and b[k]!=b[i]:
                riron_sum-=1

print(riron_sum)

Fixed code:
a=int(input())
b=str(input())
sum=0

riron_sum=b.count('R')*b.count('G')*b.count('B')

for i in range(0,a):
    for n in range(0,a+1):
        j = i+n
        k = j+n
        #print(j)
        #print(k)
        if k>=a:
        	break

        if b[i]!=b[j] and b[j]!=b[k] and b[k]!=b[i]:
                riron_sum-=1

print(riron_sum)
Buggy code:
N = int(input())
s = list(input())
counts = dict(Counter(s))
r = 0;g = 0;b= 0
for i in s:
    if i=="R":
        r += 1
    elif i=="G":
        g += 1
    else:
        b += 1
all = r*g*b
sub = 0
for i in range(N-1):
    for j in range(i+1,N):
        if s[i]==s[j]:
            continue
        k = 2*j - i
        if k >= N:
            continue
        else:
            if (s[k]!=s[i] and s[k]!=s[j]):
                sub += 1
print(all-sub)

Fixed code:
N = int(input())
s = list(input())
r = 0;g = 0;b= 0
for i in s:
    if i=="R":
        r += 1
    elif i=="G":
        g += 1
    else:
        b += 1
all = r*g*b
sub = 0
for i in range(N-1):
    for j in range(i+1,N):
        if s[i]==s[j]:
            continue
        k = 2*j - i
        if k >= N:
            continue
        else:
            if (s[k]!=s[i] and s[k]!=s[j]):
                sub += 1
print(all-sub)
Buggy code:
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]) & (s[i] != s[k]) & (s[j] != s[k]):
      tot -= 1

print(tot)

Fixed code:
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)
Buggy code:
n = int(input())
s = input()
r,g,b = 0,0,0
r = s.count("R");g = s.count("G");b = s.count("B")
k=0    
count = r*g*b
print(count)
for j in range(n):
  for i in range(j):
    if (k==2*j-i)<n:
      if s[i]!=s[k]!=s[j]!=s[i]:
        count-=1   
print(count)

Fixed code:
n = int(input())
s = input()
r = s.count("R");g = s.count("G");b = s.count("B")
count = r*g*b
for j in range(n):
  for i in range(j):
    if (k:=2*j-i)<n:
      if s[i]!=s[k]!=s[j]!=s[i]:
        count-=1   
print(count)
Buggy code:
import bisect
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 = 0
for i in r:
	for j in g:
		ans += len(b)
		if i > j:
			k = j-abs(i-j)
			m = i+abs(i-j)
		else:
			k = j+abs(i-j)
			m = i-abs(i-j)
		if k < b[-1] and k > b[0]:
			x = bisect.bisect_left(b,k)
			if b[x] == k:
				ans -= 1
		if m < b[-1] and m > b[0]:
			x = bisect.bisect_left(b,m)
			if b[x] == m:
				ans -= 1
		l = (i+j)//2
		if abs(i-l) == abs(j-l):
			x = bisect.bisect_left(b,l)
			if b[x] == l:
				ans -= 1
print (ans)

Fixed code:
import bisect
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 = 0
if len(r) == 0 or len(g) == 0 or len(b) == 0:
	print (0)
	exit()
for i in r:
	for j in g:
		ans += len(b)
		if i > j:
			k = j-abs(i-j)
			m = i+abs(i-j)
		else:
			k = j+abs(i-j)
			m = i-abs(i-j)
		if k <= b[-1] and k >= b[0]:
			x = bisect.bisect_left(b,k)
			if x >= 0 and x < len(b):
				if b[x] == k:
					ans -= 1
		if m <= b[-1] and m >= b[0]:
			x = bisect.bisect_left(b,m)
			if x >= 0 and x < len(b):
				if b[x] == m:
					ans -= 1
		l = (i+j)//2
		if abs(i-l) == abs(j-l):
			x = bisect.bisect_left(b,l)
			if x >= 0 and x < len(b):
				if b[x] == l:
					ans -= 1
print (ans)
Buggy 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(1,(n+1)//2):
  for j in range(n-2*i):
    print(s[j],s[j+i],s[j+2*i])
    if len(set([s[j],s[j+i],s[j+2*i]]))==3:
      print(j,j+i,j+2*i)
      ans-=1
print(ans)

Fixed 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(1,(n+1)//2):
  for j in range(n-2*i):
    if len(set([s[j],s[j+i],s[j+2*i]]))==3:
      ans-=1
print(ans)
Buggy code:
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)

Fixed code:
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)
Buggy code:
N = int(input())
S = input()
r = []
g = []
b = []
for idx, i in enumerate(S, 1):
    if i == 'R':
        r.append(idx)
    elif i == 'G':
        g.append(idx)
    else:
        b.append(idx)

b = set(b)
cnt = len(b) * len(r) * len(g)
if cnt == 0:
    print(0)
    exit()

for j in g:
    for i in r:
        if i > j:
            i, j = j, i
        d = j - i
        if j + d in b:
            cnt -= 1
        if i - d in b:
            cnt -= 1
        if d % 2 == 0 and (i + j) // 2 in b:
            cnt -= 1
print(cnt)


Fixed code:
N = int(input())
S = input()
r = []
g = []
b = []
for idx, i in enumerate(S, 1):
    if i == 'R':
        r.append(idx)
    elif i == 'G':
        g.append(idx)
    else:
        b.append(idx)

b = set(b)
cnt = len(b) * len(r) * len(g)
for i in r:
    original = i
    for j in g:
        i = original
        if i > j:
            i, j = j, i
        d = j - i
        if j + d in b:
            cnt -= 1
        if i - d in b:
            cnt -= 1
        if d % 2 == 0 and (i + j) // 2 in b:
            cnt -= 1
print(cnt)
Buggy code:
N= int(input())
S=input()
r=[]
g=[]
b=[]
A=0
B=0
C=0
for i in range(N):
    if S[i]=="R":
        r.append(i)
        A+=1
    elif S[i]=="G":
        g.append(i)
        B+=1
    else:
        b.append(i)
        C+=1
k=0
for i in range(N-2):
    for j in range(i+1,N-1):
        t=2*j-i
        if t<N:
            if S[i]!=S[j] and S[i]!=S[t] and S[t]!=S[j] :
                k+=1
                print(i,j,t)
print(k)
print(A*B*C-k)

Fixed code:
N= int(input())
S=input()
r=[]
g=[]
b=[]
A=0
B=0
C=0
for i in range(N):
    if S[i]=="R":
        r.append(i)
        A+=1
    elif S[i]=="G":
        g.append(i)
        B+=1
    else:
        b.append(i)
        C+=1
k=0
for i in range(N-2):
    for j in range(i+1,N-1):
        t=2*j-i
        if t<N:
            if S[i]!=S[j] and S[i]!=S[t] and S[t]!=S[j] :
                k+=1

print(A*B*C-k)
Buggy code:
n = int(input())
s = input()
r_num = s.count('R')
g_num = s.count('G')
b_num = s.count('B')
tot = r_num*g_num*b_num
print(tot)
for i in range(n):
    for j in range(i+1,n):
        k = j+(j-i)

        if k<n:
            if s[i]!=s[j] and s[i]!=s[k] and s[j] != s[k]:
                tot -= 1

print(tot)


Fixed code:
n = int(input())
s = input()
r_num = s.count('R')
g_num = s.count('G')
b_num = s.count('B')
tot = r_num*g_num*b_num
for i in range(n):
    for j in range(i+1,n):
        k = j+(j-i)

        if k<n:
            if s[i]!=s[j] and s[i]!=s[k] and s[j] != s[k]:
                tot -= 1

print(tot)