Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M = map(int, input().split())
    box = []
    for i in range(M):
        LR = [j for j in map(int, input().split())]
        box += LR

    # for i in range(M):
    #     L, R = map(int, input().split())
    #     box.append(L)
    #     box.append(R)

    # print(box)
    num = 0
    for j in range(1, N+1):
        plus = 1
        # print(j)
        if plus == 1:
            for i in range(0, len(box), 2):
                # print(box[i], box[i+1])
                if j < box[i] or box[i+1] < j:
                    plus = 0
                    break

            num += plus

    print(num)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, M = map(int, input().split())

    L = []
    R = []
    for i in range(M):
        l, r = map(int, input().split())
        L.append(l)
        R.append(r)

    Lout = max(L)
    Rout = min(R)
    ans = Rout - Lout+1
    if ans < 0:
        print(0)
    else:
        print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M = map(int, input().split())
    box = []
    for i in range(M):
        L, R = map(int, input().split())
        box.append(L)
        box.append(R)

    # print(box)
    num = 0
    for j in range(1, N+1):
        plus = 1
        # print(j)
        if plus == 1:
            for i in range(0, len(box), 2):
                # print(box[i], box[i+1])
                if j < box[i] or box[i+1] < j:
                    plus = 0
                    break

            num += plus

    print(num)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, M = map(int, input().split())

    L = []
    R = []
    for i in range(M):
        l, r = map(int, input().split())
        L.append(l)
        R.append(r)

    Lout = max(L)
    Rout = min(R)
    ans = Rout - Lout+1
    if ans < 0:
        print(0)
    else:
        print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M = map(int, input().split())
    box = []
    for i in range(M):
        L, R = map(int, input().split())
        box.append(L)
        box.append(R)

    # print(box)
    num = 0
    for j in range(1, N+1):
        plus = 1
        # print(j)
        for i in range(0, len(box), 2):
            # print(box[i], box[i+1])
            if j < box[i] or box[i+1] < j:
                plus = 0
                break

        num += plus

    print(num)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, M = map(int, input().split())

    L = []
    R = []
    for i in range(M):
        l, r = map(int, input().split())
        L.append(l)
        R.append(r)

    Lout = max(L)
    Rout = min(R)
    ans = Rout - Lout+1
    if ans < 0:
        print(0)
    else:
        print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    s = list(input())
    k = input()
    n = len(s)
    for i in range(n):
        if s[i] != "1":
            ans = s[i]
            break
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    s = list(input())
    k = int(input())
    n = len(s)
    for i in range(n):
        if s[i] != "1":
            ans = s[i]
            break
        if i == k-1:
            ans = s[i]
            break
        if i == n-1:
            ans = s[0]
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    d, g = map(int, input().split())
    pc = [list(map(int, input().split())) for _ in range(d)]

    n = len(pc)
    ans = float("inf")

    for i in range(2**n):
        point, cnt = 0, 0
        for j in range(n):
            if (i>>j) & 1:
                point += (j+1)*100*pc[j][0] + pc[j][1]
                cnt += pc[j][0]
        if point >= g:
            ans = min(ans, cnt)
        # print(cnt, point)
        else:
            for j in range(n+1, -1, -1):
                if (i >> j) & 1:
                    continue
                else:
                    for k in range(pc[j][0]):
                        if point >= g:
                            ans = min(ans, cnt)
                            break
                        point += (j+1)*100
                        cnt += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    d, g = map(int, input().split())
    pc = [list(map(int, input().split())) for _ in range(d)]

    n = len(pc)
    ans = float("inf")

    for i in range(2**n):
        point, cnt = 0, 0
        for j in range(n):
            if (i>>j) & 1:
                point += (j+1)*100*pc[j][0] + pc[j][1]
                cnt += pc[j][0]
        if point >= g:
            ans = min(ans, cnt)
        # print(cnt, point)
        else:
            for j in range(n-1, -1, -1):
                if (i >> j) & 1:
                    continue
                else:
                    for k in range(pc[j][0]):
                        if point >= g:
                            ans = min(ans, cnt)
                            break
                        point += (j+1)*100
                        cnt += 1
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def main():
    n = int(input())
    As = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        if factorization(As[i])[0][0] == 2:
            ans += factorization(As[i])[0][1]
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    As = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        temp = As[i]
        if temp % 2 == 0:
            cnt = 0
            while temp % 2 == 0:
                cnt += 1
                temp //= 2
            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def main():
    n = int(input())
    As = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        if factorization(As[i])[0][0] == 2:
            ans += factorization(As[i])[0][1]
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    As = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        temp = As[i]
        if temp % 2 == 0:
            cnt = 0
            while temp % 2 == 0:
                cnt += 1
                temp //= 2
            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    ss = list(input())

    ans = float("inf")
    for i in range(n):
        ans_temp = 0
        for j in range(n):
            if j < i and ss[j] == 'W':
                ans_temp += 1
            if j > i and ss[j] == 'E':
                ans_temp += 1
            if ans_temp >= ans:
                break
        ans = min(ans, ans_temp)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    ss = list(input())

    ans = float("inf")
    ans = [0] * n
    cum_sum_w = [0] * (n+1)
    cum_sum_e = [0] * (n+1)
    for i in range(n):
        if ss[i] == 'W':
            add = 1
        else:
            add = 0
        cum_sum_w[i+1] = cum_sum_w[i] + add
    for i in range(n):
        if ss[i] == 'E':
            add = 1
        else:
            add = 0
        cum_sum_e[i+1] = cum_sum_e[i] + add
    for i in range(n):
        ans[i] = cum_sum_w[i] + (cum_sum_e[n] - cum_sum_e[i+1])
    print(min(ans))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    a, b, k = map(int, input().split())

    line = list(range(a, b+1))
    n = len(line)
    for i in range(n):
        if i < k or n-k <= i:
            print(line[i])


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    a, b, k = map(int, input().split())
    s = set()

    for i in range(a, min(a+k, b+1)):
        s.add(i)

    for i in range(b, max(a-1, b-k), -1):
        s.add(i)

    s = sorted(s)

    for i in s:
        print(i)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    As = list(map(int, input().split()))

    As.append(0)
    for i in range(n):
        s = 0
        ans = 0
        for j in range(n+1):
            if j == i:
                continue
            ans += abs(As[j] - s)
            s = As[j]
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    As = [0] + list(map(int, input().split())) + [0]

    cumsum = [0] * (n+1)
    for i in range(1, n+2):
        cumsum[i-1] = abs(As[i] - As[i-1])
    cumsum_sum = sum(cumsum)
    for i in range(1, n+1):
        ans = cumsum_sum - cumsum[i-1] - cumsum[i] + abs(As[i+1] - As[i-1])
        print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    As = [int(input()) for _ in range(n)]

    move = []
    i = 0
    ans = 1
    while As[i] != 2:
        if As[i] not in move:
            move.append(As[i])
            ans += 1
            i = As[i]-1
        else:
            ans = -1
            break
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    As = [int(input()) for _ in range(n)]

    x = [0]*n
    i = 0
    ans = 0
    while x[i] == 0:
        ans += 1
        x[i] = 1
        i = As[i] - 1
        if i == 1:
            print(ans)
            exit()
    print(-1)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    As = [int(input()) for _ in range(n)]

    move = []
    i = 0
    ans = 1
    while As[i] != 2:
        if As[i] not in move:
            move.append(As[i])
            ans += 1
            i = As[i]-1
        else:
            ans = -1
            break
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    As = [int(input()) for _ in range(n)]

    x = [0]*n
    i = 0
    ans = 0
    while x[i] == 0:
        ans += 1
        x[i] = 1
        i = As[i] - 1
        if i == 1:
            print(ans)
            exit()
    print(-1)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    As = list(map(int, input().split()))
    nums = []
    rainbow = 0
    for A in As:
        num = A // 400
        if num < 8:
            if num not in nums:
                nums.append(num)
        else:
            rainbow += 1
    ans_max = len(nums)+rainbow
    ans_min = max(len(1, nums))
    print(ans_min, ans_max)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    As = list(map(int, input().split()))
    nums = []
    rainbow = 0
    for A in As:
        num = A // 400
        if num < 8:
            if num not in nums:
                nums.append(num)
        else:
            rainbow += 1
    ans_max = len(nums)+rainbow
    ans_min = max(1, len(nums))
    print(ans_min, ans_max)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    a, b = map(int, input().split())
    if a == b:
        ans = 'Draw'
    elif a == 1:
        ans = 'Alice'
    elif b == 1:
        ans = 'Bob'
    elif a > b:
        ans = 'Alice'
    elif b < a:
        ans = 'Bob'
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    a, b = map(int, input().split())
    if a == b:
        ans = 'Draw'
    elif a == 1:
        ans = 'Alice'
    elif b == 1:
        ans = 'Bob'
    elif a > b:
        ans = 'Alice'
    elif a < b:
        ans = 'Bob'
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    k, s = map(int, input().split())
    # print(k, s)
    ans = 0
    for z in range(k+1):
        if z <= s:
            for y in range(k+1):
                if z + y <= s:
                    for x in range(k+1):
                        if x + y + z == s:
                            ans += 1
                            break
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    k, s = map(int, input().split())
    # print(k, s)
    ans = 0
    for z in range(k+1):
        if z <= s:
            for y in range(k+1):
                x = s - z - y
                if 0 <= x and x <= s and x <= k:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    k, s = map(int, input().split())
    # print(k, s)
    ans = 0
    for z in range(k, -1, -1):
        for y in range(k, -1, -1):
            for x in range(k, -1, -1):
                if x + y + z == s:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    k, s = map(int, input().split())
    # print(k, s)
    ans = 0
    for z in range(k+1):
        if z <= s:
            for y in range(k+1):
                x = s - z - y
                if 0 <= x and x <= s and x <= k:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# 入力
