Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
N = int (input ())
L = input ().split ()
l = [int(s) for s in L]
list.sort (l, reverse=True)
a = 0
x = 0
m = math.ceil(N/2)
for i in range (m):
    x += int (l[a])
    a += 2
a = 1
y = 0
for i in range (N-m):
    y += int (l[a])
    b += 2
print (x-y)

Fixed submission:
n = int (input ())
a = int (input ())
o = n%500
if a < o:
  print ('No')
else:
  print ('Yes')
Buggy python submission (verdict: Runtime Error):
a = int (inout ())
if a[0]==a[1]==a[2] or a[1]==a[2]==a[3]:
  print ('Yes')
else:
  print ('No')

Fixed submission:
a = input ()
if a[0]==a[1]==a[2] or a[1]==a[2]==a[3]:
  print ('Yes')
else:
  print ('No')
Buggy python submission (verdict: Runtime Error):
a,b = input ().split ()
if a < b:
  print ('<')
elif a > b:
  pritn ('>')
else:
  print ('=')

Fixed submission:
a,b = input ().split ()
if a < b:
  print ('<')
elif a > b:
  print ('>')
else:
  print ('=')
Buggy python submission (verdict: Runtime Error):
x,a,b = (int(x) for x in input().split())
if a < b:
  if b-a > c:
    print ('dengerous')
  else:
    print ('safe')
else:
  print ('delicious')


Fixed submission:
x,a,b = (int(i) for i in input().split())
if a < b:
  if b-a > x:
    print ('dangerous')
  else:
    print ('safe')
else:
  print ('delicious')
Buggy python submission (verdict: Runtime Error):
l1 = [1,3,5,7,8,10,12]
l2 = [4,6,9,11]
l3 = [2]
n = 0
if x in l1:
  if y in l1:
    print ('Yes')
    n = 1
elif x in l2:
  if y in l2:
    print ('Yes')
    n = 1
else:
  if y in l3:
    print ('Yes')
    n = 1
if n == 0:
  print ('No')

Fixed submission:
x,y = (int(x) for x in input().split())
l1 = [1,3,5,7,8,10,12]
l2 = [4,6,9,11]
l3 = [2]
n = 0
if x in l1:
  if y in l1:
    print ('Yes')
    n = 1
elif x in l2:
  if y in l2:
    print ('Yes')
    n = 1
else:
  if y in l3:
    print ('Yes')
    n = 1
