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

Fixed submission:
h, w, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

c = [0 for _ in range(h)]
r = [0 for _ in range(w)]
bakuset = {}
for i, j in hw:
    # print(i, j)
    c[i-1] += 1
    r[j-1] += 1
    if not str(i-1) + "+" + str(j-1) in bakuset:
        bakuset[str(i-1) + "+" + str(j-1)] = 0
    # print(bakuset, i-1, j-1)
    bakuset[str(i-1) + "+" + str(j-1)] += 1

ans = max(c) + max(r)

mc = max(c)
mr = max(r)
cc = []
rr = []

for i in range(h):
    if c[i] == mc:
        cc.append(i)

for i in range(w):
    if r[i] == mr:
        rr.append(i)

flag = 10**10

for i in cc:
    for j in rr:
        if not str(i) + "+" + str(j) in bakuset:
            flag = 0
            break
        flag = min(flag, bakuset[str(i) + "+" + str(j)])
    if not flag:
        break

if flag:
    ans -= flag

print(ans)

Buggy submission (verdict: Runtime Error):
h, w, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

c = [0 for _ in range(h)]
r = [0 for _ in range(w)]
bakuset = {}
for i, j in hw:
    # print(i, j)
    c[i-1] += 1
    r[j-1] += 1
    if not str(i-1) + "+" + str(j-1) in bakuset:
        bakuset[str(i-1) + "+" + str(j-1)] = 0
    # print(bakuset, i-1, j-1)
    bakuset[str(i-1) + "+" + str(j-1)] += 1

ans = max(c) + max(r)

mc = max(c)
mr = max(r)
cc = []
rr = []

for i in range(h):
    if c[i] == mc:
        cc.append(i)

for i in range(h):
    if r[i] == mr:
        rr.append(i)

flag = 10**10

for i in cc:
    for j in rr:
        if not str(i) + "+" + str(j) in bakuset:
            flag = 0
            break
        flag = min(flag, bakuset[str(i) + "+" + str(j)])
    if not flag:
        break

if flag:
    ans -= 1

print(ans)
Problem p02598 (python)

Fixed submission:
def possible(x):
    global k
    cnt = 0
    for i in a:
        if i % x == 0:
            cnt += i // x - 1
        else:
            cnt += i // x

    if cnt <= k:
        return True
    return False

n, k = map(int, input().split())

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

mini = 1
maxi = max(a)

while mini <= maxi:
    mid = (mini + maxi) // 2
    res = possible(mid)
    if res:
        maxi = mid
    else:
        mini = mid
    # print(mini, mid, maxi)

    if mini+1 >= maxi:
        if maxi < mini:
            mini, maxi = maxi, mini
        if possible(mini):
            ans = mini
        else:
            ans = maxi
        break

print(ans)
# print(possible(4))

Buggy submission (verdict: Runtime Error):
def possible(x):
    global k
    cnt = 0
    for i in a:
        if i % x == 0:
            cnt += i // x - 1
        else:
            cnt += i // x

    if cnt <= k:
        return True
    return False

n, k = map(int, input().split())

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

mini = 0
maxi = max(a)

while mini <= maxi:
    mid = (mini + maxi) // 2
    res = possible(mid)
    if res:
        maxi = mid
    else:
        mini = mid
    # print(mini, mid, maxi)

    if mini+1 == maxi:
        if possible(maxi):
            ans = maxi
        else:
            ans = mini
        break

print(ans)
# print(possible(4))
Problem p02623 (python)

Fixed submission:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
ia = -1
ib = -1

nowtime = 0
cnt = 0
for i in range(n):
    if nowtime + a[i] <= k:
        nowtime += a[i]
        cnt += 1
        ia = i
    else:
        break

ans = cnt
# print(ans, nowtime)
for i in range(m):
    while nowtime + b[i] > k and ia >= 0:
        nowtime -= a[ia]
        cnt -= 1
        ia -= 1
    if nowtime + b[i] > k:
        break
    nowtime += b[i]
    cnt += 1
    ans = max(ans, cnt)

