Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import exit
from random import randrange
MOD = 10**9+7
n, k = map(int, input().split())
b = list(map(int, input().split()))
a = []
if n == k:
	ans = 1
	for x in b:
		ans *= x
		ans %= MOD
	print(ans)
	exit()
for x in b:
	if x != 0:
		a.append(x)
if len(a) < k:
	print(0)
	exit()

a.sort(key=lambda x: -abs(x))
#print(a)
ans = 1
minus = 0
for i in range(k):
	ans *= a[i]
	ans %= MOD
	if a[i] < 0:
		minus += 1

if minus%2 == 0:
	print(ans)
	exit()

if len(a) == k:
	if len(a) < n:
		print(0)
		exit()

for i in range(k, len(a)):
	if a[i] < 0:
		minus += 1

if minus == len(a):
	if len(a) < n:
		print(0)
		exit()
	ans = 1
	for i in range(k):
		ans *= a[-i-1]
		ans %= MOD
	print(ans)
	exit()

for i in range(k-1, -1, -1):
	if a[i] * a[k] < 0:
		p, q = a[i], a[k]
		break
for i in range(k, len(a)):
	if a[k-1] * a[i] < 0:
		r, s = a[k-1], a[i]
		break
if abs(q*r) >= abs(p*s):
	ans *= pow(p, MOD-2, MOD)
	ans *= q
	print(ans%MOD)
else:
	ans *= pow(r, MOD-2, MOD)
	ans *= s
	print(ans%MOD)

Fixed submission:
from sys import exit
from random import randrange
MOD = 10**9+7
n, k = map(int, input().split())
b = list(map(int, input().split()))
a = []
if n == k:
	ans = 1
	for x in b:
		ans *= x
		ans %= MOD
	print(ans)
	exit()
for x in b:
	if x != 0:
		a.append(x)
if len(a) < k:
	print(0)
	exit()

a.sort(key=lambda x: -abs(x))
#print(a)
ans = 1
minus = 0
for i in range(k):
	ans *= a[i]
	ans %= MOD
	if a[i] < 0:
		minus += 1

if minus%2 == 0:
	print(ans)
	exit()

if len(a) == k:
	if len(a) < n:
		print(0)
		exit()

for i in range(k, len(a)):
	if a[i] < 0:
		minus += 1

if minus == len(a):
	if len(a) < n:
		print(0)
		exit()
	ans = 1
	for i in range(k):
		ans *= a[-i-1]
		ans %= MOD
	print(ans)
	exit()

flg1 = False
for i in range(k-1, -1, -1):
	if a[i] * a[k] < 0:
		p, q = a[i], a[k]
		flg1 = True
		break

flg2 = False
for i in range(k, len(a)):
	if a[k-1] * a[i] < 0:
		r, s = a[k-1], a[i]
		flg2 = True
		break

if flg1 and flg2:
	if abs(q*r) >= abs(p*s):
		ans *= pow(p, MOD-2, MOD)
		ans *= q
		print(ans%MOD)
	else:
		ans *= pow(r, MOD-2, MOD)
		ans *= s
		print(ans%MOD)

elif flg1:
	ans *= pow(p, MOD-2, MOD)
	ans *= q
	print(ans%MOD)

elif flg2:
	ans *= pow(r, MOD-2, MOD)
	ans *= s
	print(ans%MOD)

else:
	print("コーナーケース多すぎん？")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a.sort()
ok = [True for _ in range(10**6+1)]
ans = 0
for i, x in enumerate(a):
	if ok[x]:
		if i == n-1:
			ans += 1
		elif a[i+1] != x:
			ans += 1
	for y in range(x, 10**6+1, x):
		ok[y] = False
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
num = [0 for _ in range(10**6+1)]
for x in a:
	num[x] += 1

ok = [True for _ in range(10**6+1)]
ans = 0
for i in range(1, 10**6+1):
	if num[i] == 1 and ok[i] == True:
		ans += 1
	if num[i]:
		for j in range(i, 10**6+1, i):
			ok[j] = False
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit
n = int(input())
ans = 1
a = list(map(int, input().split()))
for x in a:
	ans *= x
if ans > 10**18:
	print(-1)
	exit()
print(ans)

