Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = sorted(input())
for i in range(len(s)-1):
  if ord(s[i+1])-ord(s[i])>=2:
    print(chr(ord(s[i]+1)))
    break


Fixed submission:
s = set(input())
al = set(list(map(chr, [i for i in range(97, 97+26)])))
print('None' if len(s)==len(al) else min(al-s))
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):
n = int(input())
print(pow(10, n, mod) - 2*pow(9, n, mod) - pow(9, n, mod))

Fixed submission:
n = int(input())
mod = 10**9 + 7
print((pow(10, n, mod) - 2*pow(9, n, mod) + pow(8, n, mod)) % mod)
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self._n = n
        self._table = [-1]*n

    def _root(self, x):
        stack = []
        while self._table[x] >= 0:
            stack.append(x)
            x = self._table[x]
        for y in stack:
            self._table[y] = x
        return x
    
    def unite(self, x, y):
        x, y = self._root(x), self._root(y)
        if x == y:
            return
        if x > y:
            x, y = y, x
        self._table[x] += self._table[y]
        self._table[y] = x
    
    def same(self, x, y):
        return self._root(x) == self._root(y)

    def count_members(self, x):
        return -self._table[self._root(x)]
    
    def count_groups(self):
        return len({self._root(i) for i in range(self._n)})
    
    def __str__(self):
        return str([self._root(i) for i in range(self._n)])
    
    def __repr__(self):           
        return repr([self._root(i) for i in range(self._n)])

n, m, *AB = map(int, open(0).read().split())
uf = UnionFind(n)
for a, b in zip(AB[::2], AB[1::2]):
    uf.unite(a, b)
s = 0
for group in {uf._root(i) for i in range(n)}:
    s += uf.count_members(group)-1
print(s)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self._n = n
        self._table = [-1]*n

    def _root(self, x):
        stack = []
        while self._table[x] >= 0:
            stack.append(x)
            x = self._table[x]
        for y in stack:
            self._table[y] = x
        return x
    
    def unite(self, x, y):
        x, y = self._root(x), self._root(y)
        if x == y:
            return
        if x > y:
            x, y = y, x
        self._table[x] += self._table[y]
        self._table[y] = x
    
    def same(self, x, y):
        return self._root(x) == self._root(y)

    def count_members(self, x):
        return -self._table[self._root(x)]
    
    def count_groups(self):
        return len({self._root(i) for i in range(self._n)})
    
    def __str__(self):
        return str([self._root(i) for i in range(self._n)])
    
    def __repr__(self):           
        return repr([self._root(i) for i in range(self._n)])

n, m, *AB = map(int, open(0).read().split())
uf = UnionFind(n)
for a, b in zip(AB[::2], AB[1::2]):
    uf.unite(a-1, b-1)
print(max(uf.count_members(group) for group in {uf._root(i) for i in range(n)}))
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd, sqrt
from functools import reduce

n, *A = map(int, open(0).read().split())
def f(A):
    sup = max(A)+1
    table = [set() for i in range(sup)]
    for i in range(2, sup):
        if not table[i]:
            for j in range(i, sup, i):
                table[j].add(i)
    D = set()
    for a in A:
        for b in table[a]:
            if b not in D:
                D.add(b)
            else:
                return False
    return True

if reduce(gcd, A) == 1:
    if f(A):
        print('pairwise coprime')
    else:
        print('setwise coprime')
else:
    print('not coprime')

Fixed submission:
from math import gcd, sqrt
from functools import reduce

n, *A = map(int, open(0).read().split())
def f(A):
    sup = max(A)+1
    table = [set() for i in range(sup)]
    for i in range(2, sup):
        if not table[i]:
            for j in range(i, sup, i):
                table[j].add(i)
    D = set()
    for a in A:
        for b in table[a]:
            if b not in D:
                D.add(b)
            else:
                return False
    return True

