Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
for i,ai in enumerate(A):
  total += ai * sum(A[i+1:])
print(total % (10 ** 9 + 7))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
  sum_A -= ai
  total += ai * sum_A
print(total % (10 ** 9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sumA = []
for i,ai in enumerate(A):
  sumA.append(sum(A[i+1:]))

for i,ai in enumerate(A):
  total += ai * sumA[i]
print(total % (10 ** 9 + 7))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
  sum_A -= ai
  total += ai * sum_A
print(total % (10 ** 9 + 7))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sumA = []
for i,ai in enumerate(A):
  sumA.append(sum(A[i+1]))

for i,ai in enumerate(A):
  total += ai * sumA[i]
print(total % (10 ** 9 + 7))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
  sum_A -= ai
  total += ai * sum_A
print(total % (10 ** 9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
for i,ai in enumerate(A):
  for aj in A[i+1:]:
    total += ai * aj
    #A[i] * A[j]
#    print(A[i], A[j])
print(total % (10 ** 9 + 7))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
  sum_A -= ai
  total += ai * sum_A
print(total % (10 ** 9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
for i in range(0, N-1):
  for j in range(i+1, N):
    total += A[i] * A[j]
#    print(A[i], A[j])
print(total % (10 ** 9 + 7))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
  sum_A -= ai
  total += ai * sum_A
print(total % (10 ** 9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
for i in range(0, N):
  for j in range(i+1, N):
    total += A[i] * A[j]
#    print(A[i], A[j])
print(total % (10 ** 9 + 7))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
  sum_A -= ai
  total += ai * sum_A
print(total % (10 ** 9 + 7))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())
total = 0
for i in range(1, N+1):
  for j in range(i, N+1):
    total += A[i] * A[j]
print(total)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
  sum_A -= ai
  total += ai * sum_A
print(total % (10 ** 9 + 7))