Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque

H, W = map(int,input().split())
maze = list(list(input()) for i in range(H))



def bfs(maze,maze_s,sy,sx):
  maze_s[sy][sx] = 0
  queue = deque([[sy,sx]])
  while queue:
    y,x = queue.popleft()
    if maze[y][x] == "g":
      return maze_s[y][x]
    else:
      for j,k in [(0,1),(0,-1),(1,0),(-1,0)]:
        new_y,new_x = y+j, x+k
        if 0 <= new_y <= H-1 and 0 <= new_x <= W-1:
          if maze[new_y][new_x] != "#" and maze_s[new_y][new_x] == -1:
            maze_s[new_y][new_x] = maze_s[y][x] + 1
            queue.append([new_y,new_x])

maze_s = list([-1] * W for i in range(H))
count = 0
for row in maze:
  count += row.count(".")

maze[H-1][W-1] = "g"

ans = count - bfs(maze,maze_s,0,0) -1
print(ans)

Fixed submission:
from collections import deque

H, W = map(int,input().split())
maze = list(list(input()) for i in range(H))



def bfs(maze,maze_s,sy,sx):
  maze_s[sy][sx] = 0
  queue = deque([[sy,sx]])
  while queue:
    y,x = queue.popleft()
    if maze[y][x] == "g":
      return maze_s[y][x]
    else:
      for j,k in [(0,1),(0,-1),(1,0),(-1,0)]:
        new_y,new_x = y+j, x+k
        if 0 <= new_y <= H-1 and 0 <= new_x <= W-1:
          if maze[new_y][new_x] != "#" and maze_s[new_y][new_x] == -1:
            maze_s[new_y][new_x] = maze_s[y][x] + 1
            queue.append([new_y,new_x])
  else:
    print(-1)
    exit()

maze_s = list([-1] * W for i in range(H))
count = 0
for row in maze:
  count += row.count(".")

maze[H-1][W-1] = "g"

ans = count - bfs(maze,maze_s,0,0) -1
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
it = lambda: list(map(int, input().strip().split()))


def solve():
    N, X, M = it()
    value = defaultdict(int)
    history = defaultdict(int)
    cur = 0
    cnt = 0
    for i in range(N):
        if X in history:
            break
        value[X] = cur
        history[X] = i
        cnt += 1
        cur += X
        X = X * X % M
    period = i - history[X]
    cur += (N - cnt) // period * (cur - value[X])
    for i in range((N - cnt) % period):
        cur += X
        X = X * X % M
    return cur

if __name__ == '__main__':
    print(solve())

Fixed submission:
from collections import defaultdict
it = lambda: list(map(int, input().strip().split()))


def solve():
    N, X, M = it()
    if N == 1:
        return X % M
    value = defaultdict(int)
    history = defaultdict(int)
    cur = 0
    cnt = 0
    for i in range(N):
        if X in history:
            break
        value[X] = cur
        history[X] = i
        cnt += 1
        cur += X
        X = X * X % M
    period = i - history[X]
    cur += (N - cnt) // period * (cur - value[X])
    for i in range((N - cnt) % period):
        cur += X
        X = X * X % M
    return cur