print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0
i = 0
j = 0
while k >= 0:
    if i >= len(a) and j >= len(b):
        break

    if i >= len(a):
        if k >= b[i]:
            k -= b[i]
            j += 1
            cnt += 1
        else:
            break
        continue
    if j >= len(b):
        if k >= a[i]:
            k -= a[i]
            i += 1
            cnt += 1
        else:
            break
        continue

    if a[i] >= b[j]:
        if k >= a[i]:
            k -= a[i]
            i += 1
            cnt += 1
        else:
            break
    else:
        if k >= b[i]:
            k -= b[i]
            j += 1
            cnt += 1
        else:
            break

print(cnt)
Problem p02685 (python)

Fixed submission:
n, m, k = map(int, input().split())
# tmp = m
mod = 998244353
ans = m * pow(m-1, n-1, mod)
ans %= mod
ncm = 1
ncm_list = [0 for _ in range(k)]
for i in range(k):
    ncm *= n-1-i
    ncm *= pow(i+1, mod-2, mod)
    ncm %= mod
    ncm_list[i] = ncm

powm_list = [0 for _ in range(k)]
tmp = m * pow(m-1, n-k-1, mod)
if k != 0:
    powm_list[k-1] = tmp
    for i in range(k-2, -1, -1):
        tmp *= (m-1)
        tmp %= mod
        powm_list[i] = tmp

for i in range(k):
    ans += ncm_list[i] * powm_list[i]
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
# tmp = m
mod = 998244353
ans = m * pow(m-1, n-1, mod)
ans %= mod
ncm = 1
ncm_list = [0 for _ in range(k)]
for i in range(k):
    ncm *= n-1-i
    ncm *= pow(i+1, mod-2, mod)
    ncm %= mod
    ncm_list[i] = ncm

powm_list = [0 for _ in range(k)]
tmp = m * pow(m-1, n-k-1, mod)
powm_list[k-1] = tmp
for i in range(k-2, -1, -1):
    tmp *= (m-1)
    tmp %= mod
    powm_list[i] = tmp

for i in range(k):
    ans += ncm_list[i] * powm_list[i]
    ans %= mod

print(ans)
Problem p02948 (python)

Fixed submission:
import heapq
n, m = map(int, input().split())

jobs = [[] for i in range(10**5+1)]

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

candidate = []
ans = 0
for i in range(m+1):
    for j in jobs[i]:
        heapq.heappush(candidate, -j)

    # print(i, candidate)
    if len(candidate) >= 1:
        ans += heapq.heappop(candidate) * -1


print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

jobs = [[] for i in range(10**4+1)]

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

job_schedules = [0 for _ in range(m+1)]
today = m
for i in range(len(jobs)-1, -1, -1):
    jobs[i].sort()
    for j in jobs[i]:
        day = min(today, m - j)
        while job_schedules[day] and day >= 0:
            day -= 1
        if day < 0:
            break
        job_schedules[day] = i

print(sum(job_schedules))
Problem p02987 (python)

Fixed submission:
s = list(input())
s.sort()
cnt = 1
ans = 1
# print(s)
for i in range(1, 4):
  # print(cnt)
  if s[i - 1] != s[i]:
    if cnt < 2:
      ans = 0
      break
    cnt = -1
  if not ans:
    break
  cnt += 1
if cnt > 3:
  ans = 0
if not ans:
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
s = input()
s.sort()
cnt = 1
ans = 1
for i in range(1, 4):
  if s[i - 1] != s[i]:
    if cnt < 2:
      ans = 0
      break
    cnt = 1
  if not ans:
    break
if cnt > 2:
  ans = 0
if not ans:
  print("No")
else:
  print("Yes")
Problem p03127 (python)

Fixed submission:
import fractions
N = int(input())
A = list(map(int, input().split()))
import math
A.sort()
ans = A[0]

for i in A:
    ans = fractions.gcd(ans, i)

print(ans)

Buggy submission (verdict: Runtime Error):
import fraction
N = int(input())
A = list(map(int, input().split()))
import math
A.sort()
ans = 10000000000000000000000000000000000000000000

for i in A:
    ans = fraction.gcd(ans, i)

print(ans)
Problem p03776 (python)