if n == 0:
  print ('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int (input ())
x = 1
for i in range (n):
  x = x*(i+1)
x = x%(10**9+7)
print (x)

Fixed submission:
n = int (input ())
x = 1
for i in range (n):
  x = x*(i+1)
  x = x%(10**9+7)
print (x)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map (int ,input ().split ())
x = 0
y = 0
z = 0
p = 0
while x <= k:
  while y <= k:
    while z <= k:
      if x+y+z == s:
        p += 1
      z += 1
    y += 1
    z = 0
  x += 1
  y,z = 0,0
print (p)

Fixed submission:
k,s = map (int ,input ().split ())
x = 0
y = 0
p = 0
while x <= k:
  while y <= k:
    if x+y > s:
      break
    z = s-(x+y)
    if 0 <= z <= k:
      p += 1
    y += 1
  x += 1
  y = 0
print (p)
Buggy python submission (verdict: Runtime Error):
a,b,c = input ().split ()
a,b = int (a,b)
if b == '+':
  print (a+b)
else:
  print (a-b)


Fixed submission:
a,b,c = input ().split ()
a = int (a)
c = int (c)
if b == '+':
  print (a+c)
else:
  print (a-c)
Buggy python submission (verdict: Runtime Error):
N = int (input ())
S = input()
S = S.replace('a','')
S = S.replace('i','')
S = S.replace('u','')
S = S.replace('e','')
S = S.replace('o','')
print (N-int (len(S)))

Fixed submission:
S = input()
if S=='a' or S=='i' or S=='u' or S=='e' or S=='o':
  print ('vowel')
else:
  print ('consonant')
Buggy python submission (verdict: Runtime Error):
list.sort (l, reverse=True)
a = int (l[0])
b = int (l[1])
c = int (l[2])
if a == b+c:
  print ('Yes')
else:
  print ('No')

Fixed submission:
l = [int(x) for x in input().split()]
if l[2]==l[0]+l[1] or l[0]==l[1]+l[2] or l[1]==l[0]+l[2]:
  print ('Yes')
else:
  print ('No')
Buggy python submission (verdict: Runtime Error):
a,b,c = (int(x) for x in input().split())
if a == b:
  if a == c:
    print (1)
  else:
    pritn (2)
else:
  if a == c:
    print (2)
  else:
    if b == c:
      print (2)
    else:
      print (3)

Fixed submission:
a,b,c = (int(x) for x in input().split())
if a == b:
  if a == c:
    print (1)
  else:
    print (2)
else:
  if a == c:
    print (2)
  else:
    if b == c:
      print (2)
    else:
      print (3)

Buggy python submission (verdict: Runtime Error):
a,b,c = (int(x) for x in input().split())
if a == b:
  if a == c:
    print (1)
  else:
    pritn (2)
else:
  if a == c:
    print (2)
  else:
    print (3)


Fixed submission:
a,b,c = (int(x) for x in input().split())
if a == b:
  if a == c:
    print (1)
  else:
    print (2)
else:
  if a == c:
    print (2)
  else:
    if b == c:
      print (2)
    else:
      print (3)
Buggy python submission (verdict: Runtime Error):
a = int (input ())
b = int (input ())
h = int (input ()/2)
print ((a+b)*h)


Fixed submission:
a = int (input ())
b = int (input ())
h = int (input ())
print ((a+b)*(round(h/2)))
Buggy python submission (verdict: Runtime Error):
N = int (input ())
print (N*(N+1))/2


Fixed submission:
N = int (input ())
x =0
for i in range (N):
  x += N-i
print (x)
Buggy python submission (verdict: Runtime Error):
n,m=list(map(int,input().split()))
par=[i for i in range(n)]
ro=dict(int)
for i in range(n):
    ro[i]=1
def root(i):
    if par[i]==i:
        return i
    else:
        return root(par[i])

def unite(x,y):
    rx=root(x)
    ry=root(y)
    if rx!=ry:
        par[rx]=ry
        ro[ry]+=ro[rx]
        ro[rx]=0

for i in range(m):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    unite(a,b)


# for i in range(n):
#     ro[root(i)]+=1

print(max(ro.values()))

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

if t*s>=d:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
s = input()

l = len(s)
mod = 10**9+7 #出力の制限

n = l+k
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

ans = 0
for i in range(l,l+k+1):
    ans = (ans+cmb(i-1,l-1)*power(25,k-(l+k-i))*power(26,l+k-i)) % mod

print(ans)

Fixed submission:
k = int(input())
s = input()
 
l = len(s)
mod = 10**9+7 #出力の制限
 
n = l+k
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 

 
ans = 0
for i in range(l,l+k+1):
    ans = (ans+cmb(i-1,l-1)*pow(25,k-(l+k-i),mod)*pow(26,l+k-i,mod)) % mod
 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a=list(map(int,input().split()))
a.sort(reverse = True)
from collections import deque
from collections import Counter as cnt
aaa = dict(cnt(a))

maa = a[0]//2
ma = maa+1


ans = []
a = deque(a)
while True:
    if len(a) <1:
        break
    i = a.pop()
    ans.append(i)

    b = deque()
    while len(a)>0:
        j = a.pop()
        if j%i !=0:
            b.appendleft(j)
    a = b.copy()

    if i >= ma:
        ans += a
        break





mans = 0
for i,v in aaa.items():
    if (i in ans) & (v == 1) :
        mans+=1

print(mans)

Fixed submission:
n = int(input())

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

from collections import Counter as cnt
aaa = dict(cnt(a))

ma = max(a)
dp = [True for i in range(ma+1)]

for i in a:
    if dp[i]:
        mul = i*2
        while mul<=ma:
            dp[mul] =False
            mul += i

mans = 0
for i,v in aaa.items():
    if dp[i] & (v == 1) :
        mans+=1

print(mans)

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

from collections import deque
from collections import Counter as cnt

aaa = dict(cnt(a))

ans = []
a = deque(a)
while True:
    if len(a) <1:
        break
    i = a.pop()
    ans.append(i)
    b = deque()
    while len(a)>0:
        j = a.pop()
        if j%i !=0:
            b.appendleft(j)
    a = b.copy()




mans = 0
for i,v in aaa.items():
    if (i in ans) & (v == 1) :
        mans+=1

print(mans)

Fixed submission:
n = int(input())

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

from collections import Counter as cnt
aaa = dict(cnt(a))

ma = max(a)
dp = [True for i in range(ma+1)]

for i in a:
    if dp[i]:
        mul = i*2
        while mul<=ma:
            dp[mul] =False
            mul += i

mans = 0
for i,v in aaa.items():
    if dp[i] & (v == 1) :
        mans+=1

print(mans)
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:ans=-1
print(ans)

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

ans=1

if 0 in a:
    ans=0
else:
    for i in a:
        ans*=i
        if ans > 10 ** 18:
            ans = -1
            break

print(ans)
Buggy python submission (verdict: Runtime Error):
input())
a=list(map(int,input().split()))
ok=True

