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

Fixed submission:
S,W=map(int,input().split())
if W>=S:
    print("unsafe")
else:
    print("safe")

Buggy submission (verdict: Runtime Error):
S=str(input())
ans=0
N=len(S)
for i in range(N):
    j=i+4
    while j<=N:
        if int(S[i:j])%2019==0:
            ans+=1
            i=j+1
            j=j+4
        else:
            j=j+1
print(ans)
Problem p02723 (python)

Fixed submission:
from sys import stdin


inp = stdin.readline

t = inp().strip()

if t[2] == t[3] and t[4] == t[5]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
if s[2] == s[3] and s[4] == s[5]:
  print('Yes')
else:
  print('No)
Problem p03631 (python)

Fixed submission:
s = input()
if s[0] == s[-1]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s - input()
if s[0] == s[-1]:
  print("Yes")
else:
  print("No")
Problem p02627 (python)

Fixed submission:
N = input()
if N.isupper():
  print('A')
else:
  print('a')

Buggy submission (verdict: Runtime Error):
N = input()
if N.isupper():
  print('A')
else:
  print(a)
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
timeA, timeB = 0, 0
numA, numB = 0, 0
for i in range(N):
    if timeA + A[i] <= K:
        numA += 1
        timeA += A[i]
    else:
        break
for i in range(M):
    if timeB + B[i] <= K - timeA:
        numB += 1
        timeB += B[i]
    else:
        break
ans = numA + numB
t = numA
for i in reversed(range(numA)):
    t -= 1
    timeA -= A[i]
    while numB < M:
        if timeB + B[numB] <= K - timeA:
            timeB += B[numB]
            numB += 1
        else:
            break
    ans = max(ans, t + numB)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
timeA, timeB = 0, 0
numA, numB = 0, 0
for i in range(N):
    if timeA + A[i] <= K:
        numA += 1
        timeA += A[i]
    else:
        break
for i in range(M):
    if timeB + B[i] <= K - timeA:
        numB += 1
        timeB += B[i]
    else:
        break
ans = numA + numB
t = numA
j = numB
for i in reversed(range(numA)):
    t -= 1
    timeA -= A[i]
    while j < M:
        if timeB + B[j] <= K - timeA:
            numB += 1
            timeB += B[i]
            j += 1
        else:
            break
    ans = max(ans, t + numB)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
timeA, timeB = 0, 0
numA, numB = 0, 0
for i in range(N):
    if timeA + A[i] <= K:
        numA += 1
        timeA += A[i]
    else:
        break
for i in range(M):
    if timeB + B[i] <= K - timeA:
        numB += 1
        timeB += B[i]
    else:
        break
ans = numA + numB
t = numA
j = numB
for i in reversed(range(numA)):
    t -= 1
    timeA -= A[i]
    while j < M:
        if timeB + B[j] <= K - timeA:
            numB += 1
            timeB += B[i]
        else:
            break
    ans = max(ans, t + numB)
print(ans)
Problem p02781 (python)

Fixed submission:
import math

def Comb(n, r):
  if n < r:
    return 0
  else:
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

N = input()
K = int(input())
ans = 0
for i in range(1, len(N)):
  if i < K:
    pass
  else:
    ans += 9 ** K * Comb(i-1, K-1)
ans += (int(N[0])-1) * Comb(len(N)-1, K-1) * 9 ** (K-1)
if K == 1:
  ans += 1
elif K == 2:
  for i in range(1, len(N)):
    if N[i] != '0':
      ans += int(N[i]) + 9 * (len(N) - i - 1)
      break
else:
  for i in range(1, len(N)):
    if N[i] != '0':
      if len(N) - i - 1 >= 2:
        ans += Comb(len(N) - i - 1, 2) * 9 ** 2
      if len(N) - i - 1 >= 1:
        ans += (int(N[i]) - 1) * 9 * (len(N) - i - 1)
      for j in range(i+1, len(N)):
        if N[j] != '0':
          ans += int(N[j]) + 9 * (len(N) - j - 1)
          break
      break
print(ans)

Buggy submission (verdict: Runtime Error):
import math

def Comb(n, r):
  return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

N = input()
K = int(input())
ans = 0
for i in range(1, len(N)):
  if i < K:
    pass
  else:
    ans += 9 ** K * Comb(i-1, K-1)
ans += (int(N[0])-1) * Comb(len(N)-1, K-1) * 9 ** (K-1)
if K == 1:
  ans += 1
elif K == 2:
  for i in range(1, len(N)):
    if N[i] != '0':
      ans += int(N[i]) + 9 * (len(N) - i - 1)
      break
else:
  for i in range(1, len(N)):
    if N[i] != '0':
      if len(N) - i - 1 >= 2:
        ans += Comb(len(N) - i - 1, 2) * 9 ** 2
      if len(N) - i - 1 >= 1:
        ans += (int(N[i]) - 1) * 9 * (len(N) - i - 1)
      for j in range(i+1, len(N)):
        if N[j] != '0':
          ans += int(N[j]) + 9 * (len(N) - j - 1)
          break
      break
print(ans)
Problem p03011 (python)

Fixed submission:
l = sorted([int(x) for x in input().split()])
print(l[0]+l[1])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
m = 0
if M > 0:
  broken = int(input())
else:
  broken = 0
a1, a2, a3 = 1, 0, 0
for i in range(1, N+1):
  a3, a2 = a2, a1
  if i == broken:
    a1 = 0
    m += 1
    if m < M:
      broken = int(input())
  else:
    a1 = (a2 + a3) % 1000000007
print(a1)
Problem p02550 (python)

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

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

A_history = [-1] * M
sum_history = [0] * (M + 1)
A = X
all_sum = A

sum_history[0] = A

for i in range(M):
    Anext = (A * A) % M
    all_sum += Anext
    sum_history[i + 1] = all_sum
    if A_history[A] == -1:
        A_history[A] = i
    else:
        break
    A = Anext

if i >= N:
    print(sum_history[N - 1])
else:
    cycle_start = A_history[A]
    cycle_end = i - 1
    cycle_length = cycle_end - cycle_start + 1
    cycle_time = N - cycle_start
    cycle_count = cycle_time // cycle_length
    cycle_mod = cycle_time % cycle_length
    ans = sum_history[cycle_start] + (sum_history[cycle_end + 1] - sum_history[cycle_start]) * cycle_count + \
          (sum_history[cycle_start + cycle_mod - 1] - sum_history[cycle_start])
    print(ans)

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

A_history = [-1] * M
sum_history = [0] * (M + 1)
A = X
all_sum = A

sum_history[0] = A

for i in range(M):
    Anext = (A * A) % M
    all_sum += Anext
    sum_history[i + 1] = all_sum
    if A_history[A] == -1:
        A_history[A] = i
    else:
        break
    A = Anext

if i >= N:
    print(sum_history[N - 1])
else:
    cycle_start = A_history[A]
    cycle_end = i - 1
    cycle_length = cycle_end - cycle_start + 1
    cycle_time = N - cycle_start
    cycle_count = cycle_time // cycle_length
    cycle_mod = cycle_time % cycle_length
    ans = sum_history[cycle_start] + (sum_history[cycle_end + 1] - sum_history[cycle_start]) * cycle_count + \
          (sum_history[cycle_start + cycle_mod - 1] - sum_history[cycle_start])
    print(ans)
Problem p02580 (python)

Fixed submission:
H, W, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

bombs_row = [0] * H
bombs_col = [0] * W

for b in B:
    bombs_row[b[0] - 1] += 1
    bombs_col[b[1] - 1] += 1

row_max = max(bombs_row)
col_max = max(bombs_col)

row_max_count = bombs_row.count(row_max)
col_max_count = bombs_col.count(col_max)

ans = row_max + col_max

possible_point = row_max_count * col_max_count

bombed_point = 0

for b in B:
    if bombs_row[b[0] - 1] == row_max and bombs_col[b[1] - 1] == col_max:
        bombed_point += 1

if bombed_point == possible_point:
    ans -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
H, W, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

bombs_row = [0] * H
bombs_col = [0] * W

for b in B:
    bombs_row[b[0] - 1] += 1
    bombs_col[b[1] - 1] += 1

row_max = max(bombs_row)
col_max = max(bombs_col)

row_max_count = bombs_row.count(row_max)
col_max_count = bombs_col.count(col_max)

ans = row_max + col_max

possible_point = row_max_count * col_max_count

bombed_point = 0

for b in B:
    if bombs_row[b[0]] == row_max and bombs_col[b[1]] == col_max:
        bombed_point += 1

if bombed_point == possible_point:
    ans -= 1

print(ans)
Problem p02781 (python)

Fixed submission:
N_str = str(input())
K = int(input())

digit_length = len(N_str)
topmost_digit = int(N_str[0])

C_table = [[0, 0, 0, 0] for _ in range(digit_length+10)]


def C(all, pick):
    if C_table[all][pick] == 0:
        count_child = 1
        count_parent = 1
        for i in range(pick):
            count_child *= all - i
            count_parent *= i + 1
        C_table[all][pick] = count_child // count_parent
    return C_table[all][pick]


def get_count(top_digit, digit_count, needed_nonzero):
    if needed_nonzero <= 0 or needed_nonzero > digit_count:
        return 0

    if digit_count == 1:
        if needed_nonzero == 1:
            return top_digit
        else:
            return 0

    if top_digit == 0:
        return get_count(int(N_str[digit_length - digit_count + 1]) ,digit_count - 1, needed_nonzero)

    if top_digit >= 1:
        count = C(digit_count - 1, needed_nonzero) * (9 ** needed_nonzero)
        if needed_nonzero == 1:
            count += 1

    if top_digit > 1:
        count += C(digit_count - 1, needed_nonzero - 1) * (9 ** (needed_nonzero - 1)) * (top_digit - 1)

    return count + get_count(int(N_str[digit_length - digit_count + 1]) ,digit_count - 1, needed_nonzero - 1)


print(get_count(topmost_digit, digit_length, K))

Buggy submission (verdict: Runtime Error):
N_str = str(input())
K = int(input())

digit_length = len(N_str)
topmost_digit = int(N_str[0])

C_table = [[0, 0, 0] for _ in range(digit_length)]


def C(all, pick):
    if C_table[all][pick] == 0:
        count_child = 1
        count_parent = 1
        for i in range(pick):
            count_child *= all - i
            count_parent *= i + 1
        C_table[all][pick] = count_child // count_parent
    return C_table[all][pick]


def get_count(top_digit, digit_count, needed_nonzero):
    if needed_nonzero <= 0 or needed_nonzero > digit_count:
        return 0

    if digit_count == 1:
        if needed_nonzero == 1:
            return top_digit
        else:
            return 0

    if top_digit == 0:
        return get_count(int(N_str[digit_length - digit_count + 1]) ,digit_count - 1, needed_nonzero)

    if top_digit >= 1:
        count = C(digit_count - 1, needed_nonzero) * (9 ** needed_nonzero)
        if needed_nonzero == 1:
            count += 1

    if top_digit > 1:
        count += C(digit_count - 1, needed_nonzero - 1) * (9 ** (needed_nonzero - 1)) * (top_digit - 1)

    return count + get_count(int(N_str[digit_length - digit_count + 1]) ,digit_count - 1, needed_nonzero - 1)


print(get_count(topmost_digit, digit_length, K))
Problem p02815 (python)

Fixed submission:
N = int(input())
C = list(map(int, input().split()))

C.sort()

ans = 0

mod = 10 ** 9 + 7

pattern = (2 ** (N - 2)) % mod

if N != 1:
    for i in range(N):
        c = C[i]
        ans += c * (N + 1 - i) * pattern
        ans %= mod
    ans *= 2 ** N
else:
    ans = C[0] * 2

ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

N = int(input())
C = list(map(int, input().split()))

ans = 0

if N != 1:
    C = heapq.heapify(C)
    for i in range(N):
        c = heapq.heappop(C)
        ans += c * (N + 1 - i) * (2 ** (N - 2))
        ans %= 10 ** 9 + 7
    ans *= 2 ** N
else:
    ans = C[0] * 2

ans %= 10 ** 9 + 7

print(ans)
Problem p02835 (python)

Fixed submission:
A = list(map(int,input().split()))
if sum(A) <= 21:
  print("win")
else:
  print("bust")

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
Nloop = N + 1
A = np.zeros((Nloop, Nloop), dtype="int")
Acount = np.zeros(Nloop, dtype="int")

for i in range(1, Nloop):
    Acount[i] = int(input())
    for _ in range(Acount[i]):
        x, y = map(int, input().split())
        A[i, x] = 1 if y == 1 else -1

honest_loop = 2 ** N
honest_num = np.zeros(Nloop, dtype="int")

ans = 0

for i in range(1, honest_loop):
    for l in range(1, Nloop):
        honest_num[l] = 1 if i >> (l - 1) & 1 == 1 else -1

    check = np.dot(A, honest_num)

    honest_check = True
    for l in range(1, Nloop):
        # lの人が正直者のとき
        if honest_num[l] == 1 and Acount[l] != check[l]:
            honest_check = False

    if honest_check:
        ans = max(sum(honest_num == 1), ans)

print(ans)
Problem p02933 (python)

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

if a < 3200:
  print("red")
else:
  print(s)

Buggy submission (verdict: Runtime Error):
a=int(input())
s=input()

if a >= 3200:
  print("red")
  else
  print(s)
Problem p02948 (python)

Fixed submission:
import heapq
from collections import deque

N, M = map(int,input().split())

work = [list(map(int,input().split())) for _ in range(N)]

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappush(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
from collections import deque

N, M = map(int,input().split())

work = [list(map(int,input().split())) for _ in range(N)]

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappop(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
from collections import deque

N, M = map(int,input().split())

work = [list(map(int,input().split())) for _ in range(N)]

wq = deque(sorted(work))

paytree = deque([])

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        bisect.insort_right(paytree,wq.popleft()[1])
    if len(paytree) > 0:
        ans += paytree.pop()

print(ans)
Problem p02970 (python)

Fixed submission:
N, D = map(int,input().split())
 
watch = D * 2 + 1
 
ans = ( N + watch - 1 ) // watch
 
print(ans)

Buggy submission (verdict: Runtime Error):
N, D = map(int,input())

watch = D * 2 + 1

ans = ( N + watch - 1 ) // watch

print(ans)
Problem p03012 (python)

Fixed submission:
N = int(input())

w = list(map(int, input().split()))

anslight = 0
ansheavy = sum(w)

ans = ansheavy

for i in w:
    anslight += i
    ansheavy -= i
    ans = min(abs(ansheavy-anslight), ans)

print(ans)

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

w = list(map(int, input()))

anslight = 0
ansheavy = sum(w)

ans = ansheavy

for i in w:
    anslight += i
    ansheavy -= i
    ans = min(abs(ansheavy-anslight), ans)
    
print(ans)
Problem p03017 (python)

Fixed submission:
def has_path(start, goal):
    for step in range(start, goal):
        if (not isRoad[step]) and (not isRoad[step-1]):
            return False
    return True


N, A, B, C, D = map(int, input().split())
S = input()
isRoad = [True if c == "." else False for c in S]

if C <= B:      # すぬけ・ふぬけの二人が独立になっているとき
    if has_path(A, C) and has_path(B, D):
        print("Yes")
    else:
        print("No")
    exit()
elif C < D:    # ふぬけを動かしてからすぬけを動かせば良いとき
    if has_path(A, C) and has_path(B, D):
        print("Yes")
    else:
        print("No")
    exit()
else:       # どこかでふぬけがすぬけを追い越さなければいけない場合
    for i in range(B - 1, D):   # 追い抜く場所があるかどうかを探索
        if isRoad[i - 1] and isRoad[i] and isRoad[i + 1]:
            print("Yes")
            exit()
    print("No")

Buggy submission (verdict: Runtime Error):
def has_path(start, goal):
    for step in range(start, goal):
        if (not isRoad[step]) and (not isRoad[step-1]):
            return False
    return True


N, A, B, C, D = map(int, input().split())
S = input()
isRoad = [True if c == "." else False for c in S]

if C <= B:      # すぬけ・ふぬけの二人が独立になっているとき
    if has_path(A, C) and has_path(B, D):
        print("Yes")
    else:
        print("No")
    exit()
elif C < D:    # ふぬけを動かしてからすぬけを動かせば良いとき
    if has_path(A, C) and has_path(B, D):
        print("Yes")
    else:
        print("No")
    exit()
else:       # どこかでふぬけがすぬけを追い越さなければいけない場合
    for i in range(B - 1, D + 1):   # 追い抜く場所があるかどうかを探索
        if isRoad[i - 1] and isRoad[i] and isRoad[i + 1]:
            print("Yes")
            exit()
    print("No")
Problem p02594 (python)

Fixed submission:
n = int(input())
if n <30:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
temparr = input()
temparr = temparr.split()
n = int(temparr[0])
k = int(temparr[1])
temparr = input()
import math
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i))
arr = sorted(arr)
#print(arr)

left = 1
right = arr[-1] + 1
ans = arr[-1]
while left <= right:
    mid = (left + right) // 2 
    count = 0 
    for i in arr :
        if i <= mid:
            continue 
        else:
            count += math.ceil(i / mid) - 1 
    if count <= k :
        right = mid - 1 
        if mid < ans:
            ans = mid 
    else:
        left = mid + 1 
print(ans)
Problem p02598 (python)

Fixed submission:
temparr = input()
temparr = temparr.split()
n = int(temparr[0])
k = int(temparr[1])
temparr = input()
import math
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i))
arr = sorted(arr)
#print(arr)