Fixed submission:
import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def ABC057D():

    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v)[::-1]

    anslist = []
    for i in range(A, B + 1):

        anslist.append([sum(v[0:i]) / i, i, v[i - 1]])
    anslist.sort()
    anslist = anslist[::-1]
    ans = anslist[0][0]
    key = anslist[0][2]
    long = anslist[0][1]
    print(ans)
    for i in range(1, len(anslist)):
        if anslist[i][0] == anslist[i - 1][0]:
            ans = anslist[i][0]
            key = anslist[i][2]
            long = anslist[i][1]
        else:
            break
    #print(anslist)
    #print(ans, key, long)
    cnt = 0
    for i in v:
        if i == key:
            cnt += 1

    c = 0
    for i in v[:long]:
        #print(i)
        if i == key:
            c += 1
    #print(c, long)
    ans = 0
    if c == long:
        for i in range(A,  min(B + 1, cnt + 1)):
            ans += cc(cnt, i)
    else:
        ans = cc(cnt, c)
    #print(anslist)
    #print(cnt, c, long)
    print(ans)
ABC057D()

Buggy submission (verdict: Runtime Error):
def ABC057D():

    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v)[::-1]

    anslist = []
    for i in range(A, B + 1):

        anslist.append([sum(v[0:i]) / i, i, v[i - 1]])
    anslist.sort()
    anslist = anslist[::-1]
    ans = anslist[0][0]
    key = anslist[0][2]
    long = anslist[0][1]
    print(ans)
    for i in range(1, len(anslist)):
        if anslist[i][0] == anslist[i - 1][0]:
            ans = anslist[i][0]
            key = anslist[i][2]
            long = anslist[i][1]
        else:
            break
    #print(anslist)
    #print(ans, key, long)
    cnt = 0
    for i in v:
        if i == key:
            cnt += 1

    c = 0
    for i in v[:long]:
        #print(i)
        if i == key:
            c += 1
    #print(c, long)
    ans = 0
    if c == long:
        for i in range(A,  min(B + 1, cnt + 1)):
            ans += cc(cnt, i)
    else:
        ans = cc(cnt, c)
    #print(anslist)
    #print(cnt, c, long)
    print(ans)
ABC057D()
Problem p03803 (python)

Fixed submission:
A, B = map(int, input().split())
if A == B:
  print("Draw")
elif A == 1:
  print("Alice")
elif B == 1:
  print("Bob")
else:
  if A < B:
    print("Bob")
  else:
    print("Alice")

Buggy submission (verdict: Runtime Error):
A, B = map(int, input())
if A == B:
  print("Draw")
elif A == 1:
  print("Alice")
elif B == 1:
  print("Bob")
else:
  if A < B:
    print("Bob")
  else:
    print("Alice")
Problem p02623 (python)

Fixed submission:
from itertools import accumulate

N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
cumsum_A, cumsum_B = [0] + list(accumulate(A)), [0] + list(accumulate(B))
ans = 0
j = M
for i in range(N+1):
    if cumsum_A[i] > K: break
    while cumsum_A[i] + cumsum_B[j] > K: j -= 1
    ans = max(ans, i + j)
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
cumsum_A, cumsum_B = [0] + list(accumulate(A)), [0] + list(accumulate(B))
ans = 0
j = M
for i in range(N+1):
    if cumsum_A[i] > K: break
    while cumsum_A[i] + cumsum_B[j] >= K: j -= 1
    ans = max(ans, i + j)
print(ans)
Problem p02833 (python)

Fixed submission:
from math import log10

