Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

sc = [list(map(int, input().split())) for _ in range(n)]



def solve():
    global n, m, sc
    ans = [None] * n
    for s, c in sc:
        if s > n:
            return -1
        if ans[s-1] is None:
            ans[s-1] = c
            continue
        if ans[s-1] != c:
            return -1
        if s+1 == n and c == 0:
            return -1
    ans = [x or 0 for x in ans]
    ans = list(map(str, ans))
    return ''.join(ans)

print(solve())

Fixed submission:
n, m = map(int, input().split())

sc = [list(map(int, input().split())) for _ in range(m)]

def solve():
    global n, m, sc
    for i in range(1000):
        tmp = str(i)
        if len(tmp) != n:
            continue
        check = True
        for s, c in sc:
            if int(tmp[s-1]) != c:
                check = False
        if check:
            return tmp
    return -1
print(solve())

Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split(' ')))
sc = [list(map(int, input().split(' '))) for i in range(M)]


ans_l = [False for i in range(N)]


dup = False
for s, c in sc:
    if (not ans_l[s-1]) or ans_l[s-1] == str(c):
        if s > N or s < 1:
            out = True
            break
        ans_l[s-1] = str(c)
    else:
        dup = True
        break

# ans_l

for ix, x in enumerate(ans_l):
    if x:
        break
    ans_l[ix] = '1'

for ix, x in enumerate(ans_l):
    if x:
        pass
    else:
        ans_l[ix] = '0'

ans_n = int(''.join(ans_l))

ans_final = ans_n
if dup or out:
    ans_final = -1
if len(str(ans_n)) != N:
    ans_final = -1

print(str(ans_final))

Fixed submission:
n, m = map(int, input().split())

sc = [list(map(int, input().split())) for _ in range(m)]

def solve():
    global n, m, sc
    for i in range(1000):
        tmp = str(i)
        if len(tmp) != n:
            continue
        check = True
        for s, c in sc:
            if int(tmp[s-1]) != c:
                check = False
        if check:
            return tmp
    return -1
print(solve())

Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split(' ')))
sc = [list(map(int, input().split(' '))) for i in range(M)]


ans_l = [0 for i in range(N)]

ans_final = 0

for s, c in sc:
    if (not ans_l[s-1]) or ans_l[s-1] == str(c):
        ans_l[s-1] = str(c)
    else:
        ans_final = -1
        break

ans_l = list(map(str, ans_l))

ans_n = 0

if not ans_final:
    ans_n = int(''.join(ans_l))

ans_final = ans_n
if len(str(ans_n)) != n:
    ans_final = -1

print(str(ans_final))

Fixed submission:
n, m = map(int, input().split())

sc = [list(map(int, input().split())) for _ in range(m)]

def solve():
    global n, m, sc
    for i in range(1000):
        tmp = str(i)
        if len(tmp) != n:
            continue
        check = True
        for s, c in sc:
            if int(tmp[s-1]) != c:
                check = False
        if check:
            return tmp
    return -1
print(solve())
Buggy python submission (verdict: Runtime Error):
if sum(cc) >= a:
    print('Yes')
else:
    print('No')

Fixed submission:
a,b,*cc = map(int, open(0).read().split())

if sum(cc) >= a:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())

from decimal import Decimal

import sys

for i in range(60000):
    if int(Decimal(i) * Decimal('1.08')) == n:
        print(i)
        sys.exit()

print(':(')

Fixed submission:
m1,_ = input().split()
m2,_ = input().split()

if m1==m2:
  print(0)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
d = [0]*100

for a in range(1, 10):
    for b in range(1, 10):
        d[a*b] = 1

if d[int(input())]:
    print('Yes')
else:
    print('No')

Fixed submission:
from collections import defaultdict
d = defaultdict(int)

for a in range(1, 10):
    for b in range(1, 10):
        d[a*b] = 1

if d[int(input())]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n,k,q, *aa = map(int, open(0).read().split())

scores = [k-q]*n

for a in aa:
    scores[a] += 1

for s in scores:
    if s<=0:
        print('No')
    else:
        print('Yes')

