Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

MOD = 10 ** 9 + 7

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

def factorize(n):
    res = defaultdict(int)
    d = 2
    while d * d <= n:
        while n % d == 0:
            n //= d
            res[d] += 1
        d += 1
    if n > 1:
        res[n] += 1
    return res

factors = [factorize(val) for val in a]
lcm = defaultdict(int)
for d in factors:
    for num in d.keys():
        lcm[num] = max(lcm[num], d[num])

ret = 0
for i, d in enumerate(factors):
    val = 1
    for num in lcm.keys():
        val *= pow(num, lcm[num] - d[num], MOD)
        val %= MOD
    ret += val
    ret %= MOD
print(ret)

Fixed submission:
from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def getLcm(a, b):
    return a * b // gcd(a, b)

def lcmArr(a):
    return reduce(getLcm, a)

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

lcm = lcmArr(a)
lcm %= MOD
ret = 0
for val in a:
    ret += lcm * pow(val, MOD - 2, MOD)
    ret %= MOD
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

MOD = 10 ** 9 + 7

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

def factorize(n):
    res = []
    d = 2
    while d * d <= n:
        while n % d == 0:
            n //= d
            res.append(d)
        d += 1
    if n > 1:
        res.append(n)
    return res

factors = []
for val in a:
    d = defaultdict(int)
    for factor in factorize(val):
        d[factor] += 1
    factors.append(d)
lcm = defaultdict(int)
for d in factors:
    for num, cnt in d.items():
        lcm[num] = max(lcm[num], cnt)

ret = 0
for i, d in enumerate(factors):
    val = 1
    for num, cnt in lcm.items():
        val *= max(1, num ** (cnt - d[num]))
    ret += val
    ret %= MOD
print(ret)

Fixed submission:
from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def getLcm(a, b):
    return a * b // gcd(a, b)

def lcmArr(a):
    return reduce(getLcm, a)

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

lcm = lcmArr(a)
lcm %= MOD
ret = 0
for val in a:
    ret += lcm * pow(val, MOD - 2, MOD)
    ret %= MOD
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

MOD = 10 ** 9 + 7

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

def factorize(n):
    res = []
    d = 2
    while d * d <= n:
        while n % d == 0:
            n //= d
            res.append(d)
        d += 1
    if n > 1:
        res.append(n)
    return res

factors = []
for val in a:
    d = defaultdict(int)
    for factor in factorize(val):
        d[factor] += 1
    factors.append(d)
lcm = defaultdict(int)
for d in factors:
    for num, cnt in d.items():
        lcm[num] = max(lcm[num], cnt)

ret = 0
for i, d in enumerate(factors):
    val = 1
    for num, cnt in lcm.items():
        val *= pow(num, cnt - d[num], MOD)
        val %= MOD
    ret += val
    ret %= MOD
print(ret)

Fixed submission:
from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def getLcm(a, b):
    return a * b // gcd(a, b)

def lcmArr(a):
    return reduce(getLcm, a)

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

lcm = lcmArr(a)
lcm %= MOD
ret = 0
for val in a:
    ret += lcm * pow(val, MOD - 2, MOD)
    ret %= MOD
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def getLcm(a, b):
    return a * b // gcd(a, b)

def lcmArr(a):
    return reduce(getLcm, a)

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

lcm = lcmArr(a)
ret = 0
for val in a:
    ret += lcm // val
    ret %= MOD
print(ret)

Fixed submission:
from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def getLcm(a, b):
    return a * b // gcd(a, b)

def lcmArr(a):
    return reduce(getLcm, a)

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

lcm = lcmArr(a)
lcm %= MOD
ret = 0
for val in a:
    ret += lcm * pow(val, MOD - 2, MOD)
    ret %= MOD
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def getLcm(a, b):
    return a * b // gcd(a, b)

def lcmArr(a):
    return reduce(getLcm, a)

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

lcm = lcmArr(a)
ret = 0
for val in a:
    ret += lcm // val
    ret %= MOD
print(ret)

Fixed submission:
from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def getLcm(a, b):
    return a * b // gcd(a, b)

def lcmArr(a):
    return reduce(getLcm, a)

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

lcm = lcmArr(a)
lcm %= MOD
ret = 0
for val in a:
    ret += lcm * pow(val, MOD - 2, MOD)
    ret %= MOD
print(ret)