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

Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

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

a_list = [list(input()) for i in range(H)]

isEnd = False
_a_list = a_list[::][::]
cnt = 0
while not isEnd:
    isEnd = True
    next_a_list = [["." for i in range(H)] for j in range(W)]
    for i in range(H):
        for j in range(W):
            a = _a_list[i][j]
            if a == ".":
                #  白色
                isEnd = False
            else:
                next_a_list[i][j] = "#"
                #  黒色
                if i > 0:
                    next_a_list[i-1][j] = "#"
                if i < H-1:
                    next_a_list[i+1][j] = "#"
                if j > 0:
                    next_a_list[i][j-1] = "#"
                if j < W-1:
                    next_a_list[i][j+1] = "#"
    cnt += 1
    _a_list = next_a_list[::]

print(cnt-1)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
a = []
INF = 10**9
for i in range(H):
    a.append(input())

# 黒マスの位置を記録
black_pos = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            black_pos.append([i, j])

# 白マスごとに最近傍の黒マスまでの距離を計算
dist_list = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            continue
        min_dist = INF
        for pos in black_pos:
            dist = abs(pos[0]-i) + abs(pos[1]-j)
            if dist < min_dist:
                min_dist = dist
        dist_list.append(min_dist)

print(max(dist_list))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
a = []
INF = 10**9
for i in range(H):
    a.append(input())

# 黒マスの位置を記録
black_pos = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            black_pos.append([i, j])

# 白マスごとに最近傍の黒マスまでの距離を計算
dist_list = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            continue
        min_dist = INF
        for pos in black_pos:
            dist = abs(pos[0]-i) + abs(pos[1]-j)
            if dist < min_dist:
                min_dist = dist
        dist_list.append(min_dist)

print(max(dist_list))
Problem p03209 (python)

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

a = [2**(i+2) - 3 for i in range(N+1)]
p = [2**(i+1) - 1 for i in range(N+1)]

ans = 0

def calc(n, x):
    if n == 0:
        return 1
    if x == 1:
        return 0
    elif 1 < x < a[n-1]+2:
        return calc(n-1, x-1)
    elif x == 2 + a[n-1]:
        return p[n-1] + 1
    elif 2 + a[n-1] < x < 3 + 2*a[n-1]:
        return p[n-1] + 1 + calc(n-1, x-2-a[n-1])
    elif x == 3 + 2*a[n-1]:
        return 2*p[n-1] + 1


ans = calc(N, X)
print(ans)

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

a = [2**(i+2) - 3 for i in range(N+1)]
p = [2**(i+1) - 1 for i in range(N+1)]

ans = 0

def calc(n, x):
    if n == 0:
        return 1
    if x == 1:
        return 0
    elif 1 < x < a[n-1]+1:
        return calc(n-1, x-1)
    elif x == 2 + a[n-1]:
        return p[n-1] + 1
    elif 2 + a[n-1] < x < 3 + 2*a[n-1]:
        return p[n-1] + 1 + calc(n-1, x-2-a[n-1])
    elif x == 3 + 2*a[n-1]:
        return 2*p[n-1] + 1


ans = calc(N, X)
print(ans)

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

a = [2**(i+2) - 3 for i in range(N+1)]
p = [2**(i+1) - 1 for i in range(N+1)]

ans = 0

def calc(n, x):
    if n == 0:
        return 1
    if x == 1:
        return 0
    elif 1 < x < a[n-1]+1:
        return calc(n-1, x-1)
    elif x == 2 + a[n-1]:
        return p[n-1] + 1
    elif 2+ a[n-1] < x < 3 + 2*a[n-1]:
        return p[n-1] + 1 + calc(n-1, x-2-a[n-1])
    elif x == 3 + 2*a[n-2]:
        return 2*p[n-1] + 1


ans = calc(N, X)
print(ans)
Problem p03618 (python)

Fixed submission:
a = input()
n = len(a)
cnt = [0]*(ord('z')-ord('a')+1)


res = 0
for s in a:
    idx = ord(s) - ord('a')
    res += cnt[idx]
    cnt[idx]+= 1
