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

Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())))
print(a[n//2] - a[n//2-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int, input().split())))
print(a[n/2] - a[n/2-1])
Problem p03053 (python)

Fixed submission:
from collections import deque

# 上下左右1マスを検索するために必要とする
dis_x = [1, 0, -1, 0]
dis_y = [0, 1, 0, -1]

# 迷路の縦幅,横幅
max_h, max_w = map(int, input().split())

s = []
for _ in range(max_h):
    line = input()
    # 横1マスを壁でPadding. これでindex out of boundを防ぐ
    s.append(list("#{}#".format(line)))

# 縦1マスを壁でPadding. これでindex out of boundを防ぐ
s = [list("#" * (max_w + 2))] + s + [list("#" * (max_w + 2))]
dist = [ [0] * (max_w + 2) for _ in range(max_h+2)]

queue = deque()
for i in range(1, max_h+1):
    for j in range(1, max_w+1):
        if s[i][j] == '#':
            queue.append((i, j))

while queue:
    # 先頭の値を取り出す
    h, w = queue.popleft()

    # 上下左右4マスに対し処理
    for i in range(4):

        # 移動距離
        dx, dy = dis_x[i], dis_y[i]

        # もし次のマスの黒塗りが終わっていないなら
        if s[h+dy][w+dx] == '.':
            s[h+dy][w+dx] = '#'
            dist[h+dy][w+dx] = dist[h][w] + 1

            queue.append((h+dy, w+dx))


print(max(max(l) for l in dist))

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

# 上下左右1マスを検索するために必要とする
dis_x = [1, 0, -1, 0]
dis_y = [0, 1, 0, -1]

# 迷路の縦幅,横幅
max_h, max_w = map(int, input().split())

s = []
for _ in range(max_h):
    line = input()
    # 横1マスを壁でPadding. これでindex out of boundを防ぐ
    s.append(list("#{}#".format(line)))

# 縦1マスを壁でPadding. これでindex out of boundを防ぐ
s = [list("#" * (max_w + 2))] + s + [list("#" * (max_w + 2))]
dist = [ [0] * (max_w + 2) for _ in range(max_h+2)]

queue = deque()
for i in range(1, max_h+1):
    for j in range(1, max_w+1):
        if s[i][j] == '#':
            queue.append((i, j))

while queue:
    # 先頭の値を取り出す
    h, w = queue.popleft()

    # 上下左右4マスに対し処理
    for i in range(4):

        # 移動距離
        dx, dy = dis_x[i], dis_y[i]

        # もし次のマスが通路かつ黒塗りが終わっていないなら
        if s[h+dy][w+dx] == '.' and target_count != 0:
            s[h+dy][w+dx] = '#'
            dist[h+dy][w+dx] = dist[h][w] + 1
            target_count -= 1

            queue.append((h+dy, w+dx))


print(max(max(l) for l in dist))
Problem p03242 (python)

Fixed submission:
f = lambda c : "1" if c == "9" else "9"
  
print(''.join(list(map(f, input()))))

Buggy submission (verdict: Runtime Error):
def f(c):
  if c == "1":
    return "9"
  elif c == "9":
    return 1
  else:
    return c
  
print(''.join(list(map(f, input()))))
Problem p02623 (python)

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

a = [0]*(N+1)
b = [0]*(M+1)

for i in range(N):
    a[i+1] = a[i] + A[i]
for j in range(M):
    b[j+1] = b[j] + B[j]

n_b = M
best = 0

for n_a in range(N+1):
    if K < a[n_a]:
        break

    while  K < a[n_a] + b[n_b]:
        n_b -= 1

    best = max(n_a + n_b,best)

print(int(best))

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

i_a = 0
i_b = 0

total_time = 0

while True:
    if i_a == N and i_b == M:
        break
    else:
        if i_a == N:
            read_a = False:
        elif i_b ==M:
            read_a = True:
        elif A[i_a] <= B[i_b]:
            read_a = True
    
    if read_a:
        if A[i_a] <= K - total_time:
            total_time += A[i_a]
            i_a += 1
        else:
            break
    else:
        if B[i_b] <= K - total_time:
            total_time += B[i_b]
            i_b += 1
        else:
            break

print(int(i_a+i_b))

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

i_a = 0
i_b = 0

total_time = 0

while True:
    if i_a == N and i_b == M:
        break
    else:
        if i_a < N and A[i_a] <= B[i_b]:
            read_a = True
        else:
            read_a = False
    
    if read_a:
        if A[i_a] <= K - total_time:
            total_time += A[i_a]
            i_a += 1
        else:
            break
    else:
        if B[i_b] <= K - total_time:
            total_time += B[i_b]
            i_b += 1
        else:
            break

print(int(i_a+i_b))

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

i_a = 0
i_b = 0

total_time = 0

while True:
    if i_a == N and i_b == M:
        break
    else:
        if i_a < N and A[i_a] < B[i_b]:
            read_a = True
        else:
            read_a = False
    
    if read_a:
        if A[i_a] <= K-total_time:
            total_time += A[i_a]
            i_a += 1
        else:
            break
    else:
        if B[i_b] <= K-total_time:
            total_time += B[i_b]
            i_b += 1
        else:
            break

print(int(i_a+i_b))
Problem p02596 (python)

Fixed submission:
k = int(input())
x = 7%k

flg = False
for i in range(1,k+1):
  x = x%k
  if x ==0:
    flg = True
    break
  else:
    x = x*10+7
  
print(i if flg else '-1')

Buggy submission (verdict: Runtime Error):
k = int(input())
x = 7%k

flg = True
for i in range(1,k):
  x = x%k
  if x ==0:
    break
  else:
    x = x*10+7
    
if k%2==0:
  flg = False
    
print(i if flg else '-1')
Problem p02623 (python)

Fixed submission:
import bisect

n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))

