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

Fixed submission:
a = list(map(int, input().split()))
if a.count(5) == 2 and a.count(7) == 1:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
a = map(int, input().split())
if a.count(5) == 2 and a.count(7) == 1:
    print('YES')
else:
    print('NO')
Problem p02579 (python)

Fixed submission:
from collections import deque

H, W = map(lambda x: int(x)+4, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())

grid = '#' * W * 2
for _ in range(H-4):
  grid += '##' + input() + '##'
grid += '#' * W * 2

magic_list = []
for i in range(5):
  for j in range(5):
    if (i, j) in [(2, 2), (1, 2), (2, 1), (2, 3), (3, 2)]:
      continue
    else:
      magic_list.append(i-2 + W*(j-2))

move_list = [-1, 1, W, -W]

def bfs(start):
  INF = 10 ** 9
  dist = [INF] * (H*W)
  dist[start] = 0
  q = deque([start])
  while q:
    v = q.popleft()
    dv = dist[v]
    for move in move_list:
      w = v + move
      if grid[w] == '#':
        continue
      dw = dv
      if dw >= dist[w]:
        continue
      dist[w] = dw
      q.appendleft(w)
    for magic in magic_list:
      w = v + magic
      if grid[w] == '#':
        continue
      dw = dv + 1
      if dw >= dist[w]:
        continue
      dist[w] = dw
      q.append(w)
  return dist

ans = bfs( (Ch+1)*W + Cw+1 )[(Dh+1)*W + Dw+1]

if ans == 10**9:
  print(-1)
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(lambda x: int(x)+4, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())

grid = '#' * W * 2
for _ in range(H-4):
  grid += '##' + input() + '##'
grid += '#' * W * 2

def bfs(start):
  INF = 10 ** 9
  dist = [INF] * (H*W)
  magic = [INF] * (H*W)
  dist[start] = 0
  magic[start] = 0
  q = deque([start])
  move_list = [-1, 1, W, -W]
  mag_list1 = [-2*W, -W, 0, W, 2*W]
  mag_listW = [-2, -1, 0, 1, 2]
  while q:
    v = q.popleft()
    dv = dist[v]
    mv = magc[v]
    magic_list = []
    for move in move_list:
      w = v + move
      if grid[w] == '#':
        magic_list.append(move)
      dw = dv + 1
      if dw >= dist[w]:
        continue
      dist[w] = dw
      q.append(w)
    for move in magic_list:
      if abs(move) == 1:
        for mag in mag_list1:
          w = v + 2*move + mag
          if grid[w] == '#':
            continue
          mw = mv + 1
          if mw >= magic[w]:
            continue
          magic[w] = mw
          q.append(w)
      else:
        for mag in mag_list2:
          w = v + 2*move + mag
          if grid[w] == '#':
            continue
          mw = mv + 1
          if mw >= magic[w]:
            continue
          magic[w] = mw
          q.append(w)
  return magic

print(bfs(W*(2+Ch-1)+2+Cw)[W*(2+Dh-1)+2+Dw])
Problem p02608 (python)

Fixed submission:
N = int(input())
ans = [0]*(N)

if N <= 3:
  for i in range(N):
    print(0)
  exit()

M = int((N-2)**0.5)
 
for x in range(1, M+1):
  for y in range(1, M+1):
    for z in range(1, M+1):
      a = (x+y+z)**2 - (x*y + y*z + z*x)
      if a <= N:
      	ans[a-1] += 1
 
for i in range(N):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = [0]*(N)

M = int((N-2)**0.5)

for x in range(1, M+1):
  for y in range(1, M+1):
    for z in range(1, M+1):
      a = (x+y+z)**2 - (x*y + y*z + z*x)
      if a <= N:
      	ans[a-1] += 1

for i in range(N):
  print(ans[i])
Problem p02609 (python)

Fixed submission:
N = int(input())
X = input()

def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x = x + (x >> 8) 
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f

a = X.count("1")
ap, am = a+1, a-1
Flag = True

if am == 0:
  Flag = False
  am += 1

Ap = [1]
Am = [1]

for i in range(N-1):
  Ap.append(Ap[-1]*2%ap)
  Am.append(Am[-1]*2%am)

Aps = 0
Ams = 0