Fixed submission:
n,k,q, *aa = map(int, open(0).read().split())

scores = [k-q]*n

for a in aa:
    scores[a-1] += 1

for s in scores:
    if s<=0:
        print('No')
    else:
        print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction
from math import log, ceil
import heapq

(n, m), aa = [list(map(int, s.split())) for s in open(0)]
aa = [-Fraction(a) for a in aa]

heapq.heapify(aa)

while m:
    m1 = heapq.heappop(aa)
#     print(f'{m=},{m1=}')
    if len(aa):
        m2 = heapq.nsmallest(1, aa)[0]
        use = min(max(ceil(log(m1/m2)/log(2)), 1), m)
#         print(f'{m2=},{use=}')
    else:
        use = min(max(ceil(log(-m1)/log(2)), 1), m)
#         print(f'else, {use=}')
#         print(f'{ceil(log(-m1)/log(2))=}')
#     print(f'{m1/Fraction(2**use)}')
    heapq.heappush(aa, m1 / Fraction(2**use))
    m -= use
    if -heapq.nsmallest(1, aa)[0] < 1:
        break

aa = [int(-a) for a in aa]

print(sum(aa))

Fixed submission:
from fractions import Fraction
from math import log, ceil
import heapq

(n, m), aa = [list(map(int, s.split())) for s in open(0)]
aa = [-Fraction(a) for a in aa]

heapq.heapify(aa)

while m:
    m1 = heapq.heappop(aa)
#     print(f'{m=},{m1=}')
    if len(aa):
        m2 = aa[0]
        use = min(max(ceil(log(m1/m2)/log(2)), 1), m)
#         print(f'{m2=},{use=}')
    else:
        use = min(max(ceil(log(-m1)/log(2)), 1), m)
#         print(f'else, {use=}')
#         print(f'{ceil(log(-m1)/log(2))=}')
#     print(f'{m1/Fraction(2**use)}')
    heapq.heappush(aa, m1 / Fraction(2**use))
    m -= use
    if -(aa[0]) < 1:
        break

aa = [int(-a) for a in aa]

print(sum(aa))

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction

import heapq

(m, n), aa = [list(map(int, s.split())) for s in open(0)]

aa = [-Fraction(a) for a in aa]

heapq.heapify(aa)

for _ in range(n):
    mx = heapq.heappop(aa)
    heapq.heappush(aa, mx / Fraction(2))

aa = [int(-a) for a in aa]

print(sum(aa))

Fixed submission:
from fractions import Fraction
from math import log, ceil
import heapq

(n, m), aa = [list(map(int, s.split())) for s in open(0)]
aa = [-Fraction(a) for a in aa]

heapq.heapify(aa)

while m:
    m1 = heapq.heappop(aa)
#     print(f'{m=},{m1=}')
    if len(aa):
        m2 = aa[0]
        use = min(max(ceil(log(m1/m2)/log(2)), 1), m)
#         print(f'{m2=},{use=}')
    else:
        use = min(max(ceil(log(-m1)/log(2)), 1), m)
#         print(f'else, {use=}')
#         print(f'{ceil(log(-m1)/log(2))=}')
#     print(f'{m1/Fraction(2**use)}')
    heapq.heappush(aa, m1 / Fraction(2**use))
    m -= use
    if -(aa[0]) < 1:
        break

aa = [int(-a) for a in aa]

print(sum(aa))
Buggy python submission (verdict: Runtime Error):
ss = input()
tt = input()

print(sum([s==t for s, t in zip(s,t)]))

Fixed submission:
ss = input()
tt = input()

print(sum([s==t for s, t in zip(ss,tt)]))
Buggy python submission (verdict: Runtime Error):
(n,),*xy = [list(map(int, s.split())) for s in open(0)]

from collections import Counter
from itertools import combinations
c = Counter()
for (xa,ya),(xb,yb) in combinations(xy,2):
    c[(xa-xb, ya-yb)] += 1
    c[(xb-xa, yb-ya)] += 1

print(n - max(c.values()))

Fixed submission:
(n,),*xy = [list(map(int, s.split())) for s in open(0)]

