Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
tmp = list(map(int, input().split()))
A = [a % M for a in tmp]
ans = 0
for i in range(1,n):
    ans += (A[i-1] * ((sum(A[i::])%M)))%M
print(ans%M)

Fixed submission:
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
    s += A[i]
    s %= M

for i in range(n):
    s = s - A[i]
    if s < 0:
        s += M
    ans += A[i] * s
    ans %= M
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
tmp = list(map(int, input().split()))
A = [a % M for a in tmp]
M = 1000000007
ans = 0
for i in range(1,n):
    ans += (A[i-1] * ((sum(A[i::])%M)))%M
print(ans%M)

Fixed submission:
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
    s += A[i]
    s %= M

for i in range(n):
    s = s - A[i]
    if s < 0:
        s += M
    ans += A[i] * s
    ans %= M
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
M = 1000000007
ans = 0
for i in range(1,n):
    ans += (A[i-1] * (sum(A[i::])%M))%M
print(ans%M)

Fixed submission:
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
    s += A[i]
    s %= M

for i in range(n):
    s = s - A[i]
    if s < 0:
        s += M
    ans += A[i] * s
    ans %= M
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
M = 1000000007
a = [A[i] * A[j] for i in range(n-1) for j in range(i+1,n)]
print(sum(a)%M)

Fixed submission:
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
    s += A[i]
    s %= M

for i in range(n):
    s = s - A[i]
    if s < 0:
        s += M
    ans += A[i] * s
    ans %= M
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
M = 1000000007
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += A[i] * A[j]
print(ans%M)

Fixed submission:
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
    s += A[i]
    s %= M

for i in range(n):
    s = s - A[i]
    if s < 0:
        s += M
    ans += A[i] * s
    ans %= M
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
M = 1000000007
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += (A[i] * A[j] % M)
print(ans%M)

Fixed submission:
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
    s += A[i]
    s %= M

for i in range(n):
    s = s - A[i]
    if s < 0:
        s += M
    ans += A[i] * s
    ans %= M
print(ans)