for i in range(N):
  if X[-1-i] == "1":
    Aps += Ap[i]
    Aps %= ap
    Ams += Am[i]
    Ams %= am 

for i in range(N):
  cnt = 1
  if X[i] == "1":
    if Flag:
      p = Ams - Am[-1-i]
      p %= am
    else:
      cnt -= 1
      p = 0
  else:
    p = Aps + Ap[-1-i]
    p %= ap
  temp = p
  while temp > 0:
    temp %= popcount(temp)
    cnt += 1
  print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = input()

def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x = x + (x >> 8) 
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f

a = X.count("1")
ap, am = a+1, a-1

Ap = []
Am = []
temp = 1

for i in range(N):
  if i == 0:
    Ap.append(temp%ap)
    Am.append(temp%am)
  else:
    temp *= 2
    Ap.append(temp%ap)
    Am.append(temp%am)

Aps = 0
Ams = 0

for i in range(N):
  if X[-1-i] == "1":
    Aps += Ap[i]
    Aps %= ap
    Ams += Am[i]
    Ams %= am

for i in range(N):
  cnt = 1
  if X[i] == "1":
    p = Ams - Am[-1-i]
    p %= am
  else:
    p = Aps + Ap[-1-i]
    p %= ap
  temp = p
  while temp > 0:
    temp %= popcount(temp)
    cnt += 1
  print(cnt)
Problem p02616 (python)

Fixed submission:
import copy

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

mod = 10**9 + 7

Am, Ap = [], []
pm = [0, 0]
B = []

def ans(A):
  ans = 1
  for x in A:
    ans *= x
    ans %= mod
  return ans

if N == K:
  print(ans(A))
  exit()

for x in A:
  if x < 0:
    Am.append(-x)
    B.append((-x, 1))
    pm[0] += 1
  else:
    Ap.append(x)
    B.append((x, 0))
    pm[1] += 1

Am.sort()

if pm[0] == N:
  if K%2 == 0:
    print(ans(Am[N-K:]))
  else:
    print((-1 * ans(Am[:K]))%mod)
  exit()

P = []
B.sort(reverse = True)

cnt = 0

p_min = (-1, -1)
m_min = (-1, -1)

for i in range(K):
  P.append(B[i][0])
  cnt ^= B[i][1]
  if B[i][1] == 0:
    p_min = (B[i][0], i)
  else:
    m_min = (B[i][0], i)

if cnt == 0:
  print(ans(P))
  exit()

P1 = copy.deepcopy(P)
P2 = copy.deepcopy(P)

p_max = (-1, -1)
m_max = (-1, -1)

for i in range(K, N):
  if B[i][1] == 0:
    p_max = (B[i][0], i)
    break

for i in range(K, N):
  if B[i][1] == 1:
    m_max = (B[i][0], i)
    break

Flag1 = False
Flag2 = False

if p_min[1] != -1 and m_max[1] != -1:
  Flag1 = True
  P1[p_min[1]] = 1
  P1.append(m_max[0])
  ans1 = ans(P1)

if m_min[1] != -1 and p_max[1] != -1:
  Flag2 = True
  P2[m_min[1]] = 1
  P2.append(p_max[0])
  ans2 = ans(P2)

if Flag1 and Flag2:
  if m_min[0]*m_max[0] > p_min[0]*p_max[0]:
    print(ans1)
  else:
    print(ans2)
elif Flag1:
  print(ans1)
else:
  print(ans2)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10**9 + 7

Am, Ap = [], []
pm = [0, 0, 0]
Flag = True

for x in A:
  if x < 0:
    Am.append(-x)
    pm[0] += 1
  elif x == 0:
    pm[1] += 1
  else:
    Ap.append(x)
    pm[2] += 1

Am.sort()
Ap.sort()
ans = 1

if N-K < pm[1]:
  print(0)
  exit()

if pm[0] == N:
  for i in range(K):
    ans *= Am[i]
    ans %= mod
  ans *= (-1)
  print(ans%mod)
  exit()

Bm = sorted(zip(Am, [1]*pm[0]))
Bp = sorted(zip(Ap, [0]*pm[2]))

B = Bm + Bp
B.sort(reverse = True)
cnt = 0

for i in range(K):
  if i == K-1:
    cnt %= 2
    if cnt != B[i][1]:
      break
    else:
      ans *= B[i][0]
      ans %= mod
      print(ans)
      exit()
  else:
    ans *= B[i][0]
    ans %= mod
    cnt += B[i][1]

