Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
tree = {}

for i in range(M):
    a, b, c = map(int, input().split())
    v= tree.get(a,[])
    v.append([b, c])
    tree[a] = v

def has_loop(tree):
    pass

m = []
def cost(v, c, visited):
    if v in visited:
        print('inf')
        exit()
    b = tree.get(v, None)
    if b is None:
        return 
    elif len(b) == 1 and tree.get(b[0][0],None) == None:
        j = c+b[0][1]
        m.append(j)
    else:
        for b, c2 in b: 
            cost(b, c+c2, visited + [v])

if has_loop(tree):
    print('inf')
    exit()

cost(1, 0, [])
print(max(m))


Fixed submission:
A,B,C = map(int,input().split())
if A <= C and C <= B:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())

l = []

for i in range(N):
    a, b = map(int, input().split())
    l += [a] * b

print(sorted(l)[K-1])

Fixed submission:
A,B,C = map(int,input().split())
if A <= C and C <= B:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):

N, K = map(int,input().split())

l = []

for i in range(N):
    a, b = map(int, input().split())
    l += [a] * b

print(sorted(l)[K-1])

Fixed submission:
N, K = map(int,input().split())

l = []

for i in range(N):
    a, b = map(int, input().split())
    l.append((a,b))
def c(x):
    return  x[0]
l = sorted(l, key=c)
t = 0
for a,b in l:
    t2 = t
    t += b
    if t2 <= K and t >= K:
        break

