Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
def lcm(a,b):
    return a*b // gcd(a,b)

N = int(input())
A = list(map(int,input().split()))
M = 10**9+7
l = 1
for a in A:
    l = lcm(l,a)
ans = 0
for a in A:
    ans += l//a
print(ans%M)


Fixed submission:
from fractions import gcd
def lcm(a,b):
    return a*b // gcd(a,b)

N = int(input())
A = list(map(int,input().split()))
M = 10**9+7
l = 1
for a in A:
    l = lcm(l,a)
ans = 0
for a in A:
    ans += l//a
print(ans%M)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from math import sqrt, floor
N = int(input())
A = list(map(int,input().split()))
M = 10**9+7
def factorize(n):
    fct = defaultdict(int)
    m = floor(sqrt(n))+1
    for b in range(2,m):
        e = 0
        while n%b == 0:
            n = n // b
            e += 1
        if e > 0:
            fct[b] = e
    if n > 1:
        fct[n] = 1
    return fct
dct = defaultdict(int)
dctT = [0]*N
for i,a in enumerate(A):
    dctT[i] = factorize(a)
    for key in dctT[i].keys():
        dct[key] = max(dct[key],dctT[i][key])
ans = 0
for i in range(N):
    t = 1
    for k,v in dct.items():
        t *= pow(k,v-dctT[i][k],M)
    ans += t%M
print(ans%M)

Fixed submission:
from fractions import gcd
def lcm(a,b):
    return a*b // gcd(a,b)

N = int(input())
A = list(map(int,input().split()))
M = 10**9+7
l = 1
for a in A:
    l = lcm(l,a)
ans = 0
for a in A:
    ans += l//a
print(ans%M)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from math import sqrt, floor
N = int(input())
A = list(map(int,input().split()))
M = 10**9+7
def factorize(n):
    fct = defaultdict(int)
    m = floor(sqrt(n))+1
    for b in range(2,m):
        e = 0
        while n%b == 0:
            n = n // b
            e += 1
        if e > 0:
            fct[b] = e
    if n > 1:
        fct[n] = 1
    return fct
dct = defaultdict(int)
dctT = [0]*N
for i,a in enumerate(A):
    dctT[i] = factorize(a)
    for key in dct.keys() | dctT[i].keys():
        dct[key] = max(dct[key],dctT[i][key])
ans = 0
for i in range(N):
    t = 1
    for k,v in dct.items():
        t *= pow(k,v-dctT[i][k],M)
    ans += t%M
print(ans%M)

Fixed submission:
from fractions import gcd
def lcm(a,b):
    return a*b // gcd(a,b)

N = int(input())
A = list(map(int,input().split()))
M = 10**9+7
l = 1
for a in A:
    l = lcm(l,a)
ans = 0
for a in A:
    ans += l//a
print(ans%M)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
M = 10**9+7
def factorize(n):
    fct = defaultdict(int)
    b, e = 2, 0
    while b*b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct[b] = e
        b, e = b+1, 0
    if n > 1:
        fct[n] = 1
    return fct
dct = defaultdict(int)
dctT = [0]*N
for i,a in enumerate(A):
    dctT[i] = factorize(a)
    for key in dct.keys() | dctT[i].keys():
        dct[key] = max(dct[key],dctT[i][key])
ans = 0
for i in range(N):
    t = 1
    for k,v in dct.items():
        t *= pow(k,v-dctT[i][k],M)
    ans += t
print(ans%M)

Fixed submission:
from fractions import gcd
def lcm(a,b):
    return a*b // gcd(a,b)

N = int(input())
A = list(map(int,input().split()))
M = 10**9+7
l = 1
for a in A:
    l = lcm(l,a)
ans = 0
for a in A:
    ans += l//a
print(ans%M)