left = 1
right = arr[-1] + 1
ans = arr[-1]
while left <= right:
    mid = (left + right) // 2 
    count = 0 
    for i in arr :
        if i <= mid:
            continue 
        else:
            count += math.ceil(i / mid) - 1 
    if count <= k :
        right = mid - 1 
        if mid < ans:
            ans = mid 
    else:
        left = mid + 1 
print(ans)

Buggy submission (verdict: Runtime Error):
temparr = input()
temparr = temparr.split()
n = int(temparr[0])
k = int(temparr[1])
temparr = input()
import math
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i))
arr = sorted(arr)
#print(arr)

left = 0 
right = arr[-1] + 1
ans = arr[-1]
while left <= right:
    mid = (left + right) // 2 
    count = 0 
    for i in arr :
        if i <= mid:
            continue 
        else:
            count += math.ceil(i / mid) - 1 
    if count <= k :
        right = mid - 1 
        if mid < ans:
            ans = mid 
    else:
        left = mid + 1 
print(ans)
Problem p02550 (python)

Fixed submission:
N,X,M = map(int,input().split())
A = [100001]*(2*(10**5)+100)
A[1] = X
S = {X}
ans = X
for i in range(2,min(2*M+1,N)+1):
  X = X**2
  X %= M
  ans += X
  A[i] = X
  if X in S:
    break
  S.add(X)
  #print(i)