ans = (n*(n-1)/2)-res+1
print(int(ans))

Buggy submission (verdict: Runtime Error):
a = input()
n = len(a)
cnt = [0]*(ord('z')-ord('a'))


res = 0
for s in a:
    idx = ord(s) - ord('a')
    res += cnt[idx]
    cnt[idx]+= 1
ans = (n*(n-1)/2)-res+1
print(int(ans))
Problem p03634 (python)

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

n = int(input())
edges = [[] for _ in range(n)]
costs = [-1]*n
def dfs(current):

    for nex, cost in edges[current]:
        if costs[nex] != -1:
            continue
        costs[nex] = costs[current] + cost
        dfs(nex)

for i in range(n-1):
    a, b, c = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c))
    edges[b].append((a, c))

q, k = map(int, input().split())
k -= 1
costs[k] = 0
dfs(k)

res = []
for _ in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    res.append(costs[x]+costs[y])

for ans in res:
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
edges = [[] for _ in range(n)]
costs = [-1]*n
def dfs(current):

    for nex, cost in edges[current]:
        if costs[nex] != -1:
            continue
        costs[nex] = costs[current] + cost
        dfs(nex)

for i in range(n-1):
    a, b, c = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c))
    edges[b].append((a, c))

q, k = map(int, input().split())
k -= 1
costs[k] = 0
dfs(k)

res = []
for _ in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    res.append(costs[x]+costs[y])

for ans in res:
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
edges = [[] for _ in range(n)]
costs = [-1]*n
def dfs(current, d):
    costs[current] = d
    for nex in edges[current]:
        if costs[nex[0]] != -1:
            continue
        dfs(nex[0], d+nex[1])

for i in range(n-1):
    a, b, c = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c))
    edges[b].append((a, c))

q, k = map(int, input().split())
k -= 1
dfs(k, 0)

res = []
for _ in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    res.append(costs[x]+costs[y])

for ans in res:
    print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

INF = 10**15
n = int(input())
edges = [[] for _ in range(n)]
costs = [INF]*n
def dfs(current, prev, d):
    costs[current] = d
    for nex in edges[current]:
        if nex[0] == prev:
            continue
        dfs(nex[0], current, d+nex[1])

for i in range(n-1):
    a, b, c = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c))
    edges[b].append((a, c))

q, k = map(int, input().split())
k -= 1
dfs(k, -1, 0)

res = []
for _ in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    res.append(costs[x]+costs[y])

for ans in res:
    print(ans)
Problem p03775 (python)

Fixed submission:
from math import ceil, log10, sqrt

n = int(input())
ans = 0
for i in range(1, ceil(sqrt(n))+1)[::-1]:
    if n % i == 0:
        a = i
        b = n//i
        ans = max(len(str(a)), len(str(b)))
        break
print(ans)

Buggy submission (verdict: Runtime Error):
from math import ceil, log10, sqrt

n = int(input())
ans = 0
for i in range(ceil(sqrt(n)))[::-1]:
    if n % i == 0:
        a = i
        b = n//i
        ans = max(len(str(a)), len(str(b)))
        break
print(ans)
Problem p02597 (python)

Fixed submission:
N = int(input())
c = list(input())
ans = 0
cnt = c.count("W")
ans = c[N-cnt:].count("R")
if cnt != 0:
    print(ans)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
c = list(input())
ans = 0
#print(c)
for i in range(N):
    flag = 0
    if c[i] == "R":
        continue
    elif c[i] == "W":
        #print(c, ans, i, sep=" ",)
        for j in reversed(range(N)):
            if i == j:
                flag = 1
                break
            if c[j] == "R":
                c[i], c[j] = c[j], c[i]
                ans += 1
                print(c, ans, sep=" ")
                break
        else:
            continue
        if flag == 1:
            break

print(ans)
Problem p02598 (python)

Fixed submission:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = max(A)
ans = abs(end + start) // 2 + 1
while abs(start - end) > 1:
    ans = abs(end + start) // 2
    cnt = 0
    for i in range(N):
        cnt += math.floor(A[i]/ans - 0.0000000001)
        if cnt > K: #ダメだったら
            start = ans
            break
    else: #オッケーだったら
        end = ans
        continue

