Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys

H, W = map(int, input().split())
square = []
for i in range(H):
    a = list(map(str, input()))
    square += a

for i in range(H*W):
    if square[i] == '#':
        if i % W != 0:
            if square[i+1] == '#' or square[i-1] == '#':
                continue
        else:
            if square[i+1] == '#':
                continue
        if i-W > 0:
            if square[i-W] == '#':
                continue
        if i+W < H*W:
            if square[i+W] == '#':
                continue
        print('No')
        sys.exit()
        
print('Yes')
            


Fixed submission:
import sys

H, W = map(int, input().split())
square = []
for i in range(H):
    a = list(map(str, input()))
    square += a

if H == W == 1:
    print('Yes')
    sys.exit()
    
for i in range(H*W):
    if square[i] == '#':
        if i % W != W-1:
            if square[i+1] == '#':
                continue
        if i % W != 0:
            if square[i-1] == '#':
                continue
            
        if i-W >= 0:
            if square[i-W] == '#':
                continue
        if i+W <= H*W:
            if square[i+W] == '#':
                continue
        print('No')
        sys.exit()
        
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
from statistics import median
from operator import itemgetter
N = int(input())
x = list(map(int, input().split()))
y = [x for x in range(N)]
z = list(zip(x, y))
z.sort()
x_, y = zip(*z)
val = N//2

for i in range(N):
    if list(y).index(i) < val:
        print(x_[val])
    else:
        print(x_[val-1])



Fixed submission:
from statistics import median
from operator import itemgetter
N = int(input())
x = list(map(int, input().split()))
x_ = sorted(x)
m0 = median(x_[1:])
m1 = median(x_[:-1])
for i in x:
    if m1 >= i:
        print(m0)
    else:
        print(m1)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.special import comb

n = int(input())
a = sorted(list(map(int, input().split())))
num0, num1, val = 0, 0, 0

if n == 2:
    print(a[1], a[0])
