Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def renew(lis,id1,id2):
  tar = lis[id1]; bow = lis[id2]
  if tar[0] < bow[0]:
    tar = [bow[0],max(bow[1],tar[0])]
  else:
    tar[1] = max(bow[0],tar[1])
  lis[id1] = tar
  return

n = int(input())
a = [[x,0] for x in list(map(int, input().split()))]
for j in range(n):
  t = 1<<j
  for i in range(1<<n):
    if not i&t:
      renew(a,i|t,i)
a = [x+y for x,y in a]
for i in range(1,1<<n):
  if a[i] < a[i-1]:
    a[i] = a[i-1]
for x in a[1:]:
  print(x)


Fixed submission:
def renew(lis,id1,id2):
  tar = lis[id1]; bow = lis[id2]
  if tar[0] < bow[0]:
    tar = [bow[0],max(bow[1],tar[0])]
  else:
    tar[1] = max(bow[0],tar[1])
  lis[id1] = tar
  return

n = int(input())
a = [[x,0] for x in list(map(int, input().split()))]
for j in range(n):
  for i in range(2**n):
    if not i & (1<<j):
      renew(a,i|(1<<j),i)
a = [x+y for x,y in a[1:]]
for i in range(1,2**n-1):
  if a[i] < a[i-1]:
    a[i] = a[i-1]
for x in a:
  print(x)

Buggy python submission (verdict: Time Limit Exceeded):
def renew(lis,id1,id2):
  tar = lis[id1]; bow = lis[id2]
  if tar[0] < bow[0]:
    tar = [bow[0],max(bow[1],tar[0])]
  else:
    tar[1] = max(bow[0],tar[1])
  lis[id1] = tar
  return

n = int(input())
a = [[x,0] for x in list(map(int, input().split()))]
for j in range(n):
  for i in range(2**n):
    if not i & (1<<j):
      renew(a,i|(1<<j),i)
a = [x+y for x,y in a[1:]]
for i in range(1,2**n-1):
  if a[i] < a[i-1]:
    a[i] = a[i-1]
for x in a:
  print(x)


Fixed submission:
def renew(lis,id1,id2):
  tar = lis[id1]; bow = lis[id2]
  if tar[0] < bow[0]:
    tar = [bow[0],max(bow[1],tar[0])]
  else:
    tar[1] = max(bow[0],tar[1])
  lis[id1] = tar
  return

n = int(input())
a = [[x,0] for x in list(map(int, input().split()))]
for j in range(n):
  for i in range(2**n):
    if not i & (1<<j):
      renew(a,i|(1<<j),i)
a = [x+y for x,y in a[1:]]
for i in range(1,2**n-1):
  if a[i] < a[i-1]:
    a[i] = a[i-1]
for x in a:
  print(x)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = n
l9 = [9**i for i in range(6,0,-1)]
l6 = [6**i for i in range(7,-1,-1)]
for i in range(n//9+1):
  x9 = i*9
  x61= n-x9
  csum = 0
  for x in l9:
    csum += x9//x
    x9 %= x
  for x in x61:
    csum += x61//x
    x61 %= x
  if ans > csum:
    ans = csum
print(ans)    

Fixed submission:
n = int(input())
ans = n
l9 = [9**i for i in range(6,0,-1)]
l6 = [6**i for i in range(7,-1,-1)]
for i in range(n//9+1):
  x9 = i*9
  x61= n-x9
  csum = 0
  for x in l9:
    csum += x9//x
    x9 %= x
  for x in l6:
    csum += x61//x
    x61 %= x
  if ans > csum:
    ans = csum
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
tot = 10**12
n,c = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(n)]
clr = [list(map(int, input().split())) for _ in range(n)]
l = [dict()]*3
for y in range(n):
  for x in range(n):
    l[(x+y)%3][clr[y][x]] += 1
for c1 in range(c):
  for c2 in range(c):
    if c1 == c2:
      continue
    for c3 in range(c):
      if c1==c3 or c2==c3:
        continue
      ctot = 0
      cl = [c1,c2,c3]
      for i in range(3):
        for x in l[i]:
          ctot += d[x-1][c[i]]*l[i][x]
      if tot > ctot:
        tot = ctot
print(tot)
      

Fixed submission:
from collections import defaultdict as ddict
tot = 10**12
n,c = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(c)]
clr = [list(map(int, input().split())) for _ in range(n)]
l = [ddict(int) for _ in range(3)]
for y in range(n):
  for x in range(n):
    l[(x+y)%3][clr[y][x]] += 1
