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

Fixed submission:
N = int(input())
X = input()
val = int(X,2)
C = X.count("1")

if C==1:
  for i in range(N):
    if X[i]=='1':
      print(0)
    elif i==N-1:
      print(2)
    else:
      print(1)
  exit()

# xをpopcountで割ったあまりに置き換える
def f(x):
  if x==0: return 0
  return 1 + f(x % bin(x).count("1"))

# 初回のpopcountでの割り方は、(C+1) or (C-1)
Y = val%(C+1)
if C-1 != 0:
  Z = val%(C-1)
else:
  Z = 0

for i in range(N):
  if X[i] == "1":
    if Z - 1 == 0:
      print(0)
      continue
    k = (Z - pow(2,N-i-1,C-1)) % (C-1)
  else:
    k = (Y + pow(2,N-i-1,C+1)) % (C+1)
  print(f(k)+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = input()
val = int(X,2)
C = X.count("1")

# xをpopcountで割ったあまりに置き換える
def f(x):
  if x==0: return 0
  return 1 + f(x % bin(x).count("1"))

# 初回のpopcountでの割り方は、(C+1) or (C-1)
Y = val%(C+1)
if C-1 != 0:
  Z = val%(C-1)
else:
  Z = 0

for i in range(N):
  if X[i] == "1":
    if Z - 1 == 0:
      print(0)
      continue
    k = (Z - pow(2,N-i-1,C-1)) % (C-1)
  else:
    k = (Y + pow(2,N-i-1,C+1)) % (C+1)
  print(f(k)+1)

Buggy submission (verdict: Runtime Error):

import sys
sys.setrecursionlimit(10**6)

n = int(input())
x = input()
xi = int('0b' + x, 2)
xc = x.count("1")

if xc == 0:
  for _ in range(n):
    print(1)
  exit()

xip = xi % (xc+1)
xim = xi % (xc-1)

def f(u):
  if u==0: return 0
  m = u % bin(u).count("1")
  return 1 + f(m)

for i in range(n):
  if x[i] == "0":
    # y = xip + (pow(2, n-i-1, )%(xc+1))
    y = xip + pow(2, n-i-1, xc+1)
    y = y % (xc+1)
  elif xc == 1:
    print(0)
    continue
  else:
    # y = xim - (pow(2, n-i-1)%(xc-1))
    y = xim - pow(2, n-i-1, xc-1)
    y = y % (xc-1)

  print(f(y)+1)

Buggy submission (verdict: Runtime Error):

import sys
sys.setrecursionlimit(10**6)

n = int(input())
x = input()
xi = int('0b' + x, 2)
xc = x.count("1")

xip = xi % (xc+1)
xim = xi % (xc-1)

def f(u):
  if u==0: return 0
  m = u % bin(u).count("1")
  return 1 + f(m)

for i in range(n):
  if x[i] == "0":
    # y = xip + (pow(2, n-i-1, )%(xc+1))
    y = xip + pow(2, n-i-1, xc+1)
    y = y % (xc+1)
  elif xc == 1:
    print(0)
    continue
  else:
    # y = xim - (pow(2, n-i-1)%(xc-1))
    y = xim - pow(2, n-i-1, xc-1)
    y = y % (xc-1)

  print(f(y)+1)

Buggy submission (verdict: Runtime Error):

import sys
sys.setrecursionlimit(10**6)

n = int(input())
x = input()
xi = int('0b' + x, 2)
xc = x.count("1")

xip = xi % (xc+1)
xim = xi % (xc-1)

def f(u):
  if u==0: return 0
  m = u % bin(u).count("1")
  return 1 + f(m)

for i in range(n):
  if x[i] == "0":
    # y = xip + (pow(2, n-i-1, )%(xc+1))
    y = xip + pow(2, n-i-1, xc+1)
    y = y % (xc+1)
  else:
    # y = xim - (pow(2, n-i-1)%(xc-1))
    y = xim - pow(2, n-i-1, xc-1)
    y = y % (xc-1)

  print(f(y)+1)

Buggy submission (verdict: Runtime Error):

n = int(input())
x = input()
xi = int('0b' + x, 2)
xc = x.count("1")

xip = xi % (xc+1)
xim = xi % (xc-1)

def f(u):
  if u==0: return 0
  m = u % bin(u).count("1")
  return 1 + f(m)

for i in range(n):
  if x[i] == "0":
    y = xip + (pow(2, n-i-1)%(xc+1))
    y = y % (xc+1)
  else:
    y = xim - (pow(2, n-i-1)%(xc-1))
    y = y % (xc-1)

  print(f(y)+1)
Problem p02612 (python)

Fixed submission:
n = int(input())

i = n%1000
if i != 0:
  print(1000-i)
else:
  print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())

