Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
da=list(map(int,input().split()))
ans=0
da=sorted(da)
for i in range(1,n-1):
    for j in range(i):
        ok,ng=0,0
        ok+=i
        ng+=n
        while ng-ok!=1:
            mi=(ok+ng)//2
            if da[mi]<da[i]+da[j]:
                ok=0
                ok+=mi
            else:
                ng=0
                ng+=mi
        ans+=ok-i
print(ans)

Fixed submission:
n=int(input())
da=list(map(int,input().split()))

def bina(x,ok,ng):
    global da
    while ng-ok!=1:
        mi=(ok+ng)//2
        if da[mi]<x:
            ok=0
            ok+=mi
        else:
            ng=0
            ng+=mi
    return ok


ans=0
da=sorted(da)
for i in range(1,n-1):
    for j in range(i):
        ans+=bina(da[i]+da[j],i,n)-i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
da=list(map(int,input().split()))

def bina(x,ok,ng):
    global da
    while ng-ok!=1:
        mi=(ok+ng)//2
        if da[mi]<x:
            ok=0
            ok+=mi
        else:
            ng=0
            ng+=mi
    return ok


ans=0
da=sorted(da)
for i in range(1,n-1):
    for j in range(i):
        ans+=bina(da[i]+da[j],i,n)-i
print(ans)

Fixed submission:
n=int(input())
da=list(map(int,input().split()))

def bina(x,ok,ng):
    global da
    while ng-ok!=1:
        mi=(ok+ng)//2
        if da[mi]<x:
            ok=0
            ok+=mi
        else:
            ng=0
            ng+=mi
    return ok


ans=0
da=sorted(da)
for i in range(1,n-1):
    for j in range(i):
        ans+=bina(da[i]+da[j],i,n)-i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
da=list(map(int,input().split()))

def bina(x,ok,ng):
    global da
    if ng-ok==1:
        return ok
    mi=(ng+ok)//2
    if da[mi]<x:
        ok=mi
    else:
        ng=mi
    return bina(x,ok,ng)

ans=0
da=sorted(da)
for i in range(1,n-1):
    for j in range(i):
        ans+=bina(da[i]+da[j],i,n)-i
print(ans)

Fixed submission:
n=int(input())
da=list(map(int,input().split()))

def bina(x,ok,ng):
    global da
    while ng-ok!=1:
        mi=(ok+ng)//2
        if da[mi]<x:
            ok=0
            ok+=mi
        else:
            ng=0
            ng+=mi
    return ok


ans=0
da=sorted(da)
for i in range(1,n-1):
    for j in range(i):
        ans+=bina(da[i]+da[j],i,n)-i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
da=list(map(int,input().split()))

def bina(x,ok,ng):
    global da
    if ng-ok==1:
        return ok
    mi=(ng+ok)//2
    if da[mi]<x:
        ok=mi
    else:
        ng=mi
    return bina(x,ok,ng)

ans=0
da=sorted(da)
for i in range(1,n-1):
    for j in range(i):
        ans+=bina(da[i]+da[j],i,n)-i
print(ans)

Fixed submission:
n=int(input())
da=list(map(int,input().split()))

def bina(x,ok,ng):
    global da
    while ng-ok!=1:
        mi=(ok+ng)//2
        if da[mi]<x:
            ok=0
            ok+=mi
        else:
            ng=0
            ng+=mi
    return ok


ans=0
da=sorted(da)
for i in range(1,n-1):
    for j in range(i):
        ans+=bina(da[i]+da[j],i,n)-i
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
ans=False
if s[0]==s[1]:
    if s[0]!=s[2] and a[2]==s[3]:
        ans=True
elif s[0]==s[2]:
    if s[0]!=s[1] and s[1]==s[3]:
        ans=True
elif s[0]==s[3]:
    if s[0]!=s[1] and s[1]==s[2]:
        ans=True
if ans:
    print('Yes')
else:
    print('No')

Fixed submission:
s=input()
ans=False
if s[0]==s[1]:
    if s[0]!=s[2] and s[2]==s[3]:
        ans=True
elif s[0]==s[2]:
    if s[0]!=s[1] and s[1]==s[3]:
        ans=True
elif s[0]==s[3]:
    if s[0]!=s[1] and s[1]==s[2]:
        ans=True