ans1 = ans
ans2 = ans * B[K][0] % mod

mcnt1 = 0
for i in range(K, N-pm[1]):
  if B[i][1] == cnt:
    mcnt1 += 1
    ans1 *= B[i][0]
    ans1 %= mod
    break

#mcnt2 = 0
for i in range(K-1, -1, -1):
  if B[i][1] == cnt:
    #mcnt2 += 1
    r = pow(B[i][0], mod-2, mod)
    ans1 *= r
    ans1 %= mod
    break

if mcnt1 == 1:
  print(max(ans1, ans2))
else:
  print(ans2)
Problem p02632 (python)

Fixed submission:
K = int(input())
S = input()
s = len(S)
L = []

mod = 10 ** 9 + 7
N = 2 * 10**6
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]

def cmb(n, r):
  return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
 
for i in range(2, N + 1):
  fac.append( ( fac[-1] * i ) % mod )
  inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
  finv.append( finv[-1] * inv[-1]  % mod )

for i in range(K+1):
  L.append( cmb(i+s-1, s-1) * pow(25, i, mod) % mod )

ans = []

for i, x in enumerate(L):
  if i == 0:
    ans.append(x)
  else:
    ans.append( ( ans[i-1]*26%mod + x ) % mod )

print(ans[K])

Buggy submission (verdict: Runtime Error):
K = int(input())
S = input()
s = len(S)
L = []

mod = 10 ** 9 + 7
N = 10 ** 6
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]

def cmb(n, r):
  return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
 
for i in range(2, N + 1):
  fac.append( ( fac[-1] * i ) % mod )
  inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
  finv.append( finv[-1] * inv[-1]  % mod )

for i in range(K+1):
  L.append( cmb(i+s-1, s-1) * pow(25, i, mod) % mod )

ans = []

for i, x in enumerate(L):
  if i == 0:
    ans.append(x)
  else:
    ans.append( ( ans[i-1]*26%mod + x ) % mod )

print(ans[K])
Problem p02657 (python)

Fixed submission:
A, B = map(int, input().split())

print(A*B)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
print(A*B)
Problem p02690 (python)

Fixed submission:

X = int(input())

def make_div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def f(x, y):
  return x**5 - y**5 - X

Flag = True

for A in range(-1000, 1000):
  if Flag:
    for i in make_div(X):
      B = A - i
      if f(A, B) == 0:
        print(A, B)
        Flag = False
        break
  else:
    break

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

import sympy
x = sympy.Symbol('x')

def make_div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

for i in make_div(X):
  sol = sympy.solve(x**5 - (x-i)**5 - 33)[0]
  if sympy.im(sol) == 0:
    print(sol, sol - i)
  else:
    continue
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
ans = ["0"] * (N)
Flag = True

for i in range(M):
  s, c = map(int, input().split())
  if ans[s-1] == "0":
    ans[s-1] = c
  elif ans[s-1] == c:
    continue
  else:
    Flag = False

if N > 1:
  if ans[0] == 0:
    Flag = False
  elif ans[0] == "0":
    ans[0] = 1

if Flag:
  print(int("".join([str(i) for i in ans])))
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
ans = [-1] * (N+1)
Flag = True

for i in range(M):
  s, c = map(int, input().split())
  if ans[s-1] < 0:
    ans[s-1] = c
  elif ans[s-1] == c:
    continue
  else:
    Flag = False

if N > 1:
  if ans[0] == 0:
    Flag = False
  elif ans[0] == -1:
    ans[0] = 1
    #三項演算子 真の値 if 条件式 else 偽の値
    ans = [0 if i == -1 else i for i in ans]

ans = ans[:N]

if Flag:
  print(int("".join([str(i) for i in ans])))
else:
  print(-1)
Problem p02811 (python)

Fixed submission:
K, X = map(int,input().split())

if 500*K >= X:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
K, X = map(int,input().split())

if 500*K >= X:
  print('Yes')
  else:
    print('No')

Buggy submission (verdict: Runtime Error):
K X = map(int,input().split())
if 500*K >= X:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
K X = map(int,input().split())
if 500*K >= X:
    print('Yes')
else:
    print('No')
Problem p02812 (python)

