Buggy python submission (verdict: Time Limit Exceeded):
#####
# C #
#####

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

ans = 0
for i in range(len(A)-1):
    tmp1 = A[i] % (10**9 + 7)
    tmp2 = sum(A[i+1:]) % (10**9 + 7)
    ans += tmp1 * tmp2
    ans %= (10**9 + 7)
    # for j in range(1,len(A)-i
    #     # print(A[i],'A[i]',A[i+j],'A[i+j]')
    #     tmp_ai = A[i] % (10**9 + 7)
    #     tmp_aij = A[i+j] % (10**9 + 7)
    #     tmp += (tmp_ai * tmp_aij) % (10**9 + 7)
    #     # print(tmp,'tmp')
    # tmp %= (10**9 + 7)
    # ans += tmp

# ans %= (10**9 + 7)
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))

sumA = sum(A)
ans = 0
for i in range(len(A)-1):
    sumA -= A[i]
    tmp1 = A[i] % (10**9 + 7)
    tmp2 = sumA % (10**9 + 7)
    ans += tmp1 * tmp2
    ans %= (10**9 + 7)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

ans = 0
for i in range(len(A)-1):
    ans += A[i]*sum(A[i+1:])
ans %= (10**9 + 7)
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))

sumA = sum(A)
ans = 0
for i in range(len(A)-1):
    sumA -= A[i]
    tmp1 = A[i] % (10**9 + 7)
    tmp2 = sumA % (10**9 + 7)
    ans += tmp1 * tmp2
    ans %= (10**9 + 7)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
# print(A)
# print(len(A))

ans = 0
for i in range(len(A)-1):
    tmp = 0
    for j in range(1,len(A)-i):
        # print(A[i],'A[i]',A[i+j],'A[i+j]')
        tmp_ai = A[i] % (10**9 + 7)
        tmp_aij = A[i+j] % (10**9 + 7)
        tmp += (tmp_ai * tmp_aij) % (10**9 + 7)
        # print(tmp,'tmp')
    tmp %= (10**9 + 7)
    ans += tmp

ans %= (10**9 + 7)
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))

sumA = sum(A)
ans = 0
for i in range(len(A)-1):
    sumA -= A[i]
    tmp1 = A[i] % (10**9 + 7)
    tmp2 = sumA % (10**9 + 7)
    ans += tmp1 * tmp2
    ans %= (10**9 + 7)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
# print(A)
# print(len(A))

ans = 0
for i in range(len(A)-1):
    tmp = 0
    for j in range(1,len(A)-i):
        # print(A[i],'A[i]',A[i+j],'A[i+j]')
        tmp_ai = A[i] % (10**9 + 7)
        tmp_aij = A[i+j] % (10**9 + 7)
        tmp += tmp_ai * tmp_aij
        # print(tmp,'tmp')
    tmp %= (10**9 + 7)
    ans += tmp

ans %= (10**9 + 7)
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))

sumA = sum(A)
ans = 0
for i in range(len(A)-1):
    sumA -= A[i]
    tmp1 = A[i] % (10**9 + 7)
    tmp2 = sumA % (10**9 + 7)
    ans += tmp1 * tmp2
    ans %= (10**9 + 7)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
# print(A)
# print(len(A))

ans = 0
for i in range(len(A)-1):
    tmp = 0
    for j in range(1,len(A)-i):
        # print(A[i],'A[i]',A[i+j],'A[i+j]')
        tmp_ai = A[i] % (10**9 + 7)
        tmp_aij = A[i+j] % (10**9 + 7)
        tmp += tmp_ai * tmp_aij
        # print(tmp,'tmp')
    ans += tmp

ans %= (10**9 + 7)
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))

sumA = sum(A)
ans = 0
for i in range(len(A)-1):
    sumA -= A[i]
    tmp1 = A[i] % (10**9 + 7)
    tmp2 = sumA % (10**9 + 7)
    ans += tmp1 * tmp2
    ans %= (10**9 + 7)
    
print(ans)