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

Fixed submission:

import collections
import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = collections.deque([])
for i in range(n):
  conditions.append([int(x) for x in input().split()])

conditions = sorted(conditions)

cnt, ans = 0, 0
candidates = []
for reversed_day in range(1, m + 1):
  while cnt < len(conditions) and conditions[cnt][0] <= reversed_day:
    heapq.heappush(candidates, -conditions[cnt][1])
    cnt += 1

  if len(candidates) == 0:
    continue
  ans -= heapq.heappop(candidates)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = {}
for i in range(n):
  inputs = [int(x) for x in input().split()]
  if inputs[0] in conditions.keys():
    conditions[inputs[0]].append(inputs[1])
  else:
    conditions[inputs[0]] = [inputs[1]]

for day in conditions.keys():
  conditions[day].sort(reverse=True)

ans = 0
candidates = []
for reversed_day in range(1, m + 1):
  if reversed_day in conditions.keys():
    candidates.append(conditions[reversed_day])

  cand_len = len(candidates)
  if cand_len == 0:
    continue
  maxval, maxidx = 0, 0
  for i in range(cand_len):
    if candidates[i][0] > maxval:
      maxval = candidates[i][0]
      maxidx = i
  ans += candidates[maxidx].pop(0)
print(ans)

Buggy submission (verdict: Runtime Error):
inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = {}
for i in range(n):
  inputs = [int(x) for x in input().split()]
  if inputs[0] in conditions.keys():
    conditions[inputs[0]].append(inputs[1])
  else:
    conditions[inputs[0]] = [inputs[1]]

for day in conditions.keys():
  conditions[day].sort(reverse=True)

ans = 0
candidates = []
for reversed_day in range(1, m+1):
  if reversed_day in conditions.keys():
    candidates.append(conditions[reversed_day])

  cand_len = len(candidates)
  if cand_len == 0:
    continue
  maxval, maxidx = 0, 0
  for i in range(cand_len):
    if candidates[i][0] > maxval:
      maxval = candidates[i][0]
      maxidx = i
  ans += candidates[maxidx].pop(0)
print(ans)

Buggy submission (verdict: Runtime Error):
inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = {}
for i in range(n):
  inputs = [int(x) for x in input().split()]
  if inputs[0] in conditions.keys():
    conditions[inputs[0]].append(inputs[1])
  else:
    conditions[inputs[0]] = [inputs[1]]

for day in conditions.keys():
  conditions[day].sort(reverse=True)

print(conditions)

ans = 0
candidates = []
for reversed_day in range(1, m+1):
  if reversed_day in conditions.keys():
    candidates.append(conditions[reversed_day])

  cand_len = len(candidates)
  if cand_len == 0:
    continue
  maxval, maxidx = 0, 0
  for i in range(cand_len):
    if candidates[i][0] > maxval:
      maxval = candidates[i][0]
      maxidx = i
  ans += candidates[maxidx].pop(0)
print(ans)
Problem p02955 (python)

Fixed submission:
inputs = [int(x) for x in input().split()]
n, k = inputs[0], inputs[1]
ls = [int(x) for x in input().split()]
s = sum(ls)

