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


def validate(r):
    return int(r)


def main(args):
    r = validate(args[1])
    print(r**2)


if __name__ == '__main__':
    main(sys.argv)


Fixed submission:
import sys


def main():
    r = int(input())
    print(r**2)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys


def main(n: int, s: str):
    if n//2 != 0:
        print('No')

    if s[0:n/2] == s[n/2:]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    args = [input() for i in range(2)]
    main(int(args[0]), args[1])


Fixed submission:
import sys


def main(n: int, s: str):
    if n % 2 != 0:
        print('No')
        return

    p = int(n / 2)
    if s[:p] == s[p:]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    args = [input() for i in range(2)]
    main(int(args[0]), args[1])
Buggy python submission (verdict: Runtime Error):
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


@lru_cache()
def distance(p1, p2):
    return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))


def distances(arr):
    return [distance(arr[i], arr[i+1]) for i in range(len(arr)-1)]


def main(n: int, points: list):
    ret = []
    for x in permutations(points):
        ret.append(sum(distances(x)))

    print(mean(ret))


if __name__ == '__main__':
    a = []
    while True:
        l = input()
        if l:
            a.append(l)
        else:
            break

    args = '\n'.join(a)
    points = [s.split(' ') for s in a[1:]]

    main(
        int(a[0]),
        [(int(p[0]), int(p[1])) for p in points]
    )


Fixed submission:
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


@lru_cache()
def distance(p1, p2):
    return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))


def distances(arr):
    return [distance(arr[i], arr[i+1]) for i in range(len(arr)-1)]


def main(n: int, points: list):
    ret = []
    for x in permutations(points):
        ret.append(sum(distances(x)))

    print(mean(ret))


if __name__ == '__main__':
    n = int(input())
    a = [input() for i in range(n)]

    points = [s.split(' ') for s in a]

    main(
        n,
        [(int(p[0]), int(p[1])) for p in points]
    )

Buggy python submission (verdict: Runtime Error):
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


@lru_cache()
def distance(p1, p2):
    return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))


def distances(arr):
    return [distance(arr[i], arr[i+1]) for i in range(len(arr)-1)]


def main(n: int, points: list):
    ret = []
    for x in permutations(points):
        ret.append(mean(distances(x)))

    print(mean(ret))


if __name__ == '__main__':
    a = []
    while True:
        l = input()
        if l:
            a.append(l)
        else:
            break

    args = '\n'.join(a)
    points = [s.split(' ') for s in a[1:]]

    main(
        int(a[0]),
        [(int(p[0]), int(p[1])) for p in points]
    )


Fixed submission:
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


@lru_cache()
def distance(p1, p2):
    return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))


def distances(arr):
    return [distance(arr[i], arr[i+1]) for i in range(len(arr)-1)]


def main(n: int, points: list):
    ret = []
    for x in permutations(points):
        ret.append(sum(distances(x)))

    print(mean(ret))


if __name__ == '__main__':
    n = int(input())
    a = [input() for i in range(n)]

    points = [s.split(' ') for s in a]

    main(
        n,
        [(int(p[0]), int(p[1])) for p in points]
    )
Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
inputs = list(map(int, input().split()))

total = 1
flag = 0
for i in range(len(inputs)):
    total = total * inputs[i]

if total > 10 ** 18:
    print(-1)
else:
    print(total)

Fixed submission:
N = int(input())
inputs = list(map(int, input().split()))
#print(inputs)
total = 1
flag = 0
if 0 in inputs:
    print('0')
else:
    for i in range(len(inputs)):
        total = total * inputs[i]
        if total > 10 ** 18:
            print('-1')
            flag = 1
            break
    if flag == 0:
        print(total)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
purint(N * M)

Fixed submission:
N, M = map(int, input().split())
print(N * M)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import re

def check(list, word):
  isMatch = False
  for i in reversed(range(len(list))):
    #match =re.search(word+'*', list[i])
    if word == list[i]:
      isMatch = True    
      list.pop(i)

  return isMatch, list

def calc(list):
  count = 0
  while len(list) > 0:
    ret = check(list, min(list))
    if ret[0] == True:
      count += 1
    list = ret[1]

  return count

N = int(input())
A = sys.stdin.readlines()
#改行コード削除
A = [b.strip() for b in A]

#print(N)
#print(A)
#print(min(A))

#最小文字数の単語から調査
#正規表現として、同じ重複があったらカウントし、リストからその要素を削除
#何種類あるかをカウント
print(calc(A))
  


Fixed submission:
import sys
import re

N = int(input())
A = sys.stdin.readlines()
#改行コード削除
A = [b.strip() for b in A]