for c1 in range(c):
  for c2 in range(c):
    if c1 == c2:
      continue
    for c3 in range(c):
      if c1==c3 or c2==c3:
        continue
      ctot = 0
      cl = [c1,c2,c3]
      for i in range(3):
        for x in l[i]:
          ctot += d[x-1][cl[i]]*l[i][x]
      if tot > ctot:
        tot = ctot
print(tot)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = n
for i in range(n//2+1):
  s = min(s, sum(list(str(i))) + sum(list(str(n-i))))
print(s)
  

Fixed submission:
n = int(input())
s = n
for i in range(1, n//2+1):
  s = min(s, sum(map(int, list(str(i)))) + sum(map(int, list(str(n-i)))))
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial as fac
def cc(n,r):
  def fac2(n,r):
    m = 1
    for i in range(n-r+1,n+1):
      m*=i
    return m
  r = min(r,n-r)
  return fac2(n,r)//fac(r)
n, a, b, k = map(int, input().split())
mod = 998244353
ans = 0
for i in range(min(k//a+1,n+1)):
  jof = k-a*i
  if jof%b==0 and jof<=n*b:
    j = jof//b
    ans += cc(n,i)*cc(n,j)
    ans %= mod
print(ans)

Fixed submission:
n,a,b,k = map(int,input().split())
mod = 998244353
fun = [1]*(n+1)
for i in range(1,n+1):
  fun[i] = fun[i-1]*i%mod
rev = [1]*(n+1)
rev[n] = pow(fun[n],mod-2,mod)
for i in range(n-1,0,-1):
  rev[i] = rev[i+1]*(i+1)%mod
def nCr(n,r):
  if r > n:
    return 0
  return fun[n]*rev[r]%mod*rev[n-r]%mod
ans = 0
for i in range(min(n,k//a)+1):
  j = (k-a*i)//b
  if i*a+j*b == k and 0<=j<=n:
    ans += nCr(n,i)*nCr(n,j)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial as fac
def cc(n,r):
  return fac(n)//fac(r)//fac(n-r)
n, a, b, k = map(int, input().split())
mod = 998244353
ans = 0
for i in range(min(k//a+1,n+1)):
  jof = k-a*i
  if jof%b==0 and jof<=n*b:
    j = jof//b
    ans += cc(n,i)*cc(n,j)%mod
    ans %= mod
print(ans)

Fixed submission:
n,a,b,k = map(int,input().split())
mod = 998244353
fun = [1]*(n+1)
for i in range(1,n+1):
  fun[i] = fun[i-1]*i%mod
rev = [1]*(n+1)
rev[n] = pow(fun[n],mod-2,mod)
for i in range(n-1,0,-1):
  rev[i] = rev[i+1]*(i+1)%mod
def nCr(n,r):
  if r > n:
    return 0
  return fun[n]*rev[r]%mod*rev[n-r]%mod
ans = 0
for i in range(min(n,k//a)+1):
  j = (k-a*i)//b
  if i*a+j*b == k and 0<=j<=n:
    ans += nCr(n,i)*nCr(n,j)
    ans %= mod
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial as fac
def cc(n,r):
  return fac(n)//fac(r)//fac(n-r)
n, a, b, k = map(int, input().split())
mod = 998244353
for i in range(min(k//a+1,n+1)):
  j = k-a*i
  if j%b == 0 andj<=n:
    ans += cc(n,i)*cc(n,j)%mod
    ans %= mod
print(ans)

Fixed submission:
n,a,b,k = map(int,input().split())
mod = 998244353
fun = [1]*(n+1)
for i in range(1,n+1):
  fun[i] = fun[i-1]*i%mod
rev = [1]*(n+1)
rev[n] = pow(fun[n],mod-2,mod)
for i in range(n-1,0,-1):
  rev[i] = rev[i+1]*(i+1)%mod
def nCr(n,r):
  if r > n:
    return 0
  return fun[n]*rev[r]%mod*rev[n-r]%mod
ans = 0
for i in range(min(n,k//a)+1):
  j = (k-a*i)//b
  if i*a+j*b == k and 0<=j<=n:
    ans += nCr(n,i)*nCr(n,j)
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().spit())
ans = "No"
if abs(c-a) <= d:
  ans = "Yes"
elif abs(b-a) <= d and abs(c-b) <= d:
  ans = "Yes"
print(ans) 

Fixed submission:
a, b, c, d = map(int, input().split())
ans = "No"
if abs(c-a) <= d:
  ans = "Yes"
elif abs(b-a) <= d and abs(c-b) <= d:
  ans = "Yes"
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
p = list(map(int,input().split()))
d = [list() for _ in range(n+1)]
cnt = 0
for _ in range(m):
  x,y = map(int, input().split())
  d[x].append(y)
  d[y].append(x)
gr = [0]*(n+1)
gr[0] = -1
gn = 0
for x in range(1,n+1):
  if gr[x] == 0:
    gn += 1
    gr[x] = gn
    l = [x]
    while l:
      cur = l.pop()
      for i in d[cur]:
        if i not in l and gr[i] == 0:
          gr[i] = gn
          l.append(i)
for i in range(n):
  if gr[i+1] == gr[p[i]]:
    cnt += 1
print(cnt)

Fixed submission:
s = input()
k = int(input())
sub = set()
for i in range(len(s)):
  for j in range(1,k+1):
    sub.add(s[i:i+j])
print(sorted(list(sub))[k-1])

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
sub = set()
for i in range(len(s)):
  for j in range(1,k):
    sub.add(s[i:i+j])
print(sorted(list(sub))[k-1])

Fixed submission:
s = input()
k = int(input())
sub = set()
for i in range(len(s)):
  for j in range(1,k+1):
    sub.add(s[i:i+j])
print(sorted(list(sub))[k-1])

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
sub = set()
for i in range(n):
  for j in range(1,k):
    sub.add(s[i:i+j])
print(sorted(list(sub))[k-1])

Fixed submission:
s = input()
k = int(input())
sub = set()
for i in range(len(s)):
  for j in range(1,k+1):
    sub.add(s[i:i+j])
print(sorted(list(sub))[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
p = list(map(int,input().split()))
d = [list() for _ in range(n+1)]
cnt = 0
for _ in range(m):
  x,y = map(int, input().split())
  d[x].append(y)
  d[y].append(x)
gr = [0]*(n+1)
gr[0] = -1
gn = 0
for x in range(1,n+1):
  if gr[x] == 0:
    gn += 1
    gr[x] = gn
    l = [x]
    while l:
      cur = l.pop()
      for i in d[cur]:
        if i not in l and gr[i] == 0:
          gr[i] = gn
          l.append(i)
for i in range(n):
  if gr[i+1] == gr[p[i]]:
    cnt += 1
print(cnt)

Fixed submission:
n,m = map(int, input().split())
p = list(map(int,input().split()))
d = [list() for _ in range(n+1)]
cnt = 0
for _ in range(m):
  x,y = map(int, input().split())
  d[x].append(y)
  d[y].append(x)
gr = [0]*(n+1)
gr[0] = -1
gn = 0
for x in range(1,n+1):
  if gr[x] == 0:
    gn += 1
    gr[x] = gn
    l = [x]
    while l:
      cur = l.pop()
      for i in d[cur]:
        if i not in l and gr[i] == 0:
          gr[i] = gn
          l.append(i)
for i in range(n):
  if gr[i+1] == gr[p[i]]:
    cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
p = list(map(int,input().split()))
d = [set() for _ in range(n+1)]
cnt = 0
for _ in range(m):
  x,y = map(int, input().split())
  d[x].add(y)
  d[y].add(x)
gr = [0]*(n+1)
gr[0] = -1
gn = 0
for x in range(1,n+1):
  if gr[x] == 0:
    gn += 1
    gr[x] = gn
    l = [x]
    while l:
      cur = l.pop()
      for i in d[cur]:
        if i not in l and gr[i] == 0:
          gr[i] = gn
          l.append(i)
for i in range(n):
  if gr[i+1] == gr[p[i]]:
    cnt += 1
print(cnt)

Fixed submission:
n,m = map(int, input().split())
p = list(map(int,input().split()))
d = [list() for _ in range(n+1)]
cnt = 0
for _ in range(m):
  x,y = map(int, input().split())
  d[x].append(y)
  d[y].append(x)
gr = [0]*(n+1)
gr[0] = -1
gn = 0
for x in range(1,n+1):
  if gr[x] == 0:
    gn += 1
    gr[x] = gn
    l = [x]
    while l:
      cur = l.pop()
      for i in d[cur]:
        if i not in l and gr[i] == 0:
          gr[i] = gn
          l.append(i)
for i in range(n):
  if gr[i+1] == gr[p[i]]:
    cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [input() for i in range(n)]
for i in range(h):
  for j in range(w):
    if s[i][j] = "#":
      d = set()
      if i>0:
        d.add(s[i-1][j])
      if i<h-1:
        d.add(s[i+1][j])
      if j>0:
        d.add(s[i][j-1])
      if j<w-1:
        d.add(s[i][j+1])
      if "#" not in d:
        print("No")
        exit()
print("Yes")

Fixed submission:
h, w = map(int, input().split())
s = [input() for i in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      d = set()
      if i>0:
        d.add(s[i-1][j])
      if i<h-1:
        d.add(s[i+1][j])
      if j>0:
        d.add(s[i][j-1])
      if j<w-1:
        d.add(s[i][j+1])
      if "#" not in d:
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [list(input()) for _ in range(n)]
ans = 0
for s in range(n):
  f = 1
  for i in range(n):
    if not f:
      break
    for j in range(n):
      if a[(i+s)%n][j] != a[(j+s)%n][i]:
        f = 0
        break
  if f:
    ans += n
print(ans)

Fixed submission:
n = int(input())
a = [list(input()) for _ in range(n)]
ans = 0
for s in range(n):
  f = 1
  for i in range(n):
    if not f:
      break
    for j in range(n):
      if a[(i+s)%n][j] != a[(j+s)%n][i]:
        f = 0
        break
  if f:
    ans += n
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input
if s.count("a") == 1 and s.count("b") == 1:
  print("Yes")
else:
  print("No")
s = input

Fixed submission:
s = input()
if s.count("a") == 1 and s.count("b") == 1:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
s = input
if s.count("a") == 1 ans s.count("b") == 1:
  print("Yes")
else:
  print("No")

Fixed submission:
s = input()
if s.count("a") == 1 and s.count("b") == 1:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
def check(a, b):
  if b < a:
    a, b = b, a
  if b - a <= 1:
    return 2 * a - 2
  c = int((a * b - 1)**.5)
  assert(c**2 < a * b <= (c + 1)**2)
  return 2 * c - 1 - (c * (c + 1) >= a * b)

for _ in range(int(input())):
  print(check(*list(map(int, input().split()))))

Fixed submission:
def check(a, b):
  if b < a:
    a, b = b, a
  if b - a <= 1:
    return 2 * a - 2
  d = a * b
  c, ng = a, b
  while ng - c > 1:
    mid = (ng + c) // 2
    if mid ** 2 < d:
      c = mid
    else:
      ng = mid
  return 2 * c - 1 - (c * (c + 1) >= a * b)

for _ in range(int(input())):
  print(check(*list(map(int, input().split()))))
Buggy python submission (verdict: Runtime Error):
n,*l = map(int,open(0).read().split())
a = l[::2]
b = l[1::2]
print(sum(a) - min(b[i] for i in range(n) if b[i] < a[i]))

Fixed submission:
n,*l = map(int,open(0).read().split())
a = l[::2]
b = l[1::2]
print(0 if a==b else sum(a) - min(b[i] for i in range(n) if b[i] < a[i]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [{}, {}, {}, {2, 5, 63}, {2, 5, 20, 63}, {2, 3, 4, 6, 9}]
if n <= 5:
  print(*l[n])
l = [2, 3, 4, 6]
s = set()
for i in range(n):
  s.add(l[i%4] + 6*(i//4))
if sum(s) % 6 == 2:
  s.remove(8)
  s.add(30000)
if sum(s) % 6 == 3:
  s.remove(9)
  s.add(30000)
if sum(s) % 6 == 5:
  s.remove(9)
  s.add(29998)
print(*s)

Fixed submission:
n = int(input())
l = [{}, {}, {}, {2, 5, 63}, {2, 5, 20, 63}, {2, 3, 4, 6, 9}]
if n <= 5:
  print(*l[n])
  exit(0)
l = [2, 3, 4, 6]
s = set()
for i in range(n):
  s.add(l[i%4] + 6*(i//4))
if sum(s) % 6 == 2:
  s.remove(8)
  s.add(30000)
if sum(s) % 6 == 3:
  s.remove(9)
  s.add(30000)
if sum(s) % 6 == 5:
  s.remove(9)
  s.add(29998)
print(*s)
Buggy python submission (verdict: Runtime Error):
a, b, c, d =map(int, input().split())
print(min(a, b)+min(c, d))

Fixed submission:
a, b, c, d = [int(input()) for i in range(4)]
print(min(a, b)+min(c, d))
Buggy python submission (verdict: Runtime Error):
n = int(input)
s = input().split()
if "Y" in s:
  print("Four")
else:
  print("Three")

Fixed submission:
n = int(input())
s = input().split()
if "Y" in s:
  print("Four")
else:
  print("Three")
Buggy python submission (verdict: Runtime Error):
import math

def norm(p, q): # normal vector: (p -> q) * -1j
    return (q[1] - p[1], p[0] - q[1])

def magnitude(a):
    return (a[0]**2 + a[1]**2)**.5

def dot(p, q):
    return p[0]*q[0] + p[1]*q[1]

def angle(p, q):
    return math.acos(dot(p, q) / (magnitude(p) * magnitude(q)))

def cross(a, b, c):
    return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])

def convex_hull(ps):
    ps = sorted(ps)
    qs = []
    n = len(ps)
    for p in ps:
        while len(qs) > 1 and cross(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    t = len(qs)
    for i in range(n - 2, -1, -1):
        p = ps[i]
        while len(qs) > t and cross(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    return qs

n = int(input())
s = [tuple(map(int, input().split())) for _ in range(n)]
ch = convex_hull(s)
ch.pop()
m = len(ch)
d = dict()
for i in range(m):
  u = angle(norm(ch[i-1], ch[i]), norm(ch[i], ch[(i+1)%m]))
  d[ch[i]] = u / 2 / math.pi
for t in s:
  print(0.0 if t not in d else d[t])

Fixed submission:
import math

def norm(p, q): # normal vector: (p -> q) * -1j
    return (q[1] - p[1], p[0] - q[0])

def magnitude(a):
    return (a[0]**2 + a[1]**2)**.5

def dot(p, q):
    return p[0]*q[0] + p[1]*q[1]

def angle(p, q):
    return math.acos(dot(p, q) / (magnitude(p) * magnitude(q)))

def cross(a, b, c):
    return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])

def convex_hull(ps):
    ps = sorted(ps)
    qs = []
    n = len(ps)
    for p in ps:
        while len(qs) > 1 and cross(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    t = len(qs)
    for i in range(n - 2, -1, -1):
        p = ps[i]
        while len(qs) > t and cross(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    return qs

n = int(input())
s = [tuple(map(int, input().split())) for _ in range(n)]
ch = convex_hull(s)
ch.pop()
m = len(ch)
d = dict()
for i in range(m):
  u = angle(norm(ch[i-1], ch[i]), norm(ch[i], ch[(i+1)%m]))
  d[ch[i]] = u / 2 / math.pi
for t in s:
  print(0.0 if t not in d else d[t])
Buggy python submission (verdict: Runtime Error):
s = list(input())
s[3] = 8
print(''.join(s))

Fixed submission:
s = list(input())
s[3] = '8'
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
throw = []
blow = 0
cnt = 0
n,h = map(int, input().split())
for _ in range(n):
  a,b = map(int, input().split())
  blow = max(blow,a)
  throw.append(b)
throw.sort()
while h and throw[-1]>blow:
  h -= throw.pop()
  cnt += 1
if h > 0:
  cnt += h//blow + (h%blow>0)
print(cnt)  

Fixed submission:
throw = []
blow = 0
cnt = 0
n,h = map(int, input().split())
for _ in range(n):
  a,b = map(int, input().split())
  blow = max(blow,a)
  throw.append(b)
throw.sort()
while h>0 and throw and throw[-1]>blow:
  h -= throw.pop()
  cnt += 1
if h > 0:
  cnt += h//blow + (h%blow>0)
print(cnt)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
s = input().split(-)
if len(s[0]) == a and len(s[1]) == b:
  print("Yes")
else:
  print("No")

Fixed submission:
a, b = map(int, input().split())
s = input().split('-')
if len(s[0]) == a and len(s[1]) == b:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print(max(1+int(math.log2(b//a)), 0))


Fixed submission:
a, b, c, d = map(int, input().split())
if a+b == c+d:
  print("Balanced")
elif a+b > c+d:
  print("Left")
else:
  print("Right")
Buggy python submission (verdict: Runtime Error):
import math
a b = map(int, input().split())
print(1+int(math.log2(b/a)))

Fixed submission:
a, b = map(int, input().split())
t = 0
while a <= b:
  a *= 2
  t += 1
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
for i in set(a):
    if i <= a.count(i):
        n -= i
print(n)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
for k,v in d.items():
    if k <= v:
        n -= k
print(n)

Buggy python submission (verdict: Time Limit Exceeded):
_ = int(input())
a = list(map(int, input().split()))
tot = 0
for i in set(a):
    if i > a.count(i):
        tot += a.count(i)
    else:
        tot += a.count(i) - i
print(tot)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
for k,v in d.items():
    if k <= v:
        n -= k
print(n)
Buggy python submission (verdict: Runtime Error):
s = list(map(len,input().split("T")))
x = s[::2]
y = s[1::2]
gx,gy = map(int,input().split())
if sum(x) < abs(gx) or sum(y) < abs(gy):
  print("No")
  exit(0)
dpx = [0]*(len(x)+1)
dpy = [0]*(len(y)+1)
dpx[1] = set(x[0])
dpy[0] = set([0])
for i in range(2,len(x)+1):
  s1 = set([v + x[i-1] for v in dpx[i-1]])
  s2 = set([v - x[i-1] for v in dpx[i-1]])
  dpx[i] = s1|s2
for i in range(1,len(y)+1):
  s1 = set([v + y[i-1] for v in dpy[i-1]])
  s2 = set([v - y[i-1] for v in dpy[i-1]])
  dpy[i] = s1|s2
if gx in dpx[-1] and gy in dpy[-1]:
  print("Yes")
else:
  print("No")


Fixed submission:
s = list(map(len,input().split("T")))
x = s[::2]
y = s[1::2]
gx,gy = map(int,input().split())
if sum(x) < abs(gx) or sum(y) < abs(gy):
  print("No")
  exit(0)
dpx = [0]*(len(x)+1)
dpy = [0]*(len(y)+1)
dpx[0] = set([0])
dpy[0] = set([0])
for i in range(1,len(x)+1):
  s1 = set([v + x[i-1] for v in dpx[i-1]])
  s2 = set([v - x[i-1] for v in dpx[i-1]])
  if i == 1:
    dpx[i] = s1
  else:
    dpx[i] = s1|s2
for i in range(1,len(y)+1):
  s1 = set([v + y[i-1] for v in dpy[i-1]])
  s2 = set([v - y[i-1] for v in dpy[i-1]])
  dpy[i] = s1|s2
if gx in dpx[-1] and gy in dpy[-1]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
def luca(n):
  if n == 2:
    return 1
  elif n == 1:
    return 2
  luca(n) = luca(n-1) + luca(n-2)
  return

print(luca(int(input()))

Fixed submission:
def luca(n, a=1, b=2):
  if n <= 1:
    return a
  return luca(n-1, a+b, a)

a = int(input())
print(luca(a))

Buggy python submission (verdict: Runtime Error):
def luca(n):
  if n == 2:
    return 1
  elif n == 1:
    return 2
  luca(n) = luca(n-1) + luca(n-2)
  return

print(luca(int(input()))

Fixed submission:
def luca(n, a=1, b=2):
  if n <= 1:
    return a
  return luca(n-1, a+b, a)

a = int(input())
print(luca(a))
Buggy python submission (verdict: Runtime Error):
s = list("abcdef")
x, y = input().split()
if s.index(x) > s.index(y):
  print(">")
elif s.index(x) < s.index(y):
  print("<")
else:
  print("=")

Fixed submission:
s = list("ABCDEF")
x, y = input().split()
if s.index(x) > s.index(y):
  print(">")
elif s.index(x) < s.index(y):
  print("<")
else:
  print("=")

Buggy python submission (verdict: Runtime Error):
s = list("abcdef")
x, y = input().split()
if s.index(x) > s.index(y):
  print(">")
elif s.index(x) < s.index(y):
  print("<")
else:
  print("=")

Fixed submission:
s = list("ABCDEF")
x, y = input().split()
if s.index(x) > s.index(y):
  print(">")
elif s.index(x) < s.index(y):
  print("<")
else:
  print("=")
Buggy python submission (verdict: Runtime Error):
f = list(input())
s = list(input())
for i in range(1,4):
  if f[i] != s[4-i]:
    print("NO")
    exit()
print("YES")

Fixed submission:
f = list(input())
s = list(input())
for i in range(3):
  if f[i] != s[2-i]:
    print("NO")
    exit()
print("YES")
Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
c.sort()
ans = 0
for i in b:
  ans += bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x))
print(ans)

Fixed submission:
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
c.sort()
ans = 0
for x in b:
  ans += bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t = list(map(int, input().split())) + [0]
v = list(map(int, input().split())) + [0]
m = sum(t)*2
g = [10**10]*(m+1)
l = [(0, 0, 0)]
for x, y in zip(t, v):
  l.append((l[-1][1], l[-1][1] + x*2, y))
for x, y, c in l:
  for i in range(m + 1):
    d = c
    if i < x:
      d += (x - i)*.5
    elif y < i:
      d += (i - y)*.5
    if g[i] > d:
      g[i] = d
print(sum(g)/2)

Fixed submission:
n = int(input())
t = list(map(int, input().split())) + [0]
v = list(map(int, input().split())) + [0]
m = sum(t)*2
g = [10**10]*(m+1)
l = [(0, 0, 0)]
for x, y in zip(t, v):
  l.append((l[-1][1], l[-1][1] + x*2, y))
for x, y, c in l:
  for i in range(m + 1):
    d = c
    if i < x:
      d += (x - i)*.5
    elif y < i:
      d += (i - y)*.5
    if g[i] > d:
      g[i] = d
print(sum(g)/2)