v=[0 for i in range(n+2)]
import time

#start=time.time()
nextv=0

nec=2**n

for i in range(n,-1,-1):

    if nec>=v[i+1]+a[i]:
        v[i]=v[i+1]+a[i]
    else:
        v[i]=nec

    nec=nec >>1



#print(time.time()-start)

for i in range(1,n+1):
    if v[i-1]-a[i-1]<0:
        ok=False
        break
    if (v[i-1]-a[i-1])*2<v[i]:
        v[i]=(v[i-1]-a[i-1])*2

if a[0]!=0:ok=False

ans=sum(v)

if ans==0:ok=False

if ok:
    print(ans)
else:
    print(-1)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ok=True

v=[0 for i in range(n+2)]
import time

#start=time.time()
nextv=0

nec=2**n

for i in range(n,-1,-1):

    if nec>=v[i+1]+a[i]:
        v[i]=v[i+1]+a[i]
    else:
        v[i]=nec

    nec=nec >>1



#print(time.time()-start)

for i in range(1,n+1):
    if v[i-1]-a[i-1]<0:
        ok=False
        break
    if (v[i-1]-a[i-1])*2<v[i]:
        v[i]=(v[i-1]-a[i-1])*2


if n==0:
    if a[0]!=1:ok=False
else:
    if a[0] != 0:ok = False

if v[n]!=a[n]:ok=False

ans=sum(v)
if ans==0:ok=False

if ok:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):


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

ne=0
his=[]
l=False
for i in range(min(n,k)):
    if ne in his:
        back=his.index(ne)
        loop=i-back
        l=True
        break
    his.append(ne)
    ne=a[ne]-1
if l:
    ansidx=(k-back)%loop+back
    ans=his[ansidx]+1
else:
    ans=ne+1
print(ans)

Fixed submission:


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

ne=0
his=[None for i in range(n)]
l=False
for i in range(min(n,k)):
    if his[ne]!=None:
        back=his[ne]
        loop=i-back
        l=True
        break
    his[ne]=i
    #his.append(ne)
    ne=a[ne]-1

if l:
    ansidx=(k-back)%loop+back
    ans=his.index(ansidx)+1
else:
    ans=ne+1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):


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

ne=0
his=[]
l=False
for i in range(min(n,k)):
    if ne in his:
        back=his.index(ne)
        loop=i-back
        l=True
        break
    his.append(ne)
    ne=a[ne]-1
if l:
    ansidx=(k-back)%loop+back
    ans=his[ansidx]+1
else:
    ans=ne+1
print(ans)

Fixed submission:


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

ne=0
his=[None for i in range(n)]
l=False
for i in range(min(n,k)):
    if his[ne]!=None:
        back=his[ne]
        loop=i-back
        l=True
        break
    his[ne]=i
    #his.append(ne)
    ne=a[ne]-1

if l:
    ansidx=(k-back)%loop+back
    ans=his.index(ansidx)+1
else:
    ans=ne+1
