Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
an=(l*(l+1))%2019

for i in range(l,r):
    for j in range(i+1,r+1):
        if (i*j)%2019 < an:
            an=(i*j)%2019

print(an)

Fixed submission:
l,r=map(int,input().split())
an=(l*(l+1))%2019

for i in range(l,r):
    for j in range(i+1,r+1):
        if (i*j)%2019 < an:
            an=(i*j)%2019
        if an==0:
            print("0")
            exit()

print(an)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
an=[1]*n
for i in range(m):
    l,r=map(int,input().split())
    for j in range(1,n+1):
        if l <= j <= r:
            pass
        else:
            an[j-1]=0

print(sum(an))

Fixed submission:
n,m=map(int,input().split())
lm=0
rm=10**9

for i in range(m):
    l,r=map(int,input().split())
    lm=max(lm,l)
    rm=min(rm,r)

print(max(0,rm-lm+1))
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N=map(int,input().split())
ans=0

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

print(ans)

Fixed submission:
R,G,B,N=map(int,input().split())
ans=0

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

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    print(s[l-1:r].count("AC"))

Fixed submission:
n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
for i in range(n):
    if s[i:i+2]=="AC":
        t[i+1]=t[i]+1
    else:
        t[i+1]=t[i]

for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    print(s[l-1:r].count("AC"))

Fixed submission:
n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
for i in range(n):
    if s[i:i+2]=="AC":
        t[i+1]=t[i]+1
    else:
        t[i+1]=t[i]

for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
s=list(map(int,input()))
an=0
i=0

if len(s) < 2:
    print("0")
    exit()

while 1:
    if s[i]+s[i+1]==1:
        an+=2
        del s[i:i+2]
        i=0
    else:
        i+=1
    if i+1 == len(s) or len(s)==0:
        print(an)
        exit()

Fixed submission:
s=list(map(int,input()))
print(min(s.count(0),s.count(1))*2)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(map(int,input()))
an=0
i=0

if len(s) < 2:
    print("0")
    exit()

while 1:
    if s[i]+s[i+1]==1:
        an+=2
        del s[i:i+2]
        i=0
    else:
        i+=1
    if i+1 == len(s) or len(s)==0:
        print(an)
        exit()

Fixed submission:
s=list(map(int,input()))
print(min(s.count(0),s.count(1))*2)
Buggy python submission (verdict: Runtime Error):
a=[]
a.append(s)

while 1:
    if s%2==0:
        s=s/2
        a.append(s)
    else:
        s=3*s+1
        a.append(s)
    if len(a)!=len(set(a)):
        print(len(a))
        exit()

Fixed submission:
s=int(input())
a=[]
a.append(s)

while 1:
    if s%2==0:
        s=s/2
        a.append(s)
    else:
        s=3*s+1
        a.append(s)
    if len(a)!=len(set(a)):
        print(len(a))
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
MV=[list(map(int, input().split())) for _ in range(N)]
dp=[0]*(W+1)

for w,v in MV:
    for tw in range(W,w-1,-1):
        dp[tw]=max(dp[tw],dp[tw-w]+v)
        #print(dp,tw)

print(max(dp))

Fixed submission:
N,W=map(int,input().split())
MV=[list(map(int, input().split())) for _ in range(N)]
dp=[0]*(W+1)

for w,v in MV:
    for tw in range(W,w-1,-1):
        dp[tw]=max(dp[tw],dp[tw-w]+v)
        #print(dp,tw)

print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = 0

for i in range(n+1):
    i2 = list(str(i))
    if i2.count("3") >= 1 and i2.count("5") >= 1 and i2.count("7") >= 1:
        if i2.count("3") + i2.count("5") + i2.count("7") == len(i2):
            c += 1

print(c)

Fixed submission:
import itertools
n=input()
ans=0

for i in range(3,len(n)+1):
    li=itertools.product([3,5,7],repeat=i)
    
    for j in li:
        t=''.join(map(str,j))
        
        if int(t)<=int(n):
            if t.count("3")>=1 and t.count("5")>=1 and t.count("7")>=1:
                ans+=1