if ans:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=math.gcd(a,b)
ans+=b//e-(a-1)//e
print(ans)

Fixed submission:
def gcd(n,m):
    if n<m:
        return gcd(m,n)
    if n%m==0:
        return m
    else:
        return gcd(m,n%m)

a,b,c,d=map(int,input().split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=c*d//(gcd(c,d))
ans+=b//e-(a-1)//e
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().funcsplit())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=c*d
ans+=b//e-(a-1)//e
print(ans)

Fixed submission:
def gcd(n,m):
    if n<m:
        return gcd(m,n)
    if n%m==0:
        return m
    else:
        return gcd(m,n%m)

a,b,c,d=map(int,input().split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=c*d//(gcd(c,d))
ans+=b//e-(a-1)//e
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input(),split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=c*d
ans+=b//e-(a-1)//e
print(ans)


Fixed submission:
def gcd(n,m):
    if n<m:
        return gcd(m,n)
    if n%m==0:
        return m
    else:
        return gcd(m,n%m)

a,b,c,d=map(int,input().split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=c*d//(gcd(c,d))
ans+=b//e-(a-1)//e
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b,c,d=int(input().split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=c*d
ans+=b//e-(a-1)//e
print(ans)

Fixed submission:
def gcd(n,m):
    if n<m:
        return gcd(m,n)
    if n%m==0:
        return m
    else:
        return gcd(m,n%m)

a,b,c,d=map(int,input().split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=c*d//(gcd(c,d))
ans+=b//e-(a-1)//e
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[[0 for i in range(m+1)] for i in range(n+1)]
for i in range(m+1):
	dp[0][i]=1
for j in range(n+1):
	dp[j][0]=1
for i in range(n):
	for j in range(m):
		if s[i]==t[j]:
			dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j])%1000000007
		else:
			dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j]-dp[i][j])%1000000007
print(dp[n][m])

Fixed submission:
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[[0 for i in range(m+1)] for i in range(n+1)]
for i in range(m+1):
	dp[0][i]=1
for j in range(n+1):
	dp[j][0]=1
for i in range(n):
	for j in range(m):
		if s[i]==t[j]:
			dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j])%1000000007
		else:
			dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j]-dp[i][j])%1000000007
print(dp[n][m])
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
x=max(a,max(b,c))
input(a+b+c-x)


Fixed submission:
da=list(map(int,input().split()))
x=-max(da)
for i in da:
    x+=i
print(x)

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
x=max(a,max(b,c))
input(a+b+c-x)

Fixed submission:
da=list(map(int,input().split()))
x=-max(da)
for i in da:
    x+=i
print(x)
Buggy python submission (verdict: Runtime Error):
n,m,d=map(int,input().split())
da=[0 for i in range(n)]
print((n-2)*180)

Fixed submission:
n=int(input())
print((n-2)*180)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
#n = int(input())
#s = input()
n,x = map(int,input().split())
da = list(map(int,input().split()))
m = 100010
mod = 1000000007

dp = [0]*m
da.sort()
da.reverse()
dp[x] = 1
for i in range(n):
    for j in range(m):
        if j >= da[i]:
            dp[j%da[i]] += dp[j]
            dp[j] *= n-i-1
            if dp[j] >= mod: dp[j] %= mod
            if dp[j%da[i]] >= mod: dp[j] %= mod
        else:
            dp[j] *= n-i
            if dp[j] >= mod: dp[j]%=mod
ans = 0
for i in range(m):
    ans += dp[i] * i
    if ans >= mod: ans %= mod
print(ans)


Fixed submission:
#n = int(input())
#s = input()
n,x = map(int,input().split())
da = list(map(int,input().split()))
m = 100010
mod = 1000000007

dp = [0 for i in range(m)]
da.sort()
da.reverse()
dp[x] = 1
for i in range(n):
    for j in range(m):
        if j >= da[i]:
            dp[j%da[i]] += dp[j]
            dp[j] *= n-i-1
            if dp[j] >= mod: dp[j] %= mod
            if dp[j%da[i]] >= mod: dp[j] %= mod
        else:
            dp[j] *= n-i
            if dp[j] >= mod: dp[j]%=mod
ans = 0
for i in range(m):
    ans += dp[i] * i
    if ans >= mod: ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#n = int(input())