else:
    for i in range(n-1, n//2, -1):
        for j in range(i-1, 0, -1):
            val0 = comb(a[i], a[j])
            if val0 > val:
                num0 = a[i]
                num1 = a[j]
                val = val0
    print(num0, num1)


Fixed submission:
_ = int(input())
a = sorted(list(map(int, input().split())))
num0, num1, val = a[-1], 0, float('inf')

for i in a[:-1]:
    val0 = abs(i-num0/2)
    if val0 < val:
        num1 = i
        val = val0
print(num0, num1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
name = [0]*5
ans = 0
for i in range(N):
    a = input()
    if a[0] == 'M': name[0] += 1
    elif a[0] == 'A': name[1] += 1
    elif a[0] == 'R': name[2] += 1
    elif a[0] == 'C': name[3] += 1
    elif a[0] == 'H': name[4] += 1
if sum(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        ans += i[0]*i[1]*i[2]
    print(ans)



Fixed submission:
from itertools import combinations
N = int(input())
name = [0]*5
ans = 0
for i in range(N):
    a = input()
    if a[0] == 'M': name[0] += 1
    elif a[0] == 'A': name[1] += 1
    elif a[0] == 'R': name[2] += 1
    elif a[0] == 'C': name[3] += 1
    elif a[0] == 'H': name[4] += 1
if sum(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        ans += i[0]*i[1]*i[2]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
name = []

for i in range(N):
    a = input()
    if a[0] == 'M' or a[0] == 'A' or a[0] == 'R' or a[0] == 'C' or a[0] == 'H':
        name += [a[0]]
count = 0

if len(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        if i[0] != i[1] and i[1] != i[2] and i[2] != i[0]:
            count += 1
    print(count)



Fixed submission:
from itertools import combinations
N = int(input())
name = [0]*5
ans = 0
for i in range(N):
    a = input()
    if a[0] == 'M': name[0] += 1
    elif a[0] == 'A': name[1] += 1
    elif a[0] == 'R': name[2] += 1
    elif a[0] == 'C': name[3] += 1
    elif a[0] == 'H': name[4] += 1
if sum(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        ans += i[0]*i[1]*i[2]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
q = int(input())
n = 10**5
nums = [False]*2+[True]*(n-2)

for i in range(2, n):
    if nums[i]:
        for j in range(i*2, n, i):
            nums[j] = False
for _ in range(q):
    ans = 0
    l, r = map(int, input().split())
    for i in range(l, r+1, 2):
        if nums[i] == nums[(i+1)//2] == True:
            ans += 1
    print(ans)


Fixed submission:
q = int(input())
n = 10**5
nums = [False]*2+[True]*(n-2)
ans = [0]*n
for i in range(2, n):
    if nums[i]:
        for j in range(i*2, n, i):
            nums[j] = False
pre = 0
for i in range(3, n, 2):
    if nums[i] and nums[(i+1)//2]:
        ans[i] += pre+1
        pre = ans[i]
    else:
        ans[i] = pre
for _ in range(q):
    l, r = map(int, input().split())
    print(ans[r]-ans[max(l-2, 1)])
Buggy python submission (verdict: Runtime Error):
def Recording():
    n, c = map(int, input().split())
    num = 30#2*10**5+1 

    # チャンネルごとにimos配列
    imos = [[0]*num for _ in range(c)]
    
    # imos
    for _ in range(n):
        s, t, c0 = map(int, input().split())
        if imos[c0-1][s*2] < 0 and imos[c0-1][t*2-1] > 0:
            imos[c0-1][s*2] = 0
            imos[c0-1][t*2-1] = 0
        elif imos[c0-1][s*2] < 0:            
            imos[c0-1][s*2] = 0
            imos[c0-1][t*2-1] += 1
        elif imos[c0-1][t*2-1] > 0:    
            imos[c0-1][s*2-1] += 1
            imos[c0-1][t*2-1] = 0
        else:
            imos[c0-1][s*2-1] += 1
            imos[c0-1][t*2] -= 1
    ans = [0 for _ in range(num)]
    for i in range(c):
        for j in range(1, num):
            imos[i][j] += imos[i][j-1]
            ans[j] += imos[i][j]
    print(max(ans))
    
if __name__ == '__main__':
    Recording()
    


Fixed submission:
def Recording():
    n, c = map(int, input().split())
    num = 2*10**5+1 

    # チャンネルごとにimos配列
    imos = [[0]*num for _ in range(c)]
    
    # imos
    for _ in range(n):
        s, t, c0 = map(int, input().split())
        if imos[c0-1][s*2] < 0 and imos[c0-1][t*2-1] > 0:
            imos[c0-1][s*2] = 0
            imos[c0-1][t*2-1] = 0
        elif imos[c0-1][s*2] < 0:            
            imos[c0-1][s*2] = 0
            imos[c0-1][t*2] -= 1
        elif imos[c0-1][t*2-1] > 0:    
            imos[c0-1][s*2-1] += 1
            imos[c0-1][t*2-1] = 0
        else:
            imos[c0-1][s*2-1] += 1
            imos[c0-1][t*2] -= 1
    ans = [0 for _ in range(num)]
    for i in range(c):
        for j in range(1, num):
            imos[i][j] += imos[i][j-1]
            ans[j] += imos[i][j]
    print(max(ans))
    
if __name__ == '__main__':
    Recording()
Buggy python submission (verdict: Runtime Error):
s = input()
num = len(s)
l, r = 0, num-1
ans = 0

while l != r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        ans += 1
        if s[l] == 'x':
            l += 1
        elif s[r] == 'x':
            r -= 1
        else:
            print(-1)
            break
print(ans)
    


Fixed submission:
import sys
s = input()
num = len(s)
l, r = 0, num-1
ans = 0

while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        ans += 1
        if s[l] == 'x':
            l += 1
        elif s[r] == 'x':
            r -= 1
        else:
            print(-1)
            sys.exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
num = len(s)
l, r = 0, num-1

for i in range(num//2):
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        if s[l] == 'x' or s[r] == 'x':
            ans += 1
            l += 1
        else:
            print(-1)
            break
print(ans)
    


Fixed submission:
import sys
s = input()
num = len(s)
l, r = 0, num-1
ans = 0

while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        ans += 1
        if s[l] == 'x':
            l += 1
        elif s[r] == 'x':
            r -= 1
        else:
            print(-1)
            sys.exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
import queue
n, m = map(int, input().split())
route = [[] for _ in range(n)]
vals = []
for _ in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)
    vals.append([a-1, b-1])
ans = m
for i in range(m):
    route2 = set()
    q = queue.Queue()
    q.put(i)
    try:
        route[vals[i][0]].remove(vals[i][1])
        route[vals[i][1]].remove(vals[i][0])
    except:
        pass
    while not q.empty():
        a = q.get()
        if not a in route2:
            route2.add(a)
            for j in route[a]:
                q.put(j)
        if len(route2) == n:
            ans -= 1
            break
    try:
        route[vals[i][0]].append(vals[i][1])
        route[vals[i][1]].append(vals[i][0])
    except:
        pass
print(ans)
        


Fixed submission:
import queue
n, m = map(int, input().split())
route = [[] for _ in range(n)]
vals = []
for _ in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)
    vals.append([a-1, b-1])
ans = m
for i in range(m):
    route2 = set()
    q = queue.Queue()
    q.put(0)
    route[vals[i][0]].remove(vals[i][1])
    route[vals[i][1]].remove(vals[i][0])
    while not q.empty():
        a = q.get()
        if not a in route2:
            route2.add(a)
            for j in route[a]:
                q.put(j)
        if len(route2) == n:
            ans -= 1
            break
    route[vals[i][0]].append(vals[i][1])
    route[vals[i][1]].append(vals[i][0])
print(ans)

Buggy python submission (verdict: Runtime Error):
import queue
n, m = map(int, input().split())
route = [[] for _ in range(n)]
vals = []
for _ in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)
    vals.append([a-1, b-1])
ans = m
for i in range(m):
    route2 = set()
    q = queue.Queue()
    q.put(i)
    route[vals[i][0]].remove(vals[i][1])
    route[vals[i][1]].remove(vals[i][0])
    while not q.empty():
        a = q.get()
        if not a in route2:
            route2.add(a)
            for j in route[a]:
                q.put(j)
    if len(route2) == n:
        ans -= 1
    route[vals[i][0]].append(vals[i][1])
    route[vals[i][1]].append(vals[i][0])
    
print(ans)
        


Fixed submission:
import queue
n, m = map(int, input().split())
route = [[] for _ in range(n)]
vals = []
for _ in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)
    vals.append([a-1, b-1])
ans = m
for i in range(m):
    route2 = set()
    q = queue.Queue()
    q.put(0)
    route[vals[i][0]].remove(vals[i][1])
    route[vals[i][1]].remove(vals[i][0])
    while not q.empty():
        a = q.get()
        if not a in route2:
            route2.add(a)
            for j in route[a]:
                q.put(j)
        if len(route2) == n:
            ans -= 1
            break
    route[vals[i][0]].append(vals[i][1])
    route[vals[i][1]].append(vals[i][0])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def cal():
    N = int(input())

    for i in range(1, 3501):
        for j in range(1, 3501):
            num0 = 4*i*j-N*(i+j) 
            if num0 != 0:
                num = N*i*j/num0
                if num.is_integer() and 0 < num <= 3500:
                    print(i, int(num), j)
                    sys.exit()

cal()


Fixed submission:
import sys

def cal():
    N = int(input())

    for i in range(1, 3501):
        for j in range(1, 3501):
            num0 = 4*i*j-N*(i+j) 
            if num0 != 0:
                num = N*i*j/num0
                if num.is_integer() and 0 < num <= 3500:
                    print(i, int(num), j)
                    sys.exit()

cal()
Buggy python submission (verdict: Runtime Error):
n = int(input())
c = [0]*10**5
for i in range(n):
    a, b = map(int, input().split())
    for j in range(a, b+1):
        c[j] = 1
print(sum(c))


Fixed submission:
n = int(input())
c = [0]*10**5
for i in range(n):
    a, b = map(int, input().split())
    for j in range(a, b+1):
        c[j-1] = 1
print(sum(c))
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = [0]*(10**9)

for _ in range(N):
    a = int(input())
    if ans[a-1] == 0:
        ans[a-1] += 1
    else:
        ans[a-1] = 0

print(sum(ans))


Fixed submission:
N = int(input())
ans = set()

for _ in range(N):
    a = int(input())
    if not a in ans:
        ans.add(a)
    else:
        ans.remove(a)
print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = sorted(list(map(int, input().split())))
val, ans = [], []
for i in a:
    if i in set(val):
        ans.append(i)
    else:
        val.append(i)
ans.sort()
if len(ans) == 0:
    print(0)
else:
    if ans.count(ans[-1]) >= 4:
        print(ans[-1]**2)
    elif ans.count(ans[-1]) == 3:
        print(ans[-1]*ans[-4])
    elif ans.count(ans[-1]) == 2:
        print(ans[-1]*ans[-3])
    else:
        print(ans[-1]*ans[-2])
    


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
val = set()
ans = []

for i in a:
    if i in val:
        ans.append(i)
    else:
        val.add(i)
ans.sort()
if len(ans) == 0:
    print(0)
else:
    if ans.count(ans[-1]) >= 4:
        print(ans[-1]**2)
    elif ans.count(ans[-1]) == 3:
        print(ans[-1]*ans[-4])
    elif ans.count(ans[-1]) == 2:
        print(ans[-1]*ans[-3])
    else:
        print(ans[-1]*ans[-2])
Buggy python submission (verdict: Runtime Error):
import sys
N, M = map(int, input().split())
route = [[] for i in range(M)]
for _ in range(M):
    a, b = map(int, input().split())
    route[a-1].append(b)
    
for i in route[0]:
    if len(route) != 1:
        for j in route[i-1]:
            if j == N:
                print('POSSIBLE')
                sys.exit()
    else:
        if i == N:
            print('POSSIBLE')
            sys.exit()
                
print('IMPOSSIBLE')


Fixed submission:
import sys
N, M = map(int, input().split())
route = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    route[a-1].append(b)
    
for i in route[0]:
    if len(route) != 1:
        for j in route[i-1]:
            if j == N:
                print('POSSIBLE')
                sys.exit()
    else:
        if i == N:
            print('POSSIBLE')
            sys.exit()
                
print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a = [x for x in input().split()]
b = []
for i in range(n):
    b.append(a[i])
    b.reverse()
    
print(*b, sep=' ')


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

if n % 2 == 1:
    for i in reversed(range(1, n+1, 2)):
        b.append(a[i-1])
    for i in range(2, n, 2):
        b.append(a[i-1])
else:
    for i in reversed(range(2, n+1, 2)):
        b.append(a[i-1])
    for i in range(1, n, 2):
        b.append(a[i-1])
    
print(*b, sep=' ')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    b.append(a[i])
    b.reverse()
print(*b)
    


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

if n % 2 == 1:
    for i in reversed(range(1, n+1, 2)):
        b.append(a[i-1])
    for i in range(2, n, 2):
        b.append(a[i-1])
else:
    for i in reversed(range(2, n+1, 2)):
        b.append(a[i-1])
    for i in range(1, n, 2):
        b.append(a[i-1])
    
print(*b, sep=' ')
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(input())
button = [0]*N

for i in range(N):
    button[i] = int(input())-1
course = []
count, now = 0, 0

while not now in course:
    course.append(now)
    now = button[now]
    count += 1
    if now == 1:
        print(count)
        sys.exit()
print(-1)


Fixed submission:
import sys

N = int(input())
button = [0]*N

for i in range(N):
    button[i] = int(input())-1
count, now = 0, 0

while count <= N:
    now = button[now]
    count += 1
    if now == 1:
        print(count)
        sys.exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N = int(input())
a, b = [], []

for i in range(N):
    c = int(input())
    if c % 10 == 0:
        a.append(c)
    else:
        b.append(c)
if len(b) == 0:
    print(0)
else:
    ans = sum(a)
    val = 0
    for i in range(1, len(b)+1):
        for j in combinations(b, i):
            val0 = sum(j)
            if val0 % 10 != 0:
                val = max(val0, val)
    if val == 0:
        print(0)
    else:
        print(val+ans)
    


Fixed submission:
from itertools import combinations

N = int(input())
a, b = [], []

for i in range(N):
    c = int(input())
    if c % 10 == 0:
        a.append(c)
    else:
        b.append(c)
if len(b) == 0:
    print(0)
else:
    ans = sum(a)
    val = 0
    for i in reversed(range(1, 1+len(b))):
        for j in combinations(b, i):
            val0 = sum(j)
            if val0 % 10 != 0:
                val = max(val0, val)
        if val != 0:
            break
    if val == 0:
        print(0)
    else:
        print(val+ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0

for i in range(1, n+1):
    if n%i == 0:
        num = n//i
        ans = max(len(str(num)), len(str(i)))
        if num <= i:
            break
print(ans)


Fixed submission:
n = int(input())
i, ans = 1, 0

while i**2 <= n:
    if n%i == 0:
        num = n//i
        ans = max(len(str(num)), len(str(i)))
    i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from numba import jit
n = int(input())
a = []

while n%2 == 0:
    a.append(2)
    n //= 2

f = 3
while f**2 <= n:
    while n%f == 0:
        a.append(f)
        n //= f
    f += 2
if n != 1:
    a.append(n)

def cal(a):
    ans, num = 0, len(a)
    diff = float('inf')
    for i in range(2**num):
        b = ['-']*num
        c0, c1 = 1, 1
        for j in range(num):
            if ((i>>j)&1):
                b[num-1-j] = '+'
        for k in range(num):
            if b[k] == '+':
                c0 *= a[k]
            else:
                c1 *= a[k]
        if abs(c0-c1) < diff:
            ans = max(len(str(c0)), len(str(c1)))
            diff = abs(c0-c1)
    return ans
print(cal(a))


Fixed submission:
n = int(input())
i, ans = 1, 0

while i**2 <= n:
    if n%i == 0:
        num = n//i
        ans = max(len(str(num)), len(str(i)))
    i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []

while n%2 == 0:
    a.append(2)
    n //= 2

f = 3
while f**2 <= n:
    while n%f == 0:
        a.append(f)
        n //= f
    f += 2
if n != 1:
    a.append(n)

ans, num = 0, len(a)
diff = float('inf')
for i in range(2**num):
    b = ['-']*num
    c0, c1 = 1, 1
    for j in range(num):
        if ((i>>j)&1):
            b[num-1-j] = '+'
    for k in range(num):
        if b[k] == '+':
            c0 *= a[k]
        else:
            c1 *= a[k]
    if abs(c0-c1) < diff:
        ans = max(len(str(c0)), len(str(c1)))
        diff = abs(c0-c1)
print(ans)


Fixed submission:
n = int(input())
i, ans = 1, 0

while i**2 <= n:
    if n%i == 0:
        num = n//i
        ans = max(len(str(num)), len(str(i)))
    i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())
num = len(s)
for i in range(num):
    a = 122-ord(s[i])+1
    if a <= k:
        k -= a
        s[i] = 'a'
if k > 0:
    s[-1] = chr(ord(s[-1])+k)
print(*s, sep='')
        


Fixed submission:
s = list(input())
k = int(input())
num = len(s)

for i in range(num):
    a = 122-ord(s[i])+1
    if a <= k and s[i] != 'a':
        k -= a
        s[i] = 'a'
if k > 0:
    s[-1] = chr(ord(s[-1])+k%26)
print(*s, sep='')
Buggy python submission (verdict: Time Limit Exceeded):
abcd = input().split(" ")
count = 0

for mizuki in range(int(abcd[0]), int(abcd[1]) + 1):
  if mizuki % int(abcd[2]) == 0:
    count += 1
  elif mizuki % int(abcd[3]) == 0:
    count += 1
    
print(int(abcd[1]) - int(abcd[0]) + 1 - count)
    

Fixed submission:
import fractions

a, b, c, d = map(int, input().split(" "))

def howmany(num, div1, div2):
  tsumugi = num // div1
  matsuri = num // div2
  kaori = num // (div1 * div2 //fractions.gcd(div1, div2))
  mizuki = num - tsumugi - matsuri + kaori
  return mizuki

A = howmany(a - 1, c, d)
B = howmany(b, c, d)

ans = B - A

print(ans)
Buggy python submission (verdict: Runtime Error):
variable = input().split(" ")
n = int(variable[0])
x = int(variable[1])
l = input().split(" ")
d = 0
i = 0

while d <= x:
  d += int(l[i])
  i += 1
  
print(i)

Fixed submission:
inp = input().split(" ")
n = int(inp[0])
x = int(inp[1])
l = input().split(" ")
d = 0
count = 1

for i in range(n):
  d += int(l[i])
  if d <= x:
    count += 1
  else:
    break
  
print(count)

Buggy python submission (verdict: Runtime Error):
variable = input().split(" ")
n = int(variable[0])
x = int(variable[1])
l = input().split(" ")
d = 0
i = 0

while d < x:
  d += int(l[i])
  i += 1
  
print(i)

Fixed submission:
inp = input().split(" ")
n = int(inp[0])
x = int(inp[1])
l = input().split(" ")
d = 0
count = 1

for i in range(n):
  d += int(l[i])
  if d <= x:
    count += 1
  else:
    break
  
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N, *A = map(int, open(0).read().split())

MOD = 1000000007

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += (A[i] % MOD) * (A[j] % MOD)
        ans %= MOD
print(ans)

Fixed submission:
from itertools import accumulate

MOD = 10 ** 9 + 7
N, *A = map(int, open(0).read().split())

B = list(accumulate(A)) # cumsum

ans = 0
for i in range(N-1):
    ans += A[i] * (B[-1] - B[i]) % MOD
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, *A = map(int, open(0).read().split())

MOD = 1000000007

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += A[i] * A[j] % MOD
        ans %= MOD
print(ans)

Fixed submission:
from itertools import accumulate

MOD = 10 ** 9 + 7
N, *A = map(int, open(0).read().split())

B = list(accumulate(A)) # cumsum

ans = 0
for i in range(N-1):
    ans += A[i] * (B[-1] - B[i]) % MOD
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, *A = map(int, open(0).read().split())

MOD = 10 ** 9 + 7

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += A[i] * A[j] % MOD
print(ans % MOD)

Fixed submission:
from itertools import accumulate

MOD = 10 ** 9 + 7
N, *A = map(int, open(0).read().split())

B = list(accumulate(A)) # cumsum

ans = 0
for i in range(N-1):
    ans += A[i] * (B[-1] - B[i]) % MOD
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, *A = map(int, open(0).read().split())

MOD = 10 ** 9 + 7

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += A[i] * A[j] % MOD
print(ans % MOD)

Fixed submission:
from itertools import accumulate

MOD = 10 ** 9 + 7
N, *A = map(int, open(0).read().split())

B = list(accumulate(A)) # cumsum

ans = 0
for i in range(N-1):
    ans += A[i] * (B[-1] - B[i]) % MOD
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator

prod = functools.partial(functools.reduce, operator.mul)

N,K,*A = map(int, open(0).read().split())

p = None
j = 0
for i in range(K, N+1):
    c = prod(A[j:i])
    if p:
        if p < c:
            print('Yes')
        else:
            print('No')
    p = c
    j += 1

Fixed submission:
N,K,*A = map(int, open(0).read().split())

for i,n in enumerate(range(K-1, N)):
    if i == 0:
        continue
    if A[n-K] < A[n]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
print(1000 - (int(input()) % 1000)) % 1000

Fixed submission:
N = int(input())

if N % 1000 == 0:
    print(0)
else:
    print(1000 - (N % 1000))