for i in range(1,n+1):
  a[i] = a[i]+a[i-1]
for j in range(1,m+1):
  b[j] = b[j]+b[j-1]

book_cnt=0
for a_cnt in range(n+1):
  if a[a_cnt]>k:
    continue
  rest=k-a[a_cnt]
  b_cnt=bisect.bisect(b,rest)-1
  book_cnt=max(book_cnt,a_cnt+b_cnt)

print(book_cnt)

Buggy submission (verdict: Runtime Error):
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))[::-1]
b = list(map(int,input().split()))[::-1]
cnt_book=0
cnt_time=0

while cnt_time<k:
  if not a or a[-1]>=b[-1]:
    cnt_time+=b.pop()
  else:
    cnt_time+=a.pop()
  if cnt_time>k:
    break    
  cnt_book+=1

print(cnt_book)
Problem p03265 (python)

Fixed submission:
x1,y1,x2,y2=list(map(int,input().split()))

if x2>=x1 and y2>=y1:
  x3=x2-abs(y2-y1);y3=y2+abs(x2-x1);x4=x3-abs(y3-y2);y4=y3-abs(x3-x2)

elif x2<=x1 and y2>=y1:
  x3=x2-abs(y2-y1);y3=y2-abs(x2-x1);x4=x3+abs(y3-y2);y4=y3-abs(x3-x2)

elif x2<=x1 and y2<=y1:
  x3=x2+abs(y2-y1);y3=y2-abs(x2-x1);x4=x3+abs(y3-y2);y4=y3+abs(x3-x2)

elif x2>=x1 and y2<=y1:
  x3=x2+abs(y2-y1);y3=y2+abs(x2-x1);x4=x3-abs(y3-y2);y4=y3+abs(x3-x2)

  
print(x3,y3,x4,y4)

Buggy submission (verdict: Runtime Error):
x1,y1,x2,y2=list(map(int,input().split()))