print(len(list(set(A))))

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

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

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

C = collections.Counter(A)
#print(C)

for i in range(N):
  #print(A.count(i+1))
  print(C[i+1])

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

#print(N)
#print(list_i)

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

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

C = collections.Counter(A)
#print(C)

for i in range(N):
  #print(A.count(i+1))
  print(C[i+1])

Buggy python submission (verdict: Runtime Error):
N = input()
a = input().split()
list_i = [int(b) for b in a]

#print(N)
#print(list_i)

for i in range(N):
  list_i.count(i+1)

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

C = collections.Counter(A)
#print(C)

for i in range(N):
  #print(A.count(i+1))
  print(C[i+1])

Buggy python submission (verdict: Runtime Error):
N = input()
a = input().split()
list_i = [int(b) for b in a]

print(N)
print(list_i)

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

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

C = collections.Counter(A)
#print(C)

for i in range(N):
  #print(A.count(i+1))
  print(C[i+1])
Buggy python submission (verdict: Time Limit Exceeded):
def calc_sub(arg, start):
  global n,k
  sub = 0
  for i in range(n):
    if i != 0:
      idx = start + i
      if idx < n:
        sub += arg[idx] - arg[idx-1]
      else:
        idx = idx - n
        if idx == 0:
          sub += arg[0] + (k - arg[n-1])
        else:
          sub += arg[idx] - arg[idx-1]
        
  return sub

def calc_sub_r(arg, start):
  global n,k
  sub = 0
  for i in reversed(range(0, n)):
    idx = start + i
    idx = idx - n if idx >= n else idx
    if idx == n-1:
      sub += (k - arg[idx]) + arg[0]
    else:
      sub += arg[idx+1] - arg[idx]
  return sub


k, n = map(int, input().split())
a = input().split()
l_si_i = [int(s) for s in a]
#print(l_si_i)

#aaa = calc_sub(l_si_i, 2)
#bbb = calc_sub_r(l_si_i, 2)
#print(aaa)
#print(bbb)


min = 10000000
for i in range(n):
  ret = calc_sub(l_si_i,i)
  if min > ret:
    min = ret
    
  ret = calc_sub_r(l_si_i, i)
  if min > ret:
    min = ret
#  l_si_i.append(l_si_i.pop(0))

print(min)


Fixed submission:
k, n = map(int, input().split())
a = input().split()
l_si_i = [int(s) for s in a]
#print(l_si_i)

num_list = []
for i in range(n):
  if i == 0:
    sub = l_si_i[0] + (k - l_si_i[n-1])
  else:
    sub = l_si_i[i] - l_si_i[i-1]
  
  num_list.append(sub)
  
#print(num_list)
#print(sum(num_list))

idx = num_list.index(max(num_list))
#print(idx)
num_list.pop(idx)
print(sum(num_list))

Buggy python submission (verdict: Time Limit Exceeded):
def calc_sub(arg, start):
  global n,k
  sub = 0
  for i in range(n):
    if i != 0:
      idx = start + i
      if idx < n:
        sub += arg[idx] - arg[idx-1]
      else:
        idx = idx - n
        if idx == 0:
          sub += arg[0] + (k - arg[n-1])
        else:
          sub += arg[idx] - arg[idx-1]
        
  return sub

def calc_sub_r(arg, start):
  global n,k
  sub = 0
  for i in reversed(range(0, n)):
    idx = start + i
    idx = idx - n if idx >= n else idx
    if idx == n-1:
      sub += (k - arg[idx]) + arg[0]
    else:
      sub += arg[idx+1] - arg[idx]
  return sub


k, n = map(int, input().split())
a = input().split()
l_si_i = [int(s) for s in a]
#print(l_si_i)

#aaa = calc_sub(l_si_i, 2)
#bbb = calc_sub_r(l_si_i, 2)
#print(aaa)
#print(bbb)


min = 10000000
for i in range(n):
  ret = calc_sub(l_si_i,i)
  if min > ret:
    min = ret
    
  ret = calc_sub_r(l_si_i, i)
  if min > ret:
    min = ret
    
  l_si_i.append(l_si_i.pop(0))

print(min)


Fixed submission:
k, n = map(int, input().split())
a = input().split()
l_si_i = [int(s) for s in a]
#print(l_si_i)

num_list = []
for i in range(n):
  if i == 0:
    sub = l_si_i[0] + (k - l_si_i[n-1])
  else:
    sub = l_si_i[i] - l_si_i[i-1]
  
  num_list.append(sub)
  