cnt = 0
for i in range(N):
    cnt += math.floor((A[i] / ans) - 0.000000000001)

if cnt > K:  # ダメだったら
    print(ans + 1)
else:  # オッケーだったら
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = max(A)
while abs(start - end) > 1:
    ans = abs(end + start) // 2
    cnt = 0
    for i in range(N):
        cnt += math.floor(A[i]/ans - 0.0000000001)
        if cnt > K: #ダメだったら
            start = ans
            break
    else: #オッケーだったら
        end = ans
        continue

cnt = 0
for i in range(N):
    cnt += math.floor((A[i] / ans) - 0.000000000001)

if cnt > K:  # ダメだったら
    print(ans + 1)
else:  # オッケーだったら
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = max(A)
while abs(start - end) > 1:
    ans = abs(end + start) // 2
    cnt = 0
    for i in range(N):
        cnt += math.floor(A[i]/ans - 0.0000000001)
        if cnt > K: #ダメだったら
            start = ans
            break
    else: #オッケーだったら
        end = ans
        continue

cnt = 0
for i in range(N):
    cnt += math.floor((A[i] / ans) - 0.000000000001)

if cnt > K:  # ダメだったら
    print(ans + 1)
else:  # オッケーだったら
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = max(A)
while abs(start - end) > 1:
    ans = abs(end + start) // 2
    cnt = 0
    for i in range(N):
        cnt += math.floor(A[i]/ans - 0.001)
        if cnt > K: #ダメだったら
            start = ans
            break
    else: #オッケーだったら
        end = ans
        continue

cnt = 0
for i in range(N):
    cnt += math.floor(A[i] / ans - 0.001)

if cnt > K:  # ダメだったら
       print(ans + 1)
else:  # オッケーだったら
    print(ans)
Problem p02959 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
b = list(map(int, input().split()))
for i in range(n):
    if b[i] >= a[i]:
        b[i] -= a[i]
        a[i] = 0
    else:
        a[i] -= b[i]
        continue
    a[i + 1] -= b[i]
    if a[i + 1] < 0:
        a[i + 1] = 0

if a[-1] < 0:
    a[-1] = 0
print(sum_a - sum(a))

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,a[100000],b[100000],i=1,j,saidai=0,m=0,L=0;
    string s;
    cin >> n;
    for(i=0;i<n+1;i++)
    {
        cin >> a[i];
        saidai+=a[i];
    }
    for(i=0;i<n;i++)
    {
        cin >> b[i];
        L+=b[i];
    }
    for(i=0;i<n;i++)
    {
        if(a[i]<b[i])
        {
            a[i+1]-=b[i]-a[i];
            if(a[i+1]<0)
            {
                a[i+1]=0;
            }
            a[i]=0;
        }
        else
        {
            a[i]=a[i]-b[i];
        }
    }
        for(i=0;i<n+1;i++)
        {
            m+=a[i];
        }
    if(saidai-m>L)
    {
        cout << L << endl;
    }
    else
    {
        cout << saidai-m << endl;
    }
    
    
    return 0;

}
Problem p02594 (python)

Fixed submission:
x = int(input())
 
if(x >= 30 ):
  print("Yes")
else:
  print("No")

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

if(x >= 30 ):
  print(Yes)
else:
  print(No)
Problem p02595 (python)

Fixed submission:
N,D =(int(x) for x in input().split())
xy = [map(int,input().split()) for _ in range(N)]
x,y = [list(i) for i in zip(*xy)]
n = 0
 
for i in range(N):
  if(x[i]**2 + y[i]**2 <= D**2):
    n += 1
 
print(n)

Buggy submission (verdict: Runtime Error):
N,D =(int(x) for x in input().split())
xy = [map(int,input().split()) for _ int range(N)]
x,y = [list(i) for i in zip(*xy)]
n = 0

for i in range(N):
  if(x[i]**2 + y[i]**2 <= D**2):
    n += 1