from collections import Counter
from itertools import combinations
from sys import exit

if n == 1:
    print(1)
    exit()

c = Counter()

for (xa,ya),(xb,yb) in combinations(xy,2):
    c[(xa-xb, ya-yb)] += 1
    c[(xb-xa, yb-ya)] += 1

print(n - max(c.values()))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

mod = 1_000_000_007

from collections import deque

d = deque()

for _ in range(m):
    d.append(int(input()))

old = 0
new = 1

for i in range(1, n+1):
    if len(d):
        if i != d[0]:
            old, new = new, (old+new) % mod
        else:
            old, new = new, 0
            d.popleft()
    else:
        old, new = new, (old+new) % mod



print(new)

Fixed submission:
n, m = map(int, input().split())

mod = 1000000007

from collections import deque

d = deque()

for _ in range(m):
    d.append(int(input()))

old = 0
new = 1

for i in range(1, n+1):
    if len(d):
        if i != d[0]:
            old, new = new, (old+new) % mod
        else:
            old, new = new, 0
            d.popleft()
    else:
        old, new = new, (old+new) % mod



print(new)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

n, m = map(int, input().split())

aa = list(map(int, input().split()))

heapq.heapify(aa)

for _ in range(m):
    b, c = map(int, input().split())
    for _ in range(b):
        tmp = heapq.heappop(aa)
        heapq.heappush(aa, max(tmp, c))
        if tmp >= c:
            break

print(sum(aa))

Fixed submission:
n, m = map(int, input().split())

from collections import defaultdict

cb = defaultdict(int)

for a in input().split():
    cb[int(a)] += 1

for _ in range(m):
    b, c = map(int, input().split())
    cb[c] += b

cbl = sorted(cb.items())

res = n

ans = 0

while res > 0:
    c, b = cbl.pop()
    ncount = min(res, b)
    ans += c * ncount
    res -= ncount

print(ans)

Buggy python submission (verdict: Runtime Error):
from sortedcontainers import SortedList
import numpy as np

n, m = map(int, input().split())

a = SortedList(list(map(int, input().split())))

s = [list(map(int,list(input().split()))) for i in range(m)]

for l in s:
    b, c = l
    min_values = np.array(list(a.pop(0) for i in range(b)))
    min_values = np.array(min_values)
    change_cond = min_values < c
    min_values[change_cond] = c
    a.update(min_values)
a = list(a)
ans = sum(a)
print(ans)


Fixed submission:
n, m = map(int, input().split())

from collections import defaultdict

cb = defaultdict(int)

for a in input().split():
    cb[int(a)] += 1

for _ in range(m):
    b, c = map(int, input().split())
    cb[c] += b

cbl = sorted(cb.items())

res = n

ans = 0

while res > 0:
    c, b = cbl.pop()
    ncount = min(res, b)
    ans += c * ncount
    res -= ncount

print(ans)

Buggy python submission (verdict: Runtime Error):
from sortedcontainers import SortedList
import numpy as np

n, m = map(int, input().split())

a = SortedList(list(map(int, input().split())))

s = [list(map(int,list(input().split()))) for i in range(m)]

print(a)
for l in s:
    b, c = l
    min_values = np.array(list(a.pop(0) for i in range(b)))
    min_values = np.array(min_values)
    change_cond = min_values < c
    min_values[change_cond] = c
    a.update(min_values)
a = list(a)
ans = sum(a)
print(ans)




Fixed submission:
n, m = map(int, input().split())

from collections import defaultdict

cb = defaultdict(int)

for a in input().split():
    cb[int(a)] += 1

for _ in range(m):
    b, c = map(int, input().split())
    cb[c] += b

cbl = sorted(cb.items())

res = n

ans = 0

while res > 0:
    c, b = cbl.pop()
    ncount = min(res, b)
    ans += c * ncount
    res -= ncount

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
# points = np.array([0, 1, 2, 3, 4])
points = np.array([input() for _ in range(5)])
thr = input()
diff = max(points[1:] - points[:4])
if diff <= thr:
    print('Yay!')