if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Runtime Error):
q = input().strip().split()
N, X, T = int(q[0]), int(q[1]), int(q[2])
ans = ((N + x) // x - 1) * T
print(ans)

Fixed submission:
q = input().strip().split()
N, X, T = int(q[0]), int(q[1]), int(q[2])
ans = (N + X - 1) // X * T
print(ans)
Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7
it = lambda: list(map(int, input().strip().split()))

def solve():
    N, K = it()
    A = it()
    
    neg = []
    pos = []
    for i in range(N):
        if A[i] < 0:
            neg.append(A[i])
        elif A[i] > 0:
            pos.append(A[i])
    
    if not neg and not pos:
        return 0
    
    pos.sort()
    neg.sort(reverse=True)

    if not pos and K % 2 == 1:
        ans = 1
        for i in range(K):
            ans = ans * neg[i] % MOD
        return ans

    ans = 1
    i = 0
    j = 0
    for _ in range(K >> 1):
        if len(pos) >= 2 and len(neg) >= 2:
            if neg[-1] * neg[-2] >= pos[-1] * pos[-2]:
                ans = ans * neg.pop() % MOD * neg.pop() % MOD
            else:
                ans = ans * pos.pop() % MOD * pos.pop() % MOD
        elif len(pos) >= 2:
            ans = ans * pos.pop() % MOD * pos.pop() % MOD
        elif len(neg) >= 2:
            ans = ans * neg.pop() % MOD * neg.pop() % MOD
    
    if K % 2 == 1:
        if pos:
            ans = ans * pos.pop() % MOD
        else:
            ans = ans * neg.pop() % MOD
    return ans


if __name__ == '__main__':
    print(solve())

Fixed submission:
MOD = 10 ** 9 + 7
it = lambda: list(map(int, input().strip().split()))

def solve():
    N, K = it()
    A = it()
    
    zero = 0
    neg = []
    pos = []
    for i in range(N):
        if A[i] < 0:
            neg.append(A[i])
        elif A[i] > 0:
            pos.append(A[i])
        else:
            zero += 1
    
    if not neg and not pos:
        return 0
    
    pos.sort()
    neg.sort(reverse=True)

    if not pos and K % 2 == 1:
        if zero > 0:
            return 0

        ans = 1
        for i in range(K):
            ans = ans * neg[i] % MOD
        return ans

    ans = 1
    for _ in range(K >> 1):
        if len(pos) >= 2 and len(neg) >= 2:
            if neg[-1] * neg[-2] >= pos[-1] * pos[-2]:
                ans = ans * neg.pop() % MOD * neg.pop() % MOD
            else:
                ans = ans * pos.pop() % MOD * pos.pop() % MOD
        elif len(pos) >= 2:
            ans = ans * pos.pop() % MOD * pos.pop() % MOD
        elif len(neg) >= 2:
            ans = ans * neg.pop() % MOD * neg.pop() % MOD
        elif len(pos) == 1 and len(neg) == 1:
            ans = ans * pos.pop() % MOD * neg.pop() % MOD
        else:
            return 0
    
    if K % 2 == 1:
        if pos:
            ans = ans * pos.pop() % MOD
        elif neg:
            ans = ans * neg.pop() % MOD
        else:
            return 0
    if zero > 1 and ans < 0:
        return 0
    return ans


if __name__ == '__main__':
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from functools import lru_cache
itl = lambda: list(map(int, input().strip().split()))


def solve():
    N = int(input())
    nums = itl()
    S = input().strip()
    @lru_cache(None)
    def dp(i, target):
        if i == N:
            return (target == 0)
        if S[i] == '0':
            return dp(i + 1, target ^ nums[i]) or dp(i + 1, target)
        else:
            return dp(i + 1, target ^ nums[i]) and dp(i + 1, target)
    return 0 if dp(0, 0) else 1


T = int(input())
for _ in range(T):
    print(solve())

Fixed submission:
from collections import defaultdict
itl = lambda: list(map(int, input().strip().split()))


def solve():
    N = int(input())
    nums = itl()
    S = input().strip()

    basis = []
    for i in range(N - 1, -1, -1):
        v = nums[i]
        for b in basis:
            v = min(v, v ^ b)
        if v:
            if S[i] == '1':
                return 1
            basis.append(v)
    return 0    


T = int(input())
for _ in range(T):
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict
from functools import lru_cache
itl = lambda: list(map(int, input().strip().split()))


def solve():
    N = int(input())
    nums = itl()
    S = input().strip()
    @lru_cache(None)
    def dp(i, target):
        if i == N:
            return (target == 0)
        if S[i] == '0':
            return dp(i + 1, target ^ nums[i]) or dp(i + 1, target)
        else:
            return dp(i + 1, target ^ nums[i]) and dp(i + 1, target)
    return 0 if dp(0, 0) else 1


T = int(input())
for _ in range(T):
    print(solve())

Fixed submission:
from collections import defaultdict
itl = lambda: list(map(int, input().strip().split()))


def solve():
    N = int(input())
    nums = itl()
    S = input().strip()

    basis = []
    for i in range(N - 1, -1, -1):
        v = nums[i]
        for b in basis:
            v = min(v, v ^ b)
        if v:
            if S[i] == '1':
                return 1
            basis.append(v)
    return 0    


T = int(input())
for _ in range(T):
    print(solve())
Buggy python submission (verdict: Runtime Error):
A, B, H, M = map(int,input().split())

theta_M = M*6
theta_H = H*30 + M*0.5

theta = abs(theta_M - theta_H)
if theta > 180:
  theta = 360 - theta
  
import math
x = A**2 + B**2 - 2 * 3 * 4 * math.cos(math.radians(theta))
x = math.sqrt(x)
print(x)

Fixed submission:
A, B, H, M = map(int,input().split())

theta_M = M*6
theta_H = H*30 + M*0.5

theta = abs(theta_M - theta_H)
if theta > 180:
  theta = 360 - theta
  
import math
x = A**2 + B**2 - 2 * A * B * math.cos(math.radians(theta))
x = math.sqrt(x)
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())