if reduce(gcd, A) == 1:
    if f(A):
        print('pairwise coprime')
    else:
        print('setwise coprime')
else:
    print('not coprime')

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd, sqrt
from functools import reduce
def sieve(n):
    if n <= 4:
        return list(range(2, n))
    def _sieve_of_eratosthenes(n):
        table = [1] * n
        table[0] = table[1] = 0
        for i in range(2, int(sqrt(n))+1):
            if table[i]:
                for j in range(i**2, n, i):
                    table[j] = 0
        return [i for i in range(2, n) if table[i]]
    return _sieve_of_eratosthenes(n)

n, *A = map(int, open(0).read().split())
P = sieve(max(A))

def f(A, P):
    D = set()
    for a in A:
        for p in P:
            if a % p == 0:
                if p not in D:
                    D.add(p)
                    a //= p
                else:
                    return False
    return True

if reduce(gcd, A) == 1:
    if f(A, P):
        print('pairwise coprime')
    else:
        print('setwise coprime')
else:
    print('not coprime')

Fixed submission:
from math import gcd, sqrt
from functools import reduce

n, *A = map(int, open(0).read().split())
def f(A):
    sup = max(A)+1
    table = [set() for i in range(sup)]
    for i in range(2, sup):
        if not table[i]:
            for j in range(i, sup, i):
                table[j].add(i)
    D = set()
    for a in A:
        for b in table[a]:
            if b not in D:
                D.add(b)
            else:
                return False
    return True

if reduce(gcd, A) == 1:
    if f(A):
        print('pairwise coprime')
    else:
        print('setwise coprime')
else:
    print('not coprime')
Buggy python submission (verdict: Runtime Error):
n, *L = map(int, input().split())
L.sort()
c = 0
for i in range(n-2):
  li = L[i]
  for j in range(i+1, n-1):
    lj = L[j]
    if li == lj:
      continue
    for k in range(j+1, n):
      lk = L[k]
      if lj == lk or li + lj < lk:
        continue
      c += 1
print(c)

Fixed submission:
n, *L = map(int, open(0).read().split())
L.sort()
c = 0
for i in range(n-2):
  li = L[i]
  for j in range(i+1, n-1):
    lj = L[j]
    if li == lj:
      continue
    for k in range(j+1, n):
      lk = L[k]
      if lj == lk or li + lj <= lk:
        continue
      c += 1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
if k % 2 == 0:
    print(-1)
else:
    s = i = 0
    while True:
        i += 1
        s = (s*10 + 7) % k
        if s % k == 0:
            print(i)
            break

Fixed submission:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    s = i = 0
    while True:
        i += 1
        s = (s*10 + 7) % k
        if s % k == 0:
            print(i)
            break
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
inputs = open(0).readlines()
n = int(inputs[0])
S = inputs[1].strip()

R = [i for i, c in enumerate(S) if c == 'R']
G = [i for i, c in enumerate(S) if c == 'G']
B = [i for i, c in enumerate(S) if c == 'B']

def f(Z, i, x, y):
    for z in Z[i:]:
        if z == 2*y-x:
            return 1
        if z > 2*y-x:
            return 0
    return 0

ans = 0
for X, Y, Z in list(permutations([R, G, B])):
    for x in X:
        pi = 0
        for y in Y:
            if x < y:
                for i, z in enumerate(Z[pi:], pi):
                    if y < z:
                        ans += len(Z) - i - f(Z, i, x, y)
                        pi = i
                        break
print(ans)

