Buggy python submission (verdict: Time Limit Exceeded):
from math import floor, sqrt
from collections import defaultdict
def pow(x, n, mod):
    ret = 1
    while n > 0:
        if n % 2 == 1:
            ret = ret * x % mod
        x = x * x % mod
        n >>= 1
    return ret

def factors(n):
    d = defaultdict(int)
    for i in range(2,floor(sqrt(n))+1):
        while n % i == 0:
            n //= i
            d[i] += 1
        if n == 1:
            break
    if n != 1:
        d[n] += 1
    return d

mod = 10**9+7
def gcd(x,y):
    a,b = max(x,y),min(x,y)
    r = a % b
    while r != 0:
        a,b = b,r
        r = a % b
    return b
N = int(input())
a = list(map(int,input().split()))
g = a[0]
fs = [None]*N
fs[0] = factors(a[0])
fac = factors(a[0])
for i in range(1,N):
    fs[i] = factors(a[i])
    for k in fs[i]:
        fac[k] = max(fac[k], fs[i][k])
ans = 0
for i in range(N):
    tmp = 1
    for k in fac:
        tmp *= pow(k, fac[k]-fs[i][k], mod)
    ans = (ans+tmp)%mod
print(ans%mod)

Fixed submission:
def pow(x, n, mod):
    ret = 1
    while n > 0:
        if n % 2 == 1:
            ret = ret * x % mod
        x = x * x % mod
        n >>= 1
    return ret
def gcd(x,y):
    a,b = max(x,y),min(x,y)
    r = a % b
    while r != 0:
        a,b = b,r
        r = a % b
    return b
mod = 10**9+7
N = int(input())
a = list(map(int,input().split()))
g = a[0]
l = g
for i in range(1,N):
    g = gcd(l, a[i])
    l = (l*a[i])//g
ans = 0
l %= mod
for i in range(N):
    tmp = (pow(a[i], mod-2, mod)*l)%mod
    ans = (ans+tmp)%mod
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9+7
def gcd(x,y):
    a,b = max(x,y),min(x,y)
    r = a % b
    while r != 0:
        a,b = b,r
        r = a % b
    return b
N = int(input())
a = list(map(int,input().split()))
g = a[0]
l = a[0]
for i in range(1,N):
    g = gcd(l,a[i])
    l = (a[i]*l)//g
ans = 0
for i in range(N):
    ans = (ans+l//a[i])%mod
print(ans%mod)

Fixed submission:
def pow(x, n, mod):
    ret = 1
    while n > 0:
        if n % 2 == 1:
            ret = ret * x % mod
        x = x * x % mod
        n >>= 1
    return ret
def gcd(x,y):
    a,b = max(x,y),min(x,y)
    r = a % b
    while r != 0:
        a,b = b,r
        r = a % b
    return b
mod = 10**9+7
N = int(input())
a = list(map(int,input().split()))
g = a[0]
l = g
for i in range(1,N):
    g = gcd(l, a[i])
    l = (l*a[i])//g
ans = 0
l %= mod
for i in range(N):
    tmp = (pow(a[i], mod-2, mod)*l)%mod
    ans = (ans+tmp)%mod
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9+7
def gcd(x,y):
    a,b = max(x,y),min(x,y)
    r = a % b
    while r != 0:
        a,b = b,r
        r = a % b
    return b
N = int(input())
a = list(map(int,input().split()))
g = a[0]
l = a[0]
for i in range(1,N):
    g = gcd(l,a[i])
    l = (a[i]*l)//g
ans = 0
for i in range(N):
    ans = (ans+l//a[i])%mod
print(ans%mod)

Fixed submission:
def pow(x, n, mod):
    ret = 1
    while n > 0:
        if n % 2 == 1:
            ret = ret * x % mod
        x = x * x % mod
        n >>= 1
    return ret
def gcd(x,y):
    a,b = max(x,y),min(x,y)
    r = a % b
    while r != 0:
        a,b = b,r
        r = a % b
    return b
mod = 10**9+7
N = int(input())
a = list(map(int,input().split()))
g = a[0]
l = g
for i in range(1,N):
    g = gcd(l, a[i])
    l = (l*a[i])//g
ans = 0
l %= mod
for i in range(N):
    tmp = (pow(a[i], mod-2, mod)*l)%mod
    ans = (ans+tmp)%mod
print(ans%mod)