Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
res = 1
for i in a:
    res *= i
if res > 1000000000000000000:
        res = -1
print(res)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
res = 1
a.sort()
for i in a:
    res *= i
    if res > 1000000000000000000:
        res = -1
        break
print(res)

Buggy python submission (verdict: Runtime Error):
res = 1
if 0 in a:
    res = 0
else:
    for i in range(n):
        b = a.pop()
        if b != 1:
            res *= b

            if res > 1000000000000000000:
                res = -1
                break
print(res)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
res = 1
a.sort()
for i in a:
    res *= i
    if res > 1000000000000000000:
        res = -1
        break
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
res = 1
if 0 in a:
    res = 0
else:
    for i in a:
        res *= i
        if res > 1000000000000000000:
            res = -1
print(res)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
res = 1
a.sort()
for i in a:
    res *= i
    if res > 1000000000000000000:
        res = -1
        break
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
res = 1
if 0 in a:
    res = 0
else:
    for i in a:
        res *= i
        if res > 1000000000000000000:
            res = -1
print(res)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
res = 1
a.sort()
for i in a:
    res *= i
    if res > 1000000000000000000:
        res = -1
        break
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
res = 1
for i in a:
    res *= i
if res > 1000000000000000000:
        res = -1
print(res)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
res = 1
a.sort()
for i in a:
    res *= i
    if res > 1000000000000000000:
        res = -1
        break
print(res)

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


t=sorted(s)

if t[0]==0:
  print(0)
  exit()
count=1
for i in range(0,n):
  count=count*t[i]
if count>10**18:
  print(-1)
else:
  print(count)

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


t=sorted(s)

if t[0]==0:
  print(0)
  exit()
count=1
for i in range(0,n):
  count=count*t[i]
  if count>10**18:
    print(-1)
    exit()

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import math

n=int(input())

sum=0
for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      y=list([i,j,k])
      z=len(y)//3
      for h in range(0,z):
        x=math.gcd(y[0],y[1])
        p=math.gcd(x,y[2])
        sum=sum+p
print(sum)

Fixed submission:
import math

n=int(input())

sum=0
for i in range(1,n+1):
  for j in range(1,n+1):
      x=math.gcd(i,j)
      for h in range(1,n+1):
        p=math.gcd(x,h)
        sum=sum+p
print(sum)

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

n=int(input())

sum=0
for i in range(1,n):
  for j in range(1,n):
    for k in range(1,n):
      y=[[i,j,k]]
      for h in range(z):
        x=math.gcd(h[0],h[1],h[2])
        sum=sum+x
print(sum)

Fixed submission:
import math

n=int(input())

sum=0
for i in range(1,n+1):
  for j in range(1,n+1):
      x=math.gcd(i,j)
      for h in range(1,n+1):
        p=math.gcd(x,h)
        sum=sum+p
print(sum)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())

if a=b or b=c or c=a and not a=b=c:
  print("Yes")
else:
  print("No")

Fixed submission:
a,b,c=map(int,input().split())

if not a==b==c:
  if a==b or b==c or c==a:
  	print("Yes")
  else:
    print("No")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
AC=0
WA=0
AC_list=[0]*(m+1)
WA_list=[0]*(m+1)

for i in range(m):
  p,s=input().split()
  p=int(p)
  if s=="AC":
    if AC_list[p]==0:
      AC=AC+1
      AC_list[p]=1
  else:
    if AC_list[p]==0:
      WA=WA+1
    
print(AC,WA)

Fixed submission:
n, m = map(int,input().split())
 
AC = 0
# 各問題でACがとれているか確認用
# 0 = まだ正解していない, 1 = すでに正解済み
AC_list = [0] * (n + 1)
WA = 0
WA_List = [0] * (n + 1)
 