Fixed submission:
n = int(input())
S = input().strip()
r, g, b = map(S.count, 'RGB')
t = 0
for i in range(n-2):
    for w in range(1, (n-i+1) // 2):
        t += len({S[i], S[i+w], S[i+2*w]}) == 3
print(r*g*b - t)

Buggy python submission (verdict: Runtime Error):
from itertools import permutations
inputs = open(0).readlines()
n = int(inputs[0])
S = inputs[1].strip()

R = [i for i, c in enumerate(S) if c == 'R']
G = [i for i, c in enumerate(S) if c == 'G']
B = [i for i, c in enumerate(S) if c == 'B']

def f(Z, i, x, y):
    for z in Z[i:]:
        if z == 2*y-x:
            return 1
        if z > 2*y-x:
            return 0
    return 0

ans = 0
for X, Y, Z in list(permutations([R, G, B])):
    for x in X:
        for y in Y:
            if x < y:
                idx = 0
                for i, z in enumerate(Z):
                    if y < z:
                        break
                if y < z:
                    ans += len(Z) - i - f(Z, i, x, y)
print(ans)

Fixed submission:
n = int(input())
S = input().strip()
r, g, b = map(S.count, 'RGB')
t = 0
for i in range(n-2):
    for w in range(1, (n-i+1) // 2):
        t += len({S[i], S[i+w], S[i+2*w]}) == 3
print(r*g*b - t)

Buggy python submission (verdict: Time Limit Exceeded):
inputs = open(0).readlines()
n = int(inputs[0])
S = inputs[1].strip()

def is_cond(i, j, k):
    return j-i != k-j

l = []
for i in range(n-2):
    rest = {'R', 'G', 'B'}
    rest.remove(S[i])
    for j in range(i+1, n-1):
        if S[j] in rest:
            rest.remove(S[j])
            for k in range(j+1, n):
                if S[k] in rest:
                    if is_cond(i, j, k):
                        l.append((i, j, k))
            rest.add(S[j])
print(len(l))

Fixed submission:
n = int(input())
S = input().strip()
r, g, b = map(S.count, 'RGB')
t = 0
for i in range(n-2):
    for w in range(1, (n-i+1) // 2):
        t += len({S[i], S[i+w], S[i+2*w]}) == 3
print(r*g*b - t)
Buggy python submission (verdict: Runtime Error):
from string import ascii_lowercase
from functools import lru_cache
n = int(input())

@lru_cache
def make(n):
    if n == 1:
        return ['a']
    else:
        lst = []
        for s in make(n-1):
            for c in ascii_lowercase[:len(set(s))+1]:
                lst.append(s + c)
        return lst
for s in make(n):
    print(*s, sep='')

Fixed submission:
from string import ascii_lowercase
from functools import lru_cache
n = int(input())

@lru_cache(maxsize=10)
def make(n):
    if n == 1:
        return ['a']
    else:
        lst = []
        for s in make(n-1):
            for c in ascii_lowercase[:len(set(s))+1]:
                lst.append(s + c)
        return lst
for s in make(n):
    print(*s, sep='')

Buggy python submission (verdict: Runtime Error):
from string import ascii_lowercase
n = int(input())

@lru_cache
def make(n):
    if n == 1:
        return ['a']
    else:
        lst = []
        for s in make(n-1):
            for c in ascii_lowercase[:len(set(s))+1]:
                lst.append(s + c)
        return lst
for s in make(n):
    print(*s, sep='')

Fixed submission:
from string import ascii_lowercase
from functools import lru_cache
n = int(input())

@lru_cache(maxsize=10)
def make(n):
    if n == 1:
        return ['a']
    else:
        lst = []
        for s in make(n-1):
            for c in ascii_lowercase[:len(set(s))+1]:
                lst.append(s + c)
        return lst
for s in make(n):
    print(*s, sep='')
Buggy python submission (verdict: Runtime Error):
print(-~(int(input()//2))

Fixed submission:
from math import ceil
print(ceil(int(input())/2))
Buggy python submission (verdict: Time Limit Exceeded):
inputs = open(0).readlines()
n, m, k = map(int, inputs[0].split())
AB = [tuple(map(int, ab.split())) for ab in inputs[1:m+1]]
CD = [tuple(map(int, cd.split())) for cd in inputs[m+1:]]

def dfs(root, graph):
        nodes, stack = [], [root]
        while stack:
            current_node = stack.pop()
            if current_node in nodes:
                continue
            nodes.append(current_node)
            for n in graph[current_node]:
                if n not in nodes:
                    stack.append(n)
        return nodes

friends = [set() for _ in range(n)]
for n0, n1 in AB:
    friends[n0-1].add(n1-1)
    friends[n1-1].add(n0-1)
blocks = [set() for _ in range(n)]
for n0, n1 in CD:
    blocks[n0-1].add(n1-1)
    blocks[n1-1].add(n0-1)

connected_nodes = {}
candidates = []
for i in range(n):
    if i not in connected_nodes:
        nodes = set(dfs(i, friends))
        for j in nodes:
            connected_nodes[j] = nodes
    else:
        nodes = connected_nodes[i]
    candidates.append(len(nodes) - len(friends[i]) - len(nodes & blocks[i]) - 1)
print(*candidates)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find_root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
    
    def unite(self, x, y):
        x, y = self.find_root(x), self.find_root(y)
        if(x == y):
            return
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    
    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]
    
    def __str__(self):
        return 'UnionFind(n: {}, root: {}, rnk: {})'.format(self.n, self.root, self.rnk)
    
    def __repr__(self):
        return self.__str__()

inputs = open(0).readlines()
n, m, k = map(int, inputs[0].split())
AB = [tuple(map(int, ab.split())) for ab in inputs[1:m+1]]
CD = [tuple(map(int, cd.split())) for cd in inputs[m+1:]]

uf = UnionFind(n)
friends = [set() for _ in range(n)]
for n0, n1 in AB:
    uf.unite(n0-1, n1-1)
    friends[n0-1].add(n1-1)
    friends[n1-1].add(n0-1)

blocks = [set() for _ in range(n)]
for n0, n1 in CD:
    if uf.is_same_group(n0-1, n1-1):
        blocks[n0-1].add(n1-1)
        blocks[n1-1].add(n0-1)

candidates = []
for i in range(n):
    candidates.append(uf.count(i) - len(friends[i]) - len(blocks[i]) - 1)
print(*candidates)
Buggy python submission (verdict: Runtime Error):
def cmb(n, r, mod):
    c=1
    for i in range(1, r+1):
        c = (c * (n-i+1) * pow(i, mod-2, mod)) % mod
    return c

n, a, b = map(int, inputs[0]().split())
MOD = 10**9 + 7
print((pow(2, n, MOD) - cmb(n, a, MOD) - cmb(n, b, MOD) - 1) % MOD)

Fixed submission:
def cmb(n, r, mod):
    c=1
    for i in range(1, r+1):
        c = (c * (n-i+1) * pow(i, mod-2, mod)) % mod
    return c

n, a, b = map(int, input().split())
MOD = 10**9 + 7
print((pow(2, n, MOD) - cmb(n, a, MOD) - cmb(n, b, MOD) - 1) % MOD)

Buggy python submission (verdict: Runtime Error):
def comb(n, r, mod=10**9 + 7):
    c=1
    for i in range(1, r+1):
        c = (c * (n-i+1) * pow(i, mod-2, mod)) % mod
    return c

n, a, b = map(int, input().split())
print((pow(2, n, MOD) - cmb(n, a) - cmb(n, b) - 1) % MOD)

Fixed submission:
def cmb(n, r, mod):
    c=1
    for i in range(1, r+1):
        c = (c * (n-i+1) * pow(i, mod-2, mod)) % mod
    return c

n, a, b = map(int, input().split())
MOD = 10**9 + 7
print((pow(2, n, MOD) - cmb(n, a, MOD) - cmb(n, b, MOD) - 1) % MOD)

Buggy python submission (verdict: Runtime Error):
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

n, a, b = map(int, input().split())
MOD = 10**9 + 7
cmb = Combination(10**7, MOD)
print(pow(2, n, MOD) - cmb(n, a) - cmb(n, b) - 1)

Fixed submission:
def cmb(n, r, mod):
    c=1
    for i in range(1, r+1):
        c = (c * (n-i+1) * pow(i, mod-2, mod)) % mod
    return c

n, a, b = map(int, input().split())
MOD = 10**9 + 7
print((pow(2, n, MOD) - cmb(n, a, MOD) - cmb(n, b, MOD) - 1) % MOD)
Buggy python submission (verdict: Runtime Error):
if len(set(map(int, inputs[0].split()))) == 2:
    print('Yes')
else:
    print('No')

Fixed submission:
if len(set(map(int, input().split()))) == 2:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
from itertools import combinations
n, k = map(int, input().split())
*A, = map(int, input().split())
print(sorted(x*y for x, y in combinations(A, 2))[k])   

Fixed submission:
n = list(map(int, reversed(list(input()))))
a , b = 0, 9999
for x in n:
    a, b = min(a+x, b+x), min(a+10-x+1, b+10-x-1)
print(min(a, b))
Buggy python submission (verdict: Runtime Error):
S, T = input().split()
a, b = map(int, input().split())
U = input().strip()
print(a - S == U, b - S == T)

Fixed submission:
S, T = input().split()
a, b = map(int, input().split())
U = input().strip()
print(a - (S == U), b - (T == U))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
P = list(map(int, inputs[1].split()))
EP = [0.5*p + 0.5 for p in P]

print(max(sum(EP[i:i+k]) for i in range(n-k+1)))

Fixed submission:
import sys
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
P = list(map(int, inputs[1].split()))
EP = [0.5*p + 0.5 for p in P]

buffer = sum(EP[:k])
Q = [buffer]
for i in range(k, n):
    buffer += EP[i] - EP[i-k]
    Q.append(buffer)
print(max(Q))

Buggy python submission (verdict: Runtime Error):
import sys
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
P = list(map(int, inputs[1].split()))
EP = [0.5*p + 0.5 for p in P]

Q = []
buffer = sum(EP[:k])
for i in range(k, n):
    buffer += EP[i] - EP[i-k]
    Q.append(buffer)
print(max(Q))

Fixed submission:
import sys
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
P = list(map(int, inputs[1].split()))
EP = [0.5*p + 0.5 for p in P]

buffer = sum(EP[:k])
Q = [buffer]
for i in range(k, n):
    buffer += EP[i] - EP[i-k]
    Q.append(buffer)
print(max(Q))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
inputs = sys.stdin.readlines()

h, n = map(int, inputs[0].split())
AB = []
for s in inputs[1:]:
    a, b = map(int, s.split())
    AB.append((a, b))
AB.sort(key=lambda ab:ab[1])

dp = [10 ** 9] * (h+1)
dp[0] = 0
 
for i in range(h):
    for a, b in AB:
        k = min(i + a, h)
        dp[k] = min(dp[k], dp[i] + b)
print(dp[h])

Fixed submission:
import sys
inputs = sys.stdin.readlines()

h, n = map(int, inputs[0].split())
AB = []
for s in inputs[1:]:
    a, b = map(int, s.split())
    AB.append((a, b))
AB.sort(key=lambda ab:ab[1])

dp = [10 ** 9] * (h+1)
dp[0] = 0
 
for i in range(h):
    for a, b in AB:
        k = min(i + a, h)
        dp[k] = min(dp[k], dp[i] + b)
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
inputs = sys.stdin.readlines()

h, n = map(int, inputs[0].split())
AB = []
for s in inputs[1:]:
    a, b = map(int, s.split())
    AB.append((a, b))
AB.sort(key=lambda ab:ab[1])

# AB_ = [AB[0]]
# x = AB[0][0] / AB[0][1]
# for a, b in AB[1:]:
#     if a/b > x:
#         x = a/b
#         AB_.append((a, b))
# AB, n = AB_, len(AB_)

def calc_min_magic(h):
    val = float('inf')
    for i in range(n):
        a, b = AB[i]
        val = min(val, dp[h-a]+b if a <= h else b)
    return val

dp = [0] * (h+1)
for i in range(1, h+1):
    dp[i] = calc_min_magic(i)
print(dp[h])

Fixed submission:
import sys
inputs = sys.stdin.readlines()

h, n = map(int, inputs[0].split())
AB = []
for s in inputs[1:]:
    a, b = map(int, s.split())
    AB.append((a, b))
AB.sort(key=lambda ab:ab[1])

dp = [10 ** 9] * (h+1)
dp[0] = 0
 
for i in range(h):
    for a, b in AB:
        k = min(i + a, h)
        dp[k] = min(dp[k], dp[i] + b)
print(dp[h])
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
    x = str(i)
    d[(int(x[0]), int(x[-1]))] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += d[(i, j)] * d[(j, i)]
print(ans)

Fixed submission:
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
    x = str(i)
    d[(int(x[0]), int(x[-1]))] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += d[(i, j)] * d[(j, i)]
print(ans)
Buggy python submission (verdict: Runtime Error):
from functools import reduce
from fractions import gcd
mod = 10**9 + 7
n, *A = map(int, open(0).read().split())
if len(A) == 1:
    print(1)
else:
	l = reduce(lambda x, y: x*y // gcd(x, y), A) % mod
    s = 0
    for a in A:
        s += l * pow(a, mod-2, mod)
        s %= mod
    print(s)

Fixed submission:
from functools import reduce
def reduce_wrapper(func, *args):
    if len(args) == 1:
        return reduce(func, args[0])
    return reduce(func, args)

from fractions import gcd
def lcm(*args):
    return reduce_wrapper(lambda x, y: x*y // gcd(x, y), *args)

def xgcd(a, b):
    ''' return (g, x, y) such that a*x + b*y = g = gcd(a, b) '''
    x0, x1, y0, y1 = 0, 1, 1, 0
    while a != 0:
        (q, a), b = divmod(b, a), a
        y0, y1 = y1, y0 - q * y1
        x0, x1 = x1, x0 - q * x1
    return b, x0, y0

def modinv(n):
    g, x, _ = xgcd(n, mod)
    if g != 1:
        raise ValueError('Modinv is not exist! arg={}'.format(n))
    return x % mod

mod = 10**9 + 7
n, *A = map(int, open(0).read().split())

l = lcm(A) % mod
s = 0
for a in A:
    s += l * modinv(a)
    s %= mod
print(s)

Buggy python submission (verdict: Runtime Error):
from functools import reduce
from fractions import gcd
mod = 10**9 + 7
n, *A = map(int, open(0).read().split())

l = reduce(lambda x, y: x*y // gcd(x, y)) % mod
s = 0
for a in A:
    s += l * pow(a, mod-2, mod)
    s %= mod
print(s)

Fixed submission:
from functools import reduce
def reduce_wrapper(func, *args):
    if len(args) == 1:
        return reduce(func, args[0])
    return reduce(func, args)

from fractions import gcd
def lcm(*args):
    return reduce_wrapper(lambda x, y: x*y // gcd(x, y), *args)

def xgcd(a, b):
    ''' return (g, x, y) such that a*x + b*y = g = gcd(a, b) '''
    x0, x1, y0, y1 = 0, 1, 1, 0
    while a != 0:
        (q, a), b = divmod(b, a), a
        y0, y1 = y1, y0 - q * y1
        x0, x1 = x1, x0 - q * x1
    return b, x0, y0

def modinv(n):
    g, x, _ = xgcd(n, mod)
    if g != 1:
        raise ValueError('Modinv is not exist! arg={}'.format(n))
    return x % mod

mod = 10**9 + 7
n, *A = map(int, open(0).read().split())

l = lcm(A) % mod
s = 0
for a in A:
    s += l * modinv(a)
    s %= mod
print(s)