#[print(A[i]) for i in range(6)]
if N == 1:
  print(X)
  exit()
elif i == N:
  print(ans)
else:
  j = A[:i+1].index(A[i])
  if i == j:
    print(ans)
  k = (N-i)//(i-j)
  l = (N-i)%(i-j)
  #print(j,k,l)
  ans += k*sum(A[j+1:i+1])+sum(A[j+1:j+l+1])
  print(ans)

Buggy submission (verdict: Runtime Error):
N,X,M = map(int,input().split())
A = [100001]*(2*(10**5)+100)
A[1] = X
S = {X}
ans = X
for i in range(2,min(2*M+1,N)+1):
  X = X**2
  X %= M
  ans += X
  A[i] = X
  if X in S:
    break
  S.add(X)
  #print(i)
#[print(A[i]) for i in range(6)]
  
if i == N:
  print(ans)
else:
  j = A[:i+1].index(A[i])
  if i == j:
    print(ans)
  k = (N-i)//(i-j)
  l = (N-i)%(i-j)
  #print(j,k,l)
  ans += k*sum(A[j+1:i+1])+sum(A[j+1:j+l+1])
  print(ans)

Buggy submission (verdict: Runtime Error):
N,X,M = map(int,input().split())
A = [100001]*(10**5+1)
A[1] = X
S = {X}
ans = X
for i in range(2,min(2*M+1,N)+1):
  X = X**2
  X %= M
  ans += X
  A[i] = X
  if X in S:
    break
  S.add(X)
  #print(i)