s = input()

# 処理
leftLen :int = len(s) // 2 # 文字列の長さの半分
left :str = s[:leftLen] # sの左半分

# leftの回文チェック
leftLenHalf :int = leftLen // 2
isPalindromeLeft :bool = True
for i in range(0, leftLenHalf - 1):
	if left[i] != left[leftLenHalf - i]:
		isPalindromeLeft = False

# 全体の回文チェック
right :str = s[leftLen * -1:] # sの右半分
isPalindrome :bool = isPalindromeLeft and left == right

# 結果
result :str = "Yes" if isPalindrome else "No"

# 出力
print(result)


Fixed submission:
# 入力
s = input()

# 処理
leftLen = len(s) // 2 # 文字列の長さの半分
left = s[:leftLen] # sの左半分

# leftの回文チェック
leftLenHalf = leftLen // 2
isPalindromeLeft = True
for i in range(0, leftLenHalf):
	if left[i] != left[leftLen - i - 1]:
		isPalindromeLeft = False

# 全体の回文チェック
right = s[leftLen * -1:] # sの右半分
isPalindrome = isPalindromeLeft and left == right

# 結果
result = "Yes" if isPalindrome else "No"

# 出力
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()

from heapq import *

H, W = map(int, input().split())
m1 = lambda s: int(s)-1
sy, sx = map(m1, input().split())
fy, fx = map(m1, input().split())
G = [list(input()) for _ in range(H)]

