Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02612 (python)

Fixed submission:
N=int(input())
A=1000*(N//1000)-N
B=((N//1000)+1)*1000-N
if A<=B and A>=0:
  print(int(A))
else:
  print(int(B))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=N-1000*(N//1000)
B=((N//1000)+1)*1000-N
if A<=B:
  return A
else:
  return B
Problem p02786 (python)

Fixed submission:
H=int(input())
def f(H):
  if H==1:
    return 1
  elif H>1:
    return 2*f(H//2)+1
re=0
re=f(H)
print(re)

Buggy submission (verdict: Runtime Error):
H=int(input())
def f(H):
  if H==1:
    return 1
  elif H>1:
    return 2*f(H/2)+1
print(f(H))
Problem p02812 (python)

Fixed submission:
N=int(input())
S=str(input())
S=S.replace('ABC','')
if N==len(S):
  print(0)
else:
  print((N-len(S))//3)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=str(input())
S=S.remove('ABC')
if N==len(S):
  return 0
else:
  return (N-len(S))//3
Problem p02848 (python)

Fixed submission:
N=int(input())
S=list(map(str, input()))
li=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
answer=[]
for i in range(len(S)):
  for j in range(len(li)):
    if S[i]==li[j] and j<len(li)-N:
      answer.append(li[j+N])
    elif S[i]==li[j] and j>=len(li)-N:
      answer.append(li[j+N-len(li)])
print("".join(answer))

Buggy submission (verdict: Runtime Error):
N=int(input())
S=list(map(str, input()))
li=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','W','X','Y','Z']
answer=[]
for i in range(len(S)):
  for j in range(len(li)):
    if S[i]==li[j] and j<len(li)-N:
      answer.append(li[j+N])
    elif S[i]==li[j] and j>=len(li)-N:
      answer.append(li[j+N-len(li)])
print("".join(answer))

Buggy submission (verdict: Runtime Error):
N=int(input())
S=list(map(str, input()))
li=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','W','X','Y','Z']
answer=[]
for i in range(len(S)):
  for j in range(len(li)):
    if S[i]==li[j] and j<len(li)-N:
      answer.append(li[j+N])
    elif S[i]==li[j] and j>=len(li)-N:
      answer.append(li[j+N-len(li)])
print("".join(answer))
Problem p03238 (python)

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

Buggy submission (verdict: Runtime Error):
A,B,C,D=map(int,input().split())
if A<=C:
  if D<=B:
    t=B-C
  else:
    t=D-C
else:
  if D<=B:
    t=B-A
  else:
    t=D-A
  t=D-A
if t<=0:
  print(0)
else:
  print(t)
Problem p03556 (python)

Fixed submission:
N=int(input())
C=0
if N==1:
  print(1)
  exit()
for i in range(1,N):
  if i**2<N:
    C=i**2
  elif i**2==N:
    C=i**2
    break
  elif i**2>N:
    break
print(C)

Buggy submission (verdict: Runtime Error):
N=int(input())
C=0
for i in range(1,N):
  if i**2<N:
    C=i**2
  elif i**2=N:
    C=i**2
    break
  elif i**2>N:
    break
print(C)

Buggy submission (verdict: Runtime Error):
N=int(input())
C=0
for i in range(1,N):
  if i**2<N:
    C=i**2
  elif i**2=N:
    C=i**2
    break
  elif i**2<N:
    break
print(C)
Problem p03760 (python)

Fixed submission:
odd = list(map(str, input()))
even = list(map(str, input()))
if len(odd)==len(even):
  L=len(odd)*2
else:
  L=len(odd)+len(even)
li=[]

for i in range(1,L+1):
  if i%2==1:
    if i==1:
      li.append(odd[0])
    else:
      li.append(odd[i//2])
  else:
    li.append(even[i//2-1])
    
print(''.join(li))

Buggy submission (verdict: Runtime Error):
odd = list(map(str, input()))
even = list(map(str, input()))
L=len(odd)*2
li=[]

for i in range(1,L+1):
  if i%2==1:
    if i==1:
      li.append(odd[0])
    else:
      li.append(odd[i//2])
  else:
    li.append(even[i//2-1])
    
print(''.join(li))
Problem p03777 (python)

Fixed submission:
a,b=map(str,input().split())
if a=="H":
  print(b)
  exit()
else:
  if b=="H":
    print("D")
  else:
    print("H")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a=='H':
  print(b)
  exit()
else:
  if b=='H':
    print('D')
  else:
    print('H')
Problem p03778 (python)

Fixed submission:
W,a,b=map(int,input().split())
if b>a:
  if b-(a+W)<=0:
  	print(0)
  	exit()
  print(b-(a+W))
else:
  if a-(b+W)<=0:
  	print(0)
  	exit()
  print(a-(b+W))

Buggy submission (verdict: Runtime Error):
W,a,b=map(int,input().split())
if b>a:
  	if b-(a+W)==0:
  	print(0)
  	exit()
	print(b-(a+W))
else:
  if a-(b+W)==0:
  	print(0)
  	exit()
	print(a-(b+W))
Problem p03957 (python)

Fixed submission:
s=str(input())
if 'C' in s and 'F' in s:
  if s.find('C')<s.rfind('F'):
    print('Yes')
  else:
    print('No')
else:
  print('No')
  exit()

Buggy submission (verdict: Runtime Error):
s=list(map(str,input()))
if 'C' in s and 'F' in s:
  if s.index('C')<s.index('F'):
    print('Yes')
  else:
    s.remove(s[s.index('F')])
    if s.index('C')<s.index('F'):
      print('Yes')
    else:
      print('No')
else:
  print('No')
  exit()
Problem p02582 (python)

Fixed submission:
s = input()
if s == "RRS" or s == "SRR":
    print(2)
elif s == "RRR":
    print(3)
elif s == "SSS":
    print(0)
else:
    print(1)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
p = [i-1 for i in list(map(int,input().split()))]
c = list(map(int,input().split()))
ans = -float("inf")
for i in range(n):
    now = i
    cnt = [0]
    for j in range(n):
        nxt = p[now]
        cnt.append(cnt[j]+c[nxt])
        now = nxt
        if now == i:
            break
    m = len(cnt)-1
    if k <= m:
        s = max(cnt[1:(k+1)])
    elif cnt[-1] < 0:
        s = max(cnt[1:])
    else:
        t = k//m
        s = (t-1)*cnt[-1]+max(cnt[1:])
        s = max(s, t*cnt[-1]+max(cnt[:(k-t*m+1)]))
    ans = max(ans,s)
print(ans)
Problem p02612 (python)

Fixed submission:
print((1000-int(input()))%1000)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for _ in range(n)]
l = ["AC","WA","TLE","RE"]
for i in range(4):  print(l[i],"x",s.count(l[i]))
Problem p02642 (python)

Fixed submission:
from math import gcd
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a.sort()
if n == 1:
    print(1)
    quit()
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
M = max(a)
cnt = [0]*(M+1)
ans = 0
for i in range(n):
    if cnt[a[i]]:
        continue
    j = a[i]
    if i == 0:
        if a[i] == a[i+1]:
            1
        else:
            ans += 1
    elif i == n-1:
        if a[i-1] == a[i]:
            1
        else:
            ans += 1
    elif a[i] == a[i+1] or a[i-1] == a[i]:
        1
    else:
        ans += 1
    while j <= M:
        cnt[j] = 1
        j += a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a.sort()
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
M = max(a)
cnt = [0]*(M+1)
ans = 0
for i in range(n):
    if cnt[a[i]]:
        continue
    j = a[i]
    if i == 0:
        if a[i] == a[i+1]:
            1
        else:
            ans += 1
    elif i == n-1:
        if a[i-1] == a[i]:
            1
        else:
            ans += 1
    elif a[i] == a[i+1] or a[i-1] == a[i]:
        1
    else:
        ans += 1
    while j <= M:
        cnt[j] = 1
        j += a[i]
print(ans)
Problem p02678 (python)

Fixed submission:
import copy
n,m = map(int,input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
memo = [0]*n
now = [[0,0]]
nxt = []
done = [False]*n
done[0] = True


while now:
    for l in now:
        for j in graph[l[1]]:
            if not done[j]:                
                done[j] = True
                nxt.append([l[1],j])
                memo[j] = l[1]+1
    now = copy.copy(nxt)
    nxt = []
for l in now:
    done[l[1]] = True
if False in done:
    print("No")
else:
    print("Yes")
    for i in range(1,n):
        print(memo[i])

Buggy submission (verdict: Runtime Error):
import copy
n,m = map(int,input().split())
graph = [[] for _ in range(m)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
memo = [0]*n
now = [[0,0]]
nxt = []
done = [False]*n
done[0] = True


while now:
    for l in now:
        for j in graph[l[1]]:
            if not done[j]:                
                done[j] = True
                nxt.append([l[1],j])
                memo[j] = l[1]+1
    now = copy.copy(nxt)
    nxt = []
for l in now:
    done[l[1]] = True
if False in done:
    print("No")
else:
    print("Yes")
    for i in range(1,n):
        print(memo[i])

Buggy submission (verdict: Runtime Error):
import copy
n,m = map(int,input().split())
graph = [[] for _ in range(m)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
memo = [0]*n
now = [[0,0]]
nxt = []
done = [False]*n
done[0] = True


while now:
    for l in now:
        for j in graph[l[1]]:
            if not done[j]:                
                done[j] = True
                nxt.append([l[1],j])
                memo[j] = l[1]+1
    now = copy.copy(nxt)
    nxt = []
    print(memo)
for l in now:
    done[l[1]] = True
if False in done:
    print("No")
else:
    print("Yes")
    for i in range(1,n):
        print(memo[i])
Problem p02681 (python)

Fixed submission:
s = input()
t = input()
if len(t) != len(s)+1:
  print("No")
  quit()
if s == t[:len(s)]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
mod = 998244353
ans = 0
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = mod
N = 10**6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
for i in range(0,k+1):
  ans += m*pow(m-1,n-1-i,mod)*cmb(n-1,i,p)
  ans %= mod
print(ans)
Problem p02687 (python)

Fixed submission:
s = input()
if s == "ABC":
  print("ARC")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
n = int(input())
from collections import Counter
a = list(map(int,input().split()))
b = []
for i in range(n):
  b.append(a[i]-i-1)
b = Counter(b)
k = -a[0]-1
a.append(10**10)
ans = 0
for i in range(n):
  ans += b[k]
  k -= 1
  k += a[i]-a[i+1]
print(ans)
Problem p02697 (python)

Fixed submission:
n,m = map(int,input().split())
ans=[]
if m%2==1:
  for i in range(m//2):
    print(i+1,m-i)
  for i in range(m//2+1):
    print(m+1+i,2*m+1-i)
else:
  for i in range(m//2):
    print(i+1,m-i+1)
  for i in range(m//2):
    print(m+2+i,2*m+1-i)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
if n%2 == 1:
  for i in range(m):
    print(i+1,2*m-i)
else:
  ans = [[i+1] for i in range(m)]
  t = n
  for i in range(m):
    if t == i+1+n//2:
      t -= 1
    ans[i].append(t)
    t -= 1
print(ans)
Problem p02698 (python)

Fixed submission:
import bisect
import sys
sys.setrecursionlimit(10**9)
n = int(input())
a = [0]+list(map(int,input().split()))
tree = [[] for _ in range(n+1)]
for _ in range(n-1):
  u,v = map(int,input().split())
  tree[u].append(v)
  tree[v].append(u)
#print(tree)
d = [float("inf")]*(n+1)
ans = [0]*(n+1)

def dfs(now, pre):
  i = bisect.bisect_left(d, a[now])
  tmp = d[i]
  d[i] = a[now]
  ans[now] = bisect.bisect_left(d, float("inf"))
  for nxt in tree[now]:
    if nxt == pre:
      continue
    dfs(nxt, now)
  d[i] = tmp
dfs(1,-1)

for i in ans[1:]:
  print(i)

Buggy submission (verdict: Runtime Error):
import bisect
import sys
sys.setrecursionlimit(10**9)
n = int(input())
a = [0]+list(map(int,input().split()))
tree = [[] for _ in range(n+1)]
for _ in range(n-1):
  u,v = map(int,input().split())
  tree[u].append(v)
  tree[v].append(u)
#print(tree)
d = [float("inf")]*(n+1)
ans = [0]*(n+1)

def dfs(now, pre):
  print(now,pre)
  i = bisect.bisect_left(d, a[now])
  tmp = d[i]
  d[i] = a[now]
  ans[now] = bisect.bisect_left(d, float("inf"))
  print(d)
  for nxt in tree[now]:
    if nxt == pre:
      continue
    dfs(nxt, now)
  d[i] = tmp
dfs(1,-1)

for i in ans[1:]:
  print(i)
Problem p02721 (python)

Fixed submission:
n,k,c = map(int,input().split())
s = [i == "o" for i in list(input())]
i = 0
cnt = 0
l = [0]*n
r = [0]*n
while i < n:
    if s[i]:
        cnt += 1
        for j in range(i,c+i+1):
            if j < n:
                l[j] = cnt
        i += c+1
    else:
        l[i] = cnt
        i += 1
i = n-1
cnt = 0
while i >= 0:
    if s[i]:
        cnt += 1
        for j in range(i,i-1-c,-1):
            if j >= 0:
                r[j] = cnt
        i -= c+1
    else:
        r[i] = cnt
        i -= 1
#print(l,r)
r.append(0)
if r[1] < k:
    print(1)
for i in range(1,n-1):
    if not s[i]:
        continue
    if l[i-1] + r[i+1] < k:
        print(i+1)
if l[n-2] < k:
    print(n)

Buggy submission (verdict: Runtime Error):
n,k,c = map(int,input().split())
s = [i == "o" for i in list(input())]
i = 0
cnt = 0
l = [0]*n
r = [0]*n
while i < n:
    if s[i]:
        cnt += 1
        for j in range(i,c+i+1):
            if j < n:
                l[j] = cnt
        i += c+1
    else:
        l[i] = cnt
        i += 1
i = n-1
cnt = 0
while i >= 0:
    if s[i]:
        cnt += 1
        for j in range(i,i-1-c,-1):
            if j >= 0:
                r[j] = cnt
        i -= c+1
    else:
        r[i] = cnt
        i -= 1
#print(l,r)
if r[1] < k:
    print(1)
for i in range(1,n-1):
    if not s[i]:
        continue
    if l[i-1] + r[i+1] < k:
        print(i+1)
if l[n-2] < k:
    print(n)
Problem p02727 (python)

Fixed submission:
from collections import deque
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)
l = p[:x] + q[:y] + r
l.sort(reverse=True)
print(sum(l[:(x+y)]))

Buggy submission (verdict: Runtime Error):
from collections import deque
x0,y0,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()
q.sort()
r.sort()
p = deque(p)
q = deque(q)
r = deque(r)
x,y = 0,0
red = p.pop()
green = q.pop()
mu = r.pop()
ans = 0

def newmu():
  if r:
    return r.pop()
  return 0


while x < x0 or y < y0:
  if x < x0 and y < y0:
    if red >= mu and green >= mu:
      ans += red + green
      red = p.pop()
      green = q.pop()
    elif red >= mu:
      ans += red + mu
      red = p.pop()
      mu = newmu()
    elif green >= mu:
      ans += green + mu
      green = q.pop()
      mu = newmu()
    elif r:
      r2 = r.pop()
      if red >= green and red >= r2:
        ans += mu + red
        mu = r2
        red = p.pop()
      elif green >= red and green >= r2:
        ans += mu + green
        mu = r2
        green = q.poop()
      else:
        ans += mu + r2
        mu = newmu()
    elif red >= green:
      ans += mu + red
      red = p.pop()
      newmu()
    else:
      ans += mu + green
      green = q.pop()
      newmu()
    x += 1
    y += 1
  elif x < x0:
    if red >= mu:
      ans += red
      red = p.pop()
    else:
      ans += mu
      newmu()
    x += 1
  else:
    if green >= mu:
      ans += green
      green = q.pop()
    else:
      ans += mu
      newmu()
    y += 1
print(ans)
Problem p02741 (python)

Fixed submission:
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][int(input())-1])

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
if (h*w)%2 == 0:
  print((h*w)//2)
else:
  print((h*w)//2+1)
Problem p02814 (python)

Fixed submission:
from math import gcd
def lcm(x,y):
    return x*y//gcd(x,y)
def cnt(x):
    i = 0
    while x%2 == 0:
        x = x//2
        i += 1
    return i 
n,m = map(int,input().split())
a = list(map(int,input().split()))
memo = cnt(a[0])
for i in range(n):
    if cnt(a[i]) != memo:
        print(0)
        quit()
    a[i] = a[i]//2

t = 1
for i in range(n):
    t = lcm(t,a[i])
print(m//t-m//(2*t))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
def lcm(a, b):
  return a * b // gcd(a, b)
q = a[0]//2
for i in range(n):
  a = a[i]//2
  q = lcm(q,a)
cnt = 0
while True:
  for i in range(n):
    if a[i] % 2 == 0:
      cnt += 1
    else:
      a[i]//1
    if cnt:
      break
ans = (m//q) - (m//(2*q))
if cnt == n:
  print(ans)
else:
  print(0)
Problem p02885 (python)

Fixed submission:
a,b = map(int,input().split())
print(max(0,int(a-2*b)))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
print(max(0,int(a-2b)))
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n,q = map(int,input().split())
t = [[] for _ in range(n+1)]
for _ in range(n-1):
  a,b = map(int,input().split())
  t[a].append(b)
  t[b].append(a)
cnt = [0]*(n+1)
for _ in range(q):
  p,x = map(int,input().split())
  cnt[p] += x
def csum(now,bef):
  for i in t[now]:
    if i != bef:
      cnt[i] += cnt[now]
      csum(i,now)
csum(1,0)
print(*cnt[1:])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n,q = map(int,input().split())
t = [[] for _ in range(n+1)]
for _ in range(n-1):
  a,b = map(int,input().split())
  t[a].append(b)
  t[b].append(a)
cnt = [0]*(n+1)
for _ in range(q):
  p,x = map(int,input().split())
  cnt[p] += x
def csum(now,bef):
  for i in t[now]:
    if i != bef:
      cnt[i] += cnt[now]
      csum(i,now)
csum(1,0)
for i in range(1,n+1):
  print(cnt[i],end=" ")
Problem p02947 (python)

Fixed submission:
n = int(input())
l = ["".join(sorted(input())) for _ in range(n)]
ans = 0
d = {}
for i in range(n):
  if l[i] not in d:
    d[l[i]] = 1
  else:
    ans += d[l[i]]
    d[l[i]] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = ["".join(sorted(input())) for _ in range(n)]
nCr = {}
def cmb(n, r):
  if r == 0 or r == n: return 1
  if r == 1: return n
  if (n,r) in nCr: return nCr[(n,r)]
  nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
  return nCr[(n,r)]

d = {}
for i in range(n):
  if l[i] not in d:
    d[l[i]] = 1
  else:
    d[l[i]] += 1
#print(d)
    
ans = 0
for a in d.values():
  #print(a)
  if a > 1:
    ans += cmb(a,2)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = ["".join(sorted(input())) for _ in range(n)]
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

d = {}
for i in range(n):
  if l[i] not in d:
    d[l[i]] = 1
  else:
    d[l[i]] += 1

ans = 0
for a in d.values():
  if a > 1:
    ans += cmb(a,2)
print(ans)
Problem p02953 (python)

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
lowest = h[0]-1
for i in range(1,n):
  if h[i] < lowest:
    print("No")
    quit()
  else:
    lowest = max(lowest,h[i]-1)
print("Yes")

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))
lowest = h[i]
for i in range(1,n):
  if h[i] < lowest - 1:
    print("No")
    quit()
  else:
    lowest = max(lowest,h[i]-1)
print("Yes")
Problem p03001 (python)

Fixed submission:
w,h,x,y = map(int,input().split())
if x == w/2 and y == h/2:
  flag = 1
else:
  flag = 0
print(h*w/2,flag)

Buggy submission (verdict: Runtime Error):
w,h,x,y = map(int,input().split())
if x == w/2 and y = h/2:
  flag = 1
else:
  flag = 0
print(h*w/2,flag)
Problem p03109 (python)

Fixed submission:
if int(input()[5:7]) >= 5:
  print("TBD")
else:
  print("Heisei")

Buggy submission (verdict: Runtime Error):
import bisect
a,b,q = map(int,input().split())
s = [-10**11]+[int(input()) for _ in range(a)]+[10**11]
t = [-10**11]+[int(input()) for _ in range(b)]+[10**11]
for i in range(q):
  ans = 10**11
  x = int(input())
  l = bisect.bisect(s,x)
  m = bisect.bisect(t,x)
  arr = [[s[l-1],s[l]],[t[m-1],t[m]]]
  for i in range(4):
    S = 0
    now = x
    for j in range(2):
      S += (now-arr[j][i >> j & 1])*(-1)**(((now-arr[j][i >> j & 1])<0))
      now = arr[j][i >> j & 1]
    if ans > S:
      ans = S
  for i in range(4):
    S = 0
    now = x
    for j in range(2):
      S += (now-arr[1-j][i >> j & 1])*((-1)**((now-arr[1-j][i >> j & 1])<0))
      now = arr[1-j][i >> j & 1]
    if ans > S:
      ans = S
  print(ans)
Problem p03155 (python)

Fixed submission:
n = int(input())
h = int(input())
w = int(input())
print(max(0,n-w+1)*max(0,n-h+1))

Buggy submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def calc(i,j):
    return i*w+j
def calc_inv(x):
    return x//w, x%w
def judge(x,y):
    i0,j0 = calc_inv(x)
    i1,j1 = calc_inv(y)
    if s[i0][j0] != s[i1][j1]:
        return True
    return False


h,w = map(int,input().split())
s = [[(i == "#")*1 for i in list(input())] for _ in range(h)]
uf = UnionFind(h*w)

for i in range(h):
    for j in range(w):
        now = calc(i,j)
        nxt = calc(i+1,j)
        if i+1 < h:
            if judge(now,nxt):
                uf.union(now,nxt)
        nxt = calc(i,j+1)
        if j+1 < w:
            if judge(now,nxt):
                uf.union(now,nxt)


cnt = [[0,0] for _ in range(h*w)]
ind = 0
for l in uf.all_group_members().values():
    for x in l:
        i,j = calc_inv(x)
        if s[i][j]:
            cnt[ind][0] += 1
        else:
            cnt[ind][1] += 1
    ind += 1
ans = 0
for i in range(ind):
    ans += cnt[i][0]*cnt[i][1]
print(ans)
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())
if s[0] != "1":
  print(s[0])
  quit()
c = 0
while s[c] == "1":
  c += 1
  if c == len(s):
    print(1)
    quit()
if c < k:
  print(s[c])
else:
  print(s[k-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
if s[0] != "1":
  print(s[0])
  quit()
c = 0
while s[c] == "1":
  c += 1
if c < k:
  print(s[c])
else:
  print(s[k-1])