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

Fixed submission:
def solve():
    mod = 10 ** 9 + 7
    fac, finv, inv = COMinit(10 ** 6, mod)

    X, Y = map(int, input().split())
    if (X + Y) % 3 != 0:
        print(0)
        return
    
    ans = 0
    for one_cnt in range(10 ** 6):
        x1 = one_cnt * 2
        y1 = one_cnt * 1
        remain_x = X - x1
        remain_y = Y - y1
        if remain_x * 2 != remain_y or remain_x < 0 or remain_y < 0:
            continue
        two_cnt = remain_x
        ans += COM(one_cnt+two_cnt, one_cnt,mod,fac,finv,inv)
    
    print(ans)

def n_combination(n, r, mod):
    numer_sum = 1
    denom_sum = 1
    for i in range(r):
        numer_sum *= n - i
        numer_sum % mod
        denom_sum *= r - i
        numer_sum % mod
    
    return numer_sum * modinv(denom_sum, mod) % mod

def modinv(a, mod):
    return pow(a, mod-2, mod)
    
def COMinit(N, mod):
    fac = [0] * N
    finv = [0] * N
    inv = [0] * N

    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1

    for i in range(2, N):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
    
    return fac, finv, inv

def COM(n, r, mod, fac, finv, inv):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
import math
def solve():
    a,b,c = map(int, input().split())
    if (4 * a * b < (c-a-b)**2 and c-a-b>=0) or (4 * a * b > (c-a-b) ** 2 and c-a-b<0):
        print('Yes')
    else:
        print('No')
    
if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
import math
def solve():
    a,b,c = map(int, input().split())
    if (4 * a * b < (c-a-b)**2 and c-a-b>=0) \
        or (4 * a * b > (c-a-b) ** 2 and c-a-b<0):
        print('Yes')
    else:
        print('No')
    
if __name__ == '__main__':
    solve()
Problem p02990 (python)

Fixed submission:
def solve():
    N, K = map(int,input().split())
    MOD = 10 ** 9 + 7
    fac, finv, inv = COMinit(N+1,MOD)
    ans = []
    for i in range(1,K+1):
        com1 = COM(K-1,i-1,MOD,fac,finv,inv)
        if N-K-(i-1) < 0:
            ans.append(0)
            continue
        com2 = COM(N-K+1,N-K-(i-1),MOD,fac,finv,inv)
        ans.append(com1*com2%MOD)
    
    print(*ans,sep='\n')

# COMの前処理
# テーブルを作る
# O(n)
def COMinit(N, mod):
    fac = [0] * N
    finv = [0] * N
    inv = [0] * N

    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1

    for i in range(2, N):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
    
    return fac, finv, inv

# nCrを計算 前処理としてCOMinitの実行が必要
# O(1)
def COM(n, r, mod, fac, finv, inv):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
def solve():
    N, K = map(int,input().split())
    MOD = 10 ** 9 + 7
    fac, finv, inv = COMinit(N,MOD)
    ans = []
    for i in range(1,K+1):
        com1 = COM(K-1,i-1,MOD,fac,finv,inv)
        if N-K-(i-1) < 0:
            ans.append(0)
            continue
        com2 = COM(N-K+1,N-K-(i-1),MOD,fac,finv,inv)
        ans.append(com1*com2%MOD)
    
    print(*ans,sep='\n')

# COMの前処理
# テーブルを作る
# O(n)
def COMinit(N, mod):
    fac = [0] * N
    finv = [0] * N
    inv = [0] * N

    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1

    for i in range(2, N):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
    
    return fac, finv, inv

# nCrを計算 前処理としてCOMinitの実行が必要
# O(1)
def COM(n, r, mod, fac, finv, inv):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

if __name__ == '__main__':
    solve()
Problem p02790 (python)

Fixed submission:
a,b=map(int,input().split())
if a<b:
    ans=str(a)*b
else:
    ans=str(b)*a
print(ans)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a<b:
    print ('a') for i in range(b)
else:
    print ('b') for i in range(a)
Problem p02699 (python)

Fixed submission:
# import math
# import numpy as np
# import itertools
# import heapq
# =map(int,input().split())
s,w=map(int,input().split())
if w>=s:
    print('unsafe')
else:
    print('safe')