for i in range(m):
    p,S = input().split()
    p = int(p)
 
    if S == "AC":
        # 初めての正解
        if AC_list[p] == 0:
            AC += 1
            WA += WA_List[p]
            AC_list[p] = 1
        # ※すでに正解している場合は加算しない
    else:
        # まだ正解していない場合
        if AC_list[p] == 0:
            WA_List[p] += 1
        # ※すでに正解している場合は加算しない
 
print(AC,WA)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
AC=0
WA=0
AC_list=[0]*(m+1)
WA_list=[0]*(m+1)

for i in range(m):
  p,s=input().split()
  p=int(p)
  if s=="AC":
    if AC_list[p]==0:
      AC=AC+1
      WA=WA+WA_list[p]
      AC_list[p]=1
  else:
    if AC_list[p]==0:
      WA_list[p]=WA_list[p]+1
    
print(AC,WA)

Fixed submission:
n, m = map(int,input().split())
 
AC = 0
# 各問題でACがとれているか確認用
# 0 = まだ正解していない, 1 = すでに正解済み
AC_list = [0] * (n + 1)
WA = 0
WA_List = [0] * (n + 1)
 
for i in range(m):
    p,S = input().split()
    p = int(p)
 
    if S == "AC":
        # 初めての正解
        if AC_list[p] == 0:
            AC += 1
            WA += WA_List[p]
            AC_list[p] = 1
        # ※すでに正解している場合は加算しない
    else:
        # まだ正解していない場合
        if AC_list[p] == 0:
            WA_List[p] += 1
        # ※すでに正解している場合は加算しない
 
print(AC,WA)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=input()

if n%2==1:
  print("No")
else:
  count=0
  m=n//2
  for i in range(m):
    if a[i]==a[i+m]:
      count+=1
    else:
      count=0

if count==m:
  print("Yes")
else:
  print("No")

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

if n%2==1:
  print("No")
  exit()
else:
  count=0
  m=n//2
  for i in range(m):
    if a[i]==a[i+m]:
      count+=1
    else:
      count=0

if count==m:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a,b=input().split()

if len(a)>=2 or len(b)>=2:
  print(-1)
else:
  print(a*b)

Fixed submission:
a,b=input().split()

if len(a)>=2 or len(b)>=2:
  print(-1)
else:
  a=int(a)
  b=int(b)
  print(a*b)

Buggy python submission (verdict: Runtime Error):
a,b=input().split()

if len(a)>=2 or len(b)>=2:
  print("-1")
else:
  print(a*b)

Fixed submission:
a,b=input().split()

if len(a)>=2 or len(b)>=2:
  print(-1)
else:
  a=int(a)
  b=int(b)
  print(a*b)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())

if a<2b:
  print("0")
else:
  print(a-2*b)

Fixed submission:
a,b=map(int,input().split())
 
if a<2*b:
  print("0")
else:
  print(a-2*b)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(map(int,input().split()))

for i in range(1,n+1):
  print(1+s.index(i),end=" ")

Fixed submission:
n=int(input())
s=[ int(i) for i in  input().split()]
l=[0]*n

for i in range(n):
  l[s[i]-1]=str(i+1)
print(' '.join(l))
Buggy python submission (verdict: Runtime Error):
import numpy as np

N=int(input())
print(np.arange(1,N).sum())