Fixed submission:
from sys import exit
n = int(input())
ans = 1
a = list(map(int, input().split()))
if 0 in a:
	print(0)
	exit()
for x in a:
	ans *= x
	if ans > 10**18:
		print(-1)
		exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**6)
def input():
	return sys.stdin.readline()[:-1]
n = int(input())
a = list(map(int, input().split()))
adj = [[] for _ in range(n)]
for _ in range(n-1):
	u, v = map(int, input().split())
	adj[u-1].append(v-1)
	adj[v-1].append(u-1)

INF = 10**6
dp = [INF for _ in range(n)]
ans = [0 for _ in range(n)]

def dfs(x, p):
	ans[x] = bisect_left(dp, INF)
	for v in adj[x]:
		if v == p:
			continue
		ind = bisect_left(dp, a[v])
		pres = dp[ind]
		dp[ind] = a[v]
		dfs(v, x)
		dp[ind] = pres
	return

dp[0] = a[0]
dfs(0, -1)
print(*ans, sep="\n")

Fixed submission:
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**6)
def input():
	return sys.stdin.readline()[:-1]
n = int(input())
a = list(map(int, input().split()))
adj = [[] for _ in range(n)]
for _ in range(n-1):
	u, v = map(int, input().split())
	adj[u-1].append(v-1)
	adj[v-1].append(u-1)

INF = 10**10
dp = [INF for _ in range(n)]
ans = [0 for _ in range(n)]

def dfs(x, p):
	ans[x] = bisect_left(dp, INF)
	for v in adj[x]:
		if v == p:
			continue
		ind = bisect_left(dp, a[v])
		pres = dp[ind]
		dp[ind] = a[v]
		dfs(v, x)
		dp[ind] = pres
	return