#s = input()
n,x = map(int,input().split())
da = list(map(int,input().split()))
m = 100010
mod = 1000000007

dp = [0 for i in range(m)]
da.sort()
da.reverse()
dp[x] = 1
for i in range(n):
    for j in range(m):
        if j >= da[i]:
            dp[j%da[i]] += dp[j]
            dp[j] *= n-i-1
            if dp[j] >= mod: dp[j] %= mod
            if dp[j%da[i]] >= mod: dp[j] %= mod
        else:
            dp[j] *= n-i
            if dp[j] >= mod: dp[j]%=mod
ans = 0
for i in range(m):
    ans += dp[i] * i
    if ans >= mod: ans %= mod
print(ans)


Fixed submission:
#n = int(input())
#s = input()
n,x = map(int,input().split())
da = list(map(int,input().split()))
m = 100010
mod = 1000000007

dp = [0 for i in range(m)]
da.sort()
da.reverse()
dp[x] = 1
for i in range(n):
    for j in range(m):
        if j >= da[i]:
            dp[j%da[i]] += dp[j]
            dp[j] *= n-i-1
            if dp[j] >= mod: dp[j] %= mod
            if dp[j%da[i]] >= mod: dp[j] %= mod
        else:
            dp[j] *= n-i
            if dp[j] >= mod: dp[j]%=mod
ans = 0
for i in range(m):
    ans += dp[i] * i
    if ans >= mod: ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
print(min(a,b),max(a+b-n))

Fixed submission:
n,a,b=map(int,input().split())
print(min(a,b),max(a+b-n,0))
Buggy python submission (verdict: Time Limit Exceeded):
import math
m,n=map(int,input().split())
k=int(math.sqrt(n))
ju=[False for i in range(k+1)]
da=[]
ki=2
co=-1
while ki<k+1:
	if n%ki==0:
		n//=ki
		if ju[ki]:
			da[co]+=1
		else:
			co+=1
			da.append(1)
			ju[ki]=True
	else:
		ki+=1
co+=1
ans=1
for i in range(co):
	si=da[i]
	dp=[[0 for i in range(si+1)] for j in range(m+1)]
	dp[0][0]=1
	for j in range(1,m+1):
		for k in range(si+1):
			for l in range(k+1):
				dp[j][k]=(dp[j-1][l]+dp[j][k])%(1000000007)
	ans=(ans*dp[m][si])%(1000000007)
if n>1:
	ans=((ans*m)%1000000007)
print(ans)


Fixed submission:
import math
m,n=map(int,input().split())
k=int(math.sqrt(n))
ju=[False for i in range(k+1)]
da=[]
ki=2
co=-1
while ki<k+1:
	if n%ki==0:
		n//=ki
		if ju[ki]:
			da[co]+=1
		else:
			co+=1
			da.append(1)
			ju[ki]=True
	else:
		ki+=1
co+=1
ans=1
for i in range(co):
	si=da[i]
	dp=[[0 for i in range(si+1)] for j in range(m+1)]
	dp[0][0]=1
	for j in range(1,m+1):
		for k in range(si+1):
			for l in range(k+1):
				dp[j][k]=(dp[j-1][l]+dp[j][k])%(1000000007)
	ans=(ans*dp[m][si])%(1000000007)
if n>1:
	ans=((ans*m)%1000000007)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n<1200:
  print('ABC')
elif (n<2800)&&(n>=1200):
  print('ARC')
else:
  print('AGC')



Fixed submission:
n=int(input())
if n<1200:
  print('ABC')
elif n>=2800:
  print('AGC')
else:
  print('ARC')

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n<1200:
  print('ABC')
elif n<2800&&n>=1200:
  print('ARC')
else:
  print('AGC')
  

Fixed submission:
n=int(input())
if n<1200:
  print('ABC')
elif n>=2800:
  print('AGC')
else:
  print('ARC')