Q = [(0, sx, sy)]
while Q:
	d, x, y = heappop(Q)
	if G[y][x] == '#': continue
	G[y][x] = '#'

	if (x, y) == (fx, fy):
		print(d)
		break

	for dx in range(-2, 3):
		for dy in range(-2, 3):
			nx = x + dx
			ny = y + dy
			if nx < 0 or ny < 0 or nx >= W or ny >= H or G[ny][nx] == '#': continue
			heappush(Q, (d + (0 if abs(dx) + abs(dy) == 1 else 1), nx, ny))
else:
	print(-1)


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

from heapq import *

H, W = map(int, input().split())
m1 = lambda s: int(s)-1
sy, sx = map(m1, input().split())
fy, fx = map(m1, input().split())
G = [list(input()) for _ in range(H)]
D = [[10 ** 18] * W for _ in range(H)]

D[sy][sx] = 0
Q = [(0, sx, sy)]
while Q:
	d, x, y = heappop(Q)
	if D[y][x] < d: continue

	if (x, y) == (fx, fy):
		print(d)
		break

	for dx in range(-2, 3):
		for dy in range(-2, 3):
			nx = x + dx
			ny = y + dy
			if nx < 0 or ny < 0 or nx >= W or ny >= H or G[ny][nx] == '#': continue
			nd = d + (0 if abs(dx) + abs(dy) == 1 else 1)
			if nd >= D[ny][nx]: continue
			D[ny][nx] = nd
			heappush(Q, (nd, nx, ny))