dp[0] = a[0]
dfs(0, -1)
print(*ans, sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
	return sys.stdin.readline()[:-1]
n, s = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353
dp = [0 for _ in range(3001)]
dp[0] = 1
ans = 0
for i in range(n):
	for j in range(s, a[i]-1, -1):
		dp[j] += dp[j-a[i]]
		dp[j] %= MOD
	dp[a[i]] += i
	dp[a[i]] %= MOD
	ans += dp[s]
	ans %= MOD
print(ans)

Fixed submission:
import sys
def input():
	return sys.stdin.readline()[:-1]
n, s = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353
dp = [0 for _ in range(3001)]
dp[0] = 1
ans = 0
for i in range(n):
	for j in range(s, a[i]-1, -1):
		dp[j] += dp[j-a[i]]
		dp[j] %= MOD
	dp[a[i]] += i
	dp[a[i]] %= MOD
	ans += dp[s]
	ans %= MOD
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
def input():
	return sys.stdin.readline()[:-1]
n, s = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353
dp = [0 for _ in range(s+1)]
dp[0] = 1
ans = 0
for i in range(n):
	for j in range(s, a[i]-1, -1):
		dp[j] += dp[j-a[i]]
		dp[j] %= MOD
	dp[a[i]] += i
	dp[a[i]] %= MOD
	ans += dp[s]
	ans %= MOD
print(ans)

Fixed submission:
import sys
def input():
	return sys.stdin.readline()[:-1]
n, s = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353
dp = [0 for _ in range(3001)]
dp[0] = 1
ans = 0
for i in range(n):
	for j in range(s, a[i]-1, -1):
		dp[j] += dp[j-a[i]]
		dp[j] %= MOD
	dp[a[i]] += i
	dp[a[i]] %= MOD
	ans += dp[s]
	ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

s = input()
n = len(s)
q = int(input())
front = ""
back = ""
sgn = 0
for _ in range(q):
	query = input().split()
	if query[0] == "1":
		sgn ^= 1
	else:
		f, c = int(query[1])-1, query[2]
		if f ^ sgn == 0:
			front += c
		else:
			back += c
if not sgn:
	print(front[::-1] + s + back)
else:
	print(back[::-1] + s[::-1] + front)

Fixed submission:
import sys
def input():
	return sys.stdin.readline()[:-1]

s = input()
#n = len(s)
q = int(input())
front = ""
back = ""
sgn = 0
for _ in range(q):
	query = input().split()
	if query[0] == "1":
		sgn ^= 1
	else:
		f, c = int(query[1])-1, query[2]
		if f ^ sgn == 0:
			front += c
		else:
			back += c
if not sgn:
	print(front[::-1] + s + back)
else:
	print(back[::-1] + s[::-1] + front)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
	return sys.stdin.readline()[:-1]

s = input()
n = len(s)
q = int(input())
front = ""
back = ""
sgn = 0
for _ in range(q):
	query = input().split()
	if query[0] == "1":
		sgn ^= 1
	else:
		f, c = int(query[1])-1, query[2]
		if f ^ sgn == 0:
			front += c
		else:
			back += c
if not sgn:
	print(front[::-1] + s + back)
else:
	print(back[::-1] + s[::-1] + front)

Fixed submission:
import sys
def input():
	return sys.stdin.readline()[:-1]

s = input()
#n = len(s)
q = int(input())
front = ""
back = ""
sgn = 0
for _ in range(q):
	query = input().split()
	if query[0] == "1":
		sgn ^= 1
	else:
		f, c = int(query[1])-1, query[2]
		if f ^ sgn == 0:
			front += c
		else:
			back += c
if not sgn:
	print(front[::-1] + s + back)
else:
	print(back[::-1] + s[::-1] + front)
Buggy python submission (verdict: Time Limit Exceeded):
n, p = map(int, input().split())
s = input()
if p == 2:
	ans = 0
	for i in range(n):
		if int(s[i]) % 2 == 0:
			ans += i+1
	print(ans)
elif p == 5:
	ans = 0
	for i in range(n):
		if s[i] == "5" or s[i] == "0":
			ans += i+1
	print(ans)

else:
	mods = [0 for _ in range(p)]
	cur = 0
	mods[0] += 1
	t = s[::-1]
	for i in range(n):
		cur = (cur + int(t[i]) * (10 ** i)) % p
		mods[cur] += 1
	#print(mods)
	ans = 0
	for m in mods:
		ans += (m * (m-1)) // 2
	print(ans)

Fixed submission:
n, p = map(int, input().split())
s = input()
if p == 2:
	ans = 0
	for i in range(n):
		if int(s[i]) % 2 == 0:
			ans += i+1
	print(ans)
elif p == 5:
	ans = 0
	for i in range(n):
		if s[i] == "5" or s[i] == "0":
			ans += i+1
	print(ans)

else:
	mods = [0 for _ in range(p)]
	cur = 0
	mods[0] += 1
	t = s[::-1]
	for i in range(n):
		cur = (cur + int(t[i]) * pow(10, i, p)) % p
		mods[cur] += 1
	#print(mods)
	ans = 0
	for m in mods:
		ans += (m * (m-1)) // 2
	print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, p = map(int, input().split())
s = input()
if p == 2:
	ans = 0
	for i in range(n):
		if int(s[i]) % 2 == 0:
			ans += i+1
	print(ans)
elif p == 5:
	ans = 0
	for i in range(n):
		if s[i] == "5" or s[i] == "0":
			ans += i+1
	print(ans)

else:
	mods = [0 for _ in range(p)]
	cur = 0
	mods[0] += 1
	t = s[::-1]
	for i in range(n):
		cur = (cur + int(t[i]) * (10 ** i)) % p
		mods[cur] += 1
	#print(mods)
	ans = 0
	for m in mods:
		ans += (m * (m-1)) // 2
	print(ans)

Fixed submission:
n, p = map(int, input().split())
s = input()
if p == 2:
	ans = 0
	for i in range(n):
		if int(s[i]) % 2 == 0:
			ans += i+1
	print(ans)
elif p == 5:
	ans = 0
	for i in range(n):
		if s[i] == "5" or s[i] == "0":
			ans += i+1
	print(ans)

else:
	mods = [0 for _ in range(p)]
	cur = 0
	mods[0] += 1
	t = s[::-1]
	for i in range(n):
		cur = (cur + int(t[i]) * pow(10, i, p)) % p
		mods[cur] += 1
	#print(mods)
	ans = 0
	for m in mods:
		ans += (m * (m-1)) // 2
	print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k, q = map(int, input().split())
D = list(map(int, input().split()))

def solve(n, x, m):
	ds = [x%m for x in D]
	nums = [(n-1)//k + (i < ((n-1)%k)) for i in range(k)]
	zero = sum([num for num, d in zip(nums, ds) if d == 0])
	cum = x%m + sum([num * d for num, d in zip(nums, ds)])
	decr = cum // m
	return n-1 - zero - decr

for _ in range(q):
	n, x, m = map(int, input().split())
	print(solve(n, x, m))

Fixed submission:
import sys
def input():
	return sys.stdin.readline()[:-1]

k, q = map(int, input().split())
D = list(map(int, input().split()))

def solve(n, x, m):
	ds = [x%m for x in D]
	nums = [(n-1)//k + (i < ((n-1)%k)) for i in range(k)]
	zero = sum([num for num, d in zip(nums, ds) if d == 0])
	cum = x%m + sum([num * d for num, d in zip(nums, ds)])
	decr = cum // m
	return n-1 - zero - decr

for _ in range(q):
	n, x, m = map(int, input().split())
	print(solve(n, x, m))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]
s += "0"
n = len(s)
dp = [[10**7 for _ in range(2)] for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
	for j in range(2):
		x = int(s[i]) + j
		for a in range(10):
			kurisagaru = False
			if a >= x:
				b = 0
			else:
				b = 10 + a - x
				kurisagaru = True
			dp[i+1][kurisagaru] = min(dp[i+1][kurisagaru], dp[i][j]+a+b)
print(dp[n][0])

Fixed submission:
s = list(input())
s.reverse()
s += ["0"]
n = len(s)
dp = [[10**7 for _ in range(2)] for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
	for j in range(2):
		x = int(s[i]) + j
		for a in range(10):
			kurisagaru = False
			if a >= x:
				b = 0
			else:
				b = 10 + a - x
				kurisagaru = True
			dp[i+1][kurisagaru] = min(dp[i+1][kurisagaru], dp[i][j]+a+b)
print(dp[n][0])

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
s.reverse()
s += ["0"]
n = len(s)
dp = [[10**7 for _ in range(2)] for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
	for j in range(2):
		x = int(s[i]) + j
		for a in range(10):
			kurisagaru = False
			if a >= x:
				b = 0
			else:
				b = 10 + a - x
				kurisagaru = True
			dp[i+1][kurisagaru] = min(dp[i+1][kurisagaru], dp[i][j]+a+b)
print(dp[n][0])

Fixed submission:
s = list(input())
s.reverse()
s += ["0"]
n = len(s)
dp = [[10**7 for _ in range(2)] for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
	for j in range(2):
		x = int(s[i]) + j
		for a in range(10):
			kurisagaru = False
			if a >= x:
				b = 0
			else:
				b = 10 + a - x
				kurisagaru = True
			dp[i+1][kurisagaru] = min(dp[i+1][kurisagaru], dp[i][j]+a+b)
print(dp[n][0])
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
s = input()
n = int(s)
l = len(s)
k = int(input())

if k == 1:
	print(9 * (len(s)-1) + int(s[0]))

elif k == 2:
	if len(s) == 1:
		print(0)
	elif len(s) == 2:
		print(n - 9 - n//10)
	else:
		ans = 81 * (l-1) * (l-2) // 2
		for i in range(1, 10):
			for x in range(l-1):
				for j in range(1, 10):
					if i * (10**(l-1)) + j * (10**x) <= n:
						ans += 1
		print(ans)

else:
	if len(s) < 3:
		print(0)
	elif len(s) == 3:
		ans = 0
		for i in range(100, n+1):
			if "0" not in list(str(i)):
				ans += 1
		print(ans)
	else:
		ans = 729 * (l-1) * (l-2) * (l-3) // 6
		for i in range(1, 10):
			for x, y in combinations(range(l-1), 2):
				for z in range(81):
					j, k = (z//9) + 1, (z%9) + 1
					if i * (10**(l-1)) + j * (10**x) + k * (10**y) <= n:
						ans += 1
		print(ans)

Fixed submission:
from itertools import combinations

s = input()
n = int(s)
l = len(s)
k = int(input())


if k == 1:
	print(9 * (len(s)-1) + int(s[0]))

elif k == 2:
	if len(s) == 1:
		print(0)
	elif len(s) == 2:
		print(n - 9 - n//10)
	else:
		ans = 81 * (l-1) * (l-2) // 2
		for i in range(1, 10):
			for x in range(l-1):
				for j in range(1, 10):
					if i * (10**(l-1)) + j * (10**x) <= n:
						ans += 1
		print(ans)

else:
	if len(s) < 3:
		print(0)
	elif len(s) == 3:
		ans = 0
		for i in range(100, n+1):
			if "0" not in list(str(i)):
				ans += 1
		print(ans)
	else:
		ans = 729 * (l-1) * (l-2) * (l-3) // 6
		ans += (int(s[0])-1) * (l-1) * (l-2) * 81 // 2
		for x, y in combinations(range(l-1), 2):
			for z in range(81):
				j, k = (z//9) + 1, (z%9) + 1
				if int(s[0]) * (10**(l-1)) + j * (10**x) + k * (10**y) <= n:
					ans += 1
		print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect
def input():
	return sys.stdin.buffer.readline()[:-1]

class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def Get(self, i):#iを返す
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def PointAdd(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

	def SegAdd(self, l, r, x):#lからrにxを足す
		self.PointAdd(l, x)
		self.PointAdd(r+1, -x)
		return


n, d, a = map(int, input().split())
d *= 2
mo = sorted([list(map(int, input().split())) for _ in range(n)])
for i in range(n):
	mo[i][1] = (mo[i][1]-1)//a + 1
reach = []
moo = [x[0] for x in mo]
mooo = [x[1] for x in mo]
for x in moo:
	reach.append(bisect(moo, x+d)-1)
#print(reach)

bit = BIT(n)

ans = 0
for i, h in enumerate(mooo):
	gap = max(0, h - bit.Get(i+1))
	bit.SegAdd(i+1, reach[i]+1, gap)
	ans += gap

print(ans)

Fixed submission:
import sys
from bisect import bisect
def input():
	return sys.stdin.buffer.readline()[:-1]

class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def Get(self, i):#iを返す
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def PointAdd(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

	def SegAdd(self, l, r, x):#lからrにxを足す
		self.PointAdd(l, x)
		self.PointAdd(r+1, -x)
		return


n, d, a = map(int, input().split())
d *= 2
mo = sorted([list(map(int, input().split())) for _ in range(n)])
for i in range(n):
	mo[i][1] = (mo[i][1]-1)//a + 1
reach = []
moo = [x[0] for x in mo]
mooo = [x[1] for x in mo]
for x in moo:
	reach.append(bisect(moo, x+d)-1)
#print(reach)

bit = BIT(n)

ans = 0
for i, h in enumerate(mooo):
	gap = max(0, h - bit.Get(i+1))
	bit.SegAdd(i+1, reach[i]+1, gap)
	ans += gap

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	print(sum([(lcm//x)%MOD for x in a])%MOD)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	lcm %= MOD
	ans = 0
	for x in a:
		ans += lcm * pow(x, MOD-2, MOD)
		ans %= MOD
	print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	print(sum([(lcm//x)%MOD for x in a])%MOD)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	lcm %= MOD
	ans = 0
	for x in a:
		ans += lcm * pow(x, MOD-2, MOD)
		ans %= MOD
	print(ans)

Buggy python submission (verdict: Runtime Error):
from math import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	print(sum([(lcm//x)%MOD for x in a])%MOD)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	lcm %= MOD
	ans = 0
	for x in a:
		ans += lcm * pow(x, MOD-2, MOD)
		ans %= MOD
	print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	ans = 0
	for x in a:
		ans += lcm // x
		ans %= MOD
	print(ans)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	lcm %= MOD
	ans = 0
	for x in a:
		ans += lcm * pow(x, MOD-2, MOD)
		ans %= MOD
	print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	ans = 0
	for x in a:
		ans += lcm // x
		ans %= MOD
	print(ans)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	lcm %= MOD
	ans = 0
	for x in a:
		ans += lcm * pow(x, MOD-2, MOD)
		ans %= MOD
	print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
c = ["#"*(W+2)] + ["#" + input() + "#" for _ in range(H)] + ["#"*(W+2)]


def bfs(start):
	queue = deque([start])
	visited = [[False for _ in range(W+2)] for _ in range(H+2)]
	tekazu = [[0 for _ in range(W+2)] for _ in range(H+2)]
	num = 0
	while queue:

		label = queue.pop()
		
		if label not in visited:
			visited.append(label)
			#print(visited)
			if c[label[0] + 1][label[1]] == "." and [label[0] + 1, label[1]] not in visited:
				queue.appendleft([label[0] + 1, label[1]])
				tekazu[label[0] + 1][label[1]] = tekazu[label[0]][label[1]] + 1
				num = max(num, tekazu[label[0] + 1][label[1]])

			if c[label[0] - 1][label[1]] == "." and [label[0] - 1, label[1]] not in visited:
				queue.appendleft([label[0] - 1, label[1]])
				tekazu[label[0] - 1][label[1]] = tekazu[label[0]][label[1]] + 1
				num = max(num, tekazu[label[0] - 1][label[1]])

			if c[label[0]][label[1] + 1] == "." and [label[0], label[1] + 1] not in visited:
				queue.appendleft([label[0], label[1] + 1])
				tekazu[label[0]][label[1] + 1] = tekazu[label[0]][label[1]] + 1
				num = max(num, tekazu[label[0]][label[1] + 1])

			if c[label[0]][label[1] - 1] == "." and [label[0], label[1] - 1] not in visited:
				queue.appendleft([label[0], label[1] - 1])
				tekazu[label[0]][label[1] - 1] = tekazu[label[0]][label[1]] + 1
				num = max(num, tekazu[label[0]][label[1] - 1])

	return num

ans = 0
for h in range(1, H+1):
	for w in range(1, W+1):
		if c[h][w] == ".":
			ans = max(ans, bfs([h, w]))
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
c = ["#"*(W+2)] + ["#" + input() + "#" for _ in range(H)] + ["#"*(W+2)]


def bfs(start):
	queue = deque([start])
	#visited = [[False for _ in range(W+2)] for _ in range(H+2)]
	tekazu = [[-1 for _ in range(W+2)] for _ in range(H+2)]
	tekazu[start[0]][start[1]] = 0
	num = 0
	while queue:

		label = queue.pop()
		
			#print(visited)
		if c[label[0] + 1][label[1]] == "." and tekazu[label[0] + 1][label[1]] < 0:
			queue.appendleft([label[0] + 1, label[1]])
			tekazu[label[0] + 1][label[1]] = tekazu[label[0]][label[1]] + 1
			num = max(num, tekazu[label[0] + 1][label[1]])

		if c[label[0] - 1][label[1]] == "." and tekazu[label[0] - 1][label[1]] < 0:
			queue.appendleft([label[0] - 1, label[1]])
			tekazu[label[0] - 1][label[1]] = tekazu[label[0]][label[1]] + 1
			num = max(num, tekazu[label[0] - 1][label[1]])

		if c[label[0]][label[1] + 1] == "." and tekazu[label[0]][label[1] + 1] < 0:
			queue.appendleft([label[0], label[1] + 1])
			tekazu[label[0]][label[1] + 1] = tekazu[label[0]][label[1]] + 1
			num = max(num, tekazu[label[0]][label[1] + 1])

		if c[label[0]][label[1] - 1] == "." and tekazu[label[0]][label[1] - 1] < 0:
			queue.appendleft([label[0], label[1] - 1])
			tekazu[label[0]][label[1] - 1] = tekazu[label[0]][label[1]] + 1
			num = max(num, tekazu[label[0]][label[1] - 1])

	return num

ans = 0
for h in range(1, H+1):
	for w in range(1, W+1):
		if c[h][w] == ".":
			ans = max(ans, bfs([h, w]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(61):
	zero, one = 0, 0
	for x in a:
		if (x>>b)&1:
			one += 1
		else:
			zero += 1
	ans += zero*one*(1<<b)
	ans %= MOD
print(ans)

Fixed submission:
MOD = 10**9+7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(61):
	zero, one = 0, 0
	for x in a:
		if (x>>b)&1:
			one += 1
		else:
			zero += 1
	ans += zero*one*(1<<b)
	ans %= MOD
print(ans)