#[print(A[i]) for i in range(6)]
  
if i == N:
  print(ans)
else:
  j = A[:i+1].index(A[i])
  if i == j:
    print(ans)
  k = (N-i)//(i-j)
  l = (N-i)%(i-j)
  #print(j,k,l)
  ans += k*sum(A[j+1:i+1])+sum(A[j+1:j+l+1])
  print(ans)

Buggy submission (verdict: Runtime Error):
N,X,M = map(int,input().split())
A = [100001]*(10**5+1)
A[1] = X
S = {X}
ans = X
for i in range(2,min(M+1,N)+1):
  X = X**2
  X %= M
  ans += X
  A[i] = X
  if X in S:
    break
  S.add(X)
  #print(i)
#[print(A[i]) for i in range(6)]
  
if i == N:
  print(ans)
else:
  j = A[:i+1].index(A[i])
  k = (N-i)//(i-j)
  l = (N-i)%(i-j)
  #print(j,k,l)
  ans += k*sum(A[j+1:i+1])+sum(A[j+1:j+l+1])
  print(ans)
Problem p02580 (python)

Fixed submission:
H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(W+1)
A = set()
for k in range(M):
    a,b = map(int,input().split())
    P[a] += 1
    Q[b] += 1
    A.add((a,b))
Pmax = max(P)
Qmax = max(Q)
Pindex = []
Qindex = []
for i in range(H+1):
    if P[i] == Pmax:
        Pindex.append(i)