N = int(input())
if N == 0 or N % 2 == 1: print(0)
else:
    temp = [N // ((5**i) * 2) for i in range(1, 2 * int(log10(N)) + 1)]
    ans = sum(temp)
    print(ans)

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

N = int(input())
if N % 2 == 1: print(0)
else:
    temp = [N // ((5**i) * 2) for i in range(1, 2 * int(log10(N)) + 1)]
    ans = sum(temp)
    print(ans)
Problem p02948 (python)

Fixed submission:
from heapq import *
from collections import defaultdict

N, M = map(int, input().split())
arbeits = defaultdict(list)
for _ in range(N):
    a, b = map(int, input().split())
    arbeits[a].append(b)
heap = []
ans = 0
for i in range(1, M+1):
    for b in arbeits[i]:
        heappush(heap, -b)
    if heap:
        ans += - heappop(heap)
print(ans)

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

N, M = map(int, input().split())
arbeits = defaultdict(list)
for _ in range(N):
    a, b = map(int, input().split())
    arbeits[a].append(b)
heap = []
ans = 0
for i in range(1, M+1):
    for b in arbeits[i]:
        heappush(heap, -b)
    ans += - heappop(heap)
print(ans)
Problem p02951 (python)

Fixed submission:
A, B, C = map(int, input().split())
print(max(C - (A - B), 0))

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
print(max(C - (A - B)), 0)
Problem p02984 (python)

Fixed submission:
N = int(input())
*A, = map(int, input().split())
X = [0]*N
X_total = sum(A)
A_odd = sum([A[i % N] for i in range(1, N, 2)])
A_even = sum([A[i % N] for i in range(2, N+1, 2)])
for i in range(N):
    X[i] = X_total - 2*(A_odd if i % 2 == 0 else A_even)
    if i % 2 == 0: A_odd += A[i] - A[(i+1) % N]
    else: A_even += A[i] - A[(i+1) % N]
print(*X)

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

N = int(input())
*A, = map(int, input().split())
A = np.array(A, dtype='int64')
C = np.diag([1 for _ in range(N)]) + np.diag([1 for _ in range(N-1)], k=1)
C[-1, 0] = 1
C = np.array(C, dtype='int64')
X = 2*np.linalg.solve(C, A)
X = list(map(int, X))
print(*X)

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

N = int(input())
*A, = map(int, input().split())
A = np.array(A, dtype='int64')
C = np.diag([1 for _ in range(N)]) + np.diag([1 for _ in range(N-1)], k=1)
C[-1, 0] = 1
X = np.linalg.solve(C, A)
X = list(map(int, X))
print(*X)
Problem p03053 (python)

Fixed submission:
import numpy as np
from itertools import product
from collections import deque

H, W = map(int, input().split())
val = []
INF = 10**9
for i in range(H):
    tmp = input()
    val.append([0 if tmp[j] == '#' else INF for j in range(W)])
val = np.array(val)

for i in range(H-1):
    val[i+1, :] = np.minimum(val[i, :]+1, val[i+1, :])
for i in range(H-1, 0, -1):
    val[i-1, :] = np.minimum(val[i, :]+1, val[i-1, :])
for j in range(W-1):
    val[:, j+1] = np.minimum(val[:, j]+1, val[:, j+1])
for j in range(W-1, 0, -1):
    val[:, j-1] = np.minimum(val[:, j]+1, val[:, j-1])

print(val.max())

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

H, W = map(int, input().split())
A = []
checked = []
black = []
INF = 10**9
for i in range(H):
    tmp = input()
    A.append(tmp)
    checked.append([0 if tmp[j] == '#' else INF for j in range(W)])
    black += [((i, j), 0) for j in range(W) if checked[-1][j] == 0]
black = deque(black)
ans = 0
while black:
    (i, j), d = black.popleft()
    ans = max(ans, d)
    if i > 0:
        checked[i-1][j] = min(checked[i-1][j], d+1)
        black.append((i-1, j), checked[i-1][j])
    if i < H-1:
        checked[i+1][j] = min(checked[i+1][j], d+1)
        black.append((i+1, j), checked[i+1][j])
    if j > 0:
        checked[i][j-1] = min(checked[i][j-1], d+1)
        black.append((i, j-1), checked[i][j-1])
    if j < W-1:
        checked[i][j+1] = min(checked[i][j+1], d+1)
        black.append((i, j+1), checked[i][j+1])
print(ans)
Problem p03054 (python)

Fixed submission:
H, W, N = map(int, input().split())
s_r, s_c = map(int, input().split())
S = input()
T = input()

# vertical direction
up, down = 0, H-1
for i in range(N-1, -1, -1):
    if T[i] == 'U':
        down = min(H-1, down + 1)
    elif T[i] == 'D':
        up = max(0, up - 1)
    
    if S[i] == 'U':
        up += 1
    elif S[i] == 'D':
        down -= 1
    
    if up > down:
        print('NO')
        exit()
        
# horizontal direction
left, right = 0, W-1
for i in range(N-1, -1, -1):    
    if T[i] == 'L':
        right = min(W-1, right + 1)
    elif T[i] == 'R':
        left = max(0, left - 1)
    
    if S[i] == 'L':
        left += 1
    elif S[i] == 'R':
        right -= 1
    
    if left > right:
        print('NO')
        exit()
if up <= s_r-1 <=down and left <= s_c-1 <= right:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
H, W, N = map(int, input().split())
s_r, s_c = map(int, input().split())
S = input()
T = input()

# vertical direction
up, down = 0, H
for i in range(H, -1, -1):
    if T[i] == 'U':
        down = min(H, down + 1)
    elif T[i] == 'D':
        up = max(0, up - 1)
    
    if S[i] == 'U':
        up += 1
    elif S[i] == 'D':
        down -= 1
    
    if up >= down:
        print('NO')
        exit()
        
# horizontal direction
left, right = 0, W
for j in range(W-1, -1, -1):    
    if T[j] == 'L':
        right = min(W, right + 1)
    elif T[j] == 'R':
        left = max(0, left - 1)
    
    if S[j] == 'L':
        left += 1
    elif S[j] == 'R':
        right -= 1
    
    if left >= right:
        print('NO')
        exit()
if up <= s_r < down and left <= s_c < right:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
import sys

H, W, N = map(int, input().split())
s_r, s_c = map(int, input().split())
S = input()
T = input()

# vertical direction
up, down = 0, H-1
for i in range(H, -1, -1):
    if T[i] == 'U':
        down = min(H, down + 1)
    elif T[i] == 'D':
        up = max(0, up - 1)
    
    if S[i] == 'U':
        up += 1
    elif S[i] == 'D':
        down -= 1
    
    if up >= down:
        print('NO')
        sys.exit()
        
# horizontal direction
left, right = 0, W-1
for j in range(W-1, -1, -1):    
    if T[j] == 'L':
        right = min(H, right + 1)
    elif T[j] == 'R':
        left = max(0, left - 1)
    
    if S[j] == 'L':
        left += 1
    elif S[j] == 'R':
        right -= 1
    
    if left >= right:
        print('NO')
        sys.exit()
if up <= s_r <= down and left <= s_c <= right:
    print('YES')
else:
    print('NO')
Problem p03250 (python)

Fixed submission:
abc = list(map(int, input().split()))
abc = list(reversed(sorted(abc)))

ans = abc[0]*10 + abc[1] + abc[2]
print(ans)

Buggy submission (verdict: Runtime Error):
*S = sorted(input().split(), reverse=True)
print(eval(S[0]+S[1]+ '+' + S[2]))
Problem p03426 (python)

Fixed submission:
H, W, D = map(int, input().split())
pos = [None]*(H*W)

for i in range(H):
    row = list(map(int, input().split()))
    for j in range(W):
        pos[row[j]-1] = (i, j)

costs = [0]*(H*W)
for i in range(1, D+1):
    current = i + D
    while current <= H*W:
        costs[current - 1] = costs[current - 1 - D] + abs(pos[current - 1][0] - pos[current - 1 - D][0]) + abs(pos[current - 1][1] - pos[current - 1 - D][1])
        current += D

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    MP = costs[R-1] - costs[L-1]
    print(MP)

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

H, W, D = map(int, input().split())
pos = [None]*(H*W)

for i in range(H):
    row = list(map(int, input().split()))
    for j in row:
        pos[row[j]] = (i, j)

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    if L == R:
        print(0)
    else:
        to_be_checked = [i for i in range(L, R+1, D)]
        moves = len(to_be_checked)
        pos_list = [tpl for tpl in to_be_checked]

        MP = sum([np.absolute(pos_list[i][0] - pos_list[i+1][0]) for i in range(moves-1)]) + sum([np.absolute(pos_list[i][1] - pos_list[i+1][1]) for i in range(moves-1)])

        print(MP)
Problem p02777 (python)

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

if U == S:
    print(A-1, B)
else:
    print(A, B-1)

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

if U == S:
    print(S-1, T)
else:
    print(S, T-1)
Problem p02831 (python)

Fixed submission:
from fractions import gcd

A, B = map(int, input().split())
G = gcd(A, B)
print(A*B // G)

Buggy submission (verdict: Runtime Error):
from math import gcd

A, B = map(int, input().split())
G = gcd(A, B)
print(A*B // G)
Problem p02881 (python)

Fixed submission:
def make_divisors(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


N = int(input())
divs = make_divisors(N)
if len(divs) % 2 == 0:
    print(divs[len(divs)//2 - 1] + divs[len(divs)//2] - 2)
else:
    print(divs[len(divs)//2] * 2 - 2)

Buggy submission (verdict: Runtime Error):
def make_divisors(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


N = int(input())
divs = make_divisors(N)
if len(divs) % 2 == 0:
    print(divs[len(divs)//2 - 1] + divs[len(divs)//2] - 2)
else:
    print(divs[len(divs//2)] * 2 - 2)
Problem p02891 (python)

Fixed submission:
S = input()
K = int(input())
ans_s2, ans_s3 = 0, 0

# 例外処理
if len(S) == 1:
    print(K // 2)
    exit()
elif len(set(S)) == 1:
    print(len(S) * K // 2)
    exit()

S_double = S + S
for i in range(1, len(S_double)):
    if S_double[i] == S_double[i - 1]:
        S_double = S_double[: i] + "?" + S_double[i + 1:]
        ans_s2 += 1

S_triple = S + S + S
for j in range(1, len(S_triple)):
    if S_triple[j] == S_triple[j - 1]:
        S_triple = S_triple[: j] + "?" + S_triple[j + 1:]
        ans_s3 += 1

ans_increase = ans_s3 - ans_s2  #K>=3のときの増分

ans = ans_s2 + max(0, ans_increase * (K - 2))
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
ans = 0

T = ""
for _ in range(K):
    T += S

for ti in range(1, len(T)):
    if T[i] == T[i - 1]:
        T = T[: i] + "?" + T[i + 1:]
        ans += 1

print(ans)
Problem p02948 (python)

Fixed submission:
import heapq
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):
    while (j < N) and (X[j][0] <= i):
        heapq.heappush(hq, -X[j][1])
        j += 1
    if len(hq):
        ans -= heapq.heappop(hq)

print(ans)

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

N, M = map(int, input().split())
for _ in range(N):
    A, B = map(int, input().split())

hq = []
ans = 0

for i in range(1, M + 1):
    while j < N and A[j] <= i:
        heapq.heappush(hq, -B[j])
        j += 1
    if len(hq):
        ans -= heapq.heappop(hq)

print(ans)
Problem p02984 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
X = [0] * N

X[0] = sum(A) - 2 * (sum([A[i] for i in range(N) if i % 2 == 1]))

for i in range(N - 1):
	X[i + 1] = 2 * A[i] - X[i]

print(" ".join(map(str, X)))

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))

# solve "mat * x = b" about x
x, y = np.identity(N), np.identity(N)
y0 = y[0]
y = np.reshape(np.append(np.delete(y, 0, 0), y0), (N, N))
mat = (x + y) / 2

b = np.array(A)

for i in range(len(mat) - 1):
    for j in range(i + 1, len(mat)):
        coef = mat[j][i] / mat[i][i]
        mat[j] -= mat[i] * coef
        b[j] -= b[i] * coef

for i in range(len(mat) - 1, 0, -1):
    b[i] /= mat[i][i]
    mat[i] /= mat[i][i]
    for j in range(i):
        b[j] -= b[i] * mat[j][i]
        mat[j][i] = 0

b = [int(n) for n in b]
b[0] += 1
print(" ".join(map(str, b)))

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))

x = np.identity(N)
y = np.identity(N)
y0 = y[0]
y = np.reshape(np.append(np.delete(y, 0, 0), y0), (N, N))
a = (x + y) / 2

b = np.array(A)
b = b.reshape((1, N))
b = b.transpose()

ans = np.linalg.solve(a, b)
ans = [int(n) for n in ans]

print(" ".join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))

x = np.identity(N)
y = np.identity(N)
y0 = y[0]
y = np.delete(y, 0, 0)
y = np.append(y, y0)
y = np.reshape(y, (N, N))
a = x + y
b = np.array(A)

ans = np.linalg.solve(a, b)
ans = [int(n * 2) for n in ans]

print(" ".join(map(str, ans)))