print(n)
Problem p02661 (python)

Fixed submission:
n, *AB = map(int, open(0).read().split())
A, B = map(sorted, [AB[::2], AB[1::2]])
mid = n//2
if n % 2 == 0:
    a0, a1 = A[mid-1], A[mid]
    b0, b1 = B[mid-1], B[mid]
    print(b0+b1 - (a0+a1) + 1)
else:
    print(B[mid] - A[mid] + 1)

Buggy submission (verdict: Runtime Error):
from itertools import product
n, *AB = map(int, open(0).read().split())
A, B = map(sorted, [AB[::2], AB[1::2]])
mid = n//2
if n % 2 == 0:
    a, b = A[mid-1], B[mid-1]
    X = range(a, b+1)
    a, b = A[mid], B[mid]
    Y = range(a, b+1)
    Z = {a+b for a, b in product(X, Y)}
    print(len(Z))
else:
    print(B[mid] - A[mid] + 1)

Buggy submission (verdict: Runtime Error):
from itertools import product
n, *AB = map(int, open(0).read().split())
A, B = AB[::2], AB[1::2]
A, B = map(sorted, [A, B])
mid = n//2
if n % 2 == 0:
    a, b = A[mid-1], B[mid-1]
    X = range(a, b+1)
    a, b = A[mid], B[mid]
    Y = range(a, b+1)
    Z = {(a+b)/2 for a, b in product(X, Y)}
    print(len(Z))
else:
    print(B[mid] - A[mid] + 1)
Problem p02836 (python)

Fixed submission:
S = input()
RS = reversed(S)
n = int(len(S) / 2)

ans = 0
for c1, c2 in zip(S[:n], RS):
    if c1 != c2:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
bun = inputs[0]
nub = list(reversed(bun))
n = int(len(bun) / 2)

i = hug = 0
while i < n:
    if bun[i] != nub[i]:
        hug += 1
    i += 1
print(hug)

Buggy submission (verdict: Runtime Error):
bun = input()
nub = reversed(S)
n = int(len(S) / 2)

i = hug = 0
while i < n:
    if bun[i] != nub[i]:
        hug += 1
    i += 1
print(hug)
Problem p02912 (python)

Fixed submission:
import sys
inputs = sys.stdin.readlines()

from heapq import heappush, heappop
N, M = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))

queue = []
for a in A:
    heappush(queue, -a)

for _ in range(M):
    heappush(queue, -(-heappop(queue) // 2))
print(-sum(queue))

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop
N, M = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))

queue = []
for a in A:
    heappush(queue, -a)