Buggy python submission (verdict: Runtime Error):
n=int(input())
da=list(map((int,input().split()))
ans=0
for i in da:
  ans+=i-1
print(ans)


Fixed submission:
n=int(input())
da=list(map(int,input().split()))
ans=0
for i in da:
  ans+=i-1
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
da=list(map((int,input().split()))
ans=0
fro i in range da:
  ans+=i-1
print(ans)

Fixed submission:
n=int(input())
da=list(map(int,input().split()))
ans=0
for i in da:
  ans+=i-1
print(ans)
Buggy python submission (verdict: Runtime Error):
s=str(input())
ans=-4
for i in range(4):
  if s[i]='+':
    ans+=2
print(ans)


Fixed submission:
s=str(input())
ans=-4
for i in range(4):
    if s[i]=='+':
        ans+=2
print(ans)

Buggy python submission (verdict: Runtime Error):
s=str(input())
ans=-4
for i in range(4):
  if s[i]='+':
    ans+=2
input(ans)

Fixed submission:
s=str(input())
ans=-4
for i in range(4):
    if s[i]=='+':
        ans+=2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=0
while(n>0):
  S+=n%10
  S//=10
if n&S==0:
  print('Yes')
else:
  print('No')
  
  

Fixed submission:
n=int(input())
k=n
S=0
while(n>0):
  S+=n%10
  n//=10
  #print(S,k)
if k%S==0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
ans=0
for i in range(n):
  x=s[:i]
  y=s[i:]
  X=set(x)
  Y=set(y)
  ans=max(ans,X&Y)
print(ans)

Fixed submission:
n=int(input())
s=input()
ans=0
for i in range(n):
  x=s[:i]
  y=s[i:]
  X=set(list(x))
  Y=set(list(y))
  ans=max(ans,len(X&Y))
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=1
for i in range(32):
  j=i
  while(j<x):
    j*=i
  ans=max(ans,j//i)
print(ans)

Fixed submission:
import math
n=int(input())
ans=1
for i in range(2,int(math.sqrt(n))+1):
  x=1
  while(x<n+1):
    x=i*x
  ans=max(ans,x//i)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
k=int(input())
da=[]
for i in range(1,n+1):
    for j in range(i):
        da.append(s[j:i])
da=list(set(da))
da=sorted(da)
print(da[k-1])

Fixed submission:
s=input()
n=len(s)
k=int(input())
da=[]
for i in range(0,n):
    for j in range(5):
        if i+j<n+1:
            da.append(s[i:i+j+1])
da=list(set(da))
da=sorted(da)
print(da[k-1])
Buggy python submission (verdict: Runtime Error):
n=int(input().split())
if n%10==9 or n/10==9:
  print('Yes')
else:
  print('No')

Fixed submission:
n=int(input())
if n%10==9 or n//10==9:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
n,m,r=map(int,input().split())

ans=3000000000

def permu(ju,now,su,co):
    if now==0:
        global ans
        ans=min(ans,su)
        return
    else:
        for i in range(r):
            if ju[i]:
                ju[i]=False
                su+=dp[co][rute[i]-1]
                permu(ju,now-1,su,rute[i]-1)
                ju[i]=True
                su-=dp[co][rute[i]-1]
    return

rute=list(map(int,input().split()))
dp=[[30000000 for i in range(n)] for i in range(n)]
for i in range(n):
    dp[i][i]=0
for i in range(m):
    a,b,c=map(int,input().split())
    dp[a-1][b-1]=c
    dp[b-1][a-1]=c
for i in range(n):
    for j in range(n):
        for k in range(n):
            dp[j][k]=min(dp[j][i]+dp[i][k],dp[j][k])


ju=[True for i in range(r)]
for i in range(r):
    ju[i]=False
    permu(ju,r-1,0,rute[i]-1)
    ju[i]=True
print(ans)

Fixed submission:
n=int(input())
if n%10==9 or n//10==9:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n,m,r=map(int,input().split())

ans=3000000000

def permu(ju,now,su,co):
    if now==0:
        global ans
        ans=min(ans,su)
        return
    else:
        for i in range(r):
            if ju[i]:
                ju[i]=False
                su+=dp[co][rute[i]-1]
                permu(ju,now-1,su,rute[i]-1)
                ju[i]=True
                su-=dp[co][rute[i]-1]
    return

rute=list(map(int,input().split()))
dp=[[30000000 for i in range(n)] for i in range(n)]
for i in range(n):
    dp[i][i]=0
for i in range(m):
    a,b,c=map(int,input().split())
    dp[a-1][b-1]=c
    dp[b-1][a-1]=c
for i in range(n):
    for j in range(n):
        for k in range(n):
            dp[j][k]=min(dp[j][i]+dp[i][k],dp[j][k])


ju=[True for i in range(r)]
for i in range(r):
    ju[i]=False
    permu(ju,r-1,0,rute[i]-1)
    ju[i]=True
print(ans)

Fixed submission:
n,m,r=map(int,input().split())

ans=3000000000

def permu(ju,now,su,co):
    if now==0:
        global ans
        ans=min(ans,su)
        return
    else:
        for i in range(r):
            if ju[i]:
                ju[i]=False
                su+=dp[co][rute[i]-1]
                permu(ju,now-1,su,rute[i]-1)
                ju[i]=True
                su-=dp[co][rute[i]-1]
    return

rute=list(map(int,input().split()))
dp=[[30000000 for i in range(n)] for i in range(n)]
for i in range(n):
    dp[i][i]=0
for i in range(m):
    a,b,c=map(int,input().split())
    dp[a-1][b-1]=c
    dp[b-1][a-1]=c
for i in range(n):
    for j in range(n):
        for k in range(n):
            dp[j][k]=min(dp[j][i]+dp[i][k],dp[j][k])


ju=[True for i in range(r)]
for i in range(r):
    ju[i]=False
    permu(ju,r-1,0,rute[i]-1)
    ju[i]=True
print(ans)
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
if abs(a-t) > abs(b-t):
  print('B')
else:
  print('A')

Fixed submission:
x,a,b=map(int,input().split())
if abs(a-x) > abs(b-x):
  print('B')
else:
  print('A')
Buggy python submission (verdict: Runtime Error):
X=input()
if X>=30:
  print('Yes')
else:
  print('No')


Fixed submission:
X=int(input())
if X>=30:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

array = list(s)
r = len(s.replace('W', ''))
w = n - r
ans = min(r,w)

i = 0
j = len(array)-1
count = 0

while True:
  while len(array) > i and array[i] == 'R':
    i += 1
    
  while j > 0 and array[j] == 'W':
    j -= 1
    
  if(i>j):
    break
    
  array[i], array[j] = array[j], array[i]
  count += 1
  
print(min(count, ans))

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

array = list(s)
r = len(s.replace('W', ''))
w = n - r
ans = min(r,w)

i = 0
j = len(array)-1
count = 0
for i in range(r):
  if array[i] == 'W':
    count += 1
  
print(min(count, ans))
Buggy python submission (verdict: Runtime Error):
import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))

array = [-1] * (n+1)
array[1] = 0

li = []
li.append(1)

tmp = -1
i = 1
index = 0
while True:
  if array[a[index]] != -1:
    tmp = array[a[index]]
    break
    
  if i == k:
    print(a[index])
    sys.exit(0)
    
  li.append(a[index])
  array[index] = i
  index = a[index] -1
  i += 1
  
  

k -= tmp
d = len(li)

k %= d

print(li[k+tmp])

Fixed submission:
import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))