else:
    print(':(')

Fixed submission:
import numpy as np
# points = np.array([0, 1, 2, 3, 4])
points = np.array([int(input()) for _ in range(5)])
thr = int(input())
diff = (points[4] - points[0])
if diff <= thr:
    print('Yay!')
else:
    print(':(')
Buggy python submission (verdict: Time Limit Exceeded):
n,*bb = map(int, open(0).read().split())

ans = []

while bb:
    for i,v in zip(range(len(bb),0,-1),bb[::-1]):
#         print(i,v)
        if i==v:
            ans.append(v)
            del bb[i-1]
            break

for a in ans[::-1]:
    print(a)

Fixed submission:
n,*bb = map(int, open(0).read().split())

ans = []

while bb:
    imp = True
    for i,v in zip(range(len(bb),0,-1),bb[::-1]):
#         print(i,v)
        if i==v:
            ans.append(v)
            del bb[i-1]
            imp = False
            break
    if imp:
        ans = [-1]
        break

for a in ans[::-1]:
    print(a)
Buggy python submission (verdict: Runtime Error):
n = int(input())

hs = list(map(int, input().split()))

cost = {n-1:0}

def calc(k):
    if k not in cost:
        if k == n-2:
            cost[k] = abs(hs[k+1]-hs[k])
        else:
            cost[k] = min(abs(hs[k+1] - hs[k]) + calc(k+1), abs(hs[k+2] - hs[k]) + calc(k+2))
    return cost[k]

print(calc(0))

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())

hs = list(map(int, input().split()))

cost = {n-1:0, n-2:abs(hs[n-1]-hs[n-2])}

def calc(k):
    if k not in cost:
        cost[k] = min(abs(hs[k+1] - hs[k]) + calc(k+1), abs(hs[k+2] - hs[k]) + calc(k+2))
    return cost[k]

print(calc(0))
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

items = [list(map(int, input().split())) for _ in range(N)]

d = {(W, 0)}

for w, v in items:
    tmp = set()
    for rw, rv in d:
        tmp.add((rw, rv))
        if rw >= w:
            tmp.add((rw-w, rv+v))
    d = tmp

d = {elm[1] for elm in d}

print(max(d))

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

from collections import defaultdict

dp = defaultdict(int)

dp[0] = 0

for _ in range(N):
    w, v = map(int, input().split())
    for k, val in list(dp.items()):
        if k+w <= W:
            dp[k+w] = max(dp[k+w], val+v)



print(max(dp.values()))

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

items = [list(map(int, input().split())) for _ in range(N)]

d = {(W, 0)}

for w, v in items:
    tmp = set()
    for rw, rv in d:
        if rw >= w:
            tmp.add((rw-w, rv+v))
    d |= tmp

d = {elm[1] for elm in d}

print(max(d))

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

from collections import defaultdict

dp = defaultdict(int)

dp[0] = 0

for _ in range(N):
    w, v = map(int, input().split())
    for k, val in list(dp.items()):
        if k+w <= W:
            dp[k+w] = max(dp[k+w], val+v)



print(max(dp.values()))

Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split()

items = [list(map(int, input().split())) for _ in range(N)]

d = {(W, 0)}

for w, v in items:
    tmp = set()
    for rw, rv in d:
        if rw >= w:
            tmp.add((rw-w, rv+v))
    d |= tmp

d = {elm[1] for elm in d}

print(max(d))

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

from collections import defaultdict

dp = defaultdict(int)

dp[0] = 0

for _ in range(N):
    w, v = map(int, input().split())
    for k, val in list(dp.items()):
        if k+w <= W:
            dp[k+w] = max(dp[k+w], val+v)



print(max(dp.values()))
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k = map(int, open(0).read().split())

if a!=b:
    n,m = 1,0
    for i in range(k):
        n,m = m*2,n+m
    print((a-b)*(n-m))
else:
    print(0)

Fixed submission:
a,b,c,k = map(int, open(0).read().split())

fact = 1
if k%2:
    fact = -1
print((a-b)*fact)
Buggy python submission (verdict: Runtime Error):
n,*aa = map(int, open(0).read().split())