Buggy submission (verdict: Runtime Error):
# import math
# import numpy as np
# import itertools
# import heapq
# =map(int,input().split())
w=int(input())
s=int(input())
if w>=s:
    print('unsafe')
else:
    print('safe')
Problem p02723 (python)

Fixed submission:
s = input()
if s[2] == s[3]:
    if s[4] == s[5]:
        print('Yes')
    else: print('No')
else: 
    print('No')

Buggy submission (verdict: Runtime Error):
e = list(map(int,input().split()))
K = e[0]
N = e[1]
a = list(map(int,input().split()))
c = [a[i+1] - a[i] for i in range(N-1)]
f = a[0]+ K - a[N-1]
c.append(f)
d = max(c)
print(K - d)
Problem p02725 (python)

Fixed submission:
e = list(map(int,input().split()))
K = e[0]
N = e[1]
a = list(map(int,input().split()))
c = [a[i+1] - a[i] for i in range(N-1)]
f = a[0]+ K - a[N-1]
c.append(f)
d = max(c)
print(K - d)

Buggy submission (verdict: Runtime Error):
K,N = map(int,input().split())
a = list(map(int,input().split()))
c = a[1:]-a[:-1]
d = max(c)
print(K - d)
Problem p02729 (python)

Fixed submission:
a = list(map(int,input().split()))
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
x = a[0]
y = a[1]
if(x != 1) and (x != 0):
    c = (combinations_count(x, 2))
else:
    c = 0
if(y != 1) and (y != 0):
    d = (combinations_count(y, 2))
else:
    d = 0
print(c + d)

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
x = a[0]
y = a[1]
z = 1
if(x is not z){
    c = (combinations_count(x, 2));
}
else{
    c = 0;
}
if(y is not z){
    d = (combinations_count(y, 2));
}
else{
    d = 0;
}
print(c + d)

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
x = a[0]
y = a[1]
z = 1
if (x != z)
    c = (combinations_count(x, 2)) 
else 
    c = 0
if (y != z)
    d = (combinations_count(y, 2))
else 
    d = 0
print(c + d)
Problem p03775 (python)

Fixed submission:
import sys
N=int(input())
ans=[]
if N==1:
    print(1)
    sys.exit()

for i in range(int(N**0.5),0,-1):
    if N%i==0:
        a=str(N//i)
        print(len(a))
        sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
ans=[]
for i in range(int(N**0.5)-1,N+1):
    if N%i==0:
        a=str(i)
        print(len(a))
        break
Problem p02578 (python)

Fixed submission:
N = int(input())
heights = list(map(int, input().split()))
before = 0
answer = 0

for h in heights:
  if h < before:
    answer += before - h
  else:
    before = h
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
heights = list(map(int, input().split()))
before = 0
answer = 0

for h in heights:
  if h < before:
    answwer += before - h
  else:
    before = h
print(answer)
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))
a_time = 0
b_time = 0
a_times = [0 for _ in range(N+1)]
b_times = [0 for _ in range(M+1)]
for i, a in enumerate(a_books):
  a_time += a
  a_times[i+1] = a_time
  
for i, b in enumerate(b_books):
  b_time += b
  b_times[i+1] = b_time
  
result = 0
l = 0
for i in range(N+1):
  if l == M:
    break
  while(l <= M):
    if a_times[N-i] + b_times[l] <= K:
      result = max(result, N-i+l)
      l += 1
    else:
      break
print(result)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ab_sum , answer, b_i = sum(B), 0, M
for a_i in range(N+1):
  while b_i>0 and ab_sum >K:
    b_i -= 1
    ab_sum -= B[b_i]
  if ab_sum >K:
    break
  answer = max(answer, a_i+b_i)
  ab_sum += A[a_i]

print(answer)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))
a_time = 0
b_time = 0
a_times = [0 for _ in range(N+1)]
b_times = [0 for _ in range(M+1)]
for i, a in enumerate(a_books):
  a_time += a
  a_times[i+1] = a_time
  
for i, b in enumerate(b_books):
  b_time += b
  b_times[i+1] = b_time
  
result = 0
l = 0
for i in range(N+1):
  if l == M:
    break
  while(True):
    if a_times[N-i] + b_times[l] <= K:
      result = max(result, N-i+l)
      l += 1
    else:
      break
print(result)
Problem p02659 (python)