array = [-1] * (n+1)
array[1] = 0

li = []
li.append(1)

tmp = -1
index = 0
for i in range(2 * (10**5)):
  if array[a[index]] != -1:
    tmp = array[a[index]]
    break
    
  if i == k:
    print(index+1)
    sys.exit(0)
    
  li.append(a[index])
  array[a[index]] = i+1
  index = a[index] -1
  
k -= tmp
d = len(li) - tmp

k %= d

print(li[k+tmp])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

r = len(s.replace('G','').replace('B',''))
g = len(s.replace('R','').replace('B',''))
b = len(s.replace('G','').replace('R',''))

ans = r*g*b

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

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

r = len(s.replace('G','').replace('B',''))
g = len(s.replace('R','').replace('B',''))
b = len(s.replace('G','').replace('R',''))

ans = r*g*b

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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

r = [0] * (n)
g = [0] * (n)
b = [0] * (n)
if s[0] == 'R':
  r[0] = 1
elif s[0] == 'G':
  g[0] = 1
else:
  b[0] = 1

for i in range(n-1):
  r[i+1] = r[i]
  g[i+1] = g[i]
  b[i+1] = b[i]
  
  if s[i+1] == 'R':
    r[i+1] += 1
  elif s[i+1] == 'G':
    g[i+1] += 1
  else:
    b[i+1] += 1
    