for i in range(W+1):
    if Q[i] == Qmax:
        Qindex.append(i)
ans = Pmax+Qmax-1
key = 0
for x in Pindex:
  for y in Qindex:
    if (x,y) not in A:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)

Buggy submission (verdict: Runtime Error):
H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(W+1)
A = []
for k in range(M):
  a,b = map(int,input().split())
  P[a] += 1
  Q[b] += 1
  A.append(a,b)
Pindex = [i for i, v in enumerate(P) if v == max(P)]
Qindex = [i for i, v in enumerate(Q) if v == max(Q)]
Pmax = P[Pindex[0]]
Qmax = Q[Qindex[0]]
ans = Pmax+Qmax-1
key = 0
for x in Pindex:
  for y in Qindex:
    if (x,y) not in A:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)

Buggy submission (verdict: Runtime Error):
H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(W+1)
#A = [[0 for j in range(W+1)] for i in range(H+1)]
for k in range(M):
  a,b = map(int,input().split())
  P[a] += 1
  Q[b] += 1
  #A[a][b] = 1
#print(P,Q,A,Pmax,Qmax,ans)
Pindex = [i for i, v in enumerate(P) if v == max(P)]
Qindex = [i for i, v in enumerate(Q) if v == max(Q)]
Pmax = P[Pindex[0]]
Qmax = Q[Qindex[0]]
ans = Pmax+Qmax-1
key = 0
for x in Pindex:
  for y in Qindex:
    if A[x][y] == 0:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)