if x2>x1 and y2>y1:
  x3=x2-abs(y2-y1);y3=y2+abs(x2-x1);x4=x3-abs(y3-y2);y4=y3-abs(x3-x2)

elif x2<x1 and y2>y1:
  x3=x2-abs(y2-y1);y3=y2-abs(x2-x1);x4=x3+abs(y3-y2);y4=y3-abs(x3-x2)

elif x2<x1 and y2<y1:
  x3=x2+abs(y2-y1);y3=y2-abs(x2-x1);x4=x3+abs(y3-y2);y4=y3+abs(x3-x2)

elif x2>x1 and y2<y1:
  x3=x2+abs(y2-y1);y3=y2+abs(x2-x1);x4=x3-abs(y3-y2);y4=y3+abs(x3-x2)

  
print(x3,y3,x4,y4)
Problem p03745 (python)

Fixed submission:
from collections import deque
 
n = int(input())
a = list(map(int,input().split()))
d = deque(a)
 
tmp = []
cnt = 0
while d:
  v = d.popleft()
  if len(tmp)<=1:
    pass
  else:
    if not (v >= tmp[-1] >= tmp[-2] >= tmp[0] or v <= tmp[-1] <= tmp[-2] <= tmp[0]):
      tmp = []
      cnt += 1
  tmp.append(v)
#  print(d,tmp,cnt)
if tmp:
  cnt+=1
print(cnt)

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

n = int(input())
a = list(map(int,input().split()))
d = deque(a)

tmp = []
cnt = 0
while d:
  v = d.popleft()
  tmp.append(v)
  if len(tmp)<=2:
    pass
  else:
    if not ( tmp[-1] >= tmp[-2] >= tmp[-3] or tmp[-1] <= tmp[-2] <= tmp[-3]):
      tmp = [tmp[-1]]
      cnt += 1
  
  print(d,tmp,cnt)
if tmp:
  cnt+=1
print(cnt)

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

flg = "default" #increase_flg
cnt = 0
for i in range(n-1):
  if a[i+1] > a[i]:
    if not flg:
      cnt+=1
      flg = "default"
    else:
      flg = True
  elif a[i+1] < a[i]:
    if flg:
      cnt+=1
      flg = "default"
    else:
      flg = False
#  print(a[i],a[i+1],flg,cnt)

if not a[i]>=a[i-1]>=a[i-2] or a[i]<=a[i-1]<=a[i-2]:
  cnt +=1 
print(cnt)
Problem p02580 (python)

Fixed submission:
import sys
from collections import Counter
H,W,m = map(int,input().split())
h_ls = [0] * H
w_ls = [0] * W
bombers = [(0,0) for _ in range(m)]
for i in range(m):
    h,w = map(int,input().split())
    h_ls[h-1] += 1
    w_ls[w-1] += 1
    bombers[i] = (h-1,w-1)

h_max = max(h_ls)
h_counter = Counter(h_ls)
# Couter使ってみる
h_max_args = [0]*h_counter[h_max]
next_ind = 0
for i in range(H):
    if h_ls[i] == h_max:
        h_max_args[next_ind] = i
        next_ind += 1

w_max = max(w_ls)
w_counter = Counter(w_ls)
w_max_args = [0]*w_counter[w_max]
next_ind = 0
for i in range(W):
    if w_ls[i] == w_max:
        w_max_args[next_ind] = i
        next_ind += 1

bombers = set(bombers)
for h in h_max_args:
    for w in w_max_args:
        if not (h,w) in bombers:
            print(w_max+h_max)
            sys.exit()

print(w_max+h_max-1)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter
H,W,m = map(int,input().split())
h_ls = [0] * H
w_ls = [0] * W
bombers = [[0,0] for _ in range(m)]
for i in range(m):
    h,w = map(int,input().split())
    h_ls[h-1] += 1
    w_ls[w-1] += 1
    bombers[i] = [h-1,w-1]

