Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
S = input()
T = [0]*N

for n in range(N-1):
  if S[n] == "A" and S[n+1] =="C":
    T[n] += 1

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


Fixed submission:
N, Q = map(int,input().split())
S = input()
T = [0]*N

for n in range(1,N):
  T[n] = T[n-1]
  if S[n-1] == "A" and S[n] =="C":T[n] += 1

for q in range(Q):
  l, r = map(int,input().split())
  print(T[r-1]-T[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
hN = list(map(int,input().split()))
dp = [1000000000]*N
dp[0] = 0
for n in range(N-1):
  for k in range(min(K,N-n-1)):
    dp[n+k+1] = min(dp[n+k+1], dp[n]+abs(hN[n]-hN[n+k+1]))
print(dp[-1])


Fixed submission:
N, K = map(int,input().split())
hN = list(map(int,input().split()))
dp = [1000000000]*N
dp[0] = 0
for n in range(N-1):
  for k in range(min(K,N-n-1)):
    dp[n+k+1] = min(dp[n+k+1], dp[n]+abs(hN[n]-hN[n+k+1]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int,input().split())
dp = [[0]*(W+1) for _ in range(N+1)]
for n in range(1,N+1):
  wn, vn = map(int,input().split())
  dp[n][:] = dp[n-1][:]
  for w in range(W+1):
    if w + wn > W: break
    dp[n][w+wn] = max(dp[n][w+wn],dp[n-1][w]+vn)
print(max(dp[N]))

Fixed submission:
N, W = map(int,input().split())
dp = [[0]*(W+1) for _ in range(N+1)]
for n in range(1,N+1):
  wn, vn = map(int,input().split())
  dp[n][:] = dp[n-1][:]
  for w in range(W+1):
    if w + wn > W: break
    dp[n][w+wn] = max(dp[n][w+wn],dp[n-1][w]+vn)
print(max(dp[N]))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = input()
for i in range(len(S)):
  if S[i] != T[i]:
    tmp1 = S[i]
    tmp2 = T[i]
    S = S.replace(tmp1, "0")
    S = S.replace(tmp2, "1")
    S = S.replace("0", tmp2)
    S = S.replace("1", tmp1)
print("Yes" if S == T else "No")    


Fixed submission:
from collections import Counter
print("Yes" if sorted(Counter(input()).values()) == sorted(Counter(input()).values()) else "No")

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = input()
for i in range(len(S)):
  if S[i] != T[i]:
    tmp1 = S[i]
    tmp2 = T[i]
    S = S.replace(tmp1, "0")
    S = S.replace(tmp2, "1")
    S = S.replace("0", tmp2)
    S = S.replace("1", tmp1)
print("Yes" if S == T else "No")    


Fixed submission:
from collections import Counter
print("Yes" if sorted(Counter(input()).values()) == sorted(Counter(input()).values()) else "No")
Buggy python submission (verdict: Runtime Error):
print(input().replace("1","")[0])

Fixed submission:
import sys
S = input()
K = int(input())
for k in range(K):
  if S[k] != "1":
    print(S[k])
    sys.exit()
print(1)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
hairetu = []
for _ in range(N):
  a, b = map(int,input().split())
  hairetu.extend([a]*b)
print(sorted(hairetu)[K-1])

Fixed submission:
import sys
N, K = map(int,input().split())
hairetu = []
for _ in range(N): hairetu.append(list(map(int,input().split())))
hairetu.sort()
cnt = 0
for i in range(N):
  cnt += hairetu[i][1]
  if K <= cnt:
    print(hairetu[i][0])
    sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
N = int(input())
for n in range(int(math.sqrt(N)),N+1):
  if N%n==0:
    print(max(int(math.log10(n)), int(math.log10(N//n)))+1)
    sys.exit()
    


Fixed submission:
import sys
import math
N = int(input())
for n in range(int(math.sqrt(N))+1,0,-1):
  if N%n==0:
    print(max(int(math.log10(n)), int(math.log10(N//n)))+1)
    sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
N = int(input())
for n in range(int(math.sqrt(N)),N+1):
  if N%n==0:
    print(max(int(math.log10(n)), int(math.log10(N//n)))+1)
    sys.exit()
    


Fixed submission:
import sys
import math
N = int(input())
for n in range(int(math.sqrt(N))+1,0,-1):
  if N%n==0:
    print(max(int(math.log10(n)), int(math.log10(N//n)))+1)
    sys.exit()
Buggy python submission (verdict: Runtime Error):
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N,K = LI()
A = LI()

#方針
#ループ検知でmod演算に移行
hist = []
now = 0
chk = [-1] * N
while True:
	hist.append(now+1)
	if chk[now] != -1:
		# ループ検知
		break
	chk[now] = len(hist)-1
	now = A[now]-1
K-=chk[hist[len(hist)-1]-1]
cutlist = hist[hist[len(hist)-1]+1:]
K%=len(cutlist)
print(cutlist[K-1])
#print("histpos[town]:",chk)
#print("hist:",hist)


Fixed submission:
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N,K = LI()
A = LI()

#方針
#ループ検知でmod演算に移行
hist = []
now = 0
chk = [-1] * N
while True:
	hist.append(now+1)
	if chk[now] != -1:
		# ループ検知
		break
	chk[now] = len(hist)-1
	now = A[now]-1
#print("histpos[town]:",chk)
#print("hist:",hist)
loopstart = chk[hist[len(hist)-1]-1]+1
if K >= len(hist):
	K-=loopstart
	K%=len(hist)-loopstart
	print(hist[loopstart+K])
else:
	print(hist[K])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N, M = LI()
A = [I() for _ in range(M)]
md = 10**9+7

dp = [0] * (N+1)
dp[0] = 1

for now in range(N):
  for next in range(now+1, now+3):
    if next == N:
      dp[next] += dp[now]
      dp[next] %= md
      break
    if next in A:
      continue
    else:
      dp[next] += dp[now]
      dp[next] %= md

print(dp[N])

Fixed submission:
#import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N, M = LI()
A = [I() for _ in range(M)]
md = 10**9+7


dp = [0] * (N+1)
dp[0] = 1
chk = [True] * (N+1)
for a in A:
  chk[a] = False

for now in range(N):
  for next in range(now+1, now+3):
    if next == N:
      dp[next] += dp[now]
      dp[next] %= md
      break
    if not chk[next]:
      continue
    else:
      dp[next] += dp[now]
      dp[next] %= md

print(dp[N])
Buggy python submission (verdict: Runtime Error):
a = [i for i in range(int((A-1)*100/8 ), int((A+1)*100/8 ))]
b = [i for i in range(int((B-1)*100/10), int((B+1)*100/10))]

a = [i for i in a if int(i*0.08) == A]
b = [i for i in b if int(i*0.10) == B]

ans = list(set(a) & set(b))
if ans and min(ans) > 0:
    print(min(ans))
else:
    print(-1)


Fixed submission:
A, B = map(int, input().split())

a = [i for i in range(int((A-1)*100/8 ), int((A+1)*100/8 ))]
b = [i for i in range(int((B-1)*100/10), int((B+1)*100/10))]

a = [i for i in a if int(i*0.08) == A]
b = [i for i in b if int(i*0.10) == B]

ans = list(set(a) & set(b))
if ans and min(ans) > 0:
    print(min(ans))
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

s = input()
q = int(input())
rev = 0
ans = ['S']

for _ in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    rev += 1
  else:
    if int(query[1]) == 1:      # 先頭
      if rev%2 == 0:
        ans = [query[2]] + ans
      else:
        ans = ans + [query[2]]
    else:                       # 末尾
      if rev%2 == 0:
        ans = ans + [query[2]]
      else:
        ans = [query[2]] + ans

ans = ''.join(ans)
mes = ans.replace("S", s)
if rev%2 == 0:
  print(mes)
else:
  print(mes[::-1])


Fixed submission:
import collections

s = input()
q = int(input())
rev = 0
ans = collections.deque(['S'])

for _ in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    rev += 1
  else:
    if int(query[1]) == 1:      # 先頭
      if rev%2 == 0:
        ans.appendleft(query[2])
      else:
        ans.append(query[2])
    else:                       # 末尾
      if rev%2 == 0:
        ans.append(query[2])
      else:
        ans.appendleft(query[2])

ans = ''.join(ans)
mes = ans.replace("S", s)
if rev%2 == 0:
  print(mes)
else:
  print(mes[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
rev = 0
ans = 'S'

for _ in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    rev += 1
  else:
    if int(query[1]) == 1:      # 先頭
      if rev%2 == 0:
        ans = query[2] + ans
      else:
        ans = ans + query[2]
    else:                       # 末尾
      if rev%2 == 0:
        ans = ans + query[2]
      else:
        ans = query[2] + ans

mes = ans.replace("S", s)
if rev%2 == 0:
  print(mes)
else:
  print(mes[::-1])



Fixed submission:
import collections

s = input()
q = int(input())
rev = 0
ans = collections.deque(['S'])

for _ in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    rev += 1
  else:
    if int(query[1]) == 1:      # 先頭
      if rev%2 == 0:
        ans.appendleft(query[2])
      else:
        ans.append(query[2])
    else:                       # 末尾
      if rev%2 == 0:
        ans.append(query[2])
      else:
        ans.appendleft(query[2])

ans = ''.join(ans)
mes = ans.replace("S", s)
if rev%2 == 0:
  print(mes)
else:
  print(mes[::-1])
Buggy python submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))

Qa,Qw = [0 for _ in range(N)], [0 for _ in range(N)]
for _ in range(M):
    p, S = input().split()
    p = int(p)-1

    if S == 'AC':
        Qa[p] = 1
    elif S == 'WA':
        if Qa[p] <= 0:
            Qw[p] += 1

AC = sum([ac for ac in Qa])
WA = sum([Qw[i] for i in Qa if Qa[i] > 0])
print( AC, WA)


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

Qa,Qw = {}, {}
for _ in range(M):
    p, S = input().split()
    p = int(p)-1

    if p not in Qa:
        Qa[p] = 0

    if p not in Qw:
        Qw[p] = 0

    if S == 'AC':
        Qa[p] = 1
    elif S == 'WA':
        if Qa[p] <= 0:
            Qw[p] += 1

AC = sum([ac for ac in Qa.values()])
WA = sum([Qw[k] for k,v in Qa.items() if v > 0])
print( AC, WA)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N = int(input())
an = list(map(int,input().split()))
#an = [5,10,12]
an.sort()

max_v = 0
max_e = None
for i in an[:-1]:
    n,r = swap(an[-1], i)
    v = comb(n,r)
    if v > max_v:
        max_v = v
        max_e = (n,r)
    #print(c, comb(*c))

print(max_e[0], max_e[1])


Fixed submission:
import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

_ = input()
an = list(map(int,input().split()))
#an = [5,10,12]
an.sort()
target = an[-1]/2
res = min(enumerate(an), key=lambda x: abs(target - x[1]))
print(an[-1], res[1])

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

def swap(a,b):
    return max(a,b),min(a,b)

def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N = int(input())
an = list(map(int,input().split()))
#an = [5,10,12]
an.sort()

max_v = 0
max_e = None
for c in itertools.combinations(an, 2):
    n,r = swap(*c)
    v = comb(n,r)
    if v > max_v:
        max_v = v
        max_e = (n,r)
    #print(c, comb(*c))

print(max_e[0], max_e[1])



Fixed submission:
import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

_ = input()
an = list(map(int,input().split()))
#an = [5,10,12]
an.sort()
target = an[-1]/2
res = min(enumerate(an), key=lambda x: abs(target - x[1]))
print(an[-1], res[1])

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

def swap(a,b):
    return max(a,b),min(a,b)

def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N = int(input())
an = [int(input()) for i in range(N)]
#an = [5,10,12]
an.sort()

max_v = 0
max_e = None
for c in itertools.combinations(an, 2):
    v = comb(swap(c))
    if v > max_v:
        max_v = v
        max_e = swap(c)
    #print(c, comb(*c))

print(max_e)


Fixed submission:
import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

_ = input()
an = list(map(int,input().split()))
#an = [5,10,12]
an.sort()
target = an[-1]/2
res = min(enumerate(an), key=lambda x: abs(target - x[1]))
print(an[-1], res[1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter

def kumi(d):
    ans = 0
    for k, v in d.items():
        ans += v * max(0, v-1) // 2
    return ans

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    d = dict(Counter(v))
    for i in v:
        d[i] -= 1
        print(kumi(d))
        d[i] += 1


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter
from bisect import bisect_left

def f(i, d, dsum, n):
    return func(i, d) + dsum[i] + dsum[n] - dsum[i+1]

def func(i, w):
    return w[i][1] * max(0, w[i][1]-1) // 2

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    d = dict(Counter(v))
    w = []
    for k in sorted(d.keys()):
        w.append([k, d[k]])
    m = len(w)
    c = [0] * (m+1)
    for i in range(1, m+1):
        c[i] = c[i-1] + func(i-1, w)
        # print(func(i-1, w))
    q = [u[0] for u in w]
    # print(c)
    # print(w)
    for i in v:
        g = bisect_left(q, i)
        # print(q)
        # print(i)
        # print('g: ', g)
        w[g][1] -= 1
        print(f(g, w, c, m))
        w[g][1] += 1


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter

def kumi(d):
    ans = 0
    for k, v in d.items():
        ans += v * max(0, v-1) // 2
    return ans

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    d = dict(Counter(v))
    for i in v:
        t = dict(d)
        t[i] -= 1
        print(kumi(t))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter
from bisect import bisect_left

def f(i, d, dsum, n):
    return func(i, d) + dsum[i] + dsum[n] - dsum[i+1]

def func(i, w):
    return w[i][1] * max(0, w[i][1]-1) // 2

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    d = dict(Counter(v))
    w = []
    for k in sorted(d.keys()):
        w.append([k, d[k]])
    m = len(w)
    c = [0] * (m+1)
    for i in range(1, m+1):
        c[i] = c[i-1] + func(i-1, w)
        # print(func(i-1, w))
    q = [u[0] for u in w]
    # print(c)
    # print(w)
    for i in v:
        g = bisect_left(q, i)
        # print(q)
        # print(i)
        # print('g: ', g)
        w[g][1] -= 1
        print(f(g, w, c, m))
        w[g][1] += 1


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def powr(i, j, d):
    p = j
    ans = 1
    while p != 0:
        if p % 2 == 1:
            ans = (ans * i) % d
        i = i**2 % d
        p >>= 1
    return ans

def div(i, j):
    # 1/i mod(j)
    # calc i**(j-2) mod(j)
    return powr(i, j-2, j)

def make_comb(m, d):
    fac = [0] * (m+1)
    ifac = [0] * (m+1)
    # nCk
    fac[0] = 1
    ifac[0] = 1
    for i in range(m):
        fac[i+1] = (fac[i] * (i+1)) % d
        ifac[i+1] = (ifac[i] * div(i+1, d)) % d
    def comb(n, k):
        if n == 0 and k == 0:
            return 1
        if n < k or n < 0:
            return 0
        return (fac[n] * ifac[k] * ifac[n-k]) % d
    return comb

def main():
    n, a, b = list(map(int, input().strip().split()))
    d = 10**9+7
    comb = make_comb(10**6, d)
    ans = (powr(2, n, d) - 1 - comb(n, a) - comb(n, b)) % d
    if ans < 0:
        print(ans + d)
    else:
        print(ans)

    # print(comb(10, 2))
    # print(comb(5, 2))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def powr(i, j, d):
    p = j
    ans = 1
    while p != 0:
        if p % 2 == 1:
            ans = (ans * i) % d
        i = i**2 % d
        p >>= 1
    return ans

def div(i, j):
    # 1/i mod(j)
    # calc i**(j-2) mod(j)
    return powr(i, j-2, j)

# def make_comb(m, d):
#     fac = [0] * (m+1)
#     ifac = [0] * (m+1)
#     # nCk
#     fac[0] = 1
#     ifac[0] = 1
#     for i in range(m):
#         fac[i+1] = (fac[i] * (i+1)) % d
#         ifac[i+1] = (ifac[i] * div(i+1, d)) % d
#     def comb(n, k):
#         if n == 0 and k == 0:
#             return 1
#         if n < k or n < 0:
#             return 0
#         return (fac[n] * ifac[k] * ifac[n-k]) % d
#     return comb

def nck(n, k, d):
    ans = 1
    for i in range(n-(k-1), n+1):
        ans *= i % d
        ans %= d
    for i in range(1, k+1):
        ans *= div(i, d)
        ans %= d
    return ans % d

def main():
    n, a, b = list(map(int, input().strip().split()))
    d = 10**9+7
    # comb = make_comb(10**6, d)
    ans = (powr(2, n, d) - 1 - nck(n, a, d) - nck(n, b, d)) % d
    if ans < 0:
        print(ans + d)
    else:
        print(ans)

    # print(comb(10, 2))
    # print(comb(5, 2))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
MOD = 10**9+7

def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    a = v[0]
    lcm = v[0]
    for i in range(n):
        if i > 0:
            tmp = a
            a = gcd(a, v[i])
            c_lcm = tmp * v[i] // a
            lcm = c_lcm * lcm // gcd(c_lcm, lcm)
    ans = 0
    for i in range(n):
        ans += lcm // v[i] % MOD
    print(ans % MOD)
    # for i in range(n):
    #     ans += lcm * pow(v[i], MOD-2, MOD)
    # print(ans % MOD)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
MOD = 10**9+7

def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    a = v[0]
    lcm = v[0]
    for i in range(n):
        if i > 0:
            tmp = a
            a = gcd(a, v[i])
            c_lcm = tmp * v[i] // a
            lcm = c_lcm * lcm // gcd(c_lcm, lcm)
    ans = 0
    # for i in range(n):
    #     ans += lcm // v[i]
    # print(ans % (10**9+7))
    for i in range(n):
        ans += lcm * pow(v[i], MOD-2, MOD)
    print(ans % MOD)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    a = v[0]
    lcm = v[0]
    for i in range(n):
        if i > 0:
            tmp = a
            a = gcd(a, v[i])
            c_lcm = tmp * v[i] // a
            # print("lcm: ", lcm)
            # print("clcm: ", c_lcm)
            lcm = c_lcm * lcm // gcd(c_lcm, lcm)
    ans = 0
    for i in range(n):
        ans += lcm // v[i]
    print(ans % (10**9+7))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
MOD = 10**9+7

def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    a = v[0]
    lcm = v[0]
    for i in range(n):
        if i > 0:
            tmp = a
            a = gcd(a, v[i])
            c_lcm = tmp * v[i] // a
            lcm = c_lcm * lcm // gcd(c_lcm, lcm)
    ans = 0
    # for i in range(n):
    #     ans += lcm // v[i]
    # print(ans % (10**9+7))
    for i in range(n):
        ans += lcm * pow(v[i], MOD-2, MOD)
    print(ans % MOD)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from math import factorial

fac = [0] * (10**6+1)
ifac = [0] * (10**6+1)
d = 10**9 + 7

def mpow(x, n):
    ans = 1
    while n != 0:
        if n&1:
            ans = ans * x % d
        x = x*x % d
        n = n >> 1
    return ans

def comb(a, b):
    if a == 0 and b == 0:
        return 1
    if a < b or a < 0:
        return 0
    tmp = ifac[a-b] * ifac[b] % d
    return tmp * fac[a] % d

def main():
    global fac, ifac
    x, y = map(int, input().strip().split())
    if (x + y) % 3 != 0:
        print(0)
        return
    k = (x+y) // 3
    q = x - k

    fac[0] = 1
    ifac[0] = 1
    for i in range(10**6+1):
        fac[i+1] = fac[i]*(i+1) % d
        ifac[i+1] = ifac[i]*mpow(i+1, d-2) % d

    print(comb(k, q) % d)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from math import factorial

fac = [0] * (10**6+5)
ifac = [0] * (10**6+5)
d = 10**9 + 7

def mpow(x, n):
    ans = 1
    while n != 0:
        if n&1:
            ans = ans * x % d
        x = x*x % d
        n = n >> 1
    return ans

def comb(a, b):
    if a == 0 and b == 0:
        return 1
    if a < b or a < 0:
        return 0
    tmp = ifac[a-b] * ifac[b] % d
    return tmp * fac[a] % d

def main():
    global fac, ifac
    x, y = map(int, input().strip().split())
    if (x + y) % 3 != 0:
        print(0)
        return
    k = (x+y) // 3
    q = x - k
    if x - 2 * q < 0 or q < 0:
        print(0)
        return

    fac[0] = 1
    ifac[0] = 1
    for i in range(10**6+1):
        fac[i+1] = fac[i]*(i+1) % d
        ifac[i+1] = ifac[i]*mpow(i+1, d-2) % d

    print(comb(k, q) % d)

if __name__ == '__main__':
    main()