Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from numba import jit
@jit


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    l = np.array(l)

    tot = 0
    for i in range(n):
        tot += (l[i] * (np.sum(l[i + 1:n], dtype='int64') % (10 ** 9 + 7))) % (10 ** 9 + 7)

    print(tot % (10 ** 9 + 7))


if __name__ == "__main__":
    main()

Fixed submission:


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    stack = [0]*n

    totstack = 0
    for i in range(n-1):
        totstack += l[n-i-1]
        stack[n-i-2] = totstack

    tot = 0
    for i in range(n):
        tot += (l[i] * (stack[i] % (10 ** 9 + 7))) % (10 ** 9 + 7)

    print(tot % (10 ** 9 + 7))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

import numpy as np


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    l = np.array(l)

    tot = 0
    for i in range(n):
        tot += (l[i] * (np.sum(l[i + 1:n], dtype='int64') % (10 ** 9 + 7))) % (10 ** 9 + 7)
        '''
        if tot >= 10**9 + 7:
            tot %= (10**9 + 7)
        '''

    print(tot % (10 ** 9 + 7))


if __name__ == "__main__":
    main()
    

Fixed submission:


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    stack = [0]*n

    totstack = 0
    for i in range(n-1):
        totstack += l[n-i-1]
        stack[n-i-2] = totstack

    tot = 0
    for i in range(n):
        tot += (l[i] * (stack[i] % (10 ** 9 + 7))) % (10 ** 9 + 7)

    print(tot % (10 ** 9 + 7))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

import numpy as np

n = int(input().strip())
l = list(map(int, input().split()))
l = np.array(l)

tot = 0
for i in range(n):
    tot += (l[i] * (np.sum(l[i+1:n], dtype = 'int64') % (10**9 + 7))) % (10**9 + 7)
    '''
    if tot >= 10**9 + 7:
        tot %= (10**9 + 7)
    '''

print(tot % (10**9 + 7))

Fixed submission:


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    stack = [0]*n

    totstack = 0
    for i in range(n-1):
        totstack += l[n-i-1]
        stack[n-i-2] = totstack

    tot = 0
    for i in range(n):
        tot += (l[i] * (stack[i] % (10 ** 9 + 7))) % (10 ** 9 + 7)

    print(tot % (10 ** 9 + 7))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input().strip())
l = list(map(int, input().split()))

tot = 0
for i in range(n):
    tot += l[i]*sum(l[i+1:n])
    '''
    if tot >= 10**9 + 7:
        tot %= (10**9 + 7)
    '''

print(tot % (10**9 + 7))

Fixed submission:


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    stack = [0]*n

    totstack = 0
    for i in range(n-1):
        totstack += l[n-i-1]
        stack[n-i-2] = totstack

    tot = 0
    for i in range(n):
        tot += (l[i] * (stack[i] % (10 ** 9 + 7))) % (10 ** 9 + 7)

    print(tot % (10 ** 9 + 7))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input().strip())
l = list(map(int, input().split()))

tot = 0
for i in range(n):
    for j in range(i+1, n):
        tot += l[i]*l[j]
        if tot >= 10**9 + 7:
            tot %= (10**9 + 7)

print(tot % (10**9 + 7))

Fixed submission:


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    stack = [0]*n

    totstack = 0
    for i in range(n-1):
        totstack += l[n-i-1]
        stack[n-i-2] = totstack

    tot = 0
    for i in range(n):
        tot += (l[i] * (stack[i] % (10 ** 9 + 7))) % (10 ** 9 + 7)

    print(tot % (10 ** 9 + 7))


if __name__ == "__main__":
    main()