h_max = max(h_ls)
h_counter = Counter(h_ls)
# Couter使ってみる
h_max_args = [0]*h_counter[h_max]
next_ind = 0
for i in range(H):
    if h_ls[i] == h_max:
        h_max_args[next_ind] = i
        next_ind += 1

w_max = max(w_ls)
w_counter = Counter(w_ls)
w_max_args = [0]*w_counter[w_max]
next_ind = 0
for i in range(W):
    if w_ls[i] == w_max:
        w_max_args[next_ind] = i
        next_ind += 1

bombers = set(bombers)
for h in h_max_args:
    for w in w_max_args:
        if not [h,w] in bombers:
            print(w_max+h_max)
            sys.exit()

print(w_max+h_max-1)
Problem p02629 (python)

Fixed submission:
n = int(input())
alphabet = [chr(i) for i in range(97, 97+26)]
ans = ""
i = 0
while n - 26**i >= 0:
    n -= 26**i
    i += 1
# ここを抜けた時,iは桁数

for _ in range(i):
    q,r = divmod(n,26)
    n = q
    ans += alphabet[r]
print(ans[::-1])

Buggy submission (verdict: Runtime Error):
alphabet = [chr(i) for i in range(97, 97+26)]
n = int(input())
keta = 1
rest = 0
while True:
    if n <= 26 ** keta + rest:
        break
    rest += 26 ** keta
    keta += 1  

ans = ''
for i in range(keta-1,-1,-1):
    # 「26**iをいくつ含むか」をループで求める
    # 必ず1以上含む
    contain = 1
    while True:
        if n < contain * 26**i:
            break
        contain += 1
    contain -= 1
    ans += alphabet[contain-1]
    n -= contain * 26 ** i


print(ans)

Buggy submission (verdict: Runtime Error):
alphabet = [chr(i) for i in range(97, 97+26)]
n = int(input())
keta = 1
rest = 0
while True:
    if n <= 26 ** keta + rest:
        break
    rest += 26 ** keta
    keta += 1  
print(keta)
ans = ''
for i in range(keta-1,-1,-1):
    # 「26**iをいくつ含むか」をループで求める
    # 必ず1以上含む
    contain = 1
    while True:
        if n < contain * 26**i:
            break
        contain += 1
    contain -= 1
    ans += alphabet[contain-1]
    n -= contain * 26 ** i


print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
m = n

alphabet = [chr(i) for i in range(97, 97+26)]

keta = 1
while True:
    if n <= 26**(keta):
        break
    n -= 26**(keta)
    keta += 1
ans = ''

for i in range(keta-1, -1, -1):
    have = m // (26 ** i)
    ans += alphabet[have-1]
    m -= 26 ** i * have
    
print(ans)
Problem p02725 (python)

Fixed submission:
import numpy as np

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

next_ls = [0] * n
for i in range(n-1):
    next_ls[i] = a_ls[i+1] - a_ls[i]
next_ls[n-1] = k - a_ls[-1] + a_ls[0]
argmax = np.argmax(next_ls)
next_ls.pop(argmax)
print(sum(next_ls))

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

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

next_ls = [0] * n
for i in range(n-1):
    next_ls[i] = a_ls[i+1] - a_ls[i]
next_ls[n-1] = k - a_ls[-1] + a_ls[0]
argmax = np.argmax(next_ls)
next_ls.pop(argmax)
print(sum(next_ls))
Problem p02779 (python)

Fixed submission:
n = int(input())
a_list = list(map(int,input().split()))

a_set = set(a_list)
if len(a_list) == len(a_set):
    print('YES')
else:
    print('NO')

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

a_set = set(a_slit)
if len(a_list) == len(set):
    print('YES')
else:
    print('NO')
Problem p02781 (python)

Fixed submission:
str_n = input()
keta = len(str_n)
not_zero = int(input())