i = n//1000
print(min(n%(1000*i), (1000*(i+1))%n))
Problem p02616 (python)

Fixed submission:
n,k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7
# s=正の数、t=負の数
s,t = [], []
for a in A:
  if a<0:
    t.append(a)
  else:
    s.append(a)

S = len(s)
T = len(t)
ok = False
if (S>0):
  if n==k:
    # すべての負の数をペアにできる
    ok = T%2==0
  else:
    # 負の数は考慮しない
    ok = True
else:
  # kが偶数個
  ok = (k%2==0)

ans = 1
if not ok:
  A.sort(key=lambda x: abs(x))
  for i in range(k):
    ans *= A[i]
    ans %= MOD
else:
  s.sort()
  t.sort(reverse=True)
  if k%2==1:
    ans *= s.pop()
    ans %= MOD

  p = []
  while len(s) >= 2:
    x = s.pop()
    x *= s.pop()
    p.append(x)

  while len(t) >= 2:
    x = t.pop()
    x *= t.pop()
    p.append(x)

  p.sort(reverse=True)
  for i in range(k//2):
    ans *= p[i]
    ans %= MOD

print(ans % MOD)

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

if k==n:
  res = 1
  for a in A:
    res *= a
  print(res % MOD)
elif k%2==1 and all([ a<0 for a in A ]):
  A.sort(reverse=True)
  res = 1
  for i in range(k):
    res *= A[i]
  print(res % MOD)
else:
  absSorted = sorted(A,key=lambda x: abs(x), reverse=True)
  res = 1
  plus = Counter()
  minus = Counter()
  for i in range(k):
    res *= absSorted[i]
    if absSorted[i] < 0:
      minus[absSorted[i]] += 1
    else:
      plus[absSorted[i]] += 1

  if res < 0:
    counter = Counter(A)
    # (1) 負の数の中で絶対値が一番小さいものを1つ取り除き、非負の数の中で最大のものを一つ加える
    minusKeys = sorted(minus.keys(), reverse=True)
    tmp1 = res // minusKeys[0]
    for k in sorted(counter.keys(), reverse=True):
      if plus[k] < counter[k]:
        tmp1 *= k
        break

    # (2) 正の数を1つ取り除き、負の数を一つ加える
    plusKeys = sorted(plus.keys())
    tmp2 = res // plusKeys[0]
    for k in sorted(counter.keys()):
      if minus[k] < counter[k]:
        tmp2 *= k
        break

    print(max(tmp1, tmp2) % MOD)
  else:
    print(res)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

cumsum = [1]
for a in A:
  cumsum.append(cumsum[-1]*a)

res = -10**16
for i in range(k, n+1):
  res = max(res, cumsum[i]//cumsum[i-k])

print(res%MOD)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

cumsum = [1]
for a in A:
  cumsum.append(cumsum[-1]*a)

res = -10**16
for i in range(k, n+1):
  res = max(res, cumsum[i]//cumsum[i-k])

print(res%MOD)
Problem p02642 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
A.sort()
c = Counter(A)
lst = [1] * (10**6+1)
res = 0

for i,a in enumerate(A):
  if lst[a] == 0: continue
  if i==N-1 or A[i+1] != a:
    res += 1
  for j in range(a, 10**6+1, a):
    lst[j] = 0

print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A.sort()
c = Counter(A)
lst = [1] * (10**6+1)
res = 0

for i,a in enumerate(A):
  if lst[a] == 0: continue
  if i==N-1 or A[i+1] != a:
    res += 1
  for j in range(a, 10**6+1, a):
    lst[j] = 0

print(res)
Problem p02646 (python)

Fixed submission:
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if v <= w:
  print("NO")
  exit()
d = abs(a-b)
if (v-w)*t >= d:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

A = A-B
B = 0

if A+V*T >= B+W*T:
  x = (B-A) / (V-W)
  print(x)
  if x <= T:
    print("YES")
  else:
    print("NO")
else:
  print("NO")
Problem p02660 (python)

Fixed submission:
import math
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(math.sqrt(n))+1):
    if temp%i == 0:
      cnt = 0
      while temp%i == 0:
        cnt += 1
        temp //= i
      arr.append([i, cnt])
  if temp != 1:
    arr.append([temp, 1])
  if arr == []:
    arr.append([n, 1])
  return arr

n = int(input())
factors = factorization(n)
res = 0
for j,cnt in factors:
  if j == 1: continue
  i = 1
  while cnt >= i:
    cnt -= i
    i += 1
    res += 1

print(res)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
def is_prime(x):
    if x < 2: return False
    if x == 2 or x == 3 or x == 5: return True 
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False

    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

def prime_factorization(n):
  d = 2
  cnt = 0
  seen = []
  while d*d <= n:
    if n%d == 0:
      t = 1
      while d**t <= n:
        if n % (d**t) == 0:
          seen.append(d**t)
          n //= (d**t)
          cnt += 1
          t += 1
        else:
          break
    d += 1
 
  if n != 1 and is_prime(n):
    cnt += 1
 
  return cnt
 
n = int(input())
print(prime_factorization(n))

Buggy submission (verdict: Runtime Error):
def is_prime(x):
    if x < 2: return False
    if x == 2 or x == 3 or x == 5: return True 
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False

    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

def prime_factorization(n):
  d = 2
  cnt = 0
  seen = []
  while d*d <= n:
    if n%d == 0:
      t = 1
      while d**t <= n:
        if n % (d**t) == 0:
          seen.append(d**t)
          n //= (d**t)
          cnt += 1
          t += 1
        else:
          break
    d += 1
 
  if n != 1 and is_prime(n):
    cnt += 1
 
  return cnt
 
n = int(input())
print(prime_factorization(n))
Problem p02702 (python)

Fixed submission:
from collections import Counter
S = input()[::-1]
MOD = 2019
X = [0]
for i, s in enumerate(S):
  X.append((X[-1] + int(s)*pow(10,i,MOD)) % MOD)

C = Counter(X)
res = 0
for v in C.values():
  res += v*(v-1) // 2

print(res)

Buggy submission (verdict: Runtime Error):
S = input()[::-1]
cur = 0
mods = Counter()
mods[0] += 1
MOD = 2019
for i,d in enumerate(S):
  cur += int(d) * pow(10, i, MOD)
  mods[cur%MOD] += 1

res = 0
for k,v in mods.items():
  res += (v * (v-1) // 2)

print(res)

Buggy submission (verdict: Runtime Error):
S = "1817181712114"
N = len(S)
ans = 0
x = 1
# 累積和を格納
tot = 0
# 累積和のmod 2019をカウントする
cnt = [0] * 2019

for i in range(N)[::-1]:
  cnt[tot] += 1

  tot += int(S[i]) * x
  tot %= 2019
  if cnt[tot] > 0:
    import pdb; pdb.set_trace()
  ans += cnt[tot]
  x *= 10

print(ans)
Problem p02730 (python)

Fixed submission:
def is_palindrome(str):
  i, j = 0, len(str)-1
  while i <= j:
    if str[i] != str[j]:
      return False
    i += 1
    j -= 1

  return True

s = input()
n = len(s)
if is_palindrome(s) and is_palindrome(s[0:((n-1)//2)]) and is_palindrome(s[(n+3)//2-1:]):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
def is_palindrome(str):
  i, j = 0, len(str)-1
  while i >= j:
    if str[i] != str[j]:
      return False
    i += 1
    j -= 1

  return True

s = input()
n = len(s)
if is_palindrome(s) and is_palindrome(s[0:((n-1)//2)]) and is_palindrome(s[(n+3)//2-1:]):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
def is_palindrome(str):
  i, j = 0, len(str)-1
  while i != j:
    if str[i] != str[j]:
      return False
    i += 1
    j -= 1

  return True

s = input()
n = len(s)
if is_palindrome(s) and is_palindrome(s[0:((n-1)//2)]) and is_palindrome(s[(n+1)//2:]):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
def is_palindrome(str):
  i, j = 0, len(str)-1
  while i != j:
    if str[i] != str[j]:
      return False
    i += 1
    j -= 1

  return True

s = input()
n = len(s)
if is_palindrome(s) and is_palindrome(s[0:((n-1)//2)]) and is_palindrome(s[(n+3)//2-1:n]):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
def is_palindrome(str):
  i, j = 0, len(str)-1
  while i != j:
    if str[i] != str[j]:
      return False
    i += 1
    j -= 1

  return True

s = input()
n = len(s)
if is_palindrome(s) and is_palindrome(s[0:((n-1)//2)]) and is_palindrome(s[(n+3)//2-1:n]):
  print("Yes")
else:

Buggy submission (verdict: Runtime Error):
# 1. S is Palindrome
# 2. S[1, (N-1)//2]
# 3. S[(N+3)//2, N]

def is_palindrome(str):
  i, j = 0, len(str)-1
  while i != j:
    if str[i] != str[j]:
      return False
    i += 1
    j -= 1

  return True

s = input()
n = len(s)
print(is_palindrome(s) and is_palindrome(s[0:((n-1)//2)]) and is_palindrome(s[(n+3)//2-1:n]))
Problem p02760 (python)

Fixed submission:

bingo = [ list(map(int, input().split())) for _ in range(3) ]
t_or_f = [ [False]*3 for _ in range(3) ]

nums = [ r[i]for i in range(3) for r in bingo ]

n = int(input())
appear = [ int(input()) for _ in range(n) ]

for x in range(3):
  for y in range(3):
    if bingo[x][y] in appear:
      t_or_f[x][y] = True

is_bingo = False
if t_or_f[0][0] and t_or_f[1][1] and t_or_f[2][2]:
  is_bingo = True
elif t_or_f[0][2] and t_or_f[1][1] and t_or_f[2][0]:
  is_bingo = True
else:
  for i in range(3):
    if t_or_f[i][0] and t_or_f[i][1] and t_or_f[i][2]: is_bingo = True
    if t_or_f[0][i] and t_or_f[1][i] and t_or_f[2][i]: is_bingo = True

if is_bingo:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
import sys

bingo = [ list(map(int, input().split())) for _ in range(3) ]
t_or_f = [ [False]*3 for _ in range(3) ]

nums = [ r[i]for i in range(3) for r in bingo ]

n = int(input())
appear = [ int(input()) for _ in range(n) ]

for x in range(3):
  for y in range(3):
    if bingo[x][y] in appear:
      t_or_f[x][y] = True

is_bingo = False
if t_or_f[0][0] and t_or_f[1][1] and t_or_f[2][2]:
  is_bingo = True
  print('Yes')
elif t_or_f[0][2] and t_or_f[1][1] and t_or_f[2][0]:
  is_bingo = True
  print('Yes')
else:
  for i in range(3):
    if t_or_f[i][i] and t_or_f[i+1][i+1] and t_or_f[i+2][i+2]:
      is_bingo = True
      print('Yes')
      sys.exit()

if not is_bingo: print('No')

Buggy submission (verdict: Runtime Error):
import sys

bingo = [ list(map(int, input().split())) for _ in range(3) ]
t_or_f = [ [False]*3 for _ in range(3) ]

nums = [ r[i]for i in range(3) for r in bingo ]

n = int(input())
for _ in range(n):
  i = int(input())

  if i in nums:
    for x in range(3):
      for y in range(3):
        if bingo[x][y] == i:
          t_or_f[x][y] = True
          break


is_bingo = False
if t_or_f[0][0] and t_or_f[1][1] and t_or_f[2][2]:
  is_bingo = True
  print('Yes')
elif t_or_f[0][2] and t_or_f[1][1] and t_or_f[2][0]:
  is_bingo = True
  print('Yes')
else:
  for i in range(3):
    if t_or_f[i][i] and t_or_f[i+1][i+1] and t_or_f[i+2][i+2]:
      is_bingo = True
      print('Yes')
      sys.exit()

if not is_bingo: print('No')

Buggy submission (verdict: Runtime Error):
bingo = [ list(map(int, input().split())) for _ in range(3) ]
t_or_f = [ [False]*3 for _ in range(3) ]

n = int(input())
for _ in range(n):
  i = int(input())

  for x in range(3):
    for y in range(3):
      if bingo[x][y] == i:
        t_or_f[x][y] = True
        break


is_bingo = False
if t_or_f[0][0] and t_or_f[1][1] and t_or_f[2][2]:
  is_bingo = True
  print('Yes')
elif t_or_f[0][2] and t_or_f[1][1] and t_or_f[2][0]:
  is_bingo = True
  print('Yes')
else:
  for i in range(3):
    if t_or_f[i][i] and t_or_f[i+1][i+1] and t_or_f[i+2][i+2]:
      is_bingo = True
      print('Yes')

if not is_bingo: print('No')
Problem p02774 (python)

Fixed submission:
from bisect import bisect_left, bisect_right
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
neg_end = bisect_left(A, 0)
pos_start = bisect_right(A, 0)

pos_cnt = N - pos_start
neg_cnt = neg_end
zero_cnt = N - (pos_cnt + neg_cnt)

neg_pairs_cnt = pos_cnt * neg_cnt
zero_pairs_cnt = zero_cnt * (pos_cnt + neg_cnt) + (zero_cnt * (zero_cnt-1) // 2)

if K <= neg_pairs_cnt:
  # X以下のpairはK個以上あるか？
  ok, ng = 0, -10**18
  while abs(ok - ng) > 1:
    X = (ok+ng) // 2
    or_higher_cnt, r = 0, pos_start
    # それぞれのnegごとに尺取り法
    for l in range(neg_end):
      while r < N and A[l] * A[r] > X:
        r += 1
      # positive_integers - (max_point - positive_start_index)
      or_higher_cnt += pos_cnt - (r - pos_start)

    if or_higher_cnt >= K:
      ok = X
    else:
      ng = X
  print(ok)

elif K <= neg_pairs_cnt + zero_pairs_cnt:
  print(0)

else:
  K -= (neg_pairs_cnt + zero_pairs_cnt)
  ok, ng = 10**18, 0
  while abs(ok - ng)> 1:
    X = (ok+ng) // 2
    or_higher_cnt = 0

    r = N - 1
    for l in range(pos_start, N):
      while r < N and A[l] * A[r] > X and l < r:
        r -= 1
      or_higher_cnt += max(0, r-l)

    l = 0
    for r in range(neg_end-1, -1, -1):
      while l < N and A[l] * A[r] > X and l < r:
        l += 1
      or_higher_cnt += max(0, r-l)

    if or_higher_cnt >= K:
      ok = X
    else:
      ng = X

  print(ok)

Buggy submission (verdict: Runtime Error):
import sys

n,k = [ int(i) for i in input().split(" ")]
arr = [ int(i) for i in input().split(" ")]



# 10 40
# 5 4 3 2 -1 0 0 0 0 0

# 30 413
# -170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0

negatives = []
zeros = []
positives = []
tmp = []

for i in arr:
  if i < 0:
    negatives.append(i)
  elif i == 0:
    zeros.append(i)
  else:
    positives.append(i)

negatives.sort()
zeros.sort()
positives.sort()

ngs = len(negatives) * len(positives)
if k < ngs:
  for i in range(len(negatives)):
    for j in range(i+1, len(negatives)):
      tmp.append(arr[i] * arr[j])
      if len(tmp) > k: break

  print(tmp[k-1])
  sys.exit()

k = k - ngs

zs = 0
for i in range(len(zeros)):
  zs += len(arr) - i-1

if k < zs:
  print(str(0))
  sys.exit()

k = k - zs

# positives.extend(negatives)
for i in range(len(positives)):
  for j in range(i+1, len(positives)):
    tmp.append(arr[i] * arr[j])

import pdb; pdb.set_trace()
tmp.sort()
print(tmp[k-1])
Problem p02787 (python)

Fixed submission:
H,N = list(map(int,input().split()))
dp = [float("inf")] * (H+1)

for i in range(N):
  a,b = list(map(int,input().split()))

  for h in range(1, H+1):
    if h - a <= 0:
      dp[h] = min(dp[h], b)
    else:
      dp[h] = min(dp[h], b + dp[h - a])

print(dp[-1])

Buggy submission (verdict: Runtime Error):
import math
H,N = list(map(int,input().split()))
A, B = [], []
for _ in range(N):
  a,b = list(map(int,input().split()))
  A.append(a)
  B.append(b)
dp = [math.inf] * (H+1)

for h in range(1, H+1):
  for i in range(N):
      if h - A[i] <= 0:
          dp[h] = min(dp[h], B[i])
      else:
          dp[h] = min(dp[h], B[i] + dp[h - A[i]])

print(dp[-1])

Buggy submission (verdict: Runtime Error):
H,N = list(map(int,input().split()))
A, B = [], []
for _ in range(N):
  a,b = list(map(int,input().split()))
  A.append(a)
  B.append(b)
dp = [math.inf] * (H+1)

for h in range(1, H+1):
  for i in range(N):
      if h - A[i] <= 0:
          dp[h] = min(dp[h], B[i])
      else:
          dp[h] = min(dp[h], B[i] + dp[h - A[i]])

print(dp[-1])
Problem p02801 (python)

Fixed submission:
inp = input()

import string
alphabets = list(string.ascii_lowercase)

print(alphabets[alphabets.index(inp) + 1])

Buggy submission (verdict: Runtime Error):
num_of_subs, full_score, avg = [ int(i) for i in input().split(" ") ]
prevScores =  0
for i in input().split(" "):
  prevScores += int(i)

last_score = (avg * num_of_subs) - prevScores

if last_score <= 0:
  print(0)
else:
  if last_score >= 100:
    print(-1)
  else:
    print(last_score)
Problem p02811 (python)

Fixed submission:
k, a = map(int, input().split())
 
if k * 500 >= a:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
k, a = map(int(), input().split())
 
if k * 500 >= a:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
k, a = map(int(), input())

if k * 500 >= a:
  print('Yes')
else:
  print('No')
Problem p02822 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N = int(input())
adj = [ [] for _ in range(N+1) ]
for _ in range(N-1):
  a,b = map(int,input().split())
  adj[a].append(b)
  adj[b].append(a)

def dfs(v, p=-1):
  global ans

  res = 1
  ts = []
  for u in adj[v]:
    if (u==p): continue
    t = dfs(u,v)
    res += t
    ts.append(t)

  if p != -1:
    ts.append(N-res)

  # print(v, ts)

  # now = pow(2, N-1, MOD)-1
  now = pows[N-1]-1
  for t in ts:
    # now -= pow(2, t, MOD)-1
    now -= pows[t] - 1
  ans += now
  return res

ans = 0
MOD = 10**9+7
# 高速化1
pows = [1] * (N+1)
for i in range(1, N+1):
  pows[i] = (pows[i - 1] * 2) % MOD

dfs(1)
print((ans * pow(pows[N], MOD-2, MOD)) % MOD)

Buggy submission (verdict: Runtime Error):
N = int(input())
adj = [ [] for _ in range(N+1) ]
for _ in range(N-1):
  a,b = map(int,input().split())
  adj[a].append(b)
  adj[b].append(a)


def dfs(v, p=-1):
  global ans

  res = 1
  ts = []
  for u in adj[v]:
    if (u==p): continue
    t = dfs(u,v)
    res += t
    ts.append(t)

  if p != -1:
    ts.append(N-res)

  # print(v, ts)

  now = pow(2, N-1, MOD)-1
  for t in ts:
    now -= pow(2, t, MOD)-1
  ans += now
  return res

ans = 0
MOD = 10**9+7
dfs(1)
print((ans * pow(pow(2, N, MOD), MOD-2, MOD)) % MOD)
Problem p02830 (python)

Fixed submission:
length = int(input())
str1, str2 = input().split(" ")

result = ""
for i in range(len(str1)):
  result += str1[i]
  result += str2[i]
 
print(result)

Buggy submission (verdict: Runtime Error):
length = int(input())
str1, str2 = input().split(" ")

result = ""
for i in range(len(str1)):
  result += str1[i]
  result += str2[i]
 
return result
Problem p02837 (python)

Fixed submission:
N = int(input())
conditions = [[] for _ in range(N) ]
for i in range(N):
  a = int(input())
  for _ in range(a):
    x,y = map(int,input().split())
    x -= 1
    conditions[i].append([x,y])

res = 0
for i in range(1<<N):
  mapper = {1: [], 0: []}
  flg = True
  cnt = 0
  for j in range(N):
    if (i>>j)&1:
      cnt += 1
      for x,y in conditions[j]:
        if y==1 and not (i>>x)&1:
          flg = False
          break
        elif y==0 and (i>>x)&1:
          flg = False
          break
    if not flg: 
      break

  if flg:
    res = max(res, cnt)

print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
conditions = [[] for _ in range(N) ]
for i in range(N):
  a = int(input())
  for _ in range(a):
    x,y = map(int,input().split())
    x -= 1
    conditions[i].append([x,y])

res = 0
for i in range(1<<N):
  mapper = {1: [], 0: []}
  flg = True
  cnt = 0
  for j in range(N):
    if (i>>j)&1:
      for x,y in conditions[j]:
        if x in mapper[1-y] or j in mapper[0]:
          flg = False
          break
        mapper[y].append(x)
      cnt += 1
    else:
      for x,y in conditions[j] or j in mapper[1]:
        if x in mapper[y]:
          flg = False
          break
        mapper[1-y].append(x)

    if not flg: break

  if flg:
    res = max(res, cnt)

print(res)
Problem p02850 (python)

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

N = int(input())
adj = [ [] for _ in range(N) ]
for i in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  adj[a].append((b,i))

res = [None] * (N-1)
def dfs(n, c=-1, p=-1):
  if c==-1 or c>1: 
    nc = 1
  else:
    nc = c+1
  for nei,i in adj[n]:
    if nei == p: continue
    res[i] = nc
    dfs(nei, nc, n)
    nc += 1
    if nc==c: nc += 1

dfs(0)
print(max(res))
for r in res: print(r)

Buggy submission (verdict: Runtime Error):
N = int(input())
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  adj[a].append(b)

res = [None] * N
def dfs(n, c=-1, p=-1):
  res[n] = c
  if c==-1 or c>1: 
    nc = 1
  else:
    nc = c+1
  for nei in adj[n]:
    if nei == p: continue
    dfs(nei, nc, n)
    nc += 1
    if nc==c: nc += 1

dfs(0)
res = res[1:]
print(len(set(res)))
for r in res: print(r)