print(ans)
Buggy python submission (verdict: Runtime Error):
x,y,a,b,c=list(map(int,input().split()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p=[(0,i,n) for i,n in enumerate(p)]
q=[(1,i,n) for i,n in enumerate(q)]
r=[(2,i,n) for i,n in enumerate(r)]

p.extend(r)
p.sort(key=lambda x: x[2],reverse=True)

ans=0
for c,i,n in p:
    ans+=n
    if c==2:
        r.pop(i)
    x-=1
    if x==0:
        break

q.extend(r)
q.sort(key=lambda x: x[2],reverse=True)

for i in range(y):
    ans+=q[i][2]

print(ans)

Fixed submission:
x,y,a,b,c=list(map(int,input().split()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
p=p[:x]
q=q[:y]
r.extend(p)
r.extend(q)
r.sort(reverse=True)

ans=sum(r[:x+y])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b=map(int,input().split())
ans=0
end=True
while end:
    if n>=a:
        n-=a
        ans+=a
        if n>b:n-=b
        else:end=False
    else:
        ans+=n
        end=False
print(ans)

Fixed submission:
n,a,b=map(int,input().split())
ans=0
# end=True
# while end:
#     if n>=a:
#         n-=a
#         ans+=a
#         if n>b:n-=b
#         else:end=False
#     else:
#         ans+=n
#         end=False

cnt=n//(a+b)
ans+=cnt*a
ama=n%(a+b)
if ama-a>=0:ans+=a
else:ans+=ama
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
p=[]
p=list(map(int,input().split()))

ans=0
for i in range(n-k+1):
    aa=sum(p[i:i+k])
    ans=max(ans,aa)
aaaa=(ans+k)/2
print(aaaa)

Fixed submission:
n,k=map(int,input().split())
p=[]
p=list(map(int,input().split()))

ans=sum(p[0:k])
aa=sum(p[0:k])
for i in range(1,n-k+1):
    aa=aa-p[i-1]+p[i+k-1]
    ans=max(ans,aa)

aaaa=(ans+k)/2
print(aaaa)
Buggy python submission (verdict: Runtime Error):
from math import factorial as fac

def comb(n,r):
    if ( r<0 or r>n ):
        return 0
    return fac(n)/(fac(r)*fac(n-r))


n=int(input())
k=int(input())

nn=str(n)
keta=len(nn)

ans=0


for i in range(k):
    ans+=comb(keta-i-1,k-i)*9**(k-i)
    if int(nn[i])-1>=0:
        ans+=(int(nn[i])-1)*comb(keta-i-1,k-i-1)*9**(k-i-1)



print(int(ans)+1)

Fixed submission:
from math import factorial as fac

def comb(n,r):
    if ( r<0 or r>n ):
        return 0
    return fac(n)/(fac(r)*fac(n-r))


n=int(input())
k=int(input())

nn=str(n)
keta=len(nn)

ans=0

if keta<k:
    print(0)
    exit()

zero=0

# for i in range(keta):
#     if int(nn[i])==0:zero+=1
#     ans+=comb(keta-i-1,k-i+zero)*9**(k-i)
#     if int(nn[i])-1>=0:
#         ans+=(int(nn[i])-1)*comb(keta-i-1,k-i-1+zero)*9**(k-i-1+zero)
#
# if keta-zero==k:ans+=1

def search(n,k):
    if k<=0:return
    global ans
    nn = str(n)
    keta = len(nn)
    ans += comb(keta - 1, k ) * 9 ** k
    if int(nn[0])-1>0:
        ans+=(int(nn[0])-1)*comb(keta-1,k-1)*9**(k-1)
    ne=n-int(nn[0])*10**(keta-1)
    search(ne,k-1)


search(n,k)
for i in range(keta):
    if nn[i]=="0":zero+=1
if keta-zero>=k:ans+=1
print(int(ans))
Buggy python submission (verdict: Runtime Error):
h,n=map(int,input().split())
a=[]
ab=[]

for i in range(n):
    aabb=list(map(int,input().split()))
    ab.append(aabb)
    a.append(aabb[0])

loop=h+max(a)
cost=[-1 for i in range(loop)]
cost[0]=0
i=0
costlist=[]
while i<loop:
    costlist.clear()
    for j in range(n):
        ii=i-ab[j][0]
        if (0<=ii<h)&(cost[ii]>=0):
            costlist.append(cost[ii]+ab[j][1])
    if len(costlist)!=0:
        cost[i]=min(costlist)
    i+=1
acost=[i for i in cost[h:] if i!=-1]
ans=min(acost)
print(ans)

Fixed submission:
h,n=map(int,input().split())
a=[]
ab=[]

for i in range(n):
    aabb=list(map(int,input().split()))
    ab.append(aabb)
    a.append(aabb[0])

loop=h+max(a)
cost=[-1 for i in range(loop)]
cost[0]=0
i=0
costlist=[]
while i<loop:
    costlist=[]
    for j in range(n):
        ii=i-ab[j][0]
        if (0<=ii<h)&(cost[ii]>=0):
            costlist.append(cost[ii]+ab[j][1])
    if len(costlist)!=0:
        cost[i]=min(costlist)
    i+=1
acost=[i for i in cost[h:] if i!=-1]
ans=min(acost)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
a=[]
ab=[]

for i in range(n):
    aabb=list(map(int,input().split()))
    ab.append(aabb)
    a.append(aabb[0])

loop=h+max(a)
cost=[-1 for i in range(loop)]
cost[0]=0
i=0
costlist=[]
while i<loop:
    costlist.clear()
    for j in range(n):
        ii=i-ab[j][0]
        if (0<=ii<h)&(cost[ii]>=0):
            costlist.append(cost[ii]+ab[j][1])
    if len(costlist)!=0:
        cost[i]=min(costlist)
    i+=1
acost=[i for i in cost[h:] if i!=-1]
ans=min(acost)
print(ans)

Fixed submission:
h,n=map(int,input().split())
a=[]
ab=[]

for i in range(n):
    aabb=list(map(int,input().split()))
    ab.append(aabb)
    a.append(aabb[0])

loop=h+max(a)
cost=[-1 for i in range(loop)]
cost[0]=0
i=0
costlist=[]
while i<loop:
    costlist=[]
    for j in range(n):
        ii=i-ab[j][0]
        if (0<=ii<h)&(cost[ii]>=0):
            costlist.append(cost[ii]+ab[j][1])
    if len(costlist)!=0:
        cost[i]=min(costlist)
    i+=1
acost=[i for i in cost[h:] if i!=-1]
ans=min(acost)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m==map(int,input().split())
if n==m:
    print("Yes")
else:
    print("No")

Fixed submission:
n,m=map(int,input().split())
if n==m:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
p=[]*n
p=list(map(int,input().split()))
cnt=0
for i in range(n):

    for j in range(0,i+1):
        if p[j]<p[i]:
            break
        if i==j:
            cnt+=1
print(cnt)

Fixed submission:
n=int(input())
p=[]*n
p=list(map(int,input().split()))
cnt=0
com=p[0]
for i in range(n):
    if com>=p[i]:
        cnt+=1
    com=min(com,p[i])
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000000)

from fractions import gcd
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x


mod = 1000000007


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))



n=int(input())
aa=[]
aa=list(map(int,input().split()))
# for i in range(n):
#     aa.append(randint(1,10**6))

bb=lcm(aa)
mod=10**9+7
ans=0
for i in range(n):
    ccc=div(bb,aa[i])
    ans=int((ccc%mod+ans%mod)%mod)
print(int(ans))

Fixed submission:
import sys
sys.setrecursionlimit(2000000)

from fractions import gcd
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x


mod = 1000000007


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))