Fixed submission:
N = int(input())
S = input()

count = 0
for i in range(N-2):
  if S[i]+S[i+1]+S[i+2] == "ABC":
    count += 1
  else:
    continue
    
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()

count = 0
for i in range(N-3):
  if S[i]S[i+1]S[i+2] == ABC:
    count = +1
  else:
    continue
print(count)
Problem p02837 (python)

Fixed submission:
#C

N = int(input())
P = []
ans = 0

for i in range(N):
  A = int(input())
  p = []
  for j in range(A):
    x, y = map(int, input().split())
    p.append([x-1, y])
  P.append(p)

#全探索
for i in range(2**N):
  Flag = True
  for j in range(N): #N人の〇×を順に見る
    
    if (i >> j) & 1 == 1: #j桁目が1、つまりj番目が正直者→チェック
      for YN in P[j]:
        if (i >> YN[0]) & 1 != YN[1]:
          Flag = False
          break

    if Flag:
      continue
    else:
      break

  if Flag:
    ans = max(ans, bin(i).count("1"))

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools

N = int(input())
P = []
ans = 0

for i in range(N):
  A = int(input())
  p = []
  for j in range(A):
    x, y = map(int, input().split())
    p.append([x-1, y])
  P.append(p)

for YN in itertools.product([1,0], repeat = N):
  s = sum(YN)
  for j in range(len(YN)):
    if YN(j) == 1:
      for k in P[j]:
        if YN(k[0]) != k[1]:
          s = 0
          break
  ans = max(ans, s)

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools

N = int(input())
P = []
ans = 0

for i in range(N):
  A = int(input())
  p = []
  for j in range(A):
    x, y = map(int, input().split())
    p.append([x-1, y])
  P.append(p)

for YN in itertools.product([1,0], repeat = N):
  s = sum(YN)
  for j in range(len(YN)):
    if YN(j) == 1:
      for k in P[j]:
        YN(k[0]) != k[1]
        s = 0
        break
  ans = max(ans, s)

print(ans)
Problem p02850 (python)

Fixed submission:
N = int(input())
graph = [[] for _ in range(N+1)]
AB = []

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

root = 1
parent = [0] * (N+1)
order = []
stack = [root]

while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

color = [-1] * (N+1)
K = -1
for x in order:
    ng = color[x]
    c = 1
    for y in graph[x]:
        if y == parent[x]:
            continue
        if c == ng:
            c += 1
        K = max(c, K)
        color[y] = c
        c += 1

ans = []

for a, b in AB:
    if parent[a] == b:
        ans.append(color[a])
    else:
        ans.append(color[b])

print(K)
for i in ans:
  print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
graph = [[] for _ in range(N+1)]
AB = []

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

root = 1
parent = [0] * (N+1)
order = []
stack = [root]

while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

color = [-1] * (N+1)
K = -1

for x in order:
    temp = color[x]
    c = 1
    for y in graph[x]:
        if y == parent[x]:
            continue
        if c == temp:
            c += 1
        color[y] = c
        K = max(K, c)
        c += 1

ans = []

for a, b in AB:
    if parent[a] == b:
        ans.append(color[a])
    else:
        ans.append(color[b])

print(K)
for i in ans:
  print(ans)
Problem p02888 (python)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += max(bisect_left(L, L[i]+L[j]) - (j+1), 0)

print(cnt)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(len(L)-2):
  for j in range(i+1, len(L)-1):
    k = j + 1
    while L[k-1] == L[k]:
      k += 1
    cnt += bisect_left(L,L[i]+L[j]) - k

print(cnt)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(len(L)-2):
  for j in range(i+1, len(L)-1):
    k = j + 1
    while L[k-1] == L[k]:
      k += 1
    T = L[k:]
    cnt += bisect_left(T,L[i]+L[j])

print(cnt)
Problem p02936 (python)

Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
T = [[] for _ in range(N)]
ans = [0] * N

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

cnt = [0] * N
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  cnt[p] += x

def dfs(x, d, s): # x:計算する頂点（上側）, d:計算済み(0)か否か(1), s:頂点xの値
  for y in T[x]: # 頂点xとつながる各頂点yの計算を行う
    if d[y] == 1: # 頂点yが計算未了の場合
      s += cnt[y] # 頂点xの値sに頂点yの値を足す
      ans[y] = s # 頂点yの値はsに確定
      d[y] = 0 # 頂点yの計算は終わったのでd[y]=0とする
      dfs(y, d, s) # 頂点yの下層についても再帰的に計算
      s -= cnt[y] # 頂点yの下層の計算が終わったので、sを頂点xの値に戻す