ans = 0
for i in range(n):
  if s[i] == 'R':
    for j in range(i+1,n):
      if j+1 >= n:
        continue
        
      if s[j] == 'G':
        ans += b[-1] - b[j]
        if j+j-i < n and s[j+j-i] == 'B':
          ans -= 1
          
      if s[j] == 'B':
        ans += g[-1] - g[j]
        if j+j-i < n and s[j+j-i] == 'G':
          ans -= 1        
        
  if s[i] == 'G':
    for j in range(i+1,n):
      if j+1 >= n:
        continue
        
      if s[j] == 'R':
        ans += b[-1] - b[j]
        if j+j-i < n and s[j+j-i] == 'B':
          ans -= 1        
        
      if s[j] == 'B':
        ans += r[-1] - r[j]
        if j+j-i < n and s[j+j-i] == 'R':
          ans -= 1        
        
  if s[i] == 'B':
    for j in range(i+1,n):
      if j+1 >= n:
        continue
        
      if s[j] == 'G':
        ans += r[-1] - r[j]
        if j+j-i < n and s[j+j-i] == 'R':
          ans -= 1        
        
      if s[j] == 'R':
        ans += g[-1] - g[j]
        if j+j-i < n and s[j+j-i] == 'G':
          ans -= 1        

        
print(ans)
        

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

r = len(s.replace('G','').replace('B',''))
g = len(s.replace('R','').replace('B',''))
b = len(s.replace('G','').replace('R',''))

ans = r*g*b

for i in range(n):
  for j in range(n):
    if i+j+j+2 >= n:
      break
    
    if (not s[i] == s[i+j+1]) and (not s[i+j+1] == s[i+j+j+2]) and (not s[i+j+j+2] == s[i]):
      ans -= 1
      
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect as bs

n,x,y = map(int,input().split())
x -= 1
y -= 1

array = [[-1 for i in range(n)] for j in range(n)]

for i in range(n):
  for j in range(n):
    array[i][j] = abs(j-i)
    
for i in range(n):
  if array[i][x] == array[i][y]:
    pass
  
  elif array[i][x] > array[i][y]:
    array[i][x] = array[i][y] + 1
    
    index = x - 1
    while True:
      if index < 0 or array[i][index] <= array[i][index+1]:
        break
        
      array[i][index] = array[i][index+1] + 1
      index -= 1
      
    index = x + 1
    while True:
      if index >= n or array[i][index] <= array[i][index-1]:
        break
        
      array[i][index] = array[i][index-1] + 1
      index += 1
      
  else:
    array[i][y] = array[i][x] + 1
    
    index = y - 1
    while True:
      if index < 0 or array[i][index] <= array[i][index+1]:
        break
        
      array[i][index] = array[i][index+1] + 1
      index -= 1
      
    index = y + 1
    while True:
      if index >= n or array[i][index] <= array[i][index-1]:
        break
        
      array[i][index] = array[i][index-1] + 1
      index += 1
      
ans = [0] * (n+1)
for i in range(n):
  for j in range(i, n):
    tmp = array[i][j]
    ans[tmp] += 1
    
for i in range(1,n):
  print(ans[i])
  

Fixed submission:
n,x,y = map(int,input().split())
x -= 1
y -= 1

array1 = [0] * n
array2 = [0] * n

for i in range(x, y+1):
  array1[i] = min(i-x, y-i+1)
  array2[i] = min(i-x+1, y-i)

ans = [0] * (n+1)
dis = [[0 for i in range(n)] for i in range(n)]


for i in range(n):
  if i <= x:
    for j in range(i+1,n):
      if y <= j:
        tmp = (x-i) + (j-y) + 1
      elif j <= x:
        tmp = j-i
      else:
        tmp = (x-i) + array1[j]
        
      ans[tmp] += 1
      dis[i][j] = tmp
      
  elif y <= i:
    for j in range(i+1,n):
      ans[j-i] += 1
      dis[i][j] = j-i
      
  else:
    for j in range(i+1,n):
      if y <= j:
        tmp = (j-y) + array2[i]
      else:
        tmp = min(j-i, (y-x+1)-(j-i))
        
      ans[tmp] += 1
      dis[i][j] = tmp

for i in range(1,n):
  print(ans[i])