from itertools import accumulate
from collections import Counter
from math import comb

c = Counter(accumulate(aa))
c[0] += 1

ans = 0
for i,v in c.items():
    if v > 1:
        ans += comb(v,2)

print(ans)

Fixed submission:
n,*aa = map(int, open(0).read().split())

from itertools import accumulate
from collections import Counter
from math import comb

c = Counter(accumulate(aa))
c[0] += 1

ans = 0
for i,v in c.items():
    if v > 1:
        ans += comb(v,2)

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
(n,), *aaa = [list(map(int, s.split())) for s in open(0)]

aaa = np.array(aaa, dtype='int')

cost = np.stack([np.cumsum(aaa[0]), np.zeros(n, dtype='int')])
cost[1][0] = aaa[0][0] + aaa[1][0]

for i in range(1, n):
    cost[1][i] = max(cost[1][i-1], cost[0][i]) + aaa[1][i]

print(cost[-1][-1])

Fixed submission:
import numpy as np
(n,), *aaa = [list(map(int, s.split())) for s in open(0)]

aaa = np.array(aaa, dtype='int')

cost = np.stack([np.cumsum(aaa[0]), np.zeros(n, dtype='int')])
cost[1][0] = aaa[0][0] + aaa[1][0]

for i in range(1, n):
    cost[1][i] = max(cost[1][i-1], cost[0][i]) + aaa[1][i]

print(cost[-1][-1])
Buggy python submission (verdict: Runtime Error):
s = input()
s[3] = '8'
print(s)

Fixed submission:
s = input()
print(s[:3]+'8'+s[4:])

Buggy python submission (verdict: Runtime Error):
s = input()
s[3] = 8
print(s)

Fixed submission:
s = input()
print(s[:3]+'8'+s[4:])
Buggy python submission (verdict: Runtime Error):
_,*aa = map(int, open(1).read().split())

print(max(aa) - min(aa))

Fixed submission:
_,*aa = map(int, open(0).read().split())

print(max(aa) - min(aa))
Buggy python submission (verdict: Runtime Error):
hw,*aaa = open(1).read().splitlines()

h,w = map(int, hw.split())

print('#'*(w+2))
for aa in aaa:
    print(f'#{aa}#')
print('#'*(w+2))

Fixed submission:
hw,*aaa = open(0).read().splitlines()

h,w = map(int, hw.split())

print('#'*(w+2))
for aa in aaa:
    print(f'#{aa}#')
print('#'*(w+2))
Buggy python submission (verdict: Runtime Error):
x, s = *open(0),
print(x)
print(s)
n, a, b = map(int, x.rstrip.split())

p = 0
wp = 0

for char in s:
    if char == 'c' or p >= a+b:
        print('No')
        continue
    if char == 'a':
        p += 1
        print('Yes')
        continue
    if wp < b:
        p += 1
        wp += 1
        print('Yes')
    else:
        print('No')

Fixed submission:
x = input()
s = input()

n, a, b = map(int, x.split())

p = 0
wp = 0

for char in s:
    if char == 'c' or p >= a+b:
        print('No')
        continue
    if char == 'a':
        p += 1
        print('Yes')
        continue
    if wp < b:
        p += 1
        wp += 1
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
ans = 0
cnt_s = cnt_t = 0

for c in s:
    if c == 'S':
        cnt_s += 1
    else:
        cnt_t += 1
    if cnt_t > cnt_s:
        ans += cnt_s
        cnt_s = cnt_t = 0
ans += cnt_s
print(len(s) - ans*2)

Fixed submission:
s = input().rstrip()

removed = 0
cnt_s = cnt_t = 0

for c in s:
    if c == 'S':
        cnt_s += 1
    else:
        cnt_t += 1
    if cnt_t > cnt_s:
        removed += cnt_s
        cnt_s = cnt_t = 0
#     print(cnt_s,cnt_t)
removed += min(cnt_s,cnt_t)
print(len(s) - removed*2)
Buggy python submission (verdict: Runtime Error):
from string import ascii_lowercase
alp = ascii_lowercase
num = {char: i for i, char in enumerate(alp)}