dp = [[[0]*(not_zero+2) for _ in range(2)] for _ in range(keta+1)]
first = int(str_n[0])
dp[1][1][0] = 1
for k in range(1,10):
    if first == k:
        dp[1][0][1] += 1
    elif first > k:
        dp[1][1][1] += 1

for i in range(1,keta):
    # smallerからsmallerへの遷移
    for j in range(not_zero+1):
        # i桁目をゼロにする
        dp[i+1][1][j] += dp[i][1][j]
        # i桁目でゼロ以外を使う
        dp[i+1][1][j+1] += (dp[i][1][j])*9

    nex = int(str_n[i])
    # sameからsmallerへの遷移
    if not nex == 0:
        for j in range(not_zero+1):
            # i桁目をぜろにする
            dp[i+1][1][j] += dp[i][0][j]
            # i桁目でゼロ以外
            dp[i+1][1][j+1] += (dp[i][0][j]) * (nex-1)
    
    # sameからsameへの遷移
    if nex == 0:
        for j in range(not_zero+1):
            dp[i+1][0][j] = dp[i][0][j]
    else:
        for j in range(not_zero):
            dp[i+1][0][j+1] = dp[i][0][j]

print(dp[keta][1][not_zero] + dp[keta][0][not_zero])

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter
H,W,m = map(int,input().split())
h_ls = [0] * H
w_ls = [0] * W
bombers = [[0,0] for _ in range(m)]
for i in range(m):
    h,w = map(int,input().split())
    h_ls[h-1] += 1
    w_ls[w-1] += 1
    bombers[i] = [h-1,w-1]

h_max = max(h_ls)
h_counter = Counter(h_ls)
# Couter使ってみる
h_max_args = [0]*h_counter[h_max]
next_ind = 0
for i in range(H):
    if h_ls[i] == h_max:
        h_max_args[next_ind] = i
        next_ind += 1

w_max = max(w_ls)
w_counter = Counter(w_ls)
w_max_args = [0]*w_counter[w_max]
next_ind = 0
for i in range(W):
    if w_ls[i] == w_max:
        w_max_args[next_ind] = i
        next_ind += 1

bombers = set(bombers)
for h in h_max_args:
    for w in w_max_args:
        if not [h,w] in bombers:
            print(w_max+h_max)
            sys.exit()

print(w_max+h_max-1)
Problem p02829 (python)

Fixed submission:
a, b = [int(input()) for _ in range(2)]
set_ = {1,2,3}
set_.discard(a)
set_.discard(b)
print(set_.pop())

Buggy submission (verdict: Runtime Error):
import fractions
a, b = map(int,input().split())
def jk(j,k):
    return j*k//fractions.gcd(j,k)
print(jk(a, b))
Problem p02831 (python)

Fixed submission:
import fractions
a, b = map(int,input().split())
def jk(j,k):
    return j*k//fractions.gcd(j,k)
print(jk(a, b))

Buggy submission (verdict: Runtime Error):
import math
def jk(j,k):
    return j*k//math.gcd(j,k)
a, b = map(int,input().split())
print(jk(a, b))

Buggy submission (verdict: Runtime Error):
import math
def jk(j,k):
    return j*k//math.gcd(a,b)
a, b = map(int,input().split())
print(jk(a, b))
Problem p02835 (python)

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

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
if sum(list) >= 22:
  print('bust')
else:
  print('win')

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
if sum(list) >= 22:
  print('bust')
else:
  print('win')
Problem p02847 (python)

Fixed submission:
str_d = input().replace("SUN","7").replace("MON","6").replace("TUE","5").replace("WED","4").replace("THU","3").replace("FRI","2").replace("SAT","1")
ans = int(str_d)
print(ans)

