Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
 
 
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
 
 
def lcm(a, b):
    return a * b // gcd(a, b)
 
 
tmp = A[0]
for i in range(1, N):
    tmp = lcm(tmp, A[i])
 
B = [0] * N
for i in range(N):
    B[i] = tmp // A[i]
 
print(sum(B) % mod)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
 
 
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
 
 
def lcm(a, b):
    return a * b // gcd(a, b)
 
 
tmp = A[0]
for i in range(1, N):
    tmp = lcm(tmp, A[i])
 
B = [0] * N
for i in range(N):
    B[i] = tmp // A[i]
 
print(sum(B) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
import sys; readline = sys.stdin.readline
from collections import deque
sys.setrecursionlimit(1000000)

N = int(readline())
A = list(map(int, readline().split()))

P = 10 ** 9 + 7

def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        r = a % b
        a, b = b, r
    
    return b

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


def q_lcm(q, a):
    for k in q:
        a = a // gcd(k, a)
        if a == 1:
            return a
    return a

q = deque()

q.append(1)

for a in A:
    x = q_lcm(q, a)
    if x != 1:
        q.append(x)

_lcm = 1
for x in q:
    _lcm = _lcm * x % P

def mod_mult(a, N):
    if N == 0:
        return 1
    if N % 2 == 0:
        x = mod_mult(a, N // 2)
        return x * x % P
    else:
        x = mod_mult(a, N // 2)
        return x * x * a % P

def mod_s(a, b):
    b_inv = mod_mult(b, P - 2)
    return a * b_inv % P

total = 0

for a in A:
    _s = mod_s(_lcm, a)
    total += _s
    total %= P

print(total)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
 
 
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
 
 
def lcm(a, b):
    return a * b // gcd(a, b)
 
 
tmp = A[0]
for i in range(1, N):
    tmp = lcm(tmp, A[i])
 
B = [0] * N
for i in range(N):
    B[i] = tmp // A[i]
 
print(sum(B) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
import sys; readline = sys.stdin.readline
from collections import deque
sys.setrecursionlimit(1000000)

N = int(readline())
A = list(map(int, readline().split()))

P = 10 ** 9 + 7

def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        r = a % b
        a, b = b, r
    
    return b

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


def q_lcm(q, a):
    for k in q:
        a = a // gcd(k, a)
    return a

q = deque()

q.append(1)

for a in A:
    x = q_lcm(q, a)
    if x != 1:
        q.append(x)

_lcm = 1
for x in q:
    _lcm = _lcm * x % P

def mod_mult(a, N):
    if N == 0:
        return 1
    if N % 2 == 0:
        x = mod_mult(a, N // 2)
        return x * x % P
    else:
        x = mod_mult(a, N // 2)
        return x * x * a % P

def mod_s(a, b):
    b_inv = mod_mult(b, P - 2)
    return a * b_inv % P

total = 0

for a in A:
    _s = mod_s(_lcm, a)
    total += _s
    total %= P

print(total)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
 
 
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
 
 
def lcm(a, b):
    return a * b // gcd(a, b)
 
 
tmp = A[0]
for i in range(1, N):
    tmp = lcm(tmp, A[i])
 
B = [0] * N
for i in range(N):
    B[i] = tmp // A[i]
 
print(sum(B) % mod)