Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    def gen_primes2(upper_bound):
        upper_bound += 1
        P = [True] * upper_bound
        P[0] = P[1] = False
        for i in range(4,upper_bound,2):
            P[i] = False
        for i in range(3,int(upper_bound**0.5),2):
            if P[i]:
                for j in range(i**2,upper_bound,i):
                    P[j] = False
        res = []
        for i in range(upper_bound):
            if P[i]:
                res.append(i)
        return res

    N = II()
    A = LMIIS()
    upper_bound = max(A)
    primes = gen_primes2(upper_bound)
    LCMP = [0]*len(primes)
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            t = 0
            while a % primes[j] == 0:
                a //= primes[j]
                t += 1
            LCMP[j] = max(t, LCMP[j])
            if a == 1:
                break
    lcm = 1
    for i in range(len(primes)):
        lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD



    inv = [0, 1]
    for i in range(2, upper_bound+1):
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)

    ans = 0
    for a in A:
        # ans += lcm * pow(a, MOD-2, MOD)
        ans += lcm * inv[a]
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    # def gen_primes2(upper_bound):
    #     upper_bound += 1
    #     P = [True] * upper_bound
    #     P[0] = P[1] = False
    #     for i in range(4,upper_bound,2):
    #         P[i] = False
    #     for i in range(3,int(upper_bound**0.5),2):
    #         if P[i]:
    #             for j in range(i**2,upper_bound,i):
    #                 P[j] = False
    #     res = []
    #     for i in range(upper_bound):
    #         if P[i]:
    #             res.append(i)
    #     return res

    N = II()
    A = LMIIS()
    # upper_bound = max(A)
    # primes = gen_primes2(upper_bound)
    # LCMP = [0]*len(primes)
    # for i in range(N):
    #     # if i % 100 == 0:
    #     #     print(i)
    #     a = A[i]
    #     for j,p  in enumerate(primes):
    #         t = 0
    #         while a % p == 0:
    #             a //= p
    #             t += 1
    #         LCMP[j] = max(t, LCMP[j])
    #         if a == 1:
    #             break
    # lcm = 1
    # for i in range(len(primes)):
    #     lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD
    lcm = A[0]
    from fractions import gcd

    for i in range(1,N):
        lcm = lcm * A[i] // gcd(lcm,A[i])

    invans = 0
    for a in A:
        invans += pow(a, MOD-2, MOD)
        invans %= MOD
    print(lcm*invans%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    def gen_primes2(upper_bound):
        upper_bound += 1
        P = [True] * upper_bound
        P[0] = P[1] = False
        for i in range(4,upper_bound,2):
            P[i] = False
        for i in range(3,int(upper_bound**0.5),2):
            if P[i]:
                for j in range(i**2,upper_bound,i):
                    P[j] = False
        res = []
        for i in range(upper_bound):
            if P[i]:
                res.append(i)
        return res

    N = II()
    A = LMIIS()
    primes = gen_primes2(max(A))
    LCMP = [0]*len(primes)
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            t = 0
            while a % primes[j] == 0:
                a //= primes[j]
                t += 1
            LCMP[j] = max(t, LCMP[j])
            if a == 1:
                break
    lcm = 1
    for i in range(len(primes)):
        lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD

    ans = 0
    for a in A:
        ans += lcm * pow(a, MOD-2, MOD)
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    # def gen_primes2(upper_bound):
    #     upper_bound += 1
    #     P = [True] * upper_bound
    #     P[0] = P[1] = False
    #     for i in range(4,upper_bound,2):
    #         P[i] = False
    #     for i in range(3,int(upper_bound**0.5),2):
    #         if P[i]:
    #             for j in range(i**2,upper_bound,i):
    #                 P[j] = False
    #     res = []
    #     for i in range(upper_bound):
    #         if P[i]:
    #             res.append(i)
    #     return res

    N = II()
    A = LMIIS()
    # upper_bound = max(A)
    # primes = gen_primes2(upper_bound)
    # LCMP = [0]*len(primes)
    # for i in range(N):
    #     # if i % 100 == 0:
    #     #     print(i)
    #     a = A[i]
    #     for j,p  in enumerate(primes):
    #         t = 0
    #         while a % p == 0:
    #             a //= p
    #             t += 1
    #         LCMP[j] = max(t, LCMP[j])
    #         if a == 1:
    #             break
    # lcm = 1
    # for i in range(len(primes)):
    #     lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD
    lcm = A[0]
    from fractions import gcd

    for i in range(1,N):
        lcm = lcm * A[i] // gcd(lcm,A[i])

    invans = 0
    for a in A:
        invans += pow(a, MOD-2, MOD)
        invans %= MOD
    print(lcm*invans%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    def gen_primes2(upper_bound):
        upper_bound += 1
        P = [True] * upper_bound
        P[0] = P[1] = False
        for i in range(4,upper_bound,2):
            P[i] = False
        for i in range(3,int(upper_bound**0.5),2):
            if P[i]:
                for j in range(i**2,upper_bound,i):
                    P[j] = False
        res = []
        for i in range(upper_bound):
            if P[i]:
                res.append(i)
        return res

    N = II()
    A = LMIIS()
    primes = gen_primes2(max(A))
    LCMP = [0]*len(primes)
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            t = 0
            while a % primes[j] == 0:
                a //= primes[j]
                t += 1
            LCMP[j] = max(t, LCMP[j])
            if a == 1:
                break
    lcm = 1
    for i in range(len(primes)):
        lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD

    ans = 0
    for a in A:
        ans += lcm * pow(a, MOD-2, MOD)
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    # def gen_primes2(upper_bound):
    #     upper_bound += 1
    #     P = [True] * upper_bound
    #     P[0] = P[1] = False
    #     for i in range(4,upper_bound,2):
    #         P[i] = False
    #     for i in range(3,int(upper_bound**0.5),2):
    #         if P[i]:
    #             for j in range(i**2,upper_bound,i):
    #                 P[j] = False
    #     res = []
    #     for i in range(upper_bound):
    #         if P[i]:
    #             res.append(i)
    #     return res

    N = II()
    A = LMIIS()
    # upper_bound = max(A)
    # primes = gen_primes2(upper_bound)
    # LCMP = [0]*len(primes)
    # for i in range(N):
    #     # if i % 100 == 0:
    #     #     print(i)
    #     a = A[i]
    #     for j,p  in enumerate(primes):
    #         t = 0
    #         while a % p == 0:
    #             a //= p
    #             t += 1
    #         LCMP[j] = max(t, LCMP[j])
    #         if a == 1:
    #             break
    # lcm = 1
    # for i in range(len(primes)):
    #     lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD
    lcm = A[0]
    from fractions import gcd

    for i in range(1,N):
        lcm = lcm * A[i] // gcd(lcm,A[i])

    invans = 0
    for a in A:
        invans += pow(a, MOD-2, MOD)
        invans %= MOD
    print(lcm*invans%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    def gen_primes2(upper_bound):
        upper_bound += 1
        P = [True] * upper_bound
        P[0] = P[1] = False
        for i in range(4,upper_bound,2):
            P[i] = False
        for i in range(3,int(upper_bound**0.5),2):
            if P[i]:
                for j in range(i**2,upper_bound,i):
                    P[j] = False
        res = []
        for i in range(upper_bound):
            if P[i]:
                res.append(i)
        return res

    N = II()
    A = LMIIS()
    primes = gen_primes2(max(A))
    LCMP = [0]*len(primes)
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            t = 0
            while a % primes[j] == 0:
                a //= primes[j]
                t += 1
            LCMP[j] = max(t, LCMP[j])
            if a == 1:
                break
    lcm = 1
    for i in range(len(primes)):
        lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD

    ans = 0
    for a in A:
        ans += lcm * pow(a, MOD-2, MOD)
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    # def gen_primes2(upper_bound):
    #     upper_bound += 1
    #     P = [True] * upper_bound
    #     P[0] = P[1] = False
    #     for i in range(4,upper_bound,2):
    #         P[i] = False
    #     for i in range(3,int(upper_bound**0.5),2):
    #         if P[i]:
    #             for j in range(i**2,upper_bound,i):
    #                 P[j] = False
    #     res = []
    #     for i in range(upper_bound):
    #         if P[i]:
    #             res.append(i)
    #     return res

    N = II()
    A = LMIIS()
    # upper_bound = max(A)
    # primes = gen_primes2(upper_bound)
    # LCMP = [0]*len(primes)
    # for i in range(N):
    #     # if i % 100 == 0:
    #     #     print(i)
    #     a = A[i]
    #     for j,p  in enumerate(primes):
    #         t = 0
    #         while a % p == 0:
    #             a //= p
    #             t += 1
    #         LCMP[j] = max(t, LCMP[j])
    #         if a == 1:
    #             break
    # lcm = 1
    # for i in range(len(primes)):
    #     lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD
    lcm = A[0]
    from fractions import gcd

    for i in range(1,N):
        lcm = lcm * A[i] // gcd(lcm,A[i])

    invans = 0
    for a in A:
        invans += pow(a, MOD-2, MOD)
        invans %= MOD
    print(lcm*invans%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    def gen_primes(upper_bound):
        from collections import deque
        if upper_bound <= 1:
            return []
        target = range(3,upper_bound+1,2)
        top = 2
        primes = [2]
        while top <= int(upper_bound**0.5):
            primes.append(top)
            tmp = deque()
            for num in target:
                if num % top != 0:
                    tmp.append(num)
            target = tmp
            top = target[0]
        
        return primes + list(target)


    N = II()
    A = LMIIS()
    a = max(A)
    primes = gen_primes(a)
    LCMP = [0]*len(primes)
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            t = 0
            while a % primes[j] == 0:
                a //= primes[j]
                t += 1
            LCMP[j] = max(t, LCMP[j])
            if a == 1:
                break
    lcm = 1
    for i in range(len(primes)):
        lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD

    # print(lcm)

    # from fractions import gcd
    # lcm = 1
    # for a in A:
    #     g = gcd(lcm,a)
    #     lcm = lcm * a * pow(g, MOD-2, MOD) % MOD
    # print(lcm)



    ans = 0
    # for i in range(N):
    #     t = 1
    #     for j in range(len(primes)):
    #         t = t*pow(primes[j],LCMP[j] - dp[i][j],MOD)%MOD
    #     ans = (ans + t) % MOD
    for a in A:
        ans += lcm * pow(a, MOD-2, MOD)
        ans %= MOD
    print(ans)



    

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    # def gen_primes2(upper_bound):
    #     upper_bound += 1
    #     P = [True] * upper_bound
    #     P[0] = P[1] = False
    #     for i in range(4,upper_bound,2):
    #         P[i] = False
    #     for i in range(3,int(upper_bound**0.5),2):
    #         if P[i]:
    #             for j in range(i**2,upper_bound,i):
    #                 P[j] = False
    #     res = []
    #     for i in range(upper_bound):
    #         if P[i]:
    #             res.append(i)
    #     return res

    N = II()
    A = LMIIS()
    # upper_bound = max(A)
    # primes = gen_primes2(upper_bound)
    # LCMP = [0]*len(primes)
    # for i in range(N):
    #     # if i % 100 == 0:
    #     #     print(i)
    #     a = A[i]
    #     for j,p  in enumerate(primes):
    #         t = 0
    #         while a % p == 0:
    #             a //= p
    #             t += 1
    #         LCMP[j] = max(t, LCMP[j])
    #         if a == 1:
    #             break
    # lcm = 1
    # for i in range(len(primes)):
    #     lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD
    lcm = A[0]
    from fractions import gcd

    for i in range(1,N):
        lcm = lcm * A[i] // gcd(lcm,A[i])

    invans = 0
    for a in A:
        invans += pow(a, MOD-2, MOD)
        invans %= MOD
    print(lcm*invans%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    def gen_primes(upper_bound):
        from collections import deque
        target = deque(range(2,upper_bound+1))
        primes = []
        while target[0] <= upper_bound**0.5:
            top = target.popleft()
            primes.append(top)
            tmp = deque()
            for num in target:
                if num % top != 0:
                    tmp.append(num)
            target = tmp
        
        return primes + list(target)


    N = II()
    A = LMIIS()

    primes = gen_primes(max(A))
    LCMP = [0]*len(primes)
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            t = 0
            while a % primes[j] == 0:
                a //= primes[j]
                t += 1
            LCMP[j] = max(t, LCMP[j])
            if a == 1:
                break
    lcm = 1
    for i in range(len(primes)):
        lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD

    # print(lcm)

    # from fractions import gcd
    # lcm = 1
    # for a in A:
    #     g = gcd(lcm,a)
    #     lcm = lcm * a * pow(g, MOD-2, MOD) % MOD
    # print(lcm)



    ans = 0
    # for i in range(N):
    #     t = 1
    #     for j in range(len(primes)):
    #         t = t*pow(primes[j],LCMP[j] - dp[i][j],MOD)%MOD
    #     ans = (ans + t) % MOD
    for a in A:
        ans += lcm * pow(a, MOD-2, MOD)
        ans %= MOD
    print(ans)




    

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    # def gen_primes2(upper_bound):
    #     upper_bound += 1
    #     P = [True] * upper_bound
    #     P[0] = P[1] = False
    #     for i in range(4,upper_bound,2):
    #         P[i] = False
    #     for i in range(3,int(upper_bound**0.5),2):
    #         if P[i]:
    #             for j in range(i**2,upper_bound,i):
    #                 P[j] = False
    #     res = []
    #     for i in range(upper_bound):
    #         if P[i]:
    #             res.append(i)
    #     return res

    N = II()
    A = LMIIS()
    # upper_bound = max(A)
    # primes = gen_primes2(upper_bound)
    # LCMP = [0]*len(primes)
    # for i in range(N):
    #     # if i % 100 == 0:
    #     #     print(i)
    #     a = A[i]
    #     for j,p  in enumerate(primes):
    #         t = 0
    #         while a % p == 0:
    #             a //= p
    #             t += 1
    #         LCMP[j] = max(t, LCMP[j])
    #         if a == 1:
    #             break
    # lcm = 1
    # for i in range(len(primes)):
    #     lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD
    lcm = A[0]
    from fractions import gcd

    for i in range(1,N):
        lcm = lcm * A[i] // gcd(lcm,A[i])

    invans = 0
    for a in A:
        invans += pow(a, MOD-2, MOD)
        invans %= MOD
    print(lcm*invans%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    def gen_primes(upper_bound):
        from collections import deque
        target = deque(range(2,upper_bound+1))
        primes = deque()
        while target[0] <= upper_bound**0.5:
            top = target.popleft()
            primes.append(top)
            tmp = deque()
            for num in target:
                if num % top != 0:
                    tmp.append(num)
            target = tmp
        return list(primes + target)


    N = II()
    A = LMIIS()
    primes = gen_primes(max(A))
    LCMP = [0]*len(primes)
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            t = 0
            while a % primes[j] == 0:
                a //= primes[j]
                t += 1
            LCMP[j] = max(t, LCMP[j])
            if a == 1:
                break
    lcm = 1
    for i in range(len(primes)):
        lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD

    # print(lcm)

    # from fractions import gcd
    # lcm = 1
    # for a in A:
    #     g = gcd(lcm,a)
    #     lcm = lcm * a * pow(g, MOD-2, MOD) % MOD
    # print(lcm)



    ans = 0
    # for i in range(N):
    #     t = 1
    #     for j in range(len(primes)):
    #         t = t*pow(primes[j],LCMP[j] - dp[i][j],MOD)%MOD
    #     ans = (ans + t) % MOD
    for a in A:
        ans += lcm * pow(a, MOD-2, MOD)
        ans %= MOD
    print(ans)




    

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    # def gen_primes2(upper_bound):
    #     upper_bound += 1
    #     P = [True] * upper_bound
    #     P[0] = P[1] = False
    #     for i in range(4,upper_bound,2):
    #         P[i] = False
    #     for i in range(3,int(upper_bound**0.5),2):
    #         if P[i]:
    #             for j in range(i**2,upper_bound,i):
    #                 P[j] = False
    #     res = []
    #     for i in range(upper_bound):
    #         if P[i]:
    #             res.append(i)
    #     return res

    N = II()
    A = LMIIS()
    # upper_bound = max(A)
    # primes = gen_primes2(upper_bound)
    # LCMP = [0]*len(primes)
    # for i in range(N):
    #     # if i % 100 == 0:
    #     #     print(i)
    #     a = A[i]
    #     for j,p  in enumerate(primes):
    #         t = 0
    #         while a % p == 0:
    #             a //= p
    #             t += 1
    #         LCMP[j] = max(t, LCMP[j])
    #         if a == 1:
    #             break
    # lcm = 1
    # for i in range(len(primes)):
    #     lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD
    lcm = A[0]
    from fractions import gcd

    for i in range(1,N):
        lcm = lcm * A[i] // gcd(lcm,A[i])

    invans = 0
    for a in A:
        invans += pow(a, MOD-2, MOD)
        invans %= MOD
    print(lcm*invans%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    def gen_primes(upper_bound):
        from collections import deque
        target = deque(range(2,upper_bound+1))
        primes = []
        while target[0] <= upper_bound**0.5:
            top = target.popleft()
            primes.append(top)
            tmp = deque()
            for num in target:
                if num % top != 0:
                    tmp.append(num)
            target = tmp
        return primes + list(target)


    N = II()
    A = LMIIS()
    primes = gen_primes(10**6)
    LCMP = [0]*len(primes)
    dp = [[0]*len(primes) for _ in range(N)]
    from math import log
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            while a % primes[j] == 0:
                a //= primes[j]
                dp[i][j] += 1
            LCMP[j] = max(dp[i][j],LCMP[j])
            if a == 1:
                break
    lcm = 1
    for i in range(len(primes)):
        lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD

    # print(lcm)

    # from fractions import gcd
    # lcm = 1
    # for a in A:
    #     g = gcd(lcm,a)
    #     lcm = lcm * a * pow(g, MOD-2, MOD) % MOD
    # print(lcm)



    ans = 0
    # for i in range(N):
    #     t = 1
    #     for j in range(len(primes)):
    #         t = t*pow(primes[j],LCMP[j] - dp[i][j],MOD)%MOD
    #     ans = (ans + t) % MOD
    for a in A:
        ans += lcm * pow(a, MOD-2, MOD)
        ans %= MOD
    print(ans)




    

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    # def gen_primes2(upper_bound):
    #     upper_bound += 1
    #     P = [True] * upper_bound
    #     P[0] = P[1] = False
    #     for i in range(4,upper_bound,2):
    #         P[i] = False
    #     for i in range(3,int(upper_bound**0.5),2):
    #         if P[i]:
    #             for j in range(i**2,upper_bound,i):
    #                 P[j] = False
    #     res = []
    #     for i in range(upper_bound):
    #         if P[i]:
    #             res.append(i)
    #     return res

    N = II()
    A = LMIIS()
    # upper_bound = max(A)
    # primes = gen_primes2(upper_bound)
    # LCMP = [0]*len(primes)
    # for i in range(N):
    #     # if i % 100 == 0:
    #     #     print(i)
    #     a = A[i]
    #     for j,p  in enumerate(primes):
    #         t = 0
    #         while a % p == 0:
    #             a //= p
    #             t += 1
    #         LCMP[j] = max(t, LCMP[j])
    #         if a == 1:
    #             break
    # lcm = 1
    # for i in range(len(primes)):
    #     lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD
    lcm = A[0]
    from fractions import gcd

    for i in range(1,N):
        lcm = lcm * A[i] // gcd(lcm,A[i])

    invans = 0
    for a in A:
        invans += pow(a, MOD-2, MOD)
        invans %= MOD
    print(lcm*invans%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    def gen_primes(upper_bound):
        from collections import deque
        target = deque(range(2,upper_bound+1))
        primes = []
        while target[0] <= upper_bound**0.5:
            top = target.popleft()
            primes.append(top)
            tmp = deque()
            for num in target:
                if num % top != 0:
                    tmp.append(num)
            target = tmp
        return primes + list(target)


    N = II()
    A = LMIIS()
    primes = gen_primes(10**6)
    LCM = [0]*len(primes)
    dp = [[0]*len(primes) for _ in range(N)]
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            while a % primes[j] == 0:
                a //= primes[j]
                dp[i][j] += 1
            LCM[j] = max(dp[i][j],LCM[j])
    ans = 0
    for i in range(N):
        t = 1
        for j in range(len(primes)):
            t = t*pow(primes[j],LCM[j] - dp[i][j],MOD)%MOD
        ans = (ans + t) % MOD
    print(ans)




    

if __name__ == '__main__':
    main()

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    # def gen_primes2(upper_bound):
    #     upper_bound += 1
    #     P = [True] * upper_bound
    #     P[0] = P[1] = False
    #     for i in range(4,upper_bound,2):
    #         P[i] = False
    #     for i in range(3,int(upper_bound**0.5),2):
    #         if P[i]:
    #             for j in range(i**2,upper_bound,i):
    #                 P[j] = False
    #     res = []
    #     for i in range(upper_bound):
    #         if P[i]:
    #             res.append(i)
    #     return res

    N = II()
    A = LMIIS()
    # upper_bound = max(A)
    # primes = gen_primes2(upper_bound)
    # LCMP = [0]*len(primes)
    # for i in range(N):
    #     # if i % 100 == 0:
    #     #     print(i)
    #     a = A[i]
    #     for j,p  in enumerate(primes):
    #         t = 0
    #         while a % p == 0:
    #             a //= p
    #             t += 1
    #         LCMP[j] = max(t, LCMP[j])
    #         if a == 1:
    #             break
    # lcm = 1
    # for i in range(len(primes)):
    #     lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD
    lcm = A[0]
    from fractions import gcd

    for i in range(1,N):
        lcm = lcm * A[i] // gcd(lcm,A[i])

    invans = 0
    for a in A:
        invans += pow(a, MOD-2, MOD)
        invans %= MOD
    print(lcm*invans%MOD)

if __name__ == '__main__':
    main()