Buggy submission (verdict: Runtime Error):
str_d = input().replace("SUN","7").replace("MON","6").replace("TUE","5").replace("WED","4").replace("THU","3").replace("FRI","2").replace("SUT","1")
ans = int(str_d)
print(ans)
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())
ls = make_divisors(n)
pairs = []
for i in ls:
    pair = (i, n//i)
    pairs.append(pair)
count = []
for pair in pairs:
    count.append(pair[0] + pair[1] - 2)
print(min(count))

Buggy submission (verdict: Runtime Error):
n = int(input())
ls = make_divisors(n)
pairs = []
for i in ls:
    pair = (i, n//i)
    pairs.append(pair)
count = []
for pair in pairs:
    count.append(pair[0] + pair[1] - 2)
print(min(count))
Problem p02990 (python)

Fixed submission:
class Combination():
    def __init__(self, n, mod=10**9+7):
        self.mod = mod
        self.fac = [1]*(n+1)
        for i in range(1,n+1):
            self.fac[i] = self.fac[i-1] * i % self.mod
        self.invfac = [1]*(n+1)
        self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
        for i in range(n-1, 0, -1):
            self.invfac[i] = self.invfac[i+1] * (i+1) % self.mod
 
    def combination(self, n, r):
        return self.fac[n] * self.invfac[r] % self.mod * self.invfac[n-r] % self.mod
 
    def permutation(self, n, r):
        return self.factorial(n) * self.invfactorial(n-r) % self.mod
 
    def factorial(self, i):
        return self.fac[i]
 
    def invfactorial(self, i):
        return self.invfac[i]

mod = 10**9+7
N,K = map(int,input().split())
ans_ls = [0] * K
c = Combination(N+K)
for i in range(K):
    Blocks = i+1
    #print('-----')
    #print('B:',Blocks)
    if N-K+1>=Blocks:
        Points = c.combination(N-K+1,Blocks)
    else:
        Points = 0
    #print('入れ方：',Points)
    Division = c.combination(K-1,Blocks-1)
    #print('分け方：',Division)
    ans_ls[i] = (Points*Division)%mod

for ans in ans_ls:
    print(ans)

Buggy submission (verdict: Runtime Error):
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod

def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)
    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac
mod = 10**9+7
def cmb_count(n,k):
    fac,ifac = make_tables(mod,n)
    return cmb(n,k,mod,fac,ifac)

n,k = map(int,input().split())
for i in range(1,k+1):
    print(cmb_count(n-k+1,i)*cmb_count(k-1,i-1))

Buggy submission (verdict: Runtime Error):
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod

def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)
    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac

mod = 10**9+7
n,k = map(int,input().split())
for i in range(1,k+1):
    fac,ifac = make_tables(mod,k-1)
    n_divide = cmb(k-1,i-1,mod,fac,ifac)
    fac,ifac = make_tables(mod,n-k+1)
    n_amari = cmb(n-k+1,i,mod,fac,ifac)
    print(n_amari*n_divide)
Problem p03013 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

mod = 1000000007

n,m = map(int,input().split())
good = [True] * (n+1)
for _ in range(m):
    x = int(input())
    good[x] = False

dp = [0] * (n+1)
dp[0] = 1

for i in range(n):
    # 出発点になれるなら、のみでOK
        # Falseの部分が更新されることはあっても、出発点になれないから
    if good[i]:
        if i+1 <= n:
            dp[i+1] += dp[i]
            dp[i+1]%= mod
        if i+2 <= n:
            dp[i+2] += dp[i]
            dp[i+2] %= mod

print(dp[n])

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a_ls = [int(input()) for _ in range(m)]

dp = [0] * (n+1)
dp[0] = 1
dp[1] = 1 if 1 not in a_ls else 0
for i in range(n):
    if i + 2 not in a_ls and i not in a_ls and i+1 not in a_ls:
        dp[i+2] = dp[i] + dp[i+1] 
    elif dp[i+2] in a_ls:
        dp[i+2] = 0
    elif i in a_ls and i+1 not in a_ls:
        dp[i+2] = dp[i+1]
    elif i not in a_ls and i+1 in a_ls:
        dp[i+2] = dp[i]