# https://qiita.com/LorseKudos/items/9eb560494862c8b4eb56
divisors = []
for i in range(1, int(s ** 0.5) + 1):
  if s % i == 0:
    divisors.append(i)
    if i != s // i:
      divisors.append(s // i)

divisors.sort(reverse=True)
ans = 1
for d in divisors:
  mods = sorted([l % d for l in ls if l % d != 0])
  opcnt = 0
  is_success = False
  # print("{}: {}".format(d, ", ".join([str(m) for m in mods])))
  while True:
    if opcnt > k or len(mods) == 1:
      # print("opcnt: {}".format(opcnt))
      is_success = False
      break

    if len(mods) == 0:
      is_success = True
      ans = d
      # print("ans: {}, opcnt: {}".format(ans, opcnt))
      break

    if mods[0] + mods[-1] < d:
      mods[-1] += mods[0]
      opcnt += mods[0]
      mods.pop(0)
    elif mods[0] + mods[-1] == d:
      opcnt += mods[0]
      mods.pop(0)
      mods.pop(-1)
    else:
      opcnt += (d - mods[-1])
      mods[0] -= (d - mods[-1])
      mods.pop(-1)
    # print("{}: {}".format(d, ", ".join([str(m) for m in mods])))


  if is_success:
    break

print(ans)

Buggy submission (verdict: Runtime Error):

inputs = [int(x) for x in input().split()]
n, k = inputs[0], inputs[1]
ls = [int(x) for x in input().split()]
s = sum(ls)

# https://qiita.com/LorseKudos/items/9eb560494862c8b4eb56
divisors = []
for i in range(1, int(s ** 0.5) + 1):
  if s % i == 0:
    divisors.append(i)
    if i != s // i:
      divisors.append(s // i)

divisors.sort(reverse=True)
ans = 1
for d in divisors:
  mods = sorted([l % d for l in ls if l % d != 0])
  opcnt = 0
  is_success = False
  # print("{}: {}".format(d, ", ".join([str(m) for m in mods])))
  while True:
    if mods[0] + mods[-1] < d:
      mods[-1] += mods[0]
      opcnt += mods[0]
      mods.pop(0)
    elif mods[0] + mods[-1] == d:
      opcnt += mods[0]
      mods.pop(0)
      mods.pop(-1)
    else:
      opcnt += (d - mods[-1])
      mods[0] -= (d - mods[-1])
      mods.pop(-1)
    # print("{}: {}".format(d, ", ".join([str(m) for m in mods])))

    if opcnt > k or len(mods) == 1:
      # print("opcnt: {}".format(opcnt))
      is_success = False
      break
    if len(mods) == 0:
      is_success = True
      ans = d
      # print("ans: {}, opcnt: {}".format(ans, opcnt))
      break

  if is_success:
    break

print(ans)
Problem p03012 (python)

Fixed submission:
N = int(input())
W = [int(w) for w in input().split()]
ans = 100000000
for t in range(N):
  less_T = W[:t]
  more_T = W[t:]
  S_l = sum(less_T)
  S_m = sum(more_T)
  d = abs(S_l - S_m)
  if ans > d:
     ans = d
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
W = [int(w) for w in input().split
ans = 10000000
for t in range(N):
  less_T = W[:t]
  more_T = W[t:]
  S_l = sum(less_T)
  S_m = sum(more_T)
  d = abs(S_l - S_m)
  if ans > d:
     ans = d
print(ans)
Problem p02912 (python)

Fixed submission:
import heapq

x = map(int,raw_input().split())
n=x[0]
m=x[1]
a = map(int, raw_input().split())

def minus(n):
    return float(n*(-1))

def plus(n):
    return int(n*(-1))

a=list(map(minus, a))
heapq.heapify(a)

for i in range(m):
    heapq.heappush(a, heapq.heappop(a)/2)

a=list(map(plus, a))

print(sum(a))

Buggy submission (verdict: Runtime Error):
x = map(int,raw_input().split())
n=x[0]
m=x[1]
a = map(int,raw_input().split())
a.sort(reverse=True)

for i in range(m):
    if a[0]<a[1]:
        a.sort(reverse=True)
    a[0]=float(a[0])/2

a=list(map(int, a))

print(sum(a))
Problem p03127 (python)

Fixed submission:
import sys
import collections

b=[]
n = map(int, raw_input().split())
a = map(int, raw_input().split())

while True:
    a.sort()
    b=[]
    if a[0]==1:
        print(1)
        break
    elif a[0]==a[-1]:
        print(a[0])
        break
    else:
        for n in a:
            n=n%a[0]
            if n!=0:
                b.append(n)
        a=[a[0]]
        a.extend(b)

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

b=[]
n = map(int, raw_input().split())
a = map(int, raw_input().split())

while True:
    a.sort()

    if a[0]==a[-1]:
        print(a[0])
        break

    elif:
        for n, x in enumerate(a):
            n=n%a[0]
            if n!=0:
                b.append(n)
        a=[a[0]]
        a.extend(b)
Problem p02915 (python)

Fixed submission:
n = input()
print(int(n) ** 3)

Buggy submission (verdict: Runtime Error):
n = input()
print(n ** 3)
Problem p02859 (python)

Fixed submission:
a=int(input())

print(a*a)

Buggy submission (verdict: Runtime Error):
a=input()
print(a*a)
Problem p02759 (python)

Fixed submission:
n = int(input())

ans = n // 2

if n % 2 == 0:
    print(ans)
else:
    print(ans+1)

Buggy submission (verdict: Runtime Error):
List = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

ans = [[0,0,0] for i in range(3)]
ans1 = [[0,0,0] for i in range(3)]

res = False

for i in range(n):
    for a in range(3):
        for c in range(3):
            if b[n] == List[a][c]:
                ans[a][c] = 1
                ans1[c][a] = 1
                
if ans[1][1] == 1:
    if ans[0][0] > 0 and ans[2][2] > 0:
        res = True
    if ans[2][0] > 0 and ans[0][2] > 0:
        res = True
                
for i in range(3):
    if ans[i][0] > 0 and ans[i][1] > 0 and ans[i][2] > 0:
        res = True
    if ans1[i][0] > 0 and ans1[i][1] > 0 and ans1[i][2] > 0:
        res = True
   
            
if res:
    print('Yes')
else:
    print('No')
Problem p02773 (python)

Fixed submission:
import collections

n = int(input())
List = [input() for i in range(n)]
res = []

c = collections.Counter(List)
m = 0
for v in c.values():
  m = max(m, v)
  
for k, v in c.items():
  if v == m:
    res.append(k)
    
res.sort()
for i in range(len(res)):
  print(res[i])

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

c = {}
res = []

for i in range(n):
    if List[i] in c.keys():
        c[List[i]] += 1
    else:
        c[List[i]] = 1

ac = c.most_common() ##これが無いとACにならない！！！！
                     ##毎回の計算がかなりの時間ロスだった
res.append(ac[0][0])
for i in range(1, leng):
    if ac[i][1] >= ac[i-1][1]:
        res.append(ac[i][0])
    else:
        break

#res = sorted(res)
res.sort()
for j in range(len(res)):
    print(res[j])

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
List = [input() for i in range(n)]
res = []

c = collections.Counter(List)
m = 0
for v in c.values():
  m = max(m, v)
  
for k, v in c.items():
  if v == m:
    res.append(k)
    
res.sort()
for i in range(les(res)):
  print(res[i])

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
List = [input() for i in range(n)]
res = []

c = collections.Counter(List)

for v in c.values():
  m = max(m, v)
  
for k, v in c.items():
  if v == m:
    res.append(k)
    
res.sort()
for i in range(les(res)):
  print(res[i])
Problem p03835 (python)

Fixed submission:
k, s = map(int, input().split())
res = 0

for x in range(k+1):
  for y in range(k+1):
    z = s - (x + y)
    if z >= 0 and z <= k:
      res += 1
        
print(res)

Buggy submission (verdict: Runtime Error):
k, s = map(int, input().split())
res = 0

for x in range(k+1):
  if x <= s:
  	for y in range(k+1):
      if (x + y) <= s:
    	for z in range(k+1):
      		if (x + y + z) == s:
        		res += 1
        
print(res)
Problem p03041 (python)

Fixed submission:
n,k = map(int,input().split())
a = list(input())
a[k-1] = chr(ord(a[k-1]) + ord('a') - ord('A'))
print(''.join(a))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(input())
a[k-1] = chr(ord(a[k-1]) + ord(a)-ord('A'))
print(''.join(a))
Problem p02753 (python)

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

Buggy submission (verdict: Runtime Error):
s = int(input())
if not s[0] == s[1] == s[2]:
    print('No')
else: print('Yes')
Problem p02766 (python)

Fixed submission:
n, k = map(int, input().split())
i = k
y = 1
while n >= i:
    y += 1
    i *= k
print(y)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().spilt())
y = 1
while n > 1:
    y += 1
    n = n // k
print(y)

Buggy submission (verdict: Runtime Error):
n, k = map(input().spilt())
y = 1
while n > 1:
    y += 1
    n = n // k
print(y)
Problem p02781 (python)

Fixed submission:
a = int(input())
b = int(input())
def aez(n, k):
    s = str(n)
    ln = len(s)-1
    n1 = int(s[0])
    if len(s) < k:
        return 0
    else:
        if k == 1:
            return 9 * ln + n1 
        elif k == 2:
            return (81 * ln * (ln-1) // 2) + aez(int('9'*ln), 1)*(n1-1) + aez(int(s[1:]), 1)
        else:
            return (729*ln*(ln-1)*(ln-2)//6) + aez(int('9'*ln), 2)*(n1-1) + aez(int(s[1:]), 2)
print(aez(a, b))

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
def aez(n, k):
    s = str(n)
    ln = len(s)-1
    n1 = int(s[0])
    if k == 1:
        return 9 * ln + n1 
    elif k == 2:
        return (81 * ln * (ln-1) // 2) + aez(int('9'*ln), 1)*(n1-1) + aez(int(s[1:]), 1)
    else:
        return (729*ln*(ln-1)*(ln-2)//6) + aez(int('9'*ln), 2)*(n1-1) + aez(int(s[1:]), 2)
print(aez(a, b))
Problem p02832 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split())) 
a = tuple(a)
if a.count(1) == 0:
    print(-1)
else:
    s = 0
    t = 1
    for i in range(n):
        if a[i] == t:
            t += 1
        else: s += 1
    print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split())) 
if a.count(1) == 0:
    print(-1)
else:
    t = 0
    for i in range(1, n):
        if not a.count(i) == 0:
            s = a.index(i)
            for j in range(t, s+1):
                a[j] = 0
            t = s
        else:
            y = i-1
            break
    print(n-y)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split())) 