d = [1] * N
d[0] = 0

ans[0] = cnt[0]
s = cnt[0]

dfs(0, d, s)

print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(20000)

N, Q = map(int, input().split())
T = [[] for _ in range(N)]
ans = [0] * N

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

#再帰は危険かも？
def dfs(s):
  ans[s-1] += x
  for i in T[s-1]:
    dfs(i)

for _ in range(Q):
  p, x = map(int, input().split())
  dfs(p)

print(*ans)
Problem p02947 (python)

Fixed submission:
from collections import defaultdict

N = int(input())
S = defaultdict(int)

for i in range(N):
  s = sorted(input())
  w = "".join(s)
  S[w] += 1

ans = sum([(i*(i-1))//2 for i in list(S.values())])

print(ans)

Buggy submission (verdict: Runtime Error):
import collections
from sympy import prime

N = int(input())
count = 1
lis = [0]*N

for i in range(N):
  s = input()
  for j in range(10):
    count *= prime(ord(s[j])-ord("a")+1)
  lis[i] += count
  count = 0

dic = collections.Counter(lis)
newlis = list(dic.values())
ans = sum([(i*(i-1))//2 for i in newlis]) 

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
count = 0
ans = 0
lis = [0]*N

for i in range(N):
  s = input()
  for j in range(10):
    count += ord(s[j])
  lis[i] += count
  count = 0

dic = collections.Counter(lis)
newlis = list(dic.values())

for i in newlis:
  ans += i*(i-1)/2

print(int(ans))
Problem p02982 (python)

Fixed submission:
import math

N, D = map(int, input().split())
Ps = []
count = 0

for i in range(N):
  P = list(map(int, input().split()))
  Ps.append(P)

def dis2(A, B):
  dis = 0
  for i in range(D):
    dis += (A[i] - B[i])**2
  return dis

for i in range(N-1):
  for j in range(i+1, N):
    if math.sqrt(dis2(Ps[i], Ps[j])).is_integer():
      count += 1

print(count)

Buggy submission (verdict: Runtime Error):

N, D = map(int, input().split())
Ps = []
count = 0

for i in range(N):
  P = list(map(int, input().split()))
  Ps.append(P)

def dis2(A, B):
  dis = 0
  for i in range(D):
    dis += (A[i] - B[i])**2
  return dis

for i in range(N-1):
  for j in range(i+1, N):
    if math.sqrt(dis2(Ps[i], Ps[j])).is_integer():
      count += 1

print(count)
Problem p02995 (python)

Fixed submission:
import fractions

A, B, C, D = map(int, input().split())
lcm = (C * D) // fractions.gcd(C, D)

def f(x):
  return B//x - (A-1)//x

print( (B - A + 1) - (f(C) + f(D) - f(lcm)) )

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split())
lcm = (C * D) // math.gcd(C, D)

def f(x):
  return B//x - (A-1)//x

print( (B - A + 1) - (f(C) + f(D) - f(lcm)) )
Problem p03043 (python)

Fixed submission:
import math

N, K = map(int, input().split())
ans = 0

for i in range(1, N+1):
  if i < K:
    cnt = math.ceil(math.log2(K / i))
    ans += (1 / N) * (1 / 2)**cnt
  else:
    ans += 1 / N

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
ans = 0

for i in range(1, N+1):
  if i < K:
    cnt = math.ceil(math.log2(K / i))
    ans += (1 / N) * (1 / 2)**cnt
  else:
    ans += 1 / N

print(ans)
Problem p03106 (python)

Fixed submission:
A, B, K = map(int, input().split())

def make_div(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors

print(sorted(set(make_div(A))&set(make_div(B)), reverse=True)[K-1])

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
cnt = 0

for i in range(100, 0, -1):
  if A%i == 0 and B%i == 0:
    cnt += 1
    if cnt = K:
      print(i)
      exit()
Problem p03148 (python)

Fixed submission:
from collections import defaultdict
from heapq import heappop, heappush

N, K = map(int, input().split())
TD = []

for _ in range(N):
  TD.append(tuple(map(int, input().split())))

TD.sort(key = lambda x:x[1], reverse=True)
TD += [(TD[-1][0], 0)]

D = defaultdict(list)
T = [0]*N
H = []
ans = 0

for i in range(K):
  t, d = TD[i]
  T[t-1] += 1
  D[t].append(d)
  ans += d

cnt = sum(1 for c in T if c >= 1)
ans += cnt**2

for t in range(1, N+1):
  if T[t-1] >= 2:
    heappush(H, (D[t].pop(), t))
    T[t-1] -= 1

#print(ans, H, T, cnt)
for i in range(K, N):
  if H:
    t1, d1 = TD[i]
    d2, t2 = heappop(H)
    #print(t1, d1, t2, d2)
    if T[t1-1] == 0 and d1 - d2 + 2*cnt + 1 >= 0:
      ans += d1 - d2 + 2*cnt + 1
      cnt += 1
      T[t1-1] += 1
      if T[t2-1] >= 2:
        T[t2-1] -= 1
      if T[t2-1] >= 2:
        heappush(H, (D[t2].pop(), t2))
    else:
      heappush(H, (d2, t2))
    #print(ans, H, T, cnt)

#元のやつとの組み合わせ...？
ans2 = 0
T2 = [0]*N
D2 = []
cnt2 = 0
 
for t, d in TD:
  if cnt2 < K:
    if T2[t-1]:
      D2.append(d)
    else:
      T2[t-1] = 1
      ans2 += d
      cnt2 += 1

ans2 += sum(D2[:K-cnt2]) + sum(T2)**2

print(max(ans, ans2))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
TD = []

for _ in range(N):
  TD.append(tuple(map(int, input().split())))

TD.sort(key = lambda x:x[1], reverse=True)
TD += [(TD[-1][-1], 0)]

ans1 = 0
T1 = [0]*N
L = []
cnt1 = 0
temp = TD[0][1]

ans2 = 0
T2 = [0]*N
D2 = []
cnt2 = 0

for t, d in TD:
  if cnt1 < K:
    if temp == d and T1[t-1] == 1:
      L.append((t, d))
    elif temp == d and T1[t-1] == 0:
      T1[t-1] = 1
      ans1 += d
      cnt1 += 1
    else:
      while L:
        if cnt1 == K:
          break
        a, b = L.pop()
        ans1 += b
        cnt1 += 1
      if cnt1 < K:
        T1[t-1] = 1
        ans1 += d
        cnt1 += 1
        temp = d
  if cnt2 < K:
    if T2[t-1]:
      D2.append(d)
    else:
      T2[t-1] = 1
      ans2 += d
      cnt2 += 1

ans1 += sum(T1)**2
ans2 += sum(D2[:K-cnt2]) + sum(T2)**2

print(max(ans1, ans2))
Problem p03283 (python)

Fixed submission:
N, M, Q = map(int, input().split())

G = [[0]*(N+1) for _ in range(N+1)]

for _ in range(M):
  L, R = map(int, input().split())
  G[L][R] += 1

for i in range(N+1):
  for j in range(1, N+1):
    G[i][j] += G[i][j-1]

for _ in range(Q):
  p, q = map(int, input().split())
  ans = 0
  for i in range(p, q+1):
    ans += G[i][q]
  print(ans)

Buggy submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
tL = []
tR = []
for i in range(M):
    a, b = map(int, input().split())
    tL.append(a)
    tR.append(b)
ql = []
qr = []
for j in range(Q):
    c, d = map(int, input().split())
    ql.append(c)
    qr.append(d)

for j in range(Q):
    count = 0
    for i in range(M):
        if ql[j] => tL[i] or tR[i] => qr[j]:
            continue
        else:
            count += 1
    print(count)
Problem p03352 (python)

Fixed submission:
X = int(input())

if X == 1:
  print(1)
  exit()

ans = 0

for b in range(2, int(X**0.5)+2):
  temp = b
  while temp <= X:
    ans = max(ans, temp)
    temp *= b

print(ans)

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

if X == 1:
  print(1)
  exit()

ans = 0

for b in range(2, int(x**0.5)+2):
  temp = b
  while temp <= X:
    ans = max(ans, temp)
    temp *= b

print(ans)