s = input()
k = int(input())
ns = [num[char] for char in s]

for i in range(len(ns)):
    v = ns[i]
    if 26 - v <= k:
        ns[i] = 0
        k -= 26 - v

ns[-1] += k

print(''.join(alp[n] for n in ns))

Fixed submission:
from string import ascii_lowercase
s = input()
k = int(input())

def main(s, k):
    alp = ascii_lowercase
    num = {char: i for i, char in enumerate(alp)}

    ns = [num[char] for char in s]

    for i in range(len(ns)):
        v = ns[i]
        if v != 0 and 26 - v <= k:
            ns[i] = 0
            k -= 26 - v

    ns[-1] = (ns[-1] + k) % 26

    return ''.join(alp[n] for n in ns)
print(main(s, k))
Buggy python submission (verdict: Runtime Error):
H, W, A, B = map(int, open(0).read().split())
MOD = 10**9+7

def modperm(m, n, mod):
    p = 1
    for i in range(n):
        p = p * (m - i) % mod
    return p

def modcomb(m, n, mod):
    if n > m - n:
        n = m - n
    p = modperm(m, n, mod)
    q = pow(modperm(n, n, mod), -1, mod)
    return p * q % mod

total = modcomb(H + W - 2, W - 1, MOD)

tmp = modcomb(A + W - 2, W - 1, MOD)
total -= tmp

for i in range(B - 1):
    a = H - A + i
    b = i + 1
    c = W - i - 1
    d = W + A - 2 - i
#     print(a,b,c,d)
    tmp = tmp * a * c % MOD
    tmp = tmp * pow(b, MOD - 2, MOD) % MOD
    tmp = tmp * pow(d, MOD - 2, MOD) % MOD
#     print(tmp)
    total = (total - tmp) % MOD

print(total)

Fixed submission:
H, W, A, B = map(int, open(0).read().split())
MOD = 10**9+7

def modcomb(m, n, mod):
    if n > m - n:
        n = m - n
    p = 1
    q = 1
    for i in range(n):
        p = p * (m - i) % mod
        q = q * (i + 1) % mod
    result = p * pow(q, mod - 2, mod) % mod
    return result

total = modcomb(H + W - 2, W - 1, MOD)

tmp = modcomb(A + W - 2, W - 1, MOD)
total -= tmp

for i in range(B - 1):
    a = H - A + i
    b = i + 1
    c = W - i - 1
    d = W + A - 2 - i
#     print(a,b,c,d)
    tmp = tmp * a * c % MOD
    tmp = tmp * pow(b, -1, MOD) % MOD
    tmp = tmp * pow(d, -1, MOD) % MOD
#     print(tmp)
    total = (total - tmp) % MOD

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, m = map(int, input().split())

ans = []
flag = False
for i in range(n):
    if x in ans:
        v = x
        flag = True
        break
    ans.append(x)
    x = x**2 % m
if flag:
    p = ans.index(v)
    l = len(ans) - p
    d, e = divmod(n-p, l)
    print(sum(ans[:p]) + d*sum(ans[p:]) + sum(ans[p:p+e]))
else:
    print(sum(ans))

Fixed submission:
n, x, m = map(int, input().split())

ans = []
flag = False
for i in range(n):
    if x in ans:
        v = x
        flag = True
        break
    ans.append(x)
    x = x**2 % m
if flag:
    p = ans.index(v)
    l = len(ans) - p
    d, e = divmod(n-p, l)
    print(sum(ans[:p]) + d*sum(ans[p:]) + sum(ans[p:p+e]))
else:
    print(sum(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

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

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

b = 10**9+7
s = sum(a)
ans = 0
for i in range(n-1):
    s -= a[i]
    ans += a[i]*(s%b)
    ans %= b
print(ans)

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

b = 10**9+7
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        ans += a[i]*a[j]
        ans %= b
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

b = 10**9+7
s = sum(a)
ans = 0
for i in range(n-1):
    s -= a[i]
    ans += a[i]*(s%b)
    ans %= b
print(ans)