Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

ans = 0
for i in range(n-1):
    for j in range(n-1-i):
        if a[i] >= 1000000007:
            while a[i] >= 1000000007:
                a[i] = a[i] - 1000000007
            hoge = a[i] * a[i+1+j]
        elif a[i+1+j] >= 1000000007:
            while a[i+1+j] >= 1000000007:
                a[i+1+j] = a[i+1+j] - 1000000007
            hoge = a[i]*a[i+1+j]
        else:
            hoge = a[i] * a[i+1+j] % 1000000007
        while hoge >= 1000000007:
            hoge = hoge - 1000000007
        ans = ans + hoge

ans = ans % 1000000007
print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

s = sum(a)
ans = 0
mod = 10 ** 9 + 7

for i in range(n-1):
    s -= a[i]
    ans += a[i] * s % mod

ans = ans % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

ans = 0
for i in range(n-1):
    for j in range(n-1-i):
        if a[i] >= 1000000007:
            while a[i] >= 1000000007:
                a[i] = a[i] - 1000000007
            hoge = a[i] * a[i+1+j]
        elif a[i+1+j] >= 1000000007:
            while a[i+1+j] >= 1000000007:
                a[i+1+j] = a[i+1+j] - 1000000007
            hoge = a[i]*a[i+1+j]
        else:
            hoge = a[i] * a[i+1+j] % 1000000007
        while hoge >= 1000000007:
            hoge = hoge - 1000000007
        ans = ans + hoge
        if ans >= 1000000007:
            ans = ans - 1000000007
print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

s = sum(a)
ans = 0
mod = 10 ** 9 + 7

for i in range(n-1):
    s -= a[i]
    ans += a[i] * s % mod

ans = ans % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

ans = 0
for i in range(n-1):
    for j in range(n-1-i):
        hoge = a[i]*a[i+1+j]
        while hoge >= 1000000007:
            hoge = hoge - 1000000007
        ans = ans + hoge
        if ans >= 1000000007:
            ans = ans - 1000000007
print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

s = sum(a)
ans = 0
mod = 10 ** 9 + 7

for i in range(n-1):
    s -= a[i]
    ans += a[i] * s % mod

ans = ans % mod
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]

ans = 0
for i in range(n-1):
    for j in range(n-1-i):
        hoge = a[i]*a[i+1+j] % 1000000007
        ans = ans + hoge
        if ans >= 1000000007:
            ans = ans - 1000000007

print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

s = sum(a)
ans = 0
mod = 10 ** 9 + 7

for i in range(n-1):
    s -= a[i]
    ans += a[i] * s % mod

ans = ans % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

ans = 0
for i in range(n-1):
    for j in range(n-1-i):
        hoge = a[i]*a[i+1+j] % 1000000007
        ans = ans + hoge
        if ans >= 1000000007:
            ans = ans - 1000000007

print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

s = sum(a)
ans = 0
mod = 10 ** 9 + 7

for i in range(n-1):
    s -= a[i]
    ans += a[i] * s % mod

ans = ans % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

ans = 0
for i in range(n-1):
    for j in range(n-1-i):
        ans = ans + a[i]*a[i+1+j] % 1000000007
        if ans >= 1000000007:
            ans = ans - 1000000007

print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

s = sum(a)
ans = 0
mod = 10 ** 9 + 7

for i in range(n-1):
    s -= a[i]
    ans += a[i] * s % mod

ans = ans % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

ans = 0
for i in range(n-1):
    for j in range(n-1-i):
        ans = ans + a[i]*a[i+1+j]

ans = ans % 1000000007
print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

s = sum(a)
ans = 0
mod = 10 ** 9 + 7

for i in range(n-1):
    s -= a[i]
    ans += a[i] * s % mod

ans = ans % mod
print(ans)