#print(num_list)
#print(sum(num_list))

idx = num_list.index(max(num_list))
#print(idx)
num_list.pop(idx)
print(sum(num_list))
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
wr = str(input())


r_num = wr.count("R")
i_counts = [r_num]
rw_count = r_num
wr_count = 0
for i in range(num):
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

  ans = min(i_counts)

print(ans)

Fixed submission:
num = int(input())
wr = str(input())

r_num = wr.count("R")
i_counts = [r_num]
rw_count = r_num
wr_count = 0
for i in range(num):
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

ans = min(i_counts)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
wr = str(input())

i_counts = []
r_num = wr.count("R")

if r_num == 0:
  ans = 0
else:

  for i in range(r_num):
    w_counts = 0
    r_counts = 0
    for j in range(num):
      if i > j and wr[j] == "W":
        w_counts += 1
      elif i < j and wr[j] == "R":
        r_counts += 1
    i_count = max(w_counts, r_counts)
    i_counts.append(i_count)

  ans = min(i_counts)

print(ans)

Fixed submission:
num = int(input())
wr = str(input())

r_num = wr.count("R")
i_counts = [r_num]
rw_count = r_num
wr_count = 0
for i in range(num):
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

ans = min(i_counts)

print(ans)

Buggy python submission (verdict: Runtime Error):
num = int(input())
wr = str(input())

i_counts = []
r_num = wr.count("R")

for i in range(r_num):
  w_counts = 0
  r_counts = 0
  for j in range(num):
    if i > j and wr[j] == "W":
      w_counts += 1
    elif i < j and wr[j] == "R":
      r_counts += 1
  i_count = max(w_counts, r_counts)
  i_counts.append(i_count)

ans = min(i_counts)
print(ans)

Fixed submission:
num = int(input())
wr = str(input())

r_num = wr.count("R")
i_counts = [r_num]
rw_count = r_num
wr_count = 0
for i in range(num):
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

ans = min(i_counts)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
wr = str(input())

wr_list = list(wr)
i_counts = []
for i in range(num):
  w_counts = 0
  r_counts = 0
  for j in range(num):
    if i > j and wr_list[j] == "W":
      w_counts += 1
    elif i < j and wr_list[j] == "R":
      r_counts += 1
  i_count = max(w_counts, r_counts)
  i_counts.append(i_count)

ans = min(i_counts)
print(ans)

Fixed submission:
num = int(input())
wr = str(input())

r_num = wr.count("R")
i_counts = [r_num]
rw_count = r_num
wr_count = 0
for i in range(num):
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

ans = min(i_counts)

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
n, u, v = map(int, input().split())
u-=1; v-=1;
a = []; b = [];
dist = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    dist[a].append(b)
    dist[b].append(a)

def bfs(u):
    d = [-1]*n
    stack = deque([u])
    d[u] = 0
    while len(stack)!=0:
        s = stack.popleft()
        for t in dist[s]:
            if d[t]==-1:
                d[t] = d[s]+1
                stack.append(t)
    return d

A = bfs(v)
T = bfs(u)
ans=0
for i in range(n):
    if A[i]>d[i]:
        ans = max(A[i]-1, ans)
print(ans)

Fixed submission:
from collections import deque
n, u, v = map(int, input().split())
u-=1; v-=1;
a = []; b = [];
dist = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    dist[a].append(b)
    dist[b].append(a)

def bfs(u):
    d = [-1]*n
    stack = deque([u])
    d[u] = 0
    while len(stack)!=0:
        s = stack.popleft()
        for t in dist[s]:
            if d[t]==-1:
                d[t] = d[s]+1
                stack.append(t)
    return d