print(a)
Buggy python submission (verdict: Runtime Error):
N,W = map(int, input().split())
dp = [[None] * (W+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
    w, v = map(int, input().split())
    for j in range(W):#dp[i]:
        if dp[i][j] == None:
            continue
        if j + w <= W:
            dp[i+1][j+w] = max(dp[i][j] + v, dp[i][j+w] or 0)
        dp[i+1][j] = dp[i][j]
print(max([i for i in dp[N] if i != None]))

Fixed submission:
from collections import Counter
from itertools import product

N, W = map(int,input().split())
w2vl = {}
lw = []

for i in range(N):
    w, v = map(int, input().split())
    lw.append(w)
    if w2vl.get(w, None) is None:
        w2vl[w] = []
    w2vl[w].append(v)
    w2vl[w] = sorted(w2vl[w],reverse=True)

ct = Counter(lw)

args = []
ws = []
for w in range(lw[0], lw[0]+4):
    if ct[w] == 0: continue
    args.append(range(ct[w]+1))
    ws.append(w)

a = 0
for i in product(*args):
    w = sum(map(lambda x: x[0] * x[1] ,zip(i,ws)))
    if 1 > w or w > W: continue
    v = sum([sum(w2vl[k][:j]) for j,k in zip(i,ws)])
    if a < v:
        a = v

print(a)
Buggy python submission (verdict: Runtime Error):
a,b=map(int, input().split())
if a > b: print('GREATER')
elif a < b:print('LESS')
else: print('EQUAL')

Fixed submission:
a = int(input())
b = int(input())
if a > b: print('GREATER')
elif a < b:print('LESS')
else: print('EQUAL')

Buggy python submission (verdict: Runtime Error):
a,b=map(int, input().split())
if a > b: print('GREATER')
elif: a < b:print('LESS')
else: print('EQUAL')

Fixed submission:
a = int(input())
b = int(input())
if a > b: print('GREATER')
elif a < b:print('LESS')
else: print('EQUAL')
Buggy python submission (verdict: Time Limit Exceeded):
from numpy import cumsum,copy
n = int(input())
a = cumsum([int(i) for i in input().split()])
b = copy(a)
ans1 = ans2 = 0
sign = 1
for i in range(n):
    if a[i] * sign <= 0:
        k = abs(a[i] - sign)
        a += sign*k
        ans1 += k
    sign *= -1
sign = -1
for i in range(n):
    if b[i] * sign <= 0:
        k = abs(b[i] - sign)
        b += sign*k
        ans2 += k
    sign *= -1
print(min(ans1, ans2))    

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b = a[::]
ans1 = ans2 = 0
sign = 1
total = 0
for i in range(n):
    total += a[i]
    if total * sign <= 0:
        k = abs(total - sign)
        ans1 += k
        total = sign
    sign *= -1

sign = -1
total = 0
for i in range(n):
    total += b[i]
    if total * sign <= 0:
        k = abs(total - sign)
        ans2 += k
        total = sign
    sign *= -1
print(min(ans1, ans2))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from functools import reduce 
n=int(input())
print(''.join(sorted(list(reduce(lambda a,b: Counter(a) & Counter(b), [sorted(input()) for i in range(n)]).elements()))))

Fixed submission:
from collections import Counter
from functools import reduce 
n=int(input())
if n == 1: 
    print(''.join((sorted(input()))))
else:
    print(''.join(sorted(list(reduce(lambda a,b: Counter(a) & Counter(b), [sorted(input()) for i in range(n)]).elements()))))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A = A[::-1]
B = B[::-1]

ans = 0
for a, b in zip(A, B):
    a += ans
    if a % b!= 0:
        m = b - (a % b) 
    ans += m
print(ans)

Fixed submission:
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A = A[::-1]
B = B[::-1]

ans = 0
for a, b in zip(A, B):
    a += ans
    if a % b != 0: 
        m = b - (a % b) 
        ans += m
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A = A[::-1]
B = B[::-1]

ans = 0
for a, b in zip(A, B):
    a += ans
    m = b - (a % b) if b != 1 else 0
    m = b if a == 0
    ans += m
print(ans)

Fixed submission:
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A = A[::-1]
B = B[::-1]

ans = 0
for a, b in zip(A, B):
    a += ans
    if a % b != 0: 
        m = b - (a % b) 
        ans += m
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import  product
K, S = map(int, input().split())
ans = 0
for x,y in product(range(K+1),repeat=2):
    z = S - x - y
    if 0 <= z <= K and x + y + z == S:
        ans += 1
print(ans)

Fixed submission:
from itertools import  product
K, S = map(int, input().split())
ans = 0
for x,y in product(range(K+1),repeat=2):
    z = S - x - y
    if 0 <= z <= K and x + y + z == S:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
ans = 0
for x in range(K+1):
    if S - x > 2 * K:
        continue
    for y in range(K+1):
        z = S - x - y
        if 0 <= z <= K and x + y + z == S:
            ans += 1
print(ans)


Fixed submission:
from itertools import  product
K, S = map(int, input().split())
ans = 0
for x,y in product(range(K+1),repeat=2):
    z = S - x - y
    if 0 <= z <= K and x + y + z == S:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
ans = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if 0 <= z <= K and x + y + z == S:
            ans += 1
print(ans)

Fixed submission:
from itertools import  product
K, S = map(int, input().split())
ans = 0
for x,y in product(range(K+1),repeat=2):
    z = S - x - y
    if 0 <= z <= K and x + y + z == S:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int,input().split())
from itertools import product
ans = 0
for x,y,z in product(range(K+1),repeat=3):
    if x + y + z == S:ans += 1
print(ans)


Fixed submission:
from itertools import  product
K, S = map(int, input().split())
ans = 0
for x,y in product(range(K+1),repeat=2):
    z = S - x - y
    if 0 <= z <= K and x + y + z == S:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
K, S = map(int,input().split())
from itertools import product
ans = 0
for x,y,z in product(range(K+1),3):
  if x + y + z == S:ans += 1
print(ans)

Fixed submission:
from itertools import  product
K, S = map(int, input().split())
ans = 0
for x,y in product(range(K+1),repeat=2):
    z = S - x - y
    if 0 <= z <= K and x + y + z == S:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
print(b//x - (a-1)//x

Fixed submission:
a, b, x = map(int, input().split())
print(b//x - (a-1)//x)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
ans = 0
if S.count('W') == 0 or S.count('B') == 0:
    print(0)
    exit()
a = S[0]
while True:
    for i, s in enumerate(S):
        if s != a: break
    S = S[i:]
    a = S[0]
    ans += 1
    if S.count('W') == 0 or S.count('B') == 0:break
print(ans)

Fixed submission:
from collections import Counter
S = input()
ans = 0
c = Counter(S)
if c['W'] == 0 or c['B'] == 0:
    print(0)
    exit()
a = S[0]
while True:
    for i, s in enumerate(S):
        if s != a: break
    S = S[i:]
    c[a] -= i
    a = S[0]
    ans += 1
    if c['W'] == 0 or c['B'] == 0:break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, a = map(int, input().split())
x = [int(i) for i in input().split()]
X = max(a, *x)
dp = [[[0 for k in range(n*X+1)] for j in range(n+1)]for i in range(n+1)] #full((n+1, n+1, n*X+1), 0)
dp[0][0][0] = 1
for j in range(n+1):
    for k in range(n+1):
        for s in range(n*X+1):
            if j == k == s == 0: continue
            if j >= 1 and s < x[j-1]: dp[j][k][s] = dp[j-1][k][s]
            elif j >= 1 and k >= 1 and s >= x[j-1]: dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
            else: dp[j][k][s] = 0
print(sum([dp[n][k][k*a] for k in range(1, n+1)]))

Fixed submission:
n, a = map(int, input().split())
x = [int(i) for i in input().split()]
X = max(a, *x)
dp = [[[0 for k in range(n*X+1)] for j in range(n+1)]for i in range(n+1)] #full((n+1, n+1, n*X+1), 0)
dp[0][0][0] = 1
for j in range(n+1):
    for k in range(n+1):
        for s in range(n*X+1):
            if j == k == s == 0: continue
            if j >= 1 and s < x[j-1]: dp[j][k][s] = dp[j-1][k][s]
            elif j >= 1 and k >= 1 and s >= x[j-1]: dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
            else: dp[j][k][s] = 0
print(sum([dp[n][k][k*a] for k in range(1, n+1)]))
Buggy python submission (verdict: Runtime Error):
using System;

namespace myApp {
    class Program {
        static void Main (string[] args) {
            int a, v;
            int b, w;
            int t;
            string[] str = Console.ReadLine ().Split (' ');
            a = int.Parse (str[0]);
            v = int.Parse (str[1]);
            string[] str1 = Console.ReadLine ().Split (' ');
            b = int.Parse (str1[0]);
            w = int.Parse (str1[1]);
            t = int.Parse (Console.ReadLine ());

            if (a <= b) {
                if (a + v * t >= b + t * w) {
                    System.Console.WriteLine ("YES");
                } else {
                    System.Console.WriteLine ("NO");
                }
            } else {
                if (a - v * t <= b - w * t) {
                    System.Console.WriteLine ("YES");
                } else {
                    System.Console.WriteLine ("NO");
                }
            }
        }
    }
}

Fixed submission:
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a<=b:
    if (a+v*t>=b+w*t) :
        print("YES")
    else:
        print("NO")
else:
    if (a-v*t<=b-w*t) :
        print("YES")
    else:
        print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
import  functools
import operator
prod=functools.partial(functools.reduce, operator.mul)

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

ans=prod(a)

if ans>10**18:
    print(-1)
else:
    print(ans)


Fixed submission:
n=int(input())
import  functools
import operator
prod=functools.partial(functools.reduce, operator.mul)
a=list(map(int,input().split()))
a.sort(reverse=True)
if a[0]*a[1]>10**18 and a[-1]!=0:
    print(-1)
    exit()
if a[-1]==0:
    print(0)
    exit()
    
ans=prod(a)

if ans>10**18:
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
import  functools
import operator
prod=functools.partial(functools.reduce, operator.mul)

a=list(map(int,input().split()))
ans=prod(a)

if ans>10**18:
    print(-1)
else:
    print(ans)


Fixed submission:
n=int(input())
import  functools
import operator
prod=functools.partial(functools.reduce, operator.mul)
a=list(map(int,input().split()))
a.sort(reverse=True)
if a[0]*a[1]>10**18 and a[-1]!=0:
    print(-1)
    exit()
if a[-1]==0:
    print(0)
    exit()
    
ans=prod(a)

if ans>10**18:
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=1
for i in a:
    ans*=i

if ans>10**18:
    print(-1)
else:
    print(ans)


Fixed submission:
n=int(input())
import  functools
import operator
prod=functools.partial(functools.reduce, operator.mul)
a=list(map(int,input().split()))
a.sort(reverse=True)
if a[0]*a[1]>10**18 and a[-1]!=0:
    print(-1)
    exit()
if a[-1]==0:
    print(0)
    exit()
    
ans=prod(a)

if ans>10**18:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
a,b=input().split()
a=int(a)
b=str(b)
b.replace(".","")
b=int(b)
print(a*b//100)

Fixed submission:
a,b=input().split()
a=int(a)
b=str(b)
b=b.replace('.','')

b=int(b)
print(a*b//100)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
check=[[] for i in range(n)]
c=0
g=1
tmp=[]
cy=[]
non=[]

while c<n:
    if check[g-1]==[]:
        c+=1
        tmp.append(g)
        check[g - 1].append(c)
        g=a[g-1]
    else:
        cy=tmp[(check[g-1][0]-1):]
        non=tmp[:(check[g-1][0]-1)]
        break
if k<=len(non):
    print(non[k])
    exit()
k-=len(non)
k%=len(cy)


print(cy[k])

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
check=[[] for i in range(n)]
c=0
g=1
tmp=[]
cy=[]
non=[]

while c<n:
    if check[g-1]==[]:
        c+=1
        tmp.append(g)
        check[g - 1].append(c)
        g=a[g-1]
    else:
        cy=tmp[(check[g-1][0]-1):]
        non=tmp[:(check[g-1][0]-1)]
        break
if k<len(non):
    print(non[k])
    exit()
k-=len(non)
k%=len(cy)


print(cy[k])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
check=[[] for i in range(n)]
c=0
g=1
tmp=[]
cy=[]
non=[]

while c<n:
    if check[g-1]==[]:
        c+=1
        tmp.append(g)
        check[g - 1].append(c)
        g=a[g-1]
    else:
        cy=tmp[(check[g-1][0]-1):]
        non=tmp[:(check[g-1][0]-1)]
        break
k-=len(non)
k%=len(cy)
if k<=len(non):
    print(non[k-1])
    exit()

print(cy[k])

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
check=[[] for i in range(n)]
c=0
g=1
tmp=[]
cy=[]
non=[]

while c<n:
    if check[g-1]==[]:
        c+=1
        tmp.append(g)
        check[g - 1].append(c)
        g=a[g-1]
    else:
        cy=tmp[(check[g-1][0]-1):]
        non=tmp[:(check[g-1][0]-1)]
        break
if k<len(non):
    print(non[k])
    exit()
k-=len(non)
k%=len(cy)


print(cy[k])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=0

sa=[]
for i in range(n):
    sa.append(i+1+a[i])

sb=[]
for i in range(n):
    sb.append(max(0,i+1-a[i]))

for i in range(n-1):
    cnt=0
    h=sa[i]
    for j in range(i+1,n):
        if sb[j]==h:
            cnt+=1
    ans+=cnt

print(ans)



Fixed submission:
from collections import defaultdict
n=int(input())
A=list(map(int,input().split()))
ans=0
d=defaultdict(int)

for i,a in enumerate(A):
    ans+=d[i-a] #jから先
    d[i+a]+=1

print(ans)

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

sa=[]
for i in range(n):
    sa.append(i+1+a[i])

sb=[]
for i in range(n):
    sb.append(max(0,i+1-a[i]))

for i in range(n-1):
    cnt=0
    h=sa[i]
    for j in range(i+1,n):
        if sb[j]==h:
            cnt+=1
    ans+=cnt

print(ans)



Fixed submission:
from collections import defaultdict
n=int(input())
A=list(map(int,input().split()))
ans=0
d=defaultdict(int)

for i,a in enumerate(A):
    ans+=d[i-a] #jから先
    d[i+a]+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
a,b,n=map(int,input().split())
t=a*b//gcd(a,b)
if a==1:
    print(0)
    exit()

ans=0
if n%t!=0:
    n%=t

for i in range(1,n+1):
    y=int(a*i/b)-a*int(i/b)
    ans=max(ans,y)


print(ans)


Fixed submission:

a,b,n=map(int,input().split())

def f(x):
    return a*x//b-a*(x//b)

print(f(min(n,b-1)))

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
a,b,n=map(int,input().split())
t=a*b//gcd(a,b)
if a==1:
    print(0)
    exit()

ans=[]
if n%t!=0:
    n%=t

for i in range(1,n+1):
    y=int(a*i/b)-a*int(i/b)
    ans.append(y)


print(max(ans))


Fixed submission:

a,b,n=map(int,input().split())

def f(x):
    return a*x//b-a*(x//b)

print(f(min(n,b-1)))

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
a,b,n=map(int,input().split())
t=a*b//gcd(a,b)
if a==1:
    print(0)
    exit()

ans=[]
if n%t!=0:
    n%=t

for i in range(1,n+1):
    y=int(a*i/b)-a*int(i/b)
    ans.append(y)


print(max(ans))


Fixed submission:

a,b,n=map(int,input().split())

def f(x):
    return a*x//b-a*(x//b)

print(f(min(n,b-1)))

Buggy python submission (verdict: Runtime Error):
from math import gcd



a,b,n=map(int,input().split())
t=a*b//gcd(a,b)
if a==1:
    print(0)
    exit()

ans=[]

n%=t
for i in range(1,n+1):
    y=int(a*i/b)-a*int(i/b)
    ans.append(y)


print(max(ans))


Fixed submission:

a,b,n=map(int,input().split())

def f(x):
    return a*x//b-a*(x//b)

print(f(min(n,b-1)))
Buggy python submission (verdict: Time Limit Exceeded):
s=input()[::-1]

count=[0]*2019
count[0]+=1
gh=0
dd=len(s)
for i in range(0,dd):
    gh+=int(s[i])*(10**i)
    count[gh%2019]+=1

ans=0

for cnt in count:
    ans+=cnt*(cnt-1)//2

print(ans)



Fixed submission:
s=input()[::-1]

count=[0]*2019
count[0]+=1
sd=0
d=1
for c in s:
   sd+=int(c)*d
   sd%=2019
   d*=10
   d%=2019
   count[sd]+=1

ans=0
for cnt in count:
    ans+=cnt*(cnt-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()[::-1]

count=[0]*2019
count[0]+=1
gh=0
for i in range(0,len(s)):
    gh+=int(s[i])*(10**i)
    count[gh%2019]+=1

ans=0

for cnt in count:
    ans+=cnt*(cnt-1)//2

print(ans)



Fixed submission:
s=input()[::-1]

count=[0]*2019
count[0]+=1
sd=0
d=1
for c in s:
   sd+=int(c)*d
   sd%=2019
   d*=10
   d%=2019
   count[sd]+=1

ans=0
for cnt in count:
    ans+=cnt*(cnt-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()[::-1]

count=[0]*2019
count[0]+=1
gh=0
for i in range(0,len(s)):
    gh+=int(s[i])*(10**i)
    count[gh%2019]+=1

ans=0

for cnt in count:
    ans+=cnt*(cnt-1)//2

print(ans)



Fixed submission:
s=input()[::-1]

count=[0]*2019
count[0]+=1
sd=0
d=1
for c in s:
   sd+=int(c)*d
   sd%=2019
   d*=10
   d%=2019
   count[sd]+=1

ans=0
for cnt in count:
    ans+=cnt*(cnt-1)//2

print(ans)

Buggy python submission (verdict: Runtime Error):
s=input()

ans=0
dd=[]

fir=int(s[0])*1000+int(s[1])*100+int(s[2])*10+int(s[3])
dd.append(fir%673)
for i in range(4,len(s)):
    tmp=(dd[i-4]*10+int(s[i]))%673
    dd.append(tmp)

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

bit=Bit(len(dd))
for i in range(1,len(dd)+1):
    bit.add(i,dd[i-1])
#print(dd)
for i in range(1,len(dd)):
    for j in range(i+1,len(dd)+1):
        if (bit.sum(j)-bit.sum(i))%673==0 and (bit.sum(j)-bit.sum(i))%3==0 :
            ans+=1


print(ans)



Fixed submission:
s=input()[::-1]

count=[0]*2019
count[0]+=1
sd=0
d=1
for c in s:
   sd+=int(c)*d
   sd%=2019
   d*=10
   d%=2019
   count[sd]+=1

ans=0
for cnt in count:
    ans+=cnt*(cnt-1)//2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import  math
k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans+=math.gcd(math.gcd(i,j),l)

print(ans)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
k=int(input())
ans=0
first=k*(k+1)//2
second=0

for i in range(1,k):
    for j in range(i+1,k+1):
        second+=gcd(i,j)*6

thir=0
for i in range(1,k-1):
    for j in range(i+1,k):
        for h in range(j+1,k+1):
            tmp=gcd(gcd(i,j),h)
            thir+=tmp*6

if k==1:
    print(first)
elif k==2:
    print(first+second)
else:
    print(first+second+thir)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            tmp=gcd(i,j)
            ans+=gcd(tmp,k)

print(ans)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
k=int(input())
ans=0
first=k*(k+1)//2
second=0

for i in range(1,k):
    for j in range(i+1,k+1):
        second+=gcd(i,j)*6

thir=0
for i in range(1,k-1):
    for j in range(i+1,k):
        for h in range(j+1,k+1):
            tmp=gcd(gcd(i,j),h)
            thir+=tmp*6

if k==1:
    print(first)
elif k==2:
    print(first+second)
else:
    print(first+second+thir)
Buggy python submission (verdict: Runtime Error):
s=input()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
elif
    print("No")

Fixed submission:
s=input()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=[]

MOD=10**9+7
def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%MOD
    for i in range(2,k+1):
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        ans=ans*(n-k+i)*inv[i]%MOD
    return ans
cnt=[]
v=set()
yut=True
for i in range(n-1):
    if a[i]!=a[i+1]:
        yut=False
if yut:
    for i in range(n):
        print(comb(n-1,2))
    exit()
for i in range(n):
    g=a.count(a[i])
    v.add(a[i])
    cnt.append([a[i],comb(g,2)])
fg=0
cvg=[]
vsd=list(v)
for i in range(n):
    tt=vsd[fg]
    if cnt[i][0]==tt:
        cvg.append(cnt[i][1])
        if  fg<len(vsd)-1:
            fg+=1

sy=sum(cvg)-cvg[-1]
for i in range(n):
    h=a.count(a[i])
    tmp=sy-(h-1)
    ans.append(tmp)

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

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
MOD=10**9+7

d=Counter(a)
tni=0
dv=d.values()
dv=list(dv)
for i in range(len(dv)):
    tni+=dv[i]*(dv[i]-1)//2

for i in range(n):
    r=d[a[i]]
    print(tni-(r-1))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=[]
from collections import Counter
d=Counter(a)
MOD=10**9+7
def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%MOD
    for i in range(2,k+1):
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        ans=ans*(n-k+i)*inv[i]%MOD
    return ans
cnt=[]
v=set()
yut=True
for i in range(n-1):
    if a[i]!=a[i+1]:
        yut=False
if yut:
    for i in range(n):
        print(comb(n-1,2))
    exit()
for i in range(n):
    g=a.count(a[i])
    v.add(a[i])
    cnt.append([a[i],comb(g,2)])
fg=0
cvg=[]
vsd=list(v)
for i in range(n):
    tt=vsd[fg]
    if cnt[i][0]==tt:
        cvg.append(cnt[i][1])
        if  fg<len(vsd)-1:
            fg+=1

sy=sum(cvg)-cvg[-1]
for i in range(n):
    h=a.count(a[i])
    tmp=sy-(h-1)
    ans.append(tmp)

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

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
MOD=10**9+7

d=Counter(a)
tni=0
dv=d.values()
dv=list(dv)
for i in range(len(dv)):
    tni+=dv[i]*(dv[i]-1)//2

for i in range(n):
    r=d[a[i]]
    print(tni-(r-1))