print(dp[-1] % 1000000007)
Problem p03017 (python)

Fixed submission:
n,a_start,b_start,a_goal,b_goal = map(int,input().split())
s = input()

no_rock_double = True
for i in range(a_start, max(b_goal,a_goal)):
    if i+1 < n:
        if s[i] == '#' and s[i+1] == '#':
            no_rock_double = False
can_switch = False
if a_goal > b_goal:
    for i in range(b_start-1, b_goal):
        if s[i - 1:i + 2] == "...":
            can_switch = True
    if no_rock_double and can_switch:
        print('Yes')
    else:
        print('No')
else:
    if no_rock_double:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
n,a_start,b_start,a_goal,b_goal = map(int,input().split())
s = input()

no_rock_double = True
for i in range(a_start, b_goal):
    if i < n:
        if s[i] == '#' and s[i+1] == '#':
            no_rock_double = False
can_switch = False
if a_goal > b_goal:
    for i in range(b_start+1, b_goal):
        if i + 1 < n:
            if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.':
                can_switch = True
if a_goal > b_goal:
    if no_rock_double and can_switch:
        print('Yes')
    else:
        print('No')
else:
    if no_rock_double:
        print('Yes')
    else:
        print('No')
Problem p03038 (python)

Fixed submission:
from collections import Counter
n,m = map(int,input().split())
a_ls = list(map(int, input().split()))
counter = Counter(a_ls)
for i in range(m):
    b,c = map(int,input().split())
    counter[c] += b

cards = sorted(counter.items(), key = lambda x:x[0], reverse=True)
rest = n
Sum = 0
for num, count in cards:
    if count < rest:
        Sum += num * count
        rest -= count
    else:
        Sum += rest * num
        break
print(Sum)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a_ls = list(map(int, input().split()))
n_b = 0
b_ls = [[0,0] for _ in range(m)]
for i in range(m):
    num, c = map(int,input().split())
    n_b += num
    b_ls[i] = [num,c]
d_ls = [0] * (n+n_b)
c_ls = [0] * n_b
j = 0
rest = b_ls[0][0]
i = 0
while j < n_b:
    c_ls[j] = b_ls[i][1]
    j += 1
    rest -= 1
    if rest <= 0:
        i += 1
        if i == m:
            break
        rest = b_ls[i][0]
for i in range(n+n_b):
    if i < n:
        d_ls[i] = a_ls[i]
    else:
        d_ls[i] = c_ls[i-n]
d_ls.sort(reverse= True)
print(sum(d_ls[:n]))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a_ls = list(map(int, input().split()))
n_b = 0
b_ls = [[0,0] for _ in range(m)]
for i in range(m):
    num, c = map(int,input().split())
    n_b += num
    b_ls[i] = [num,c]
c_ls = [0] * n_b
j = 0
rest = b_ls[0][0]
i = 0
while j < n_b:
    c_ls[j] = b_ls[i][1]
    j += 1
    rest -= 1
    if rest <= 0:
        i += 1
        if i == m:
            break
        rest = b_ls[i][0]
a_ls = a_ls + c_ls
a_ls.sort(reverse= True)
print(sum(a_ls[:n]))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a_ls = list(map(int, input().split()))
n_b = 0
b_ls = [[0,0] for _ in range(m)]
for i in range(m):
    num, c = map(int,input().split())
    n_b += num
    b_ls[i] = [num,c]
c_ls = [0] * n_b
j = 0
rest = b_ls[0][0]
i = 0
while j < n_b:
    c_ls[j] = b_ls[i][1]
    j += 1
    rest -= 1
    if rest <= 0:
        i += 1
        if i == m:
            break
        rest = b_ls[i][0]
a_ls = a_ls + c_ls
a_ls.sort(reverse= True)
print(sum(a_ls[:n]))