for _ in range(M):
    heappush(queue, -(-heappop(queue) // 2))
print(-sum(queue))
Problem p02984 (python)

Fixed submission:
import sys
import numpy as np
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = np.array(list(map(int, inputs[1].split())))
B = np.empty((n,), dtype=np.int)
B[0] = (sum(A[::2])-sum(A[1::2])) // 2
for i in range(1, n):
    B[i] = A[i-1] - B[i-1]
print(*(B*2))

Buggy submission (verdict: Runtime Error):
import sys
from numpy.linalg import solve
import numpy as np
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = np.array(list(map(int, inputs[1].split())))
I = np.eye(n, dtype=np.int)
B = np.empty((n, n), dtype=np.int)
for i in range(n):
    B[i, :] = I[i] + I[(i+1)%n]
print(*(map(lambda x: int(2*x), solve(B, A))))
Problem p03038 (python)

Fixed submission:
from heapq import heapify, heappushpop
from operator import itemgetter
inputs = open(0).readlines()

n, m = map(int, inputs[0].split())
*A, = map(int, inputs[1].split())
heapify(A)
BC = [tuple(map(int, bc.split())) for bc in inputs[2:]]
BC.sort(key=itemgetter(1), reverse=True)

for b, c in BC:
    for _ in range(b):
        if c > A[0]:
            _ = heappushpop(A, c)
        else:
            break
print(sum(A))

Buggy submission (verdict: Runtime Error):
from heapq import heapfy, heappushpop
from operator import itemgetter
inputs = open(0).readlines()

n, m = map(int, inputs[0].split())
*A, = map(int, inputs[1].split())
heapify(A)
BC = [tuple(map(int, bc.split())) for bc in inputs[2:]]
BC.sort(key=itemgetter(1), reverse=True)

for b, c in BC:
    for _ in range(b):
        if c > A[0]:
            _ = heappushpop(A, c)
        else:
            break
print(sum(A))

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heappush
inputs = open(0).readlines()

n, m = map(int, inputs[0].split())
*A, = map(int, inputs[1].split())
heapify(A)
BC = [tuple(map(int, bc.split())) for bc in inputs[2:]]

for b, c in BC:
    for _ in range(b):
        if c > A[0]:
            _ = heappushpop(A, c)
        else:
            break
print(sum(A))

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heappush
inputs = open(0).readlines()

from heapq import heappop, heappush
inputs = open(0).readlines()

n, m = map(int, inputs[0].split())
*A, = map(int, inputs[1].split())
BC = [tuple(map(int, bc.split())) for bc in inputs[2:]]

D = []
for a in A:
    heappush(D, a)
for b, c in BC:
    for _ in range(b):
        if c > D[0]:
            heappush(D, max(heappop(D), c))
print(sum(D))
Problem p03208 (python)

Fixed submission:
n, k, *H = map(int, open(0).read().split())
H.sort()
ans = 10 ** 10
for h0, h1 in zip(H, H[k-1:]):
  ans = min(ans, h1-h0)
print(ans)

Buggy submission (verdict: Runtime Error):
n, k, H = map(int, open(0).read().split())
H.sort()
ans = 10 ** 10
for h0, h1 in zip(H, H[k-1:]):
  ans = min(ans, h1-h0)
print(ans)
Problem p03221 (python)

Fixed submission:
inputs = open(0).readlines()
n, m = map(int, inputs[0].split())
PY = [map(int, x.split()) for x in inputs[1:]]
A = [[] for _ in range(n)]
B = [''] * m
for i, (p, y) in enumerate(PY):
    A[p-1].append([y, i])
    B[i] += '{:06}'.format(p)
for a in A:
    a.sort()
    for i in range(len(a)):
        B[a[i][1]] += '{:06}'.format(i+1)
print(*B, sep='\n')

Buggy submission (verdict: Runtime Error):
inputs = open(0).readlines()
n, m = map(int, inputs[0].split())
PY = [map(int, x.split()) for x in inputs[1:]]
A = [[] for _ in range(m)]
B = []
for i, (p, y) in enumerate(PY):
    A[p-1].append([y, i])
    B.append('{:06}'.format(p))
for a in A:
    a.sort()
    for i in range(len(a)):
        B[a[i][1]] += '{:06}'.format(i+1)
print(*B, sep='\n')
Problem p03252 (python)

Fixed submission:
S = input().strip()
T = input().strip()

ds = {}
dt = {}
ans = 'Yes'
for s, t in zip(S, T):
    if s not in ds or ds[s] == t:
        ds[s] = t
    else:
        ans = 'No'
        break
    if t not in dt or dt[t] == s:
        dt[t] = s
    else:
        ans = 'No'
        break
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
S, T = map(lambda x: x.strip(), open(0).read().split())

from collections import defaultdict
S, T = map(lambda x: x.strip(), open(0).read().split())

ds, dt = defaultdict(str), defaultdict(str)
ans = 'Yes'
for s, t in zip(S, T):
    if not ds[s] or ds[s] == t:
        ds[s] = t
    else:
        ans = 'No'
        break
    if not dt[t] or dt[t] == s:
        dt[t] = s
    else:
        ans = 'No'
        break
print(ans)

Buggy submission (verdict: Runtime Error):
S = input().strip()
T = input().strip()

ds = {}
dt = {}
ans = 'Yes'
for s, t in zip(S, T):
    if s not in ds or ds[s] == t:
        ds[s] = t
    else:
        ans = 'No'
        break
    if t not in dt or dt[s] == s:
        dt[t] = s
    else:
        ans = 'No'
        break
print(ans)
Problem p03315 (python)

Fixed submission:
S = input()
ans = 0
for c in S:
  if c == '+':
  	ans += 1
  elif c == '-':
    ans -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
ans = 0
for c in S:
  if c == '+':
  	ans += 1
  else c == '-':
    ans -= 1
print(ans)
Problem p03317 (python)

Fixed submission:
import sys
from math import ceil
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))