Fixed submission:
from decimal import *
import math

A, B = input().split()
a = Decimal(A)
b = Decimal(B)
ib = Decimal(100*b)

print(math.floor((a*ib)/Decimal(100)))

Buggy submission (verdict: Runtime Error):
A, B = input().split()
a = int(A)
b = float(B)
ib = int(B*100)

print(int((a*ib)/100))

Buggy submission (verdict: Runtime Error):
A, B = input().split()
a = int(A)
fb = float(B)
ib = int(b)
print(a*ib + int(a*fb))
Problem p02695 (python)

Fixed submission:
from collections import deque

N, M, Q = map(int, input().split())
queries = [list(map(int, input().split())) for _ in range(Q)]
patterns = []

ptn = deque([])
for i in range(M):
  ptn.append([i])
while len(ptn) > 0:
  p = ptn.pop()
  if len(p) < N:
    for i in range(p[-1], M):
      ptn.append(p+[i])
  else:
    patterns.append(p)
answer = 0
for p in patterns:
  point = 0
  for a, b, c, d in queries:
    if p[b-1]-p[a-1] == c:
      point += d
  answer = max(answer, point)
print(answer)

Buggy submission (verdict: Runtime Error):
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Problem p02773 (python)

Fixed submission:
N = int(input())
words = {}
for _ in range(N):
  word = input()
  if word in words:
    words[word] += 1
  else:
    words[word] = 1
sorted_words = sorted(words.items(), key=lambda x: (-x[1], x[0]))
max_v = sorted_words[0][1]
for k, v in sorted_words:
  if v == max_v:
    print(k)
  else:
    exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
dict = {}
for _ in range(N):
  word = input()
  if word in dict:
    dict[word] += 1
  else:
    dict[word] = 1
sorted_dict = sorted(dict.items(), key=lambda(k,v): (-v,k))
max_v = sorted_dict[0][1]
for k, v in sorted_dict:
  if v == max_v:
    print(k)
  else:
    exit()
Problem p02831 (python)

Fixed submission:
import math

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

Buggy submission (verdict: Runtime Error):
import math

A, B = map(int, input().split())
print(a*b//math.gcd(a, b))
Problem p02835 (python)

Fixed submission:
if sum(list(map(int, input().split()))) > 21:
  print('bust')
else:
  print('win')

Buggy submission (verdict: Runtime Error):
if sum(list(map(int, input()))) > 21:
  print('bust')
else:
  print('win')
Problem p02935 (python)

Fixed submission:
N = int(input())
nums = list(map(int, input().split()))
nums.sort()
ans = nums[0]
for num  in nums[1:]:
  ans = (ans + num)/2
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = list(map(int, input().split()))
nums.sort()
ans = num
for num  in nums[1:]:
  ans = (ans + num)/2
print(ans)
Problem p02948 (python)

Fixed submission:
import heapq

MAX = 10**5+1
N, M = map(int, input().split())
works = [[] for _ in range(MAX)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

N, M = map(int, input().split())
works = [[] for _ in range(M+1)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

N, M = map(int, input().split())
works = [[] for _ in range(M+1)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)
Problem p02959 (python)

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

sum_m = 0
killed = 0
rest = 0
for i in range(0, N):
  killed = min(H[i]+rest, M[i])
  rest = max(0, min(H[i]+rest-killed, H[i]))
  sum_m += killed
sum_m += min(rest, M[-1])
print(sum_m)

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

sum_m = 0
rest = 0
rest = max(0, H[1]-M[1])
sum_m += min(H[1], M[1])
for i in range(1, N):
  rest = max(0, H[i]+rest-M[i])
  if M[i] >= H[i]+rest:
    sum_m += H[i]+rest
  else:
    sum_m += M[i]
sum_m += min(rest, M[-1])

print(sum_m)
Problem p03011 (python)

Fixed submission:
F, S, T = map(int, input().split())
FS = F + S
ST = S + T
TF = T + F
L = [FS, ST, TF]
print(min(L))

Buggy submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) >= abs(H - S):
    print(abs(2 * S - 2 * H))
    break
Problem p03012 (python)

Fixed submission:
num = int(input())
A = list(map(int, input().split()))
F = sum(A)
H = F / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) > abs(H - S):
    print(abs(2 * S - F))
    break

Buggy submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) >= abs(H - S):
    # print(abs(2 * S - 2 * H))
    # break()