else:
	print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

K = int(input())
if K % 2 == 0:
	print(-1)
	sys.exit()

i = 1
v = 7 % K
while v != 0:
	i += 1
	v = (10 * v + 7) % K
print(i)


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

K = int(input())
i = 1
v = 7 % K
V = {v}
while v != 0:
	i += 1
	v = (10 * v + 7) % K
	if v in V:
		print(-1)
		break
	V.add(v)
else:
	print(i)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

N, K = map(int, input().split())
A = list(map(int, input().split()))

lo = 0
hi = max(A) + 1

def ceildiv(a, b):
	return (a + b - 1) // b

while lo < hi:
	tar = (lo + hi) // 2

	cuts = 0
	for v in A:
		x = ceildiv(v, tar)
		cuts += x - 1
		if cuts > K:
			lo = tar + 1
			break
	else:
		hi = tar

print(lo)


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

N, K = map(int, input().split())
A = list(map(int, input().split()))

lo = 1
hi = max(A) + 1

def ceildiv(a, b):
	return (a + b - 1) // b

while lo < hi:
	tar = (lo + hi) // 2

	cuts = 0
	for v in A:
		x = ceildiv(v, tar)
		cuts += x - 1
		if cuts > K:
			lo = tar + 1
			break
	else:
		hi = tar

print(lo)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

prev = 1
for i in range(K):
	prev *= A[i]

for i in range(K, N):
	next = prev // A[i-K] * A[i]
	print('Yes' if next > prev else 'No')
	prev = next