Fixed submission:
N=int(input())
print((N)*(N-1)//2)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N=int(input())
print(np.arange(1,N-1).sum())

Fixed submission:
N=int(input())
print((N)*(N-1)//2)

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

count=0
for i in range(1,N):
  count=count+i
print(count)

Fixed submission:
N=int(input())
print((N)*(N-1)//2)
Buggy python submission (verdict: Runtime Error):
A,B = int(input().split())
print(max([A+B,A-B,A*B]))

Fixed submission:
A,B = map(int, input().split())
print(max([A+B,A-B,A*B]))
Buggy python submission (verdict: Runtime Error):
N=input()

if len(N)==1:
  print(N)
elif len(N)==2:
  print(9)
elif len(N)==3:
  print(9+N-99)
elif len(N)==4:
  print(909)
elif len(N)==5:
  print(909+N-9999)
elif len(N)==6:
  print(90909)

Fixed submission:
N=input()

if len(N)==1:
  print(int(N))
elif len(N)==2:
  print(9)
elif len(N)==3:
  print(9+int(N)-99)
elif len(N)==4:
  print(909)
elif len(N)==5:
  print(909+int(N)-9999)
elif len(N)==6:
  print(90909)
Buggy python submission (verdict: Runtime Error):
a,b,t=map(int,input().split())

print(t//a*b

Fixed submission:
a,b,t=map(int,input().split())
 
print(t//a*b)
Buggy python submission (verdict: Time Limit Exceeded):
import math
 
N=int(input())
 
a=math.ceil(math.sqrt(N))
 
for i in range(a,((N+1)//10+1)):
  if N%i==0:
    r=N//i
    print(max(len(str(i)),len(str(r))))
    exit()

print(len(str(N)))

Fixed submission:
import math
 
N=int(input())
 
a=math.floor(math.sqrt(N))
 
for i in range(a,0,-1):
  if N%i==0:
    r=N//i
    print(max(len(str(i)),len(str(r))))
    exit()

print(len(str(N)))

Buggy python submission (verdict: Time Limit Exceeded):
import math
 
N=int(input())
 
a=math.ceil(math.sqrt(N))
 
for i in range(a,((N+1)//2+1)):
  if N%i==0:
    r=N//i
    print(max(len(str(i)),len(str(r))))
    exit()
print(len(str(N)))

Fixed submission:
import math
 
N=int(input())
 
a=math.floor(math.sqrt(N))
 
for i in range(a,0,-1):
  if N%i==0:
    r=N//i
    print(max(len(str(i)),len(str(r))))
    exit()

print(len(str(N)))

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

N=int(input())

a=math.ceil(math.sqrt(N))

for i in range(a,((N+1)//2+1)):
  if N%i==0:
    r=N//i
    print(max(len(str(i)),len(str(r))))
    exit()
print(len(str(N)))

Fixed submission:
import math
 
N=int(input())
 
a=math.floor(math.sqrt(N))
 
for i in range(a,0,-1):
  if N%i==0:
    r=N//i
    print(max(len(str(i)),len(str(r))))
    exit()

print(len(str(N)))

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

N=int(input())

a=math.ceil(math.sqrt(N))

for i in range(a,N+1):
  if N%i==0:
    r=N//i
    print(max(len(str(i)),len(str(r))))
    exit()

Fixed submission:
import math
 
N=int(input())
 
a=math.floor(math.sqrt(N))
 
for i in range(a,0,-1):
  if N%i==0:
    r=N//i
    print(max(len(str(i)),len(str(r))))
    exit()

print(len(str(N)))
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
n,m=map(int,input().split())
s=[set(map(int,input().split())) for _ in range(n)]

ans=0
x=[i for i in range(2,n+1)]
cand=permutations(x)
for i in cand:
  crnt=1
  for nxt in i:
    if set([crnt,nxt]) in s:
      crnt=nxt
    else:
      break
  else:
    ans+=1
print(ans)

Fixed submission:
from itertools import permutations
n,m=map(int,input().split())
s=[set(map(int,input().split())) for _ in range(m)]

ans=0
x=[i for i in range(2,n+1)]
cand=permutations(x)
for i in cand:
  crnt=1
  for nxt in i:
    if set([crnt,nxt]) in s:
      crnt=nxt
    else:
      break
  else:
    ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools
n,m=map(int,input().split())
s=[set(map(int,input().split())) for _ in range(n)]

ans=0
x=[i for i in range(2,n+1)]
cand=itertools.permutations(x)
for i in cand:
  crnt=1
  for nxt in i:
    if set([crnt,nxt]) in s:
      crnt=nxt
    else:
      break
  else:
    ans+=1
print(ans)

Fixed submission:
from itertools import permutations
n,m=map(int,input().split())
s=[set(map(int,input().split())) for _ in range(m)]

ans=0
x=[i for i in range(2,n+1)]
cand=permutations(x)
for i in cand:
  crnt=1
  for nxt in i:
    if set([crnt,nxt]) in s:
      crnt=nxt
    else:
      break
  else:
    ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools
n,m=map(int,input().split())
s=[set(map(int,input().split())) for _ in range(n)]

ans=0
x=[i for i in range(2,n+1)]
print(x)
cand=itertools.permutations(x)
print(cand)
for i in cand:
  crnt=1
  for nxt in i:
    if set([crnt,nxt]) in s:
      crnt=nxt
    else:
      break
  else:
    ans+=1
print(ans)

Fixed submission:
from itertools import permutations
n,m=map(int,input().split())
s=[set(map(int,input().split())) for _ in range(m)]

ans=0
x=[i for i in range(2,n+1)]
cand=permutations(x)
for i in cand:
  crnt=1
  for nxt in i:
    if set([crnt,nxt]) in s:
      crnt=nxt
    else:
      break
  else:
    ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict
import math
n=int(input())
d=defaultdict(int)

if n>2:
    for l in range(1,n):
        for i in range(1,l-1):
            for j in range(1,l-i):
                k=l-i-j
                N=i*i+j*j+k*k+i*j+j*k+k*i
                d[N]+=1
for i in range(1,n+1):
    print(d[i])

Fixed submission:
from collections import defaultdict
import math
n=int(input())
d=defaultdict(int)

if n>2:
    m=int(math.sqrt(n))
    for k in range(1,m):
        for i in range(1,m):
            for j in range(1,m):
                N=i*i+j*j+k*k+i*j+j*k+k*i
                d[N]+=1
for i in range(1,n+1):
    print(d[i])

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import math
n=int(input())
d=defaultdict(int)

m=int(math.sqrt(n-2))+2
for l in range(3,m+1):
    for i in range(1,l-1):
        for j in range(1,l-i):
            k=l-i-j
            N=i*i+j*j+k*k+i*j+j*k+k*i
            d[N]+=1
for i in range(1,n+1):
    print(d[i])

Fixed submission:
from collections import defaultdict
import math
n=int(input())
d=defaultdict(int)

if n>2:
    m=int(math.sqrt(n))
    for k in range(1,m):
        for i in range(1,m):
            for j in range(1,m):
                N=i*i+j*j+k*k+i*j+j*k+k*i
                d[N]+=1
for i in range(1,n+1):
    print(d[i])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
Q=[True]*n
a.sort()
t=0
for i in range(n):
    if !Q[j]:
        continue
    b=a[i]
    for j in range(i,n):
        if !Q[j]:
            continue
        if a[j]%b==0:
            Q[j]=False
    t+=1
print(t)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
A.sort()
t=0
e=[True]*1000001
for i in range(n-1):
    a=A[i]
    if e[a]==False:
        continue
    b=a*2
    while b < 1000001:
        e[b]=False
        b+=a
    if A[i+1]==a:
        e[a]=False
for a in A:
    if e[a]:
        t+=1
print(t)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
Q=[]
a.sort()
t=0
for i in range(n):
    f=True
    if Q:
        for q in Q:
            if a[i]%q==0:
                f=False
                break
    if f and i<n-1 and a[i]==a[i+1]:
        f=False
        Q.append(a[i])
    if f:
        Q.append(a[i])
        t+=1
print(t)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
A.sort()
t=0
e=[True]*1000001
for i in range(n-1):
    a=A[i]
    if e[a]==False:
        continue
    b=a*2
    while b < 1000001:
        e[b]=False
        b+=a
    if A[i+1]==a:
        e[a]=False
for a in A:
    if e[a]:
        t+=1
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())

r=[[] for _ in range(n)]
d=[]
b=[n+1]*n
for _ in range(m):
    a,z=map(int,input().split())
    r[a-1].append(z-1)
    r[z-1].append(a-1)

o=0
f=1
b[o]=0
for _ in range(n):
    for i in r[o]:
        if(b[i]==n+1):
            b[i]=o
            d.append(i)
    if(d):
        f+=1
        o=d[0]
        del d[0]
    else:
        break

if (f==n):
    print("Yes")
    for i in b[1:]:
        print(i+1)
else:
    print("No")


Fixed submission:
from collections import deque
n,m=map(int,input().split())

r=[[] for _ in range(n)]
d=deque()
b=[n+1]*n
for _ in range(m):
    a,z=map(int,input().split())
    r[a-1].append(z-1)
    r[z-1].append(a-1)

o=0
f=1
b[o]=0
for _ in range(n):
    for i in r[o]:
        if(b[i]==n+1):
            b[i]=o
            d.append(i)
    if(d):
        o=d.popleft()
        f+=1
    else:
        break

if (f==n):
    print("Yes")
    for i in b[1:]:
        print(i+1)
else:
    print("No")

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

r=[[]*n for _ in range(n)]
f=[True]*n
d=[0]
b=[n+1]*n

for i in a:
    r[i[0]-1].append(i[1]-1)
    r[i[1]-1].append(i[0]-1)

o=0
#print(r[now][0])

b[o]=0
#print(now)
for _ in range(n):
    for i in r[o]:
        #i=r[now][j]
        if(b[i]==n+1):
            b[i]=o
            d.append(i)
    if(d):
        o=d[0]
        del d[0]

f=0
for i in b[1:]:
    if(i==n+1):
        f=1
if (f==0):
    print("Yes")
    for i in b[1:]:
        print(i+1)
else:
    print("No")

    

Fixed submission:
from collections import deque
n,m=map(int,input().split())

r=[[] for _ in range(n)]
d=deque()
b=[n+1]*n
for _ in range(m):
    a,z=map(int,input().split())
    r[a-1].append(z-1)
    r[z-1].append(a-1)

o=0
f=1
b[o]=0
for _ in range(n):
    for i in r[o]:
        if(b[i]==n+1):
            b[i]=o
            d.append(i)
    if(d):
        o=d.popleft()
        f+=1
    else:
        break

if (f==n):
    print("Yes")
    for i in b[1:]:
        print(i+1)
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split())) 

x=[0]*(n)
before = 0
now = 0
while x[now] == 0:
    x[now]=1+x[before]
    before=now
    now = a[now]-1
    
y=x[now]-x[0]
z=x[before]-y
l=(k-y)%z+1
for i in range(n):
    if x[i] == l+y:
        print(1+i)
        break

Fixed submission:
s=input()
t=input()
l=len(s)
if len(s)+1 == len(t):
    si=s+t[l]
else:
    si=""
if si == t and len(si) == len(t):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
a,b,n = map(int,input().split())
max = 0
s = int(b/a)
f = n+1
if b < n:
    f = b+1
for i in range(s,f):
    buf = a*(i%b)-(a*i)%b 
    if buf > max:
        max = buf

print(int(max/b))

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

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

w=min(n,b-1) 
ma=f(w)
print(ma)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,n = map(int,input().split())
max = -9999999999
for i in range(1,n+1):
    buf = a*(i%b)-(a*i)%b 
    if buf > max:
        max = buf

print(int(max/b))

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

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

w=min(n,b-1) 
ma=f(w)
print(ma)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
d = [0]*2019
d[0] = 1
total = 0

for i in range(n):
  buf = s[n-i-1:n]
  l = (int(buf))%2019
  d[l] += 1
  total += d[l] - 1
  
print(total)

Fixed submission:
S = input()[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current % 2019]
    mods[current % 2019] += 1
    x = x * 10 % 2019
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
s = input()
n = len(s)
d = defaultdict(int)
d[0] = 1
total = 0

for i in range(n):
  buf = s[n-i-1:n]
  l = (int(buf))%2019
  d[l] += 1
  total += d[l] - 1
  #print(int(buf),l)
  
print(total)

Fixed submission:
S = input()[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current % 2019]
    mods[current % 2019] += 1
    x = x * 10 % 2019
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = input()
t = len(n)
total = 0
for i in range(t-4):
    for j in range(i+4,t):
        k = (n[i:j+1])
        l = int(k)
        if l%2019 == 0:
            total += 1
            break

print(total)

Fixed submission:
S = input()[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current % 2019]
    mods[current % 2019] += 1
    x = x * 10 % 2019
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

n = input()
t = len(n)
total = 0
for i in range(t-4):
    for j in range(i+4,t):
        k = (n[i:j+1])
        l = int(k)
        #print(l)
        if l%2019 == 0:
            total += 1

print(total)

Fixed submission:
S = input()[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current % 2019]
    mods[current % 2019] += 1
    x = x * 10 % 2019
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions as ma
n=int(input())
total=0

for a in range(1,n+1):
  for b in range(1,n+1):
    d = ma.gcd(a,b)
    for c in range(1,n+1):
      total += ma.gcd(d,c)
      
print(total)

Fixed submission:
import fractions as ma
import collections
n=int(input())
total=0

d=collections.defaultdict(int)

for a in range(1,n+1):
  for b in range(1,n+1):
    d[ma.gcd(a,b)]+=1
    
for a in range(1,n+1):
  for key in d.keys():
    total += ma.gcd(key,a)*d[key]
      
print(total)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

      
def r(i) :
  if i < 2:
    return 1
  else :
    return i*r(i-1)

a = int(input())
b = list(map(int,input().split()))
for i in range(a):
  total = 0
  c = defaultdict(int)
  for j in range(a):
    if j != i:
      c[b[j]] += 1
  for key in c.keys():
    if c[key] > 1:
  #    print(c[key],key)
  #    print("###")
      total += r(c[key]) / (r(2)*r(c[key]-2))
  print(int(total))


Fixed submission:
from collections import defaultdict

def r(i) :
  if i < 2:
    return 1
  else :
    return i*(i-1)/2

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

total = 0
c = defaultdict(int)
for j in range(a):
  c[b[j]] += 1
for key in c.keys():
  if c[key] > 1:
    total += r(c[key])

for j in range(a):
  print(int(total - c[b[j]]+1))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t=0
for i in range(1,n):
    t+=i
print(t)

Fixed submission:
n = int(input())
t=(n-1)*n//2
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    n = int(input())
    A = list(map(int, sys.stdin.readline().split()))

    ans = 1
    for i in range(n):
        ans *= A[i]

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


if __name__ == '__main__':
    main()

Fixed submission:
import sys

def main():
    n = int(input())
    A = list(map(int, sys.stdin.readline().split()))

    ans = 1

    if 0 in A:
        print(0)
        sys.exit()

    for i in range(n):
        ans *= A[i]
        if ans > 10 ** 18:
            print('-1')
            sys.exit()

    print(ans)


if __name__ == '__main__':
    main()

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

def main():
    n = int(input())
    A = list(map(int, input().split()))

    ans = 1
    for i in range(n):
        ans *= A[i]

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


if __name__ == '__main__':
    main()

Fixed submission:
import sys

def main():
    n = int(input())
    A = list(map(int, sys.stdin.readline().split()))

    ans = 1

    if 0 in A:
        print(0)
        sys.exit()

    for i in range(n):
        ans *= A[i]
        if ans > 10 ** 18:
            print('-1')
            sys.exit()

    print(ans)


if __name__ == '__main__':
    main()