print(ceil((n-k)/(k-1))+1)

Buggy submission (verdict: Runtime Error):
import sys
from math import ceil
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))

if n == k:
    print(1)
else:
    former = index_min(A)[0]
    latter = n - 1 - former
    ceil(former / (k-1)), ceil(latter / (k-1))
    print(ceil(former / (k-1)) + ceil(latter / (k-1)))

Buggy submission (verdict: Runtime Error):
import sys
from math import ceil
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))

if n == k:
    print(1)
else:
    former = index_min(A)[0]
    latter = n - 1 - former
    ceil(former / (k-1)), ceil(latter / (k-1))
    print(ceil(former / (k-1)) + ceil(latter / (k-1)))
Problem p02557 (python)

Fixed submission:
from collections import Counter
import sys
import random
 
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ca = Counter(A)
cb = Counter(B)
for i in range(N+1):
    if ca[i] + cb[i] > N:
        print('No')
        sys.exit()

C = [0] * (N+1)
D = [0] * (N+1)

for i in range(N):
    C[i+1] += C[i] + ca[i+1]
    D[i+1] += D[i] + cb[i+1]

x = 0

for i in range(N):
    x = max(x, C[i+1] - D[i])

ans = [B[(i-x)%N] for i in range(N)]

print('Yes')
print(*ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
 
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ca = Counter(A)
cb = Counter(B)
if ca.most_common()[0][1] + cb.most_common()[0][1] > N:
    print('No')
    sys.exit()

print('Yes')
random.shuffle(B)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ca = Counter(A)
cb = Counter(B)
maxA = 0
maxB = 0
for item in ca.values():
    maxA = max(maxA, item)
for item in cb.values():
    maxB = max(maxB, item)
if maxA + maxB > N:
    print('No')
    sys.exit()

KEYS = sorted(cb.keys(), key=lambda x: cb[x])
KEYS.reverse()
index = 0

ans = []
for i in range(N):
    tmp = index
    while A[i] == KEYS[tmp] or cb[KEYS[tmp]] == 0:
        tmp += 1
    ans.append(KEYS[tmp])
    cb[KEYS[tmp]] -= 1
    if cb[KEYS[index]] == 0:
        index += 1

print('Yes')
print(*ans)
Problem p02580 (python)

Fixed submission:
import sys

H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W
S = set()
for _ in range(M):
    h, w = map(int,input().split())
    S.add((h-1, w-1))
    R[h-1] += 1
    C[w-1] += 1

r = max(R)
c = max(C)

HL = [i for i in range(H) if R[i] == r]
WL = [i for i in range(W) if C[i] == c]

for h in HL:
    for w in WL:
        if not (h, w) in S:
            print(r + c)
            sys.exit()

print(r + c - 1)

Buggy submission (verdict: Runtime Error):
H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W

L = []

for _ in range(M):
    h, w = map(int,input().split())
    R[h-1] += 1
    C[w-1] += 1
    L.append([h-1, w-1])

r = max(R)
c = max(C)

print(r + c - (R.count(r) * C.count(c) == sum(R[h] + C[w] == r + c for h, w in L))

Buggy submission (verdict: Runtime Error):
import sys

H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W
S = set()
for _ in range(M):
    h, w = map(int,input().split())
    S.add((h-1, w-1))
for i in range(M):
    h, w = S[i]
    R[h] += 1
    C[w] += 1

r = max(R)
c = max(C)

for h in [i for i in range(H) if R[i] == r]:
    for w in [i for i in range(W) if C[i] == c]:
        if not (h, w) in S:
            print(r + c)
            sys.exit()

print(r + c - 1)