Buggy submission (verdict: Runtime Error):
H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(M+1)
A = [[0 for j in range(W+1)] for i in range(H+1)]
for k in range(M):
  a,b = map(int,input().split())
  P[a] += 1
  Q[b] += 1
  A[a][b] = 1
Pmax = max(P)
Qmax = max(Q)
ans = Pmax+Qmax-1
Pindex = [i for i, v in enumerate(P) if v == Pmax]
Qindex = [i for i, v in enumerate(Q) if v == Qmax]
key = 0
for x in Pindex:
  for y in Qindex:
    if A[x][y] == 0:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)
Problem p02597 (python)

Fixed submission:
N = int(input())
a = list(input())
x = a.count('R')
b = a[:x]
print(b.count('W'))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(input())
b = []
for i in range(N):
  if a[i] == 'R':
    b.append(i)
M = len(b)-1
m = b[M]
ans = 0
for i in range(N):
  if i >= b[M]:
    break
  if i not in b:
    #print(i)
    M -= 1
    ans += 1
print(ans)
Problem p02598 (python)

Fixed submission:
import math
def solution(x):
  p = sum([math.ceil(a[i]/x)-1 for i in range(N)])
  return p
def solvance(y,z):
  if z-y <= 1:
    return z
  else:
    w = (y+z)//2
    #print(y,w,z)
    if solution(w) > K:
      return solvance(w,z)
    else:
      return solvance(y,w)

N,K = map(int,input().split())
a = list(map(int,input().split()))
if K == 0:
  print(max(a))
else:
  ansM = (sum(a)//K)+1
  ansm = sum(a)//(K+N)
  ans = solvance(ansm,ansM)
  print(ans)

Buggy submission (verdict: Runtime Error):
def solution(x):
  p = sum([a[i]//x for i in range(N)])
  return p
def solvance(y,z):
  if z-y <= 1:
    if solution(y) == K:
      return y
    else:
      return z
  else:
    w = (y+z)//2
    #print(y,w,z)
    if solution(w) > K:
      return solvance(w,z)
    else:
      return solvance(y,w)

N,K = map(int,input().split())
a = list(map(int,input().split()))
if K == 0:
  print(max(a))
else:
  ansM = sum(a)//K
  ansm = sum(a)//(K+N)
  ans = solvance(ansm,ansM)
  print(ans)