Fixed submission:
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(K, N):
	print('Yes' if A[i] > A[i-K] else 'No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = input()
ones = X.count('1')
Xd = int(X, 2)

from functools import lru_cache

@lru_cache(maxsize=None)
def f(i):
	if i == 0: return 0

	return 1 + f(i % popcount(i))

def popcount(x):
      b=0
      while(x > 0):
          x &= x - 1
          b+=1
      return b

for i in range(N):
	div = ones + 1 if X[i] == '0' else ones - 1
	print(1 + f((Xd ^ (1 << (N-i-1))) % div))


Fixed submission:
import sys
sys.setrecursionlimit(1<<30)

N = int(input())
X = input()
ones = X.count('1')

v1 = 0
v2 = 0
m1 = ones + 1
m2 = ones - 1
p1 = 1 % m1
p2 = 1

for i, v in enumerate(reversed(X)):
	if v == '1':
		v1 = (v1 + p1) % m1

		if m2 > 0:
			v2 = (v2 + p2) % m2

	p1 = p1 * 2 % m1
	if m2 > 0:
		p2 = p2 * 2 % m2

from functools import lru_cache

@lru_cache(maxsize=None)
def f(i):
	if i == 0: return 0

	return 1 + f(i % popcount(i))

def popcount(x):
      b=0
      while(x > 0):
          x &= x - 1
          b+=1
      return b


for i in range(N):
	div = ones + 1 if X[i] == '0' else ones - 1
	if div == 0:
		print(0)
	elif div == 1:
		print(1)
	else:

		if div == m1:
			x = (v1 + pow(2, N-i-1, m1)) % m1
		elif div == m2:
			x = (v2 - pow(2, N-i-1, m2)) % m2
		else:
			assert False

		#print(x, (int(X, 2) ^ (1 << (N-i-1))) % div, div)

		print(1 + f(x))
Buggy python submission (verdict: Runtime Error):
idx = 'ABC'
N, *hi = map(int, input().split())
lo = list(hi)

sets = [set() for _ in range(3)]
ans = []
for I in range(N):
	i, j = map(idx.index, input())
	if hi[i] == hi[j] == 0:
		print('No')
		raise SystemExit

	if hi[i] == 0:
		lo[i] = hi[i] = 1
		hi[j] -= 1
		ans.append(idx[i])
	elif hi[j] == 0:
		lo[j] = hi[j] = 1
		hi[i] -= 1
		ans.append(idx[j])
	else:
		ans.append('')
		sets[i].add(I)
		sets[j].add(I)
		for k in (i, j):
			if lo[k] == 0:
				lo[k] += 1
				hi[k] -= 1

				while True:
					J = sets[k].pop()
					if ans[J] != '': continue
					ans[J] = idx[k]
					break
			else:
				lo[k] -= 1
				hi[k] += 1

for i, s in enumerate(sets):
	for j in s:
		if ans[j] == '':
			ans[j] = idx[i]

print('Yes')
print('\n'.join(ans))


Fixed submission:
import sys
sys.setrecursionlimit(1<<30)

idx = 'ABC'
N, *vals = map(int, input().split())
evs = [tuple(map(idx.index, input())) for _ in range(N)]

def f(i, vals, path):
	if i == len(evs):
		print('Yes')
		print('\n'.join(path))
		raise SystemExit

	k, j = evs[i]
	for add, sub in ((k, j), (j, k)):
		if vals[sub] == 0: continue
		vals[add] += 1
		vals[sub] -= 1
		path.append(idx[add])

		f(i+1, vals, path)

		vals[add] -= 1
		vals[sub] += 1
		path.pop()

f(0, vals, [])

print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
AA=[0]*N
for i in range(N):
    AA[i]=A[i]%(10**9+7)

B=[0]*N
c=0

for i in range(N-1):
    for j in range(i+1,N):
      B[j]=(A[i]*AA[j])%(10**9+7)
      c=(c+B[j])%(10**9+7)
print(c)

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

c=0
for i in range(N):
    c=c+A[i]**2
    
print((sum(A)**2-c)//2%(10**9+7))

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

B=[0]*N
c=0

for i in range(N-1):
    for j in range(i+1,N):
      B[j]=(A[i]*AA[j])%(10**9+7)
      c=(c+B[j])%(10**9+7)
print(c)

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

c=0
for i in range(N):
    c=c+A[i]**2
    
print((sum(A)**2-c)//2%(10**9+7))

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

B=[0]*N
c=0

for i in range(N-1):
    for j in range(i+1,N):
      B[j]=(A[i]*A[j])%(10**9+7)
      c=(c+B[j])%(10**9+7)
print(c)

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

c=0
for i in range(N):
    c=c+A[i]**2
    
print((sum(A)**2-c)//2%(10**9+7))

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

B=[0]*N
c=0

for i in range(N-1):
    for j in range(i+1,N):
      B[j]=A[i]*A[j]
      c=(c+B[j])%(10**9+7)
print(c)

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

c=0
for i in range(N):
    c=c+A[i]**2
    
print((sum(A)**2-c)//2%(10**9+7))
Buggy python submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline
N=str(input())
NN=0
for i in range(len(N)):
    NN=NN+int(N[i])
  
if NN%9==0:print('Yes')
else:print('No')

Fixed submission:
N=str(input())
NN=0
for i in range(len(N)):
    NN=NN+int(N[i])
  
if NN%9==0:print('Yes')
else:print('No')
Buggy python submission (verdict: Runtime Error):
N,K=map(int, input().split())
A =list(map(int,input().split()))
MOD = 10 ** 9 + 7
A=sorted(A)
if N==K:
  ans0 = 1
  for a in A[0:N]:
    ans0 *= a
    ans0 %= MOD
  print(ans0)
  exit()
  
if K%2==1 and A[-1]<0:
  ans0 = 1
  for a in A[N-K:N]:
    ans0 *= a
    ans0 %= MOD
  print(ans0)
  exit()

ansA = 1
for a in A[0:K]:
  ansA *= a
  ansA %= MOD

A=sorted(A, reverse=True)
ansB = 1
for a in A[0:K]:
  ansB *= a
  ansB %= MOD

A=sorted(A, key=lambda x:abs(x), reverse=True)
ansC = 1
for a in A[0:K]:
  ansC *= a
  ansC %= MOD

ansD=1
for a in A[0:K-1]:
  ansD *= a
  ansD %= MOD
B=sorted(A[K-1:N])

if ansD>0:ansD *= B[-1]
elif ansD<0:ansD *=B[0]


if 0 in B :ansE=0
else: ansE=ansD
#print(ansA, ansB, ansC)
print(max(ansA, ansB, ansC, ansD, ansE)%MOD)


Fixed submission:
N=int(input())
l = [list(map(int, input().split())) for l in range(N-1)]
c=0
for i in range(N-1):c+=min(l[i])*(N+1-max(l[i]))
print(N*(N+1)*(N+2)//6-c)