n=int(input())
aa=[]
aa=list(map(int,input().split()))
# for i in range(n):
#     aa.append(randint(1,10**6))

bb=lcm(aa)
mod=10**9+7
ans=0
for i in range(n):
    ccc=div(bb,aa[i])
    ans=int((ccc%mod+ans%mod)%mod)
print(int(ans))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

n=int(input())
aa=[]*n
aa=list(map(int,input().split()))

bb=lcm(aa)
mod=10**9+7
ans=0
for i in range(n):
    ans=(bb/aa[i]+ans)%mod
print(int(ans))

Fixed submission:
import sys
sys.setrecursionlimit(2000000)

from fractions import gcd
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x


mod = 1000000007


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))



n=int(input())
aa=[]
aa=list(map(int,input().split()))
# for i in range(n):
#     aa.append(randint(1,10**6))

bb=lcm(aa)
mod=10**9+7
ans=0
for i in range(n):
    ccc=div(bb,aa[i])
    ans=int((ccc%mod+ans%mod)%mod)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]*n
a=list(map(int,input().split()))
num=1
bre=0
no=True
def search(pos):
    spos=pos
    global num,bre,no
    end=True
    while end:
        if spos >= n:
            break
        if a[spos]==num:
            no=False
            num+=1
            search(spos+1)
            end=False
        else:
            spos+=1
            bre+=1

search(0)
if no:
    bre=-1
print(bre)

Fixed submission:
import sys
sys.setrecursionlimit(2000000)

n=int(input())
a=[]*n
a=list(map(int,input().split()))
num=1
bre=0
no=True
def search(pos):
    spos=pos
    global num,bre,no
    end=True
    while end:
        if spos >= n:
            break
        if a[spos]==num:
            no=False
            num+=1
            search(spos+1)
            end=False
        else:
            spos+=1
            bre+=1

search(0)
if no:
    bre=-1
print(bre)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]*n
a=list(map(int,input().split()))
num=1
bre=0
no=True
def search(pos,s):
    spos=pos
    global num,bre,no
    end=True
    while end:
        if spos >= n:
            break
        if a[spos]==s:
            no=False
            bre+=spos-pos
            num+=1
            search(spos+1,num)
            end=False
        else:spos+=1
search(0, num)
if no:
    bre=-1
print(bre)

Fixed submission:
import sys
sys.setrecursionlimit(2000000)

n=int(input())
a=[]*n
a=list(map(int,input().split()))
num=1
bre=0
no=True
def search(pos):
    spos=pos
    global num,bre,no
    end=True
    while end:
        if spos >= n:
            break
        if a[spos]==num:
            no=False
            num+=1
            search(spos+1)
            end=False
        else:
            spos+=1
            bre+=1

search(0)
if no:
    bre=-1
print(bre)