print(ans)
Buggy python submission (verdict: Runtime Error):
import collections
n=int(input())
v=list(map(int,input().split()))

li1=[]
li2=[]

for i in range(n):
    if i%2==0:
        li1.append(v[i])
    else:
        li2.append(v[i])

li1=collections.Counter(li1).most_common()
li2=collections.Counter(li2).most_common()

if li1[0][0]!=li2[0][0]:
    print(n-li1[0][1]-li2[0][1])
else:
    if len(li1)==1 and len(li2)==1:
        print(n//2)
    elif len(li1)==1:
        print(n-li1[0][1]-li2[1][1])
    elif len(li2)==1:
        print(n-li1[1][1]-li2[0][1])
    else:
        print(min(n-li1[0][1]-li2[1][1]),n-li1[1][1]-li2[0][1])



Fixed submission:
import collections
n=int(input())
v=list(map(int,input().split()))

li1=[]
li2=[]

for i in range(n):
    if i%2==0:
        li1.append(v[i])
    else:
        li2.append(v[i])

li1=collections.Counter(li1).most_common()
li2=collections.Counter(li2).most_common()

if li1[0][0]!=li2[0][0]:
    print(n-li1[0][1]-li2[0][1])
else:
    if len(li1)==1 and len(li2)==1:
        print(n//2)
    elif len(li1)==1:
        print(n-li1[0][1]-li2[1][1])
    elif len(li2)==1:
        print(n-li1[1][1]-li2[0][1])
    else:
        print(min(n-li1[0][1]-li2[1][1],n-li1[1][1]-li2[0][1]))
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
    
print(lcm(2,n))

Fixed submission:
n=int(input())

if n%2==0:
    print(n)
else:
    print(n*2)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=0
flug=1

while 1:
    flug=0
    for i in range(n):
        if a[i]%2==0 and flug==0:
            a[i]=a[i]//2
            flug=1
        else:
            a[i]=a[i]*3
    else:
        if flug==1:
            ans+=1
        else:
            print(ans)
            exit()

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0

for i in range(n):
    while a[i]%2==0:
        a[i]=a[i]//2
        ans+=1

print(ans)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
s=[]
s.append("."*(h+2))

for i in range(w):
    s.append("."+input()+".")
    
s.append("."*(h+2))

for i in range(1,w+1):
    for j in range(1,h+1):
        #print(i,j)
        if s[i][j]=="#":
            if s[i][j+1]=="#" or s[i][j-1]=="#" or s[i+1][j]=="#" or s[i-1][j]=="#":
                pass
            else:
                print("No")
                exit()
        

print("Yes")

Fixed submission:
h,w=map(int,input().split())
s=[]
s.append("."*(w+2))

for i in range(h):
    s.append("."+input()+".")
    
s.append("."*(w+2))

for i in range(1,h+1):
    for j in range(1,w+1):
        #print(i,j)
        if s[i][j]=="#":
            if s[i][j+1]=="#" or s[i][j-1]=="#" or s[i+1][j]=="#" or s[i-1][j]=="#":
                pass
            else:
                print("No")
                exit()
        

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k=map(int,input().split())

for i in range(a,b+1):
    if i<a+k or i>b-k:
        print(i)

Fixed submission:
a,b,k=map(int,input().split())
li=[]

for i in range(a,min(b+1,a+k)):
    li.append(i)

for j in range(b,max(a-1,b-k),-1):
    li.append(j)

li=list(set(li))
li.sort()

for i in li:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n=int(input())
li=[]
ans=0

for i in range(n):
    s=input()
    if s[0]=="M" or s[0]=="A" or s[0]=="R" or s[0]=="C" or s[0]=="H":
        li.append(s)

tm=(list(itertools.combinations(li,3)))

for j in tm:
    if j[0][0]!=j[1][0] and j[1][0]!=j[2][0] and j[2][0]!=j[0][0]:
        ans+=1

print(ans)
        

Fixed submission:
import itertools

n=int(input())
li=[]

for i in range(n):
    li.append(input()[0])

tm=list(itertools.combinations(["M","A","R","C","H"],3))
ans=0

for j1,j2,j3 in tm:
    ans+=li.count(j1)*li.count(j2)*li.count(j3)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n=int(input())
li=[]
ans=0

for i in range(n):
    s=input()
    if s[0]=="M" or s[0]=="A" or s[0]=="R" or s[0]=="C" or s[0]=="H":
        li.append(s)

tm=(list(itertools.combinations(li,3)))

for j in tm:
    if j[0][0]!=j[1][0] and j[1][0]!=j[2][0] and j[2][0]!=j[0][0]:
        ans+=1

print(ans)

Fixed submission:
import itertools

n=int(input())
li=[]

for i in range(n):
    li.append(input()[0])

tm=list(itertools.combinations(["M","A","R","C","H"],3))
ans=0

for j1,j2,j3 in tm:
    ans+=li.count(j1)*li.count(j2)*li.count(j3)

print(ans)
Buggy python submission (verdict: Runtime Error):
n=input()

if n[0]==n[1]==n[2] or n[1]==n[2]==n[3] or n[2]==n[3]==n[4] or n[0]==n[1]==n[2]==n[3]:
    print("Yes")
else:
    print("No")


Fixed submission:
n=input()

if n[0]==n[1]==n[2] or n[1]==n[2]==n[3]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import collections

n=int(input())
d=list(map(int,input().split()))
li=collections.Counter(d)
m=int(input())
t=list(map(int,input().split()))
co=[0]*200001

for i in t:
    if (li[i]-co[i])>0:
        co[i]+=1
    else:
        print("NO")
        exit()

print("YES")

Fixed submission:
import collections

n=int(input())
d=list(map(int,input().split()))
d=collections.Counter(d)
m=int(input())
t=list(map(int,input().split()))
t=collections.Counter(t)


for i in t:
    if t[i]>d[i]:
        print("NO")
        exit()
print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
li=[]

for i in range(n):
    a=input()
    if a in li:
        li.remove(a)
    else:
        li.append(a)

print(len(li))

Fixed submission:
n=int(input())
li=[]
ans=0
fl=1

for i in range(n):
    li.append(int(input()))

li.sort()

for j in range(n-1):
    if li[j]!=li[j+1]:
        if fl%2==1:
            ans+=1
            fl=1
        else:
            fl=1
    else:
        fl+=1


if fl%2==1:
    ans+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
li=[]

for i in range(n):
    a=input()
    if a in li:
        li.remove(a)
    else:
        li.append(a)

print(len(li))

Fixed submission:
n=int(input())
li=[]
ans=0
fl=1

for i in range(n):
    li.append(int(input()))

li.sort()

for j in range(n-1):
    if li[j]!=li[j+1]:
        if fl%2==1:
            ans+=1
            fl=1
        else:
            fl=1
    else:
        fl+=1


if fl%2==1:
    ans+=1

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

n=int(input())
ans=0
ans=int(input())
if n==1:
    print(ans)
    exit()

for i in range(n-1):
    t=int(input())
    ans=lcm(ans,t)

print(ans)
    

Fixed submission:
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

n=int(input())
ans=0
ans=int(input())
if n==1:
    print(ans)
    exit()

for i in range(n-1):
    t=int(input())
    ans=lcm(ans,t)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
li=[]

for i in range(m):
    if ab[i][0]==1:
        li.append(ab[i][1])

li=list(set(li))

for j in range(m):
    if ab[j][0] in li:
        if ab[j][1]==n:
            print("POSSIBLE")
            exit()

print("IMPOSSIBLE")

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

sa=set()
sb=set()

for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        sb.add(b)
    if b==n:
        sa.add(a)

if sa&sb:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
li=[]

for i in range(m):
    if ab[i][0]==1:
        li.append(ab[i][1])

for j in range(m):
    if ab[j][0] in li:
        if ab[j][1]==n:
            print("POSSIBLE")
            exit()

print("IMPOSSIBLE")

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

sa=set()
sb=set()

for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        sb.add(b)
    if b==n:
        sa.add(a)

if sa&sb:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
li=[]

for i in range(m):
    if ab[i][0]==1:
        li.append(ab[i][1])

for j in range(m):
    if ab[j][0] in li:
        if ab[j][1]==n:
            print("POSSIBLE")
            exit()

print("IMPOSSIBLE")

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

sa=set()
sb=set()

for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        sb.add(b)
    if b==n:
        sa.add(a)

if sa&sb:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
sx,sy,tx,ty=map(int,input().split())
ans=[[] for _ in range(4)]

x=sx
y=sy

while y!=ty or x!=tx:
    if y<ty:
        y+=1
        ans[0].append("U")
        ans[1].append("D")
    elif x<tx:
        x+=1
        ans[0].append("R")
        ans[1].append("L")
       
x=sx-1
y=sy
ans[2].append("L")
ans[3].append("R")

while 1:
    if y<ty+1:
        y+=1
        ans[2].append("U")
        ans[3].append("D")
    elif x<tx:
        x+=1
        ans[2].append("R")
        ans[3].append("L")
    else:
        ans[2].append("D")
        ans[3].append("U")
        break


print(*ans[0],*ans[1],*ans[2],*ans[3],sep="")

Fixed submission:
sx,sy,tx,ty=map(int,input().split())
ans=[[] for _ in range(4)]

x=sx
y=sy

while y!=ty or x!=tx:
    if y<ty:
        y+=1
        ans[0].append("U")
        ans[1].append("D")
    elif x<tx:
        x+=1
        ans[0].append("R")
        ans[1].append("L")
       
x=sx-1
y=sy
ans[2].append("L")
ans[3].append("R")

while 1:
    if y<ty+1:
        y+=1
        ans[2].append("U")
        ans[3].append("D")
    elif x<tx:
        x+=1
        ans[2].append("R")
        ans[3].append("L")
    else:
        ans[2].append("D")
        ans[3].append("U")
        break

li=[]

for i in range(4):
    for j in ans[i]:
        li.append(j)

print(''.join(li))

#print(*ans[0],*ans[1],*ans[2],*ans[3],sep="")

Buggy python submission (verdict: Runtime Error):
sx,sy,tx,ty=map(int,input().split())
ans=[[] for _ in range(4)]

x=sx
y=sy

while y!=ty or x!=tx:
    if y<ty:
        y+=1
        ans[0].append("U")
        ans[1].append("D")
    elif x<tx:
        x+=1
        ans[0].append("R")
        ans[1].append("L")
       
x=sx-1
y=sy
ans[2].append("L")
ans[3].append("R")

while 1:
    if y<ty+1:
        y+=1
        ans[2].append("U")
        ans[3].append("D")
    elif x<tx:
        x+=1
        ans[2].append("R")
        ans[3].append("L")
    else:
        ans[2].append("D")
        ans[3].append("U")
        break


print(*ans[0],*ans[1],*ans[2],*ans[3],sep="")
print()

Fixed submission:
sx,sy,tx,ty=map(int,input().split())
ans=[[] for _ in range(4)]

x=sx
y=sy

while y!=ty or x!=tx:
    if y<ty:
        y+=1
        ans[0].append("U")
        ans[1].append("D")
    elif x<tx:
        x+=1
        ans[0].append("R")
        ans[1].append("L")
       
x=sx-1
y=sy
ans[2].append("L")
ans[3].append("R")

while 1:
    if y<ty+1:
        y+=1
        ans[2].append("U")
        ans[3].append("D")
    elif x<tx:
        x+=1
        ans[2].append("R")
        ans[3].append("L")
    else:
        ans[2].append("D")
        ans[3].append("U")
        break

li=[]

for i in range(4):
    for j in ans[i]:
        li.append(j)

print(''.join(li))

#print(*ans[0],*ans[1],*ans[2],*ans[3],sep="")
Buggy python submission (verdict: Runtime Error):
from collections import deque
INF = 10000000
N, M = map(int, input().split())
# 隣接リストを作成する
dist = [INF for _ in range(M)]
pre = [-1 for _ in range(M)]
to = [[] for _ in range(100005)] 

# 隣接リスト：to[v]の中にはvに隣接している要素が入っている
for i in range(M):
    a, b = map(int, input().split())
    a = a - 1
    b = b - 1
    to[a].append(b)
    to[b].append(a)

queue = deque()
dist[0] = 0
queue.append(0)
while(len(queue) != 0):
    v = queue.popleft()
    for u in to[v]:
        # もう値が設定されていれば更新しない
        if (dist[u] != INF):
            continue
        dist[u] = dist[v] + 1
        pre[u] = v
        queue.append(u)

print("Yes")
for i in range(N):
    if (i == 0):
        continue
    ans = pre[i]
    ans += 1
    print(ans)

Fixed submission:
from collections import deque
 
N,M=map(int,input().split())
 
graph=[[]for _ in range(N+1)]
 
for _ in range(M):
    A,B=map(int,input().split())
    graph[A].append(B)
    graph[B].append(A)
 
dist=[-1]*(N+1)
dist[0]=0
dist[1]=0
 
D=deque()
D.append(1)
 
while D:
    V=D.popleft()
    for i in graph[V]:
        if dist[i]!=-1:
            continue
        dist[i]=V
        D.append(i)
 
print('Yes')
for j in dist[2:]:
    print(j)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
 
INF         = 10000
VISITED     = 1
NOT_VISITED = 0

N, M = map(int, input().split())
route = [[INF for _ in range(N)] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    route[a-1][b-1] = 1
    route[b-1][a-1] = 1

size = len(route)
cost = [INF for _ in range(size)]
visit = [NOT_VISITED for _ in range(size)]
before = [None for _ in range(size)]
cost[0] = 0
while True:
    min = INF
    for i in range(size):
        if visit[i] == NOT_VISITED and cost[i] < min:
            x = i
            min = cost[x]
    if min == INF:
        break
    visit[x] = VISITED
 
    for i in range(size):
        if cost[i] > route[x][i] + cost[x]:
            cost[i] = route[x][i] + cost[x]
            before[i] = x

ans = [-1 for _ in range(size)]
for i in range(1, size):
    point = i
    to = before[point]
    while True:
        if to == 0:
            ans[point] = 0
            break
        elif ans[point] != -1 and to != ans[point]:
            print("No")
            sys.exit()
        ans[point] = to
        point = to
        to = before[point]

print("Yes")
for a in ans[1:]:
    print(a+1)


Fixed submission:
from collections import deque
 
N,M=map(int,input().split())
 
graph=[[]for _ in range(N+1)]
 
for _ in range(M):
    A,B=map(int,input().split())
    graph[A].append(B)
    graph[B].append(A)
 
dist=[-1]*(N+1)
dist[0]=0
dist[1]=0
 
D=deque()
D.append(1)
 
while D:
    V=D.popleft()
    for i in graph[V]:
        if dist[i]!=-1:
            continue
        dist[i]=V
        D.append(i)
 
print('Yes')
for j in dist[2:]:
    print(j)
Buggy python submission (verdict: Time Limit Exceeded):
import math
# メモを残す
K = int(input()) + 1
dic = {}
ans = 0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            # 大きい順にソートする
            l = tuple(sorted([a,b,c]))
            if l in dic:
                ans += dic[l]
            else:
                # 最大公約数を求める
                tmp_l = tuple([l[0], l[1]])
                if tmp_l in l:
                    gcd_ab = l[tmp_l]
                else:
                    gcd_ab = math.gcd(l[0], l[1])
                    dic[tmp_l] = gcd_ab

                if gcd_ab < c:
                    tmp_l = tuple([gcd_ab, c])
                else:
                    tmp_l = tuple([c, gcd_ab])

                if tmp_l in l:
                    gcd = l[tmp_l]
                else:
                    gcd = math.gcd(gcd_ab, c)
                    dic[tmp_l] = gcd
                dic[l] = gcd
                ans+=gcd
print(ans)

Fixed submission:
from math import gcd
k = int(input())
ans = 0
for a in range(1, k+1):
  for b in range(1, k+1):
    for c in range(1, k+1):
      ans += gcd(a, gcd(b, c))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
R = [i+1 for i in range(N) if S[i] == 'R']
G = [i+1 for i in range(N) if S[i] == 'G']
B = [i+1 for i in range(N) if S[i] == 'B']

len_r = len(R)
len_g = len(G)
len_b = len(B)

if len_r > len_g and len_r > len_b:
    X = G
    Y = B
    Z = R
elif len_g > len_r and len_g > len_b:
    X = R
    Y = B
    Z = G
elif len_b > len_g and len_b > len_r:
    X = G
    Y = R
    Z = B

ans = 0

for r in X:
    for g in Y:
        tmp = 0
        if r < g:
            a = r
            b = g
        else:
            a = g
            b = r
        i = b-a
        if a-i in Z:
            tmp+=1
        if b+i in Z:
            tmp+=1
        if a+(i/2) == b -(i/2) and a+(i/2) in Z:
            tmp += 1
        ans += len(Z) - tmp
print(ans)

Fixed submission:
n=int(input())
s=input()
c=s.count
a=c('R')*c('G')*c('B')
for i in range(n):
  for j in range(i+2,n,2):
    if s[i]!=s[i+j>>1]!=s[j]!=s[i]:
      a-=1
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
R = [i+1 for i in range(N) if S[i] == 'R']
G = [i+1 for i in range(N) if S[i] == 'G']
B = [i+1 for i in range(N) if S[i] == 'B']

ans = 0

for r in R:
    for g in G:
        tmp = 0
        a,b = sorted([r,g])
        i = b-a
        if a-i in B:
            tmp+=1
        if b+i in B:
            tmp+=1
        if a+(i/2) == b -(i/2) and a+(i/2) in B:
            tmp += 1
        ans += len(B) - tmp
print(ans)

Fixed submission:
n=int(input())
s=input()
c=s.count
a=c('R')*c('G')*c('B')
for i in range(n):
  for j in range(i+2,n,2):
    if s[i]!=s[i+j>>1]!=s[j]!=s[i]:
      a-=1
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
R = [i+1 for i in range(N) if S[i] == 'R']
G = [i+1 for i in range(N) if S[i] == 'G']
B = [i+1 for i in range(N) if S[i] == 'B']

ans = 0

for r in R:
    for g in G:
        for b in B:
            a,b,c = sorted([r,g,b])
            if b - a != c - b:
                ans += 1
print(ans)

Fixed submission:
n=int(input())
s=input()
c=s.count
a=c('R')*c('G')*c('B')
for i in range(n):
  for j in range(i+2,n,2):
    if s[i]!=s[i+j>>1]!=s[j]!=s[i]:
      a-=1
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from itertools import combinations
N = int(input())
items = list(map(int, input().split()))
counts = Counter(items)
cobinations = {}
count_sum = 0
for key,value in counts.items():
  if value not in cobinations:
    if value > 1:
      tmp_key = list(range(value))
      count = len(list(combinations(tmp_key, 2)))
      cobinations[value] = count
    else:
      cobinations[value] = 0
  count_sum+=cobinations[value]

for key in items:
  value = counts[key]
  if value - 1 not in cobinations:
    if value - 1 > 1:
      tmp_key = list(range(value-1))
      count = len(list(combinations(tmp_key, 2)))
      cobinations[value-1] = count
    else:
      cobinations[value-1] = 0
  
  before = cobinations[value]
  after = cobinations[value-1]
  print(count_sum - before + after)

Fixed submission:
from operator import mul
from functools import reduce
from collections import Counter
from itertools import combinations

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
items = list(map(int, input().split()))
counts = Counter(items)
cobinations = {}
count_sum = 0

for key,value in counts.items():
  if value not in cobinations:
    if value > 1:
      count = cmb(value, 2)
      cobinations[value] = count
    else:
      cobinations[value] = 0
  count_sum+=cobinations[value]

for key in items:
  value = counts[key]
  if value - 1 not in cobinations:
    if value - 1 > 1:
      # tmp_key = list(range(value-1))
      # count = len(list(combinations(tmp_key, 2)))
      # cobinations[value-1] = count
      count = cmb(value-1, 2)
      cobinations[value-1] = count
    else:
      cobinations[value-1] = 0
  
  before = cobinations[value]
  after = cobinations[value-1]
  print(count_sum - before + after)