Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    mod = 1000000007

    X = 1
    for a in A:
        g = gcd(X, a)
        X = (X * a) // g
    ans = 0
    for a in A:
        ans = (ans + X // a)%mod
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys
    from fractions import gcd
    from collections import defaultdict
    input = sys.stdin.buffer.readline

    def p(n):
        ret = defaultdict(int)
        d = 2
        m = int(n**0.5)
        while n > 1:
            if n % d == 0:
                ret[d] += 1
                n //= d
            else:
                d += 1
                if d > m:
                    ret[n] += 1
                    break
        return ret

    N = int(input())
    A = list(map(int, input().split()))
    mod = 1000000007

    prime = defaultdict(int)
    p_list = []
    for a in A:
        pp = p(a)
        p_list.append(pp)
        for pr in pp.keys():
            ppr = prime[pr]
            pppr = pp[pr]
            if ppr < pppr:
                prime[pr] = pppr

    M = 1
    for pr in prime.keys():
        M = (M * pow(pr, prime[pr], mod))%mod

    ans = 0
    for a in A:
        ans = (ans + (M * pow(a, mod-2, mod))%mod)%mod

    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from fractions import gcd
    from collections import defaultdict
    input = sys.stdin.buffer.readline

    def p(n):
        ret = defaultdict(int)
        d = 2
        m = int(n**0.5)
        while n > 1:
            if n % d == 0:
                ret[d] += 1
                n //= d
            else:
                d += 1
                if d > m:
                    ret[n] += 1
                    break
        return ret

    N = int(input())
    A = list(map(int, input().split()))
    mod = 1000000007

    prime = defaultdict(int)
    p_list = []
    for a in A:
        pp = p(a)
        p_list.append(pp)
        for pr in pp.keys():
            prime[pr] = max(prime[pr], pp[pr])

    ans = 0
    for i, pp in enumerate(p_list):
        tmp = 1
        for pr in prime.keys():
            tmp = (tmp * pow(pr, prime[pr] - pp[pr], mod)) % mod
        ans = (ans + tmp)%mod

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys
    from fractions import gcd
    from collections import defaultdict
    input = sys.stdin.buffer.readline

    def p(n):
        ret = defaultdict(int)
        d = 2
        m = int(n**0.5)
        while n > 1:
            if n % d == 0:
                ret[d] += 1
                n //= d
            else:
                d += 1
                if d > m:
                    ret[n] += 1
                    break
        return ret

    N = int(input())
    A = list(map(int, input().split()))
    mod = 1000000007

    prime = defaultdict(int)
    p_list = []
    for a in A:
        pp = p(a)
        p_list.append(pp)
        for pr in pp.keys():
            ppr = prime[pr]
            pppr = pp[pr]
            if ppr < pppr:
                prime[pr] = pppr

    M = 1
    for pr in prime.keys():
        M = (M * pow(pr, prime[pr], mod))%mod

    ans = 0
    for a in A:
        ans = (ans + (M * pow(a, mod-2, mod))%mod)%mod

    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    mod = 1000000007

    X = A[0]
    for i in range(1, N):
        g = gcd(X, A[i])
        X = (X * A[i]) // g
    ans = 0
    for i in range(N):
        ans = (ans + X // A[i])%mod
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys
    from fractions import gcd
    from collections import defaultdict
    input = sys.stdin.buffer.readline

    def p(n):
        ret = defaultdict(int)
        d = 2
        m = int(n**0.5)
        while n > 1:
            if n % d == 0:
                ret[d] += 1
                n //= d
            else:
                d += 1
                if d > m:
                    ret[n] += 1
                    break
        return ret

    N = int(input())
    A = list(map(int, input().split()))
    mod = 1000000007

    prime = defaultdict(int)
    p_list = []
    for a in A:
        pp = p(a)
        p_list.append(pp)
        for pr in pp.keys():
            ppr = prime[pr]
            pppr = pp[pr]
            if ppr < pppr:
                prime[pr] = pppr

    M = 1
    for pr in prime.keys():
        M = (M * pow(pr, prime[pr], mod))%mod

    ans = 0
    for a in A:
        ans = (ans + (M * pow(a, mod-2, mod))%mod)%mod

    print(ans)


if __name__ == '__main__':
    main()