if a.count(1) == 0:
    print(-1)
else: 
    for i in range(1, n):
        if not a.count(i) == 0:
            del a[:a.index(i)]
        else:
            y = i-1
            break
    print(n-y)
Problem p02990 (python)

Fixed submission:
from math import factorial

def comb(a,b):
    return factorial(a) // factorial(b) // factorial(abs(a-b))

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

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

def comb(a,b):
    return factorial(a) // factorial(b) // factorial(a-b)

n, k = map(int, input().split())
for i in range(k):
    print(comb(k-1, i) * comb(n-k+1, i+1) % 1000000007)
Problem p02831 (python)

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

_A, _B = min(A, B), max(A, B)

pres = _A
while True:
    res = _B % _A
    if res == 0:
        break
    else:
        pres = res
        _B = _A
        _A = res

print((A * B) // pres)

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

import math

print(int(A * B // math.gcd(A, B)))
Problem p03041 (python)

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

K -= 1

s=list(S)
if s[K]=="A":
    s[K]='a'
elif s[K]=='B':
    s[K]='b'
elif s[K]=='C':
    s[K]='c'

print(''.join(s))

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

s=list(S)
if s[K]=="A":
    s[K]='a'
elif s[K]=='B':
    s[K]='b'
elif s[K]=='C':
    s[K]='c'
print(s)

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

s=list(S)
if s[K]=="A":
    s[K]='a'
elif s[K]=='B':
    s[K]='b'
elif s[K]=='C':
    s[K]='c'
print(s)
Problem p03042 (python)

Fixed submission:
S = input()

s_1 = int(S[0:2])
s_2 = int(S[2:])

YYMM = False
MMYY = False

if 1<=s_2<=12:
    YYMM = True
if 1<=s_1<=12:
    MMYY = True
    
if YYMM and MMYY:
    print('AMBIGUOUS')
elif YYMM:
    print('YYMM')
elif MMYY:
    print('MMYY')
else:
    print('NA')

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

s_1 = int(S[0:1])
s_2 = int(S[2:])

YYMM = False
MMYY = False

if 1<=s_2<=12:
    YYMM = True
if 1<=s_1<=12:
    MMYY = True
    
if YYMM and MMYY:
    print('AMBIGUOUS')
elif YYMM:
    print('YYMM')
elif MMYY:
    print('MMYY')
else:
    print('NA')
Problem p03075 (python)

Fixed submission:
nums = []
for i in range(5):
    nums.append(int(input()))
k = int(input())
s = "Yay!"
for i in range(5):
    for m in range(5 - i):
        a = nums[i]
        if abs(a - nums[m]) > k:
             s = ":("
             break
print(s)

Buggy submission (verdict: Runtime Error):
nums=[]
for i in range(6):
  nums.append(int(input()))
s = "Yay!"
for i in nums:
  if abs(i - nums[i:-1]) > nums[-1]:
    s = ":("
print(s)

Buggy submission (verdict: Runtime Error):
nums=[]
for i in range(6):
  nums.append(int(input()))
s = "Yay!"
for i in nums:
  if abs(i - nums[i:]):
    s = ":("
print(s)

Buggy submission (verdict: Runtime Error):
for i in range(6):
  nums[i] = int(input())
s = "Yay!"
for i in nums:
  if abs(i - nums[i:]):
    s = ":("
print(s)
Problem p02785 (python)

Fixed submission:
enemmyCountN,killerTimeK = map(int,input().split())
enemyHp = list(map(int,input().split()))

enemyHp.sort()

resultEnemyCount = enemmyCountN - killerTimeK
countNormal = 0

if killerTimeK >= enemmyCountN:
    print(0)

else:
    for i in range(resultEnemyCount):
        countNormal += enemyHp[i]
    print(countNormal)

Buggy submission (verdict: Runtime Error):
N,K = input().split()
H = input().split()

if N < K:
    times = N
else:
    times = K

for i in range(times):
    H.remove(max(H))

print(sum(H))

Buggy submission (verdict: Runtime Error):
N,K = input().split()
H = input().split()

if N < K:
    times = N
else:
    times = K

for i in range(int(times)):
    H.remove(max(H))

print(sum(H))
Problem p03041 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
import types

# Input
l = list(map(int, input().split()))
_ = l[0]
K = l[1] - 1 # <---!!

#S = list(map(str, input().split()))
S = list(input())

# Process
if K == 0:
    left = list("")
else:
    left = S[:K]

if K == len(S)-1:
    right = list("")
else:
    right = S[K+1:]

output = left + list(str(S[K]).lower()) + right
print( ''.join(output) )

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
import types

# Input
l = list(map(int, input().split()))
_ = l[0]
K = l[1] - 1 # <---!!

#S = list(map(str, input().split()))
S = list(input())

# Process
if K == 0:
    left = list("")
else:
    left = S[:K]

if K == len(S)-1:
    right = ("")
else:
    right = S[K+1:]

output = left + list(str(S[K]).lower()) + right
print( ''.join(output) )
Problem p03135 (python)

Fixed submission:
a, b = input().strip().split()
print(int(a)/int(b))

Buggy submission (verdict: Runtime Error):
a, b = input().strip().Split()
print(int(a)/int(b))
Problem p03272 (python)

Fixed submission:
a, b = list(map(int, input().strip().split(" ")))
print(a-b+1)

Buggy submission (verdict: Runtime Error):
a, b = list(input().strip().split(" ")

print(b-a+1)
Problem p02984 (python)

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

S = sum(A)
x1 = S - 2 * sum([A[i] for i in range(len(A)) if i % 2 == 1])
ansList = [x1]
for i in range(1, N):
    tmp = 2 * A[i-1] - ansList[-1]
    ansList.append(tmp)
ansList = [str(a) for a in ansList]
ans = ' '.join(ansList)
print(ans)

Buggy submission (verdict: Runtime Error):
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    n: usize,
    a: [i32; n],
    }
    let mut upper: i32 = 2 * (10_i32.pow(9));
    let mut lower = 0;
    let mut ans_list = vec![];
    loop {
        let mut half = (upper + lower) / 2;
        if half % 2 == 1 {
            half += (upper + lower) % 2
        }
        let mut tmp = half;
        ans_list.push(tmp);
        for i in 0..n {
            tmp = 2 * (a[i] - tmp / 2);
            if i == n-1 {
                if tmp == ans_list[0] {
                    break
                } else {
                    ans_list.clear();
                    if i % 2 == 0{
                        upper = half
                    } else {
                        lower = half
                    }
                }
                break
            }
            else {
                if tmp < 0 {
                    if i % 2 == 0 {
                        upper = half
                    } else {
                        lower = half
                    }
                    ans_list.clear();
                    break
                } else {
                    ans_list.push(tmp);
                }
            }
        }
        if ans_list.len() == n {
            break
        }
    }
    for i in 0..n {
        print!("{}", ans_list[i]);
        if i < n-1 {
            print!("{}", " ");
        }
    }
}
Problem p02990 (python)

Fixed submission:
N, K = map(int, input().split())
R = N - K
mod = 10 ** 9 + 7


def makeTableMod(N, mod=10 ** 9 + 7):
    fac = [1 for i in range(N)]
    finv = [1 for i in range(N)]
    inv = [1 for i in range(N)]
    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


fac, finv = makeTableMod(2001, mod)


def binomialCoefficient(N, r, mod=10 ** 9 + 7):
    if N < r:
        return 0
    else:
        return fac[N] * (finv[r] * finv[N - r] % mod) % mod


def solve(i):
    # (N-K+1, i) * (K-1, i-1)を計算すれば良い
    ans = binomialCoefficient(N-K+1, i) * binomialCoefficient(K-1, i-1) % mod
    return ans


for i in range(K):
    if i == 0:
        print((R+1) % mod)
    else:
        ans = solve(i+1)
        print(ans % mod)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
R = N - K
mod = 10 ** 9 + 7


def makeTableMod(N, mod=10 ** 9 + 7):
    fac = [1 for i in range(N)]
    finv = [1 for i in range(N)]
    inv = [1 for i in range(N)]
    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


fac, finv = makeTableMod(N-K+2, mod)


def binomialCoefficient(N, r, mod=10 ** 9 + 7):
    if N < r:
        return 0
    else:
        return fac[N] * (finv[r] * finv[N - r] % mod) % mod


def solve(i):
    # (N-K+1, i) * (K-1, i-1)を計算すれば良い
    ans = binomialCoefficient(N-K+1, i) * binomialCoefficient(K-1, i-1)
    return ans


for i in range(K):
    if i == 0:
        print((R+1) % mod)
    else:
        ans = solve(i+1)
        print(ans % mod)
Problem p03013 (python)

Fixed submission:
from collections import defaultdict
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]
dict = defaultdict(int)
for a in A:
    dict[a] += 1

mod = 10 ** 9 + 7
dp = [0 for _ in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(1, N):
    if dict[i] == 0 and dict[i-1] == 0:
        dp[i+1] += ((dp[i-1] + dp[i]) % mod)
    elif dict[i] == 0:
        dp[i+1] += (dp[i] % mod)
    elif dict[i-1] == 0:
        dp[i+1] += (dp[i-1] % mod)

print(dp[-1])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]
dict = defaultdict(int)
for a in A:
    dict[a] += 1

mod = 10 ** 9 + 7
dp = [0 for _ in range(N+1)]
dp[0] = 1
dp[1] = 1 if dict[1] == 0 else dp[1] = 0
for i in range(1, N):
    if dict[i] == 0 and dict[i-1] == 0:
        dp[i+1] += ((dp[i-1] + dp[i]) % mod)
    elif dict[i] == 0:
        dp[i+1] += (dp[i] % mod)
    elif dict[i-1] == 0:
        dp[i+1] += (dp[i-1] % mod)

print(dp[-1])