A = bfs(v)
T = bfs(u)
ans=0
for i in range(n):
    if A[i]>T[i]:
        ans = max(A[i]-1, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(str(input()))
for i in range(n):
    if i+2 > len(s):
            break
    while s[i] == s[i+1]:
        s.pop(i+1)
        if i+2 > len(s):
            break
print(len(s))

Fixed submission:
n = int(input())
color = input()
old_color = color[0]
ans = 1
for i in range(1, n):
    if old_color != color[i]:
        ans += 1
        old_color = color[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = [j+1 for i in range(n) for j in range(n) if a[j] == (i+1)]

#for i in range(n)
print(*b)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
#b = [j+1 for i in range(n) for j in range(n) if a[j] == (i+1)]
c = [0]*n
for i in range(n):
    c[a[i]-1] = i+1

print(*c)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
dp = [[0]*(n+1) for i in range(n+1)]
for i in reversed(range(n)):
    for j in reversed(range(0, i, 1)):
        if s[i] == s[j]:
            dp[j][i] = dp[j+1][i+1] + 1
ans = 0
for i in reversed(range(n)):
    for j in reversed(range(0, i, 1)):
        ans = max(min(dp[j][i], i-j), ans)
print(ans)

Fixed submission:
n = int(input())
s = input()
dp = [[0]*(n+1) for i in range(n+1)]
for i in reversed(range(n)):
    for j in reversed(range(0, i, 1)):
        if s[i] == s[j]:
            dp[j][i] = dp[j+1][i+1] + 1
ans = 0
for i in reversed(range(n)):
    for j in reversed(range(0, i, 1)):
        ans = max(min(dp[j][i], i-j), ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
numlist = list(map(int, input().split()))
if 0 < numlist.count(0):
    print('0')
    quit()

total = 1
for i in numlist:
  total *= i

if 10 ** 18 < total:
  print('-1')
else:
  print(total) 

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
numlist = list(map(int, input().split()))
if 0 < numlist.count(0):
    print('0')
    quit()

total = 1
for i in numlist:
  total *= i
  if 10 ** 18 < total:
    print('-1')
    quit()

print(total)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
numlist = list(map(int, input().split()))
if 0 < numlist.count(0):
    print('0')
    quit()

total = 1
for i in numlist:
  total *= abs(i)

if 10 ** 18 < total:
  print('-1')
else:
  print(sign * total) 

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
numlist = list(map(int, input().split()))
if 0 < numlist.count(0):
    print('0')
    quit()

total = 1
for i in numlist:
  total *= i
  if 10 ** 18 < total:
    print('-1')
    quit()

print(total)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
numlist = list(map(int, input().split()))
if 0 < numlist.count(0):
    print('0')
    quit()

total = 1
for i in numlist:
  total *= abs(i)
  if 10 ** 18 < total:
    print('-1')
    quit()

print(sign * total) 

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
numlist = list(map(int, input().split()))
if 0 < numlist.count(0):
    print('0')
    quit()

total = 1
for i in numlist:
  total *= i
  if 10 ** 18 < total:
    print('-1')
    quit()

print(total)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(input())
ln = list(map(int, input().replace('W', '0 ').replace('E', '1 ').split()))

# 先頭だけ先に計算（do-while相当）
w_sum = 0                           # 西側で振り返る人
sum_min = e_sum = sum(ln) - ln[0]   # 東側で振り返る人

for i in range(1, n-1):
    #sum_min = min(sum_min, sum(ln[i+1:n]) + (i - sum(ln[0:i])))
    w_sum += 1 if ln[i-1] == 0 else 0
    e_sum -= ln[i]
    sum_min = min(sum_min, w_sum + e_sum)

# 末尾も個別に計算
else:
    w_sum += 1 if ln[n-1] == 0 else 0
    sum_min = min(sum_min, w_sum)

print(sum_min)


Fixed submission:
# -*- coding: utf-8 -*-
A, B = map(int, input().split())
print(max(A + B, A - B, A * B))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
n = int(input())
ln = list(map(int, input().replace('W', '0 ').replace('E', '1 ').split()))
sum_min = n - 1
for i in range(n):
    sum_min = min(sum_min, sum(ln[i+1:n]) + (i - sum(ln[0:i])))

print(sum_min)


Fixed submission:
# -*- coding: utf-8 -*-
n = int(input())
ln = list(map(int, input().replace('W', '0 ').replace('E', '1 ').split()))

# 先頭だけ先に計算（do-while相当）
w_sum = 0                           # 西側で振り返る人
sum_min = e_sum = sum(ln) - ln[0]   # 東側で振り返る人

for i in range(1, n-1):
    #sum_min = min(sum_min, sum(ln[i+1:n]) + (i - sum(ln[0:i])))
    w_sum += 1 if ln[i-1] == 0 else 0
    e_sum -= ln[i]
    sum_min = min(sum_min, w_sum + e_sum)

# 末尾も個別に計算
else:
    w_sum += 1 if ln[n-1] == 0 else 0
    sum_min = min(sum_min, w_sum)


print(sum_min)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
n = int(input())
ln = list(input())
sum_min = n - 1
for i in range(n):
    # E->Wに向く人数
    #ln[i+1:n].count('E')
    # W->Eに向く人数
    #ln[0:i].count('W')
    sum_min = min(sum_min, ln[i+1:n].count('E') + ln[0:i].count('W'))

print(sum_min)


Fixed submission:
# -*- coding: utf-8 -*-
n = int(input())
ln = list(map(int, input().replace('W', '0 ').replace('E', '1 ').split()))

# 先頭だけ先に計算（do-while相当）
w_sum = 0                           # 西側で振り返る人
sum_min = e_sum = sum(ln) - ln[0]   # 東側で振り返る人

for i in range(1, n-1):
    #sum_min = min(sum_min, sum(ln[i+1:n]) + (i - sum(ln[0:i])))
    w_sum += 1 if ln[i-1] == 0 else 0
    e_sum -= ln[i]
    sum_min = min(sum_min, w_sum + e_sum)

# 末尾も個別に計算
else:
    w_sum += 1 if ln[n-1] == 0 else 0
    sum_min = min(sum_min, w_sum)


print(sum_min)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
A = []
B = []

for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())

for i in range(N):
    offset = 0
    while offset + M <= N:
        pos = A[i][offset:].find(B[0])        
        if -1 == pos:
            break
        offset += pos
        for j in range(1,M):
            if 0 != A[i+j][offset:].find(B[j]):
                offset += 1
                break
        else:
            print('Yes')
            exit()
else:
    print('No')


Fixed submission:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
A = []
B = []

for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())

for i in range(N - M + 1):
    offset = 0
    while offset + M <= N:
        pos = A[i][offset:].find(B[0])        
        if -1 == pos:
            break
        offset += pos
        for j in range(1,M):
            if 0 != A[i+j][offset:].find(B[j]):
                offset += 1
                break
        else:
            print('Yes')
            exit()
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def forgive(num):
    for i in range(10):
        if ((num + i) % 10) in unforgiven:
            continue
        else:
            return num + i


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

price = [int(x) for x in str(N)]
purchase = 0
dig = 0
for num in reversed(price):
    purchase += forgive(num) * (10 ** dig)
    dig += 1

print(purchase)


Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
lst = list(map(int, input().split()))

if lst[0] == 5:
    if (lst[1] == 7 and lst[2] == 5) or (lst[1] == 5 and lst[2] == 7):
        print("YES")
        exit()

elif lst[0] == 7:
    if lst[1] == 5 and lst[2] == 5:
        print("YES")
        exit()

print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def L(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())

import re
def solver(N,A,Q,BC):

    for b,c in BC:
        #print(A,':',b,'->',c)
        bef = '[\s]*'+str(b)
        aft = ' '+str(c)
        #print("bef,aft=",bef,aft)
        A = re.sub(bef, aft, A)
        #A = A.replace(' '+str(b), ' '+str(c))
        #print(A)
        print(sum(map(int,A.split())))


def main():
    N = I()
    #A = LI()
    A = L()
    Q = I()
    BC = []*Q
    BC = [LI() for _ in range(Q)]

    #print("N,Q=",N,Q)
    #print("A=",A)
    #print("BC=",BC)

    solver(N,A,Q,BC)

if __name__ == '__main__':
    main()


Fixed submission:
import sys

def L(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())

import collections

def solver(N,A,Q,BC):
    T = sum(map(int,A))
    #print(T)

    Nums = collections.Counter(A)
    #print(Nums)
    for b,c in BC:
        diff = c - b

        T += Nums[b] * diff
        print(T)

        Nums[c] += Nums[b]
        Nums[b] = 0


def main():
    N = I()
    A = LI()
    Q = I()
    BC = []*Q
    BC = [LI() for _ in range(Q)]

    solver(N,A,Q,BC)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):

def main():
    A,V = map(int, input().split())
    B,W = map(int, input().split())
    T = int(input())
    #print(A,V,B,W,T)

    if( )

    if( (V-W)*T - abs(B - A) >= 0 ):
        return print('YES')
    else:
        return print('NO')


if __name__ == '__main__':
    main()


Fixed submission:

def main():
    A,V = map(int, input().split())
    B,W = map(int, input().split())
    T = int(input())
    #print(A,V,B,W,T)

    if( (V-W)*T - abs(B - A) >= 0 ):
        return print('YES')
    else:
        return print('NO')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):

def main():
    A,V = map(int, input().split())
    B,W = map(int, input().split())
    T = int(input())
    #print(A,V,B,W,T)

    if( )

    if( (V-W)*T - abs(B - A) >= 0 ):
        return print('YES')
    else:
        return print('NO')


if __name__ == '__main__':
    main()


Fixed submission:

def main():
    A,V = map(int, input().split())
    B,W = map(int, input().split())
    T = int(input())
    #print(A,V,B,W,T)

    if( (V-W)*T - abs(B - A) >= 0 ):
        return print('YES')
    else:
        return print('NO')


if __name__ == '__main__':
    main()