from collections import defaultdict
import queue
connection = defaultdict(lambda: defaultdict(int))

for i in range(M):
  A, B = map(int, input().split())
  connection[A-1][B-1] = 1
  connection[B-1][A-1] = 1

c = defaultdict(int)
q = queue.Queue()
d = defaultdict(int)
p = defaultdict(int)

c[0] = 1
d[0] = 0
q.put(0)

while not(q.empty()):
  u = q.get()
  for v in range(N):
    if connection[u][v] == 1 and c[v] == 0:
      c[v] = 1
      d[v] = d[u] + 1
      p[v] = u
      q.put(v)
  c[u] = 2
print("Yes")
for i in range(1,N):
  print(p[i] + 1)

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


from collections import defaultdict
import queue
connection = defaultdict(lambda: defaultdict(int))

for i in range(M):
  A, B = map(int, input().split())
  connection[A-1][B-1] = 1
  connection[B-1][A-1] = 1

c = defaultdict(int)
q = queue.Queue()
d = defaultdict(int)
p = defaultdict(int)

c[0] = 1
d[0] = 0
q.put(0)

while not(q.empty()):
  u = q.get()
  for v in connection[u]:
    if c[v] == 0:
      c[v] = 1
      d[v] = d[u] + 1
      p[v] = u
      q.put(v)
  c[u] = 2
print("Yes")
for i in range(1,N):
  print(p[i] + 1)

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


from collections import defaultdict
display_num = defaultdict(int)
move_num = defaultdict(int)
connection = defaultdict(lambda: defaultdict(int))
def_room = defaultdict(int)

for i in range(M):
  A, B = map(int, input().split())
  connection[A-1][B-1] = 1
  connection[B-1][A-1] = 1

c = defaultdict(int)
d = defaultdict(lambda: 10**10)
p = defaultdict(lambda: -1)
d[0] = 0
p[0] = -1

while True:
  mincost = 10**10
  for i in range(N):
    if c[i] != 2 and d[i] < mincost:
      mincost = d[i]
      u = i
  if mincost == 10**10:
    break
  c[u] = 2
  for v in range(N):
    if c[v] != 2 and connection[u][v] == 1:
      if d[u] + 1 < d[v]:
        d[v] = d[u] + 1
        p[v] = u
        c[v] = 1
print("Yes")
for i in range(1,N):
  print(p[i] + 1)


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


from collections import defaultdict
import queue
connection = defaultdict(lambda: defaultdict(int))

for i in range(M):
  A, B = map(int, input().split())
  connection[A-1][B-1] = 1
  connection[B-1][A-1] = 1

c = defaultdict(int)
q = queue.Queue()
d = defaultdict(int)
p = defaultdict(int)

c[0] = 1
d[0] = 0
q.put(0)

while not(q.empty()):
  u = q.get()
  for v in connection[u]:
    if c[v] == 0:
      c[v] = 1
      d[v] = d[u] + 1
      p[v] = u
      q.put(v)
  c[u] = 2
print("Yes")
for i in range(1,N):
  print(p[i] + 1)
Buggy python submission (verdict: Runtime Error):
S = input()
if S = 'ABC':
  print('ARC')
else:
  print('ABC')

Fixed submission:
S = input()
if S == 'ABC':
  print('ARC')
else:
  print('ABC')
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
H = list(map(int,input().split()))
Good = list()
Bad = list()

for i in range(M):
  A,B = map(int,input().split())
  A -= 1
  B -= 1
  if H[A] > H[B]:
    Bad.append(B)
  elif H[A] < H[B]:
    Bad.append(A)
  else:
    Bad.append(A)
    Bad.append(B)
  Bad = list(set(Bad))
print(N-len(Bad))

Fixed submission:
N,M = map(int,input().split())
H = list(map(int,input().split()))
Bad = dict()

for i in range(M):
  A,B = map(int,input().split())
  A -= 1
  B -= 1
  if H[A] > H[B]:
    Bad[B] = 1
  elif H[A] < H[B]:
    Bad[A] = 1
  else:
    Bad[A] = 1
    Bad[B] = 1
print(N-len(Bad))
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
A = 0
B = 0

while True:
  ans = A**5-B**5
  if ans == X:
    break
  elif ans < X:
    B -= 1
  elif ans > X:
    B += 1
    A += 1
print("{} {}".format(A,B))

Fixed submission:
X = int(input())
A = 0
B = int(-X**(1/5))

while True:
  ans = A**5-B**5
  if ans == X:
    break
  elif ans < X:
    A += 1
  elif ans > X:
    B += 1
print("{} {}".format(A,B))
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
A = list(map(int,input().split()))
I = list()
J = list()
ans = 0

for i in range(N):
  I.append(A[i]+i)
  J.append(i-A[i])
for i in I:
  ans += J.count(i)
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
I = defaultdict(int)
J = defaultdict(int)
ans = 0

for i in range(N):
  I[A[i]+i] += 1
  J[i-A[i]] += 1
for i,j in I.items():
  ans += J[i]*j
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
A = list(map(int,input().split()))
B = copy.deepcopy(A)
ans = 0

for i in range(N-1):
  first = A[i]
  count = first-1
  for j in range(min(N,i+first),N):
    count += 1
    final = A[j]
    if first + final == count:
      ans += 1
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
I = defaultdict(int)
J = defaultdict(int)
ans = 0

for i in range(N):
  I[A[i]+i] += 1
  J[i-A[i]] += 1
for i,j in I.items():
  ans += J[i]*j
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
A = list(map(int,input().split()))
B = copy.deepcopy(A)
ans = 0

for i in range(N-1):
  first = A[i]
  count = first-1
  for j in range(min(N,i+first),N):
    count += 1
    final = A[j]
    if first + final == count:
      ans += 1
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
I = defaultdict(int)
J = defaultdict(int)
ans = 0

for i in range(N):
  I[A[i]+i] += 1
  J[i-A[i]] += 1
for i,j in I.items():
  ans += J[i]*j
    
print(ans)

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

for i in range(N-1):
  for j in range(i+1,N):
    if A[i]+A[j] == abs(i-j):
      ans += 1
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
I = defaultdict(int)
J = defaultdict(int)
ans = 0

for i in range(N):
  I[A[i]+i] += 1
  J[i-A[i]] += 1
for i,j in I.items():
  ans += J[i]*j
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

for i in range(1,N+1):
  print(A.count(i))

Fixed submission:
N = int(input())

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

import collections
c = collections.Counter(A)

for i in range(1,N+1):
  print(c[i])
Buggy python submission (verdict: Runtime Error):
N, K, C = map(int,input().split())
S = list(input())

A = list()
B = list()

i = 0
num = 0
while num < K:
  if S[i] == "o":
    A.append(i)
    num += 1
    i += 3
  i += 1
i = len(S)-1
num = 0
while num < K:
  if S[i] == "o":
    B.append(i)
    num+=1
    i -= 3
  i -= 1
B.sort()

for i,j in zip(A,B):
  if i == j:
    print(i+1)

Fixed submission:
N, K, C = map(int,input().split())
S = list(input())

A = list()
B = list()

i = 0
num = 0
while num < K:
  if S[i] == "o":
    A.append(i)
    num += 1
    i += C
  i += 1
i = len(S)-1
num = 0
while num < K:
  if S[i] == "o":
    B.append(i)
    num+=1
    i -= C
  i -= 1
B.sort()

for i,j in zip(A,B):
  if i == j:
    print(i+1)
Buggy python submission (verdict: Runtime Error):
S,T = input.split()
print(T+S)

Fixed submission:
S,T = input().split()
print("{}{}".format(T,S))
Buggy python submission (verdict: Runtime Error):
import math

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

sa = A1 * T1
sb = B1 * T1
fa = sa + ea
fb = sb + eb

if fa < fb:
  if sa < sb:
    print(0)
  elif sa == sb:
    print(1)
  elif sa > sb:
    d1 = sa - sb
    di = fb - fa
    c = int(d1 / di) * 2 + 1
    print(c)
elif fa == fb:
  print("infinity")
elif fa > fb:
  if sa < sb:
    d1 = sb - sa
    di = fa - fb
    c = int(d1 / di) * 2 + 1
    print(c)
  elif sa == sb:
    print(1)
  elif sa > sb:
    print(0)

Fixed submission:
import math

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

sa = A1 * T1
sb = B1 * T1
ea = A2 * T2
eb = B2 * T2
fa = sa + ea
fb = sb + eb

if fa < fb:
  if sa < sb:
    print(0)
  elif sa == sb:
    print(1)
  elif sa > sb:
    d1 = sa - sb
    di = fb - fa
    c = int(d1 / di) + math.ceil(d1 / di)#  + 1
    print(c)
elif fa == fb:
  print("infinity")
elif fa > fb:
  if sa < sb:
    d1 = sb - sa
    di = fa - fb
    c = int(d1 / di) + math.ceil(d1 / di)# + 1
    print(c)
  elif sa == sb:
    print(1)
  elif sa > sb:
    print(0)
Buggy python submission (verdict: Runtime Error):
a = input()
s = input()
if a < 3200:
  print("red")
else:
  print(s)

Fixed submission:
a = int(input())
s = input()

if a < 3200:
  print("red")
else:
  print(s)
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = input().split()

v = map(lambda x: int(x), v)
for i in range(n-1):
  v.sort()
  v.append((v.pop()+v.pop())/2)
print(v[0])

Fixed submission:
n = int(input())
v = input().split()

v = list(map(lambda x: int(x), v))
for i in range(n-1):
  v.sort()
  v.append((v.pop(0)+v.pop(0))/2)
print(v[0])
Buggy python submission (verdict: Runtime Error):
n, x = input().strip().split()
n = int(n)
x = int(x)
l = input().strip().split()
now = 0
for i in range(n):
  now += l[i]
  if now > x:
    print(i)


Fixed submission:
n, x = input().strip().split()
n = int(n)
x = int(x)
l = input().strip().split()
l = list(map(int, l))
now = 0
for i in range(n):
  now += l[i]
  if now > x:
    print(i+1)
    exit()
print(n+1)

Buggy python submission (verdict: Runtime Error):
n, x = input().strip().split()
n = int(n)
x = int(x)
l = input().strip().split()
now = 0
for i in range(n):
  now += l[i]
  if now > x:
    print(i)
    exit()

Fixed submission:
n, x = input().strip().split()
n = int(n)
x = int(x)
l = input().strip().split()
l = list(map(int, l))
now = 0
for i in range(n):
  now += l[i]
  if now > x:
    print(i+1)
    exit()
print(n+1)
Buggy python submission (verdict: Runtime Error):
def present(n):
  if n%2 == 0:
    return n/2
  else:
    return (n-1)/2

s = input()
a, b, k = s.split()

for i in range(int(k)):
  if i % 2 == 0:
    a = present(a)
    b = b + a
  else:
    b = present(b)
    a = a + b

print("{} {}".format(a,b))

Fixed submission:
def present(n):
  if n%2 == 0:
    return n/2
  else:
    return (n-1)/2

s = input()
a, b, k = s.split()
a = int(a)
b = int(b)
for i in range(int(k)):
  if i % 2 == 0:
    a = present(a)
    b = b + a
  else:
    b = present(b)
    a = a + b

print("{} {}".format(int(a),int(b)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(len(a)-1):
  s_tmp = sum(a[i+1:len(a)])
  s += a[i] * s_tmp
print(s % 1000000007)

Fixed submission:
n = int(input())
s = 0
a = list(map(int, input().split()))
sum_tmp = sum(a[1:len(a)])
for i in range(len(a)-1):
  s += a[i] * sum_tmp
  sum_tmp -= a[i + 1]
print(s % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(len(a)-1):
  s_tmp = sum(a[i+1:len(a)])
  s += a[i] * s_tmp
print(s % 1000000007)



Fixed submission:
n = int(input())
s = 0
a = list(map(int, input().split()))
sum_tmp = sum(a[1:len(a)])
for i in range(len(a)-1):
  s += a[i] * sum_tmp
  sum_tmp -= a[i + 1]
print(s % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(len(a)-1):
  s_tmp = 0
  for j in range(i + 1, len(a)):
    s_tmp += a[j]
  s += a[i] * s_tmp
print(s % 1000000007)

Fixed submission:
n = int(input())
s = 0
a = list(map(int, input().split()))
sum_tmp = sum(a[1:len(a)])
for i in range(len(a)-1):
  s += a[i] * sum_tmp
  sum_tmp -= a[i + 1]
print(s % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(len(a)-1):
  s_tmp = 0
  for j in range(i + 1, len(a)):
    s_tmp += a[j]
  s += a[i] * s_tmp
print(s % 1000000007)

Fixed submission:
n = int(input())
s = 0
a = list(map(int, input().split()))
sum_tmp = sum(a[1:len(a)])
for i in range(len(a)-1):
  s += a[i] * sum_tmp
  sum_tmp -= a[i + 1]
print(s % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(len(a)-1):
  for j in range(i + 1, len(a)):
    s += a[i]*a[j] % 1000000007
print(s % 1000000007)

Fixed submission:
n = int(input())
s = 0
a = list(map(int, input().split()))
sum_tmp = sum(a[1:len(a)])
for i in range(len(a)-1):
  s += a[i] * sum_tmp
  sum_tmp -= a[i + 1]
print(s % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(len(a)-1):
  for j in range(i + 1, len(a)):
    s += a[i]*a[j]
print(s % 1000000007)



Fixed submission:
n = int(input())
s = 0
a = list(map(int, input().split()))
sum_tmp = sum(a[1:len(a)])
for i in range(len(a)-1):
  s += a[i] * sum_tmp
  sum_tmp -= a[i + 1]
print(s % 1000000007)
Buggy python submission (verdict: Runtime Error):
X = input()
ans = 'Yes' if X >= 30 else 'No'
print(ans)

Fixed submission:
X = input()
ans = 'Yes' if int(X) >= 30 else 'No'
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, k = input().split()
a = input().split()
b = input().split()

n = int(n)
m = int(m)
k = int(k)
a = list(map(int, a))
b = list(map(int, b))

a.extend(b)
a.sort()

add = 0
cnt = 0
for item in a:
  if add > k:
    break
  add += item
  cnt += 1
print(cnt)


Fixed submission:
x = int(input())
print(int(x+x**2+x **3))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
cnt = 0
for i, p in enumerate(range(s)):
  if p != t[i]:
    cnt += 1
    
print(cnt)

Fixed submission:
s = input()
t = input()
cnt = 0
for i, p in enumerate(s):
  if p != t[i]:
    cnt += 1
    
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0

for a in range(1, n+1):
  for b in range(1, n+1):
    if a % b == 0:
      ans += a

print(ans)

Fixed submission:
n = int(input())

ans = 0

for b in range(1, n+1):
  y = n // b
  ans += y*(y+1)*b/2

print(int(ans))
Buggy python submission (verdict: Runtime Error):
a, b = int(input().split())

print(a*b)

Fixed submission:
a, b = map(int, input().split())
print(a*b)
Buggy python submission (verdict: Runtime Error):
n = int(input())

n = n[-1]

if n in [2, 4, 5, 7, 9]:
  ans = 'hon'
elif n in [0, 1, 6, 8]:
  ans = 'pon'
else:
  ans = 'bon'
print(ans)

Fixed submission:
n = input()
n = int(n[-1])

if n in [2, 4, 5, 7, 9]:
  ans = 'hon'
elif n in [0, 1, 6, 8]:
  ans = 'pon'
else:
  ans = 'bon'
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0
for A in range(1, n):
  for B in range(1, n):
    if A * B >= n:
      break
    ans += 1

print(ans)

Fixed submission:
import math

n = int(input())

ans = 0

for A in range(1, n):
  if n % A == 0:
    ans += n // A - 1
  else:
    ans += n // A

print(ans)