Buggy submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S = A[i]
  if abs(H - (S + A[i+1])) >= abs(H - S):
    # print(abs(2 * S - 2 * H))
    break()

Buggy submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S = A[i]
  if abs(H - (S + A[i+1])) >= abs(H - S):
    print(abs(2 * S - 2 * H))
    break()

Buggy submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S = A[i]
  if abs(H - (S + A[i+1])) >= abs(H - S):
    print(abs(2 * S - 2 * H))

Buggy submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S = A[i]
  if (H - (S + A[i+1])) >= (H - S):
    print(abs(2 * S - 2 * H)

Buggy submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A)
S = 0
for i in range(num):
  S = A[i]
  if (H - (S + A[i+1])) >= (H - S):
    print(abs(2 * S - 2 * H)
Problem p03038 (python)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]

L = []
BC.sort(key=lambda x:x[1], reverse=True)
A.sort()
# ans = sum(A)
ans = 0
# flag = False
cnt = 0
# for k in range(N):
#     if k <= len_L-1:
#         if flag and L[k] > A[k]:
#             ans += L[k]
#         else:
#             flag = False
#             ans += A[k]
#     else:
#         ans += A[k]
for i in range(M):
    for j in range(BC[i][0]):
        if cnt < N and A[cnt] < BC[i][1]:
            ans += BC[i][1]
            cnt += 1
        else:
            break
    else:
        continue
    break

if cnt < N:
    ans += sum(A[cnt::])

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]

A.sort()
for i in range(M):
  cnt = 0
  for j in range(M):
    if cnt >= BC[i][0]:
      break
    if BC[i][1] > A[j]:
      A[j] = BC[i][1]
      cnt += 1
  if i != M-1:
    A.sort()
print(sum(A))
Problem p03041 (python)

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

if K < len(A):
    ans = A[:K-1] + A[K-1].lower() + A[K:]
else:
    ans = A[:K-1] + A[K-1].lower()
print(ans)

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

N = int(input())
W = [list(map(int, input().split())) for _ in range(N-1)]
nodes = [[] for _ in range(N+1)]
for w in W:
    nodes[w[0]].append((w[1], w[2]))
    nodes[w[1]].append((w[0], w[2]))
ans = [-1] * (N+1)
ans[1] = 0
def search(num, root, dis):
    for node in nodes[num]:
        sum_d = dis
        if node[0] != root:
            idx = node[0]
            sum_d += node[1]%2
            if sum_d%2 != 0:
                ans[idx] = 1
            else:
                ans[idx] = 0
            search(idx, num, sum_d)

search(1, 0, 0)
for answer in ans[1:]:
    print(answer)

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

A[K-1::] = A[k-1::].lower()
print(A)
Problem p03077 (python)

Fixed submission:
N = int(input())
cities = [int(input()) for i in range(5)]

min_city = min(cities)
if N <= min_city:
  print(5)
else:
  times = N//min_city
  if N%min_city == 0:
    print(5+times-1)
  else:
    print(5+times)

Buggy submission (verdict: Runtime Error):
N = int(input())
cities = [int(input()) for i in range(N)]

min_city = min(cities)
if N < min_city:
  print(5)
else:
  times = N//min_city
  print(5+times)
Problem p03107 (python)

Fixed submission:
S = input()

N = len(S)

cnt_zero = 0
for i in range(N):
  if S[i] == '0':
    cnt_zero += 1
if cnt_zero <= N - cnt_zero:
  print(cnt_zero*2)
else:
  print((N-cnt_zero)*2)

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

N = len(S)

cnt_zero = 0
for i in range(N):
  if S[i] == '0':
    cnt += 1
if cnt_zero <= N - cnt_zero:
  print(cnt_zero*2)
else:
  print((N-cnt_zero)*2)
Problem p03127 (python)

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

Lifes.sort(key=lambda x:-x)

ans = Lifes[N-1]

# for i in range(N):
#   for j in range(i, N):
#     life = Lifes[i]%Lifes[j]
#     if life > 0:
#       ans = min(ans, life)
# print(ans)

update = True
while update:
    min_num = ans
    for i in range(N):
        life_mod = Lifes[i]%ans
        if life_mod > 0:
            Lifes[i] = life_mod
            if min_num > life_mod:
                min_num = life_mod
    if ans == min_num:
        update=False
    else:
        ans = min_num
print(ans)

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

Lifes.sort(key=lambda x:-x)

ans = Lifes[N-1]

for i in range(N):
  for j in range(i, N):
    life = Lifes[i] - Lifes[j]
    if life > 0:
      ans = min(ans, life)
print(ans)

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

Lifes.sort(key=lambda x:-x)

ans = Lifes[N-1]

for i in range(N):
  for j in range(i, N):
    life = Lifes[i] - Lifes[j]
    if life > 0:
	  ans = min(ans, life)
print(ans)
Problem p03137 (python)

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

if N >= M:
  print(0)
else:
  X.sort()

  diffs = [0]*(M-1)

  for i in range(M-1):
    diffs[i] = abs(X[i+1] - X[i])

  diffs.sort(key= lambda x: -x)

  print(sum(diffs[N-1:]))

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

if N >= M:
  print(0)
else:
  X.sort()

  diffs = [0]*(M-1)

  for i in range(M-1):
    diffs[i] = abs(x[i+1] - X[i])

  diffs.sort(key= lambda x: -x[0])
  
  print(sum(diffs[N-1:]))
Problem p03221 (python)

Fixed submission:
N, M = map(int, input().split())
L = []
for i in range(M):
  P, Y = map(int, input().split())
  L.append((P, Y, i))
ans = ['']*(M)
L.sort(key=lambda x:(x[0], x[1]))
before = L[0][0]
num = 0
for i in range(M):
  if L[i][0] == before:
    num += 1
    id = '{:06d}'.format(L[i][0]) + '{:06d}'.format(num)
    ans[L[i][2]] = id
  else:
    num = 1
    id = '{:06d}'.format(L[i][0]) + '{:06d}'.format(num)
    ans[L[i][2]] = id
    before = L[i][0]
for city in ans:
  print(city)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L = []
for i in range(M):
  P, Y = map(int, input().split())
  L.append((P, Y, i))
ans = ['']*(N)

L.sort(key=lambda x:(x[0], x[1]))
before = L[0][0]
num = 1
for i in range(M):
  if L[i][0] == before:
    num += 1
    id = '{:06d}'.format(L[i][0]) + '{:06d}'.format(num)
    ans[L[i][2]] = id
  else:
    num = 1
    id = '{:06d}'.format(L[i][0]) + '{:06d}'.format(num)
    ans[L[i][2]] = id
    before = L[i][0]
for city in ans:
  print(city)
Problem p03242 (python)

Fixed submission:
N = input()
S = ''
for i in range(3):
  if N[i] == '1':
    S += '9'
  elif N[i] == '9':
    S += '1'
  else:
    S += N[i]
print(S)

Buggy submission (verdict: Runtime Error):
N = input()
for i in range(3):
  if N[i] == '1':
    N[i] = '9'
  elif N[i] == '9':
    N[i] == '1'
print(N)
Problem p03250 (python)

Fixed submission:
nums = list(map(int, input().split()))
nums.sort(key=lambda x: -x)
print(int(str(nums[0]) + str(nums[1])) + nums[2])

Buggy submission (verdict: Runtime Error):
import math

N, M = map(int, input().split())
MOD = 10**9+7

def trial_division(n):
  #素因数を格納するリスト
  factor = []
  #2から√n以下の数字で割っていく
  tmp = int(math.sqrt(n)) + 1
  for num in range(2,tmp):
    cnt = 0
    while n % num == 0:
      n //= num
      cnt += 1 
    if cnt != 0:
      factor.append(cnt)
  #リストが空ならそれは素数
  if not factor:
    return factor
  else:
    if n != 1:
      factor.append(1)
    return factor

from operator import mul
from functools import reduce

def cmb(n,r):
  r = min(n-r,r)
  if r == 0: return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under

ans = 1
cnts = trial_division(M)
for cnt in cnts:
  ans = ans * (cmb(cnt+N-1, cnt))%MOD

print(cnts)
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, C = input()
print(max(int(A+B)+int(C),int(B+A)+int(C),int(A+C)+int(B), int(C+A)+int(B), int(B+C)int(A), int(C+B)+int(A)))