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

cities = []
ps = {}

def to_id(x):
  return '0' * (6 - len(str(x))) + str(x)

for i in range(m):
  p, y = map(int, input().split())
  cities.append([p, y])
  if p in ps.keys():
    ps[p].append(y)
  else:
    ps[p] = [y]
  
years = {}
for p in ps.keys():
  years[p] = sorted(ps[p])

for i in range(m):
  p = cities[i][0]
  y = years[p].index(cities[i][1]) + 1
  print(to_id(p) + to_id(y))

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

cities = []
ps = {}

def to_id(x):
  return '0' * (6 - len(str(x))) + str(x)

for i in range(m):
  p, y = map(int, input().split())
  cities.append([p, y, ''])
  if p in ps.keys():
    ps[p].append([y, i])
  else:
    ps[p] = [[y, i]]
  
years = {}
ids = {}
for p in ps.keys():
  years[p] = sorted(ps[p], key=lambda x: x[0])
  for i, year in enumerate(years[p]):
    cities[year[1]][2] += to_id(p) + to_id(i+1)

for i in range(m):
  print(cities[i][2])
Buggy python submission (verdict: Runtime Error):
n = int(input())
xy = [[i, j] for i in range(101) for j in range(101)]

def md(x1, x2):
  return abs(x1[0]-x2[0]) + abs(x1[1]-x2[1])
        
infos = []
for i in range(n):
  info = list(map(int, input().split()))
  infos.append(info)
  
  if infos[i][2] == 0:
    xy.remove(infos[i][0], infos[i][1])
  
  if i != 0:
    for j in range(i):
      if infos[j][0] != 0:
        dh = infos[i][2] - infos[j][2]
        xy = list(filter(lambda x: md(x, infos[j][:2]) - md(x, infos[i][:2]) == dh, xy))
      
  if len(xy) == 1:    
    break

    
x = xy[0][0]
y = xy[0][1]
k = 0
for i in range(n):
  if infos[i][2] > 0:
    k = i
    break
h = md(infos[k][:2], [x, y]) + infos[k][2]
print('{} {} {}'.format(x, y, h))


Fixed submission:
if input()=='1':
  print('Hello World')
else:
  print(int(input())+int(input()))

Buggy python submission (verdict: Runtime Error):
n = int(input())
xy = [[i, j] for i in range(101) for j in range(101)]

def md(x1, x2):
  return abs(x1[0]-x2[0]) + abs(x1[1]-x2[1])
        
infos = []
for i in range(n):
  info = list(map(int, input().split()))
  infos.append(info)
  
  if i != 0:
    for j in range(i):
      if infos[j][0] != 0:
        dh = infos[i][2] - infos[j][2]
        xy = list(filter(lambda x: md(x, infos[j][:2]) - md(x, infos[i][:2]) == dh, xy))
      
  if len(xy) == 1:    
    break

    
x = xy[0][0]
y = xy[0][1]
k = 0
for i in range(n):
  if infos[i][2] > 0:
    k = i
    break
h = md(infos[k][:2], [x, y]) + infos[k][2]
print('{} {} {}'.format(x, y, h))

Fixed submission:
if input()=='1':
  print('Hello World')
else:
  print(int(input())+int(input()))
Buggy python submission (verdict: Runtime Error):
# 求める出力は，mの約数iのうち n*i <= m を満たす最大の整数n．

N, M = map(int, input().split())
fracs = []
i = 2
m = M
# mの素因数分解を求める
while m > 1 and M**0.5:
  while m % i == 0:
    m //= i
    if len(fracs)==0:
      fracs.append([i, 1])
    elif fracs[-1][0] == i:
      fracs[-1][1] += 1
    else:
      fracs.append([i, 1])    
  i += 1

if m != 1:
  fracs.append(m, 1)

# 約数を全て列挙する
divisors = []
def search(i, p):
  for j in range(fracs[i][1]+1):
    if i != len(fracs)-1:
      new_p = p * fracs[i][0] ** j
      search(i+1, new_p)
    else:
      divisors.append(p * fracs[i][0] ** j)
search(0, 1)

print(sorted(list(filter(lambda x: x*N <= M, divisors)))[-1])

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

ans = 1
for i in range(1, int(m**0.5)+2):
  if m % i == 0:
    if i * n <= m:
      ans = max(ans, i)
    if (m // i) * n <= m:
      ans = max(ans, m//i)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, x, y = map(int, input().split())
x_max = max(list(map(int, input().split())))
y_min = min(list(map(int, input().split())))

if x_max < y and x_max < y_min:
  print('No War')
else:
  print('War)

Fixed submission:
n, m, x, y = map(int, input().split())
x_max = max(list(map(int, input().split()))+[x])
y_min = min(list(map(int, input().split()))+[y])

if x_max < y_min:
  print('No War')
else:
  print('War')
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = 0
for i in range(n):
  d = x[i+k-1] - x[i] + min(abs(x[i]), abs(x[i+k-1]))
  ans = min(ans, d)
  
print(ans)

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

ans = 10**9
for i in range(n-k+1):
  d = x[i+k-1] - x[i] + min(abs(x[i]), abs(x[i+k-1]))
  ans = min(ans, d)
  
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(map(int, input().split()))

if k == 1:
  print(min(list(map(abs, x))))
  
else:

  if 0 in x:
    k -= 1
  ans = 10**9

  x_p = list(filter(lambda x: x > 0, x))
  x_n = list(filter(lambda x: x < 0, x))

  if len(x_p) >= k and k != 0:
    ans = min(ans, x_p[k-1])
  if len(x_n) >= k and k != 0:
    ans = min(ans, -x_n[-k])
  
  for i in range(n):
    if x[i] < 0 and x[i+k-1] > 0:
      d = x[i+k-1] - x[i] + min(-x[i], x[i+k-1])
      ans = min(ans, d)
    
  print(ans)

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

ans = 10**9
for i in range(n-k+1):
  d = x[i+k-1] - x[i] + min(abs(x[i]), abs(x[i+k-1]))
  ans = min(ans, d)
  
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

for i in map(int, s[:k]):
  if i != 1:
    print(i)
    break
else:
  print(1)


Fixed submission:
a, b = map(int, input().split())
print((a - 1) * (b - 1))
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
infinity = 5 * (10 ** 15) - 1

import math

i = 0
while k > 0:
  
  k -= math.floor(infinity * math.log(int(s[i]), 10)) + 1
  i += 1
  
print(s[i-1])


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

for i in map(int, s[:k]):
  if i != 1:
    print(i)
    break
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
infinity = 5 * (10 ** 15) - 1

import math

i = 0
while k > 0:
  print(s[i])
  k -= math.floor(infinity * math.log(int(s[i]), 10)) + 1
  i += 1
  print(k)
  
print(s[i-1])


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

for i in map(int, s[:k]):
  if i != 1:
    print(i)
    break
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
infinity = 5 * (10 ** 11) - 1

import math

i = 0
while k > 0:
  k -= math.floor(infinity * math.log(int(s[i]), 10)) + 1
  i += 1
  
print(s[i-1])

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

for i in map(int, s[:k]):
  if i != 1:
    print(i)
    break
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input())
if n % k == 0:
  print(0)
else:
  print(1)

Fixed submission:
n, k = map(int, input().split())
if n % k == 0:
  print(0)
else:
  print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(lambda x: x % m, map(int, input().split())))

s = 0
l = []
for i in range(n):
  if a[i] == 0:
    s += 1
  l.append(a[i])
  
for i in range(n):
  for j in range(i+1, n):
    l[i] = (l[i] + l[j]) % m
    if l[i] == 0:
      s += 1

print(s)

Fixed submission:
n, m = map(int, input().split())
a = list(map(lambda x: x % m, map(int, input().split())))

b = [0]
s = 0
for i in range(n):
  s = (s + a[i]) % m
  b.append(s)

mods = {}

ans = 0
for i in range(n+1):
  if b[i] in mods.keys():
    ans += mods[b[i]]
    mods[b[i]] += 1
  else:
    mods[b[i]] = 1
  
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
if s in t = input() * 2:
  print('Yes')
else:
  print('No')

Fixed submission:
s = input()
if s in input() * 2:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in frontiers.keys():
    frontiers[a] = min(frontiers[a], b)
  else:
    wars[a] = b

cuts = 0
frontier = 10**6

for i in range(1, n):
  if i in frontiers.keys():
    antis = min(frontier, wars[i])
  if i + 1 == frontier:
    cuts += 1
    frontier = 10**6
    
print(cuts)


Fixed submission:
n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in wars.keys():
    wars[a] = min(wars[a], b)
  else:
    wars[a] = b

cuts = 0
antis = 10**6

for i in range(1, n):
  if i in wars.keys():
    antis = min(antis, wars[i])
  if i + 1 == antis:
    cuts += 1
    antis = 10**6
    
print(cuts)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in wars.keys():
    wars[a].append(b)
  else:
    wars[a] = [b]

cuts = 0
antis = []

for i in range(1, n):
  if i in wars.keys():
    antis.append(min(wars[i]))
  if i + 1 in antis:
    cuts += 1
    antis.clear()
    
print(cuts)


Fixed submission:
n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in wars.keys():
    wars[a] = min(wars[a], b)
  else:
    wars[a] = b

cuts = 0
antis = 10**6

for i in range(1, n):
  if i in wars.keys():
    antis = min(antis, wars[i])
  if i + 1 == antis:
    cuts += 1
    antis = 10**6
    
print(cuts)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in wars.keys():
    wars[a].append(b)
  else:
    wars[a] = [b]

cuts = 0
antis = []

for i in range(1, n):
  if i in wars.keys():
    for anti in wars[i]:
      antis.append(anti)
  if i + 1 in antis:
    cuts += 1
    antis.clear()
    
print(cuts)

Fixed submission:
n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in wars.keys():
    wars[a] = min(wars[a], b)
  else:
    wars[a] = b

cuts = 0
antis = 10**6

for i in range(1, n):
  if i in wars.keys():
    antis = min(antis, wars[i])
  if i + 1 == antis:
    cuts += 1
    antis = 10**6
    
print(cuts)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

x = []
y = []
z = []
for i in range(n):
  _x, _y, _z = map(int, input().split())
  x.append(_x)
  y.append(_y)
  z.append(_z)

pm = [1, -1]

ans = 0
for i_x in pm:
  for i_y in pm:
    for i_z in pm:
      values = []
      for i in range(n):
        values.append(x * i_x + y * i_y + z * i_z)
      s = 0
      for value in sorted(values, reverse=True)[:m]:
        s += value
      ans = max(ans, s)
      
print(ans)

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

x = []
y = []
z = []
for i in range(n):
  _x, _y, _z = map(int, input().split())
  x.append(_x)
  y.append(_y)
  z.append(_z)

pm = [1, -1]

ans = 0
for i_x in pm:
  for i_y in pm:
    for i_z in pm:
      values = []
      for i in range(n):
        values.append(x[i] * i_x + y[i] * i_y + z[i] * i_z)
      s = 0
      for value in sorted(values, reverse=True)[:m]:
        s += value
      ans = max(ans, s)
      
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

x = int(input())

ans = 1
for i in range(2, 9):
  d = (math.floor(x ** (1 / i))) ** i
  if d <= x:
    ans = max(ans, d)
  
print(ans)


Fixed submission:
a, b, c, d = map(int, input().split())

if abs(a - c) <= d:
  print('Yes')
  
elif abs(a - b) <= d and abs(b - c) <= d:
  print('Yes')
  
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
abc = sorted(list(map(int, input().split())))
k = int(input())

print(a + b + c * (2 ** k))

Fixed submission:
abc = sorted(list(map(int, input().split())))
k = int(input())

print(abc[0] + abc[1] + abc[2] * (2 ** k))
Buggy python submission (verdict: Runtime Error):
n = int(input())

a = sorted(list(map(int, input())))

ans = 0
d_min = a[-1]
for i in range(n-1):
  d = abs(a[-1]/2 - a[i])
  if d < d_min:
    d_min = d
    ans = a[i]
    
print('{} {}'.format(a[-1], ans))

Fixed submission:
n = int(input())

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

ans = 0
d_min = a[-1]
for i in range(n-1):
  d = abs(a[-1]/2 - a[i])
  if d < d_min:
    d_min = d
    ans = a[i]
    
print('{} {}'.format(a[-1], ans))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())

print(min(a,b) + min(c+d))

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())

print(min(a,b) + min(c,d))
Buggy python submission (verdict: Runtime Error):
n = int(input())
dic = {}
for i in range(n):
  s = input()
  if s in dic.keys():
    dic[s] += 1
  else:
    dic[s] = 1

m = int(input())
for i in range(n):
  t = input()
  if t in dic.keys():
    dic[t] -= 1
    
ans = 0
for key in dic.keys():
  ans = max(ans, dic[key])
  
print(max(ans, 0))
  

Fixed submission:
n = int(input())
dic = {}
for i in range(n):
  s = input()
  if s in dic.keys():
    dic[s] += 1
  else:
    dic[s] = 1

m = int(input())
for i in range(m):
  t = input()
  if t in dic.keys():
    dic[t] -= 1
    
ans = 0
for key in dic.keys():
  ans = max(ans, dic[key])
  
print(max(ans, 0))
Buggy python submission (verdict: Runtime Error):
n = int(input())
march = {'m': 0, 'a': 0, 'r': 0, 'c': 0, 'h': 0}
for i in range(n):
  s = input()[0]
  try:
    march[s] += 1
  except:
    pass
ans = 0

for key1 in march.keys():
  for key2 in march.keys():
    if key1 != key2:
      for key3 in march.keys():
        if key3 != key1 and key3 != key2:
          ans += key1 * key2 * key3
print(ans)

Fixed submission:
n = int(input())
march = {'m': 0, 'a': 0, 'r': 0, 'c': 0, 'h': 0}
for i in range(n):
  s = input()[0].lower()
  try:
    march[s] += 1
  except:
    pass
ans = 0

for key1 in march.keys():
  for key2 in march.keys():
    if key1 != key2:
      for key3 in march.keys():
        if key3 != key1 and key3 != key2:
          ans += march[key1] * march[key2] * march[key3]
print(ans//6)
Buggy python submission (verdict: Runtime Error):
print("Yes" if (lambda x: x[0] * 2 <= x[1] <= x * 4)(list(map(int,input().split()))) else "No")

Fixed submission:
x,y = map(int,input().split())
if x*2 <= y <= x*4 and y % 2 == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
x,n = map(int,input().split())
p = list(map(int,input().split()))
flag = [True] * 101

for i in p:
    flag[i] = False

for i in range(101):
    if flag[x-i]:
        print(x-i)
        break
    elif flag[x+i]:
        print(x+i)
        break


Fixed submission:
x,n = map(int,input().split())
p = list(map(int,input().split()))
flag = [True] * 102

for i in p:
    flag[i] = False

for i in range(101):
    low = max(x-i, 0)
    high = min(x+i, 101)
    if flag[low]:
        print(low)
        break
    elif flag[high]:
        print(high)
        break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
total = 1
maxi = 10 ** 18
for ae in a:
    total *= ae
if total > maxi:
    print(-1)
    exit()
print(total)



Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
if a[-1] == 0:
    print(0)
    exit()
total = 1
maxi = 10 ** 18
for ae in a:
    total *= ae
    if total > maxi:
        print(-1)
        exit()
print(total)
Buggy python submission (verdict: Runtime Error):
k = int(input())
a,b = map(int,input().split())
for i in range(a, b+1):
	if i % k == 0:
    	print("OK")
        exit()
print("NG")

Fixed submission:
k = int(input())
a,b = map(int,input().split())
for i in range(a, b+1):
  if i % k == 0:
    print("OK")
    exit()
print("NG")

Buggy python submission (verdict: Runtime Error):
k = int(input())
a,b = map(int,input().split())
for i in range(a, b+1):
	if k % i == 0:
    	print("OK")
        exit()
print("NG")

Fixed submission:
k = int(input())
a,b = map(int,input().split())
for i in range(a, b+1):
  if i % k == 0:
    print("OK")
    exit()
print("NG")
Buggy python submission (verdict: Runtime Error):
a,b,n = map(int,input().split())
if a == 1 or b == 1:
    print(0)
    exit()

prev = 0

for x in range(min(b-1,n),n+1, b):
    val = floor(a*x/b) - a*floor(x/b)
    if val < prev:
        print(prev)
        exit()
    prev = val

val = floor(a*n/b) - a*floor(n/b)
print(max(prev,val))



Fixed submission:
from math import floor
a,b,n = map(int,input().split())
if a == 1 or b == 1:
    print(0)
    exit()

prev = 0

for x in range(min(b-1,n),n+1, b):
    val = floor(a*x/b) - a*floor(x/b)
    if val < prev:
        print(prev)
        exit()
    prev = val

val = floor(a*n/b) - a*floor(n/b)
print(max(prev,val))

Buggy python submission (verdict: Time Limit Exceeded):
from math import floor
a,b,n = map(int,input().split())
if a == 1:
    print(0)
    exit()

prev = 0
for x in range(min(b-1,n),n+1, b):
    val = floor(a*x/b) - a*floor(x/b)
    if val < prev:
        print(prev)
        exit()
    prev = val

val = floor(a*n/b) - a*floor(n/b)
print(max(prev,val))


Fixed submission:
from math import floor
a,b,n = map(int,input().split())
if a == 1 or b == 1:
    print(0)
    exit()

prev = 0

for x in range(min(b-1,n),n+1, b):
    val = floor(a*x/b) - a*floor(x/b)
    if val < prev:
        print(prev)
        exit()
    prev = val

val = floor(a*n/b) - a*floor(n/b)
print(max(prev,val))

Buggy python submission (verdict: Time Limit Exceeded):
from math import floor
a,b,n = map(int,input().split())
if a == 1:
    print(0)
    exit()

prev = 0
for x in range(1,n+1):
    val = floor(a*x/b) - a*floor(x/b)
    if val < prev:
        print(prev)
        exit()
    prev = val
print(prev)


Fixed submission:
from math import floor
a,b,n = map(int,input().split())
if a == 1 or b == 1:
    print(0)
    exit()

prev = 0

for x in range(min(b-1,n),n+1, b):
    val = floor(a*x/b) - a*floor(x/b)
    if val < prev:
        print(prev)
        exit()
    prev = val

val = floor(a*n/b) - a*floor(n/b)
print(max(prev,val))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
cnt = 0
for i in range(n-3):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if j-i == k-j: continue
            if s[i] != s[j]:
                if s[j] != s[k]:
                    if s[i] != s[k]:
                        cnt += 1
print(cnt)


Fixed submission:
n = int(input())
s = input()
cnt = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
    pl = 1
    while i + pl * 2 < n:
        if s[i] != s[i+pl] and s[i+pl] != s[i+pl*2] and s[i] != s[i+pl*2]:
            cnt -= 1
        pl += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

xi = 0
yi = 0
zi = 0
def next(i):
    global xi, yi, zi, p, q, r
    if i == 0:
        xi += 1
        return heapq.nlargest(xi, p)[-1]
    elif i == 1:
        yi += 1
        return heapq.nlargest(yi, q)[-1]
    else:
        zi += 1
        return heapq.nlargest(zi, r)[-1]

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

ns = [next(0), next(1), next(2)]

val = 0

while x + y - xi - yi - zi + 3 > 0:
    if ns[0] >= ns[1] and ns[0] >= ns[2]:
        val += ns[0]
        if len(p) > 0 and x - xi > 0:
            ns[0] = next(0)
        else:
            xi += 1
            ns[0] = 0
    elif ns[0] <= ns[1] and ns[1] >= ns[2]:
        val += ns[1]
        if len(q) > 0 and y - yi > 0:
            ns[1] = next(1)
        else:
            yi += 1
            ns[1] = 0
    else:
        val += ns[2]
        if len(r) > 0:
            ns[2] = next(2)
        else:
            ns[2] = 0
print(val)


Fixed submission:
import heapq

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p2 = heapq.nlargest(x, p)
q2 = heapq.nlargest(y, q)
r2 = heapq.nlargest(x+y, r)
p2.append(0)
q2.append(0)
r2.append(0)

pi = 0
qi = 0
ri = 0

val = 0

for _ in range(x+y):
    if p2[pi] >= q2[qi] and p2[pi] >= r2[ri]:
        val += p2[pi]
        pi += 1
    elif p2[pi] <= q2[qi] and q2[qi] >= r2[ri]:
        val += q2[qi]
        qi += 1
    else:
        val += r2[ri]
        ri += 1

print(val)

Buggy python submission (verdict: Time Limit Exceeded):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

ns = [p.pop(0), q.pop(0), r.pop(0)]

z = 0
val = 0

while x + y - z > 0:
    if ns[0] >= ns[1] and ns[0] >= ns[2]:
        val += ns[0]
        x -= 1
        if len(p) > 0 and x > 0:
            ns[0] = p.pop(0)
        else:
            ns[0] = 0
    elif ns[0] <= ns[1] and ns[1] >= ns[2]:
        val += ns[1]
        y -= 1
        if len(q) > 0 and y > 0:
            ns[1] = q.pop(0)
        else:
            ns[1] = 0
    else:
        val += ns[2]
        z += 1
        if len(r) > 0:
            ns[2] = r.pop(0)
        else:
            ns[2] = 0

print(val)


Fixed submission:
import heapq

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p2 = heapq.nlargest(x, p)
q2 = heapq.nlargest(y, q)
r2 = heapq.nlargest(x+y, r)
p2.append(0)
q2.append(0)
r2.append(0)

pi = 0
qi = 0
ri = 0

val = 0

for _ in range(x+y):
    if p2[pi] >= q2[qi] and p2[pi] >= r2[ri]:
        val += p2[pi]
        pi += 1
    elif p2[pi] <= q2[qi] and q2[qi] >= r2[ri]:
        val += q2[qi]
        qi += 1
    else:
        val += r2[ri]
        ri += 1

print(val)
Buggy python submission (verdict: Time Limit Exceeded):
import math

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

def combi(n):
    if n == 1: return 0
    return math.factorial(n) // (math.factorial(n - 2) * 2)

a2 = sorted(a)
a2.append(n+1)
dic = {}
n = 0
cnt = 1
total = 0
for i in a2:
    if n != i:
        if cnt > 1:
            dic[str(n)] = cnt
            total += combi(cnt)
        n = i
        cnt = 1
    else:
        cnt += 1

for i in a:
    if str(i) in dic:
        cnt = dic[str(i)]
        print(total - combi(cnt) + combi(cnt-1))
    else:
        print(total)

Fixed submission:
import math

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

def combi(n):
    if n == 1: return 0
    return math.factorial(n) // (math.factorial(n - 2) * 2)

a2 = sorted(a)
a2.append(n+1)
dic = {}
n = 0
cnt = 1
total = 0
for i in a2:
    if n != i:
        if cnt > 1:
            dic[str(n)] = cnt
            total += combi(cnt)
        n = i
        cnt = 1
    else:
        cnt += 1

for i in a:
    if str(i) in dic:
        cnt = dic[str(i)]
        print(total - cnt + 1)
    else:
        print(total)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = deque(input())
q = int(input())
for _ in range(q):
    que = input()
    if que == "1":
        s.reverse()
    else:
        f,c = que[2:].split()
        if f == "1":
            s.appendleft(c)
        else:
            s.append(c)

print("".join(s))


Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
rev = False
for _ in range(q):
    que = input()
    if que == "1":
        rev = not rev
    else:
        f,c = que[2:].split()
        if (f == "1") ^ rev:
            s.appendleft(c)
        else:
            s.append(c)

if rev: s.reverse()

print("".join(s))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int,input().split()))

cnt = 0
for idx in range(n):
    is_ok = True
    for j in range(idx):
        if p[idx] > p[j]:
            is_ok = False
            break
    if is_ok:
        cnt += 1

print(cnt)



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

ok = n + 1
cnt = 0
for i in p:
    if i <= ok:
        cnt += 1
        ok = i
print(cnt)
Buggy python submission (verdict: Runtime Error):
from math import gcd
a, b = map(int,input().split())
print(a * b // gcd(a,b))

Fixed submission:
from fractions import gcd
a, b = map(int,input().split())
print(a * b // gcd(a,b))