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

Fixed submission:
import sys
import math
import bisect
import heapq
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M=nm()
Bl=[[] for i in range(10**5+5)]

for i in range(N):
    A,B=nm()
    Bl[A].append(-B)

now=[]
if(Bl[0]!=[]):
    for i in range(len(Bl[0])):
        heapq.heappush(now,Bl[0][i])

ans=0
for i in range(1,M+2):
    if(now!=[]):
        max_val=heapq.heappop(now)
        ans+=max_val
    if(Bl[i]!=[]):
        for j in range(len(Bl[i])):
            heapq.heappush(now,Bl[i][j])

print(-ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
import bisect
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M=nm()
Bl=[[] for i in range(10**5)]

for i in range(N):
    A,B=nm()
    Bl[A].append(B)

now=Bl[0]
ans=0
for i in range(1,M+2):
    if(now!=[]):
        max_val=max(now)
        ans+=max_val
        now.remove(max_val)
    now=now+Bl[i]

print(ans)
Problem p02623 (python)

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()
import bisect

def cumsum(a):
   r = [0]
   for v in a:
      r.append(r[-1] + v)
   return r

n, m, k = map(int, input().split())
a = cumsum(list(map(int, input().split())))
b = cumsum(list(map(int, input().split())))

ans = 0
for a_num, v in enumerate(a):
   tmp = 0
   if k >= v:
      b_num = bisect.bisect_right(b, k - v) - 1
      tmp = a_num + b_num
   ans = max(ans, tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()
import bisect

def cumsum(a):
   r = [0]
   for v in a:
      r.append(r[-1] + v)
   return r

def solve():
   n, m, k = map(int, input().split())
   a = cumsum(list(map(int, input().split())))
   b = cumsum(list(map(int, input().split())))

   ans = 0
   for a_num, v in enumerate(a):
      tmp = 0
      if k >= v:
         b_num = bisect.bisect_right(b, k - v) - 1
         tmp = a_num + b_num
      ans = max(ans, tmp)
   print(ans)

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

   # bの累積和
   b_sums = cumsum(b)
   ans = 0
   a = [0] + a

   j = len(b_sums) - 1
   a_sum = 0
   for i, v in enumerate(a):
      a_sum += v
      while a_sum + b_sums[j] > k:
         j -= 1
         if j < 0:
            break
      ans = max(ans, i + j)
   print(ans)


solve2()
Problem p02726 (python)

Fixed submission:
from collections import deque, defaultdict
n, x, y = map(int, input().split())

edges = defaultdict(lambda: [])
for i in range(1, n):
    edges[i].append(i+1)
    edges[i+1].append(i)
edges[x].append(y)
edges[y].append(x)

# 幅優先
counter = [0 for i in range(n)]
for i in range(1, n+1):
    d = deque()
    is_checked = [False for _ in range(n+1)]
    dist = [-1 for _ in range(n+1)]
    dist[i] = 0
    d.append((i, 0))
    while len(d) > 0:
        e, pre_dist = d.popleft()
        if is_checked[e]:
            continue
        else:
            is_checked[e] = True
            dist[e] = pre_dist + 1
            for next_e in edges[e]:
                if not is_checked[next_e]:
                    d.append((next_e, pre_dist+1))
    for j in range(i+1, n+1):
        counter[dist[j]-1] += 1
print("\n".join(list(map(str, counter[1:]))))

Buggy submission (verdict: Runtime Error):
from collections import deque, defaultdict
n, x, y = map(int, input().split())

edges = defaultdict(lambda: [])
for i in range(1, n):
    edges[i].append(i+1)
    edges[i+1].append(i)
edges[x].append(y)
edges[y].append(x)

# 幅優先
counter = [0 for i in range(n)]
for i in range(1, n+1):
    d = deque()
    dist = [-1 for _ in range(n+1)]
    d.append((i, -1))
    while len(d) > 0:
        e, pre_dist = d.popleft()
        if dist[e] != -1:
            continue
        else:
            dist[e] = pre_dist + 1
            for next_e in edges[e]:
                if not is_checked[next_e]:
                    d.append((next_e, pre_dist+1))
    for j in range(i+1, n+1):
        counter[dist[j]-1] += 1
print("\n".join(list(map(str, counter[1:]))))
Problem p02792 (python)

Fixed submission:
n = int(input())

c = [[0 for _ in range(10)] for _ in range(10)]
for k in range(1, n+1):
    s = str(k)
    c[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from functools import reduce
input = sys.stdin.readline

# python > pypy
MOD = 10**9 + 7
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

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

lcm_ = a[0]
for i in range(n):
    lcm_ = lcm(lcm_, a[i])

b = list(map(lambda x: lcm_//x, a))
ans = 0
for i in range(len(b)):
    ans += b[i]
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from functools import reduce
input = sys.stdin.readline

# python > pypy
MOD = 10**9 + 7
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

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

lcm_ = a[0]
for i in range(n):
    lcm_ = lcm(lcm_, a[i])

b = list(map(lambda x: lcm_//x, a))
ans = 0
for i in range(len(b)):
    ans += b[i]
    ans %= MOD
print(ans)
Problem p02833 (python)

Fixed submission:
n = int(input())

def f(num):
    num = num - int(str(num)[-1])
    count = 0
    i = 1
    while True:
        if ((5 ** i) * (2)) > num:
            break
        count += (num // ((5 ** i) * (2)))
        i += 1
    return count


# 偶数 => 出てくる5の個数
# 奇数 => 0
if n % 2 == 1:
    print(0)
    exit()
else:
    print(f(n))

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


def f()
def f(num):
    num = num - int(str(num)[-1])
    count = 0
    i = 1
    while True:
        if ((5 ** i) * (2)) > num:
            break
        count += (num // ((5 ** i) * (2)))
        i += 1
    return count


# 偶数 => 出てくる5の個数
# 奇数 => 0
if n % 2 == 1:
    print(0)
    exit()
else:
    print(f(n))
Problem p02880 (python)

Fixed submission:
n = int(input())
l = []
for i in range(1, 10):
  for j in range(1, 10):
    l.append(i*j)

if n in l:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
l = []
for i in range(1, 10):
  for j in range(1, 10):
    l.appned(i*j)

if n in l:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
l = []
for i in range(1, 10):
  for j in range(1, 10):
    l.appned(i, j)

if n in l:
  print("Yes")
else:
  print("No")
Problem p02990 (python)

Fixed submission:
from math import factorial

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

class Facts():
    # 階乗のメモ化
    # 組み合わせ数、順列数の計算を高速に行う
    def __init__(self, max_num=10**5, p=10**9 + 7):
        self.p = p
        self.max_num = max_num
        self.fact = [1] * (self.max_num + 1)
        for i in range(1, self.max_num + 1):
            self.fact[i] = self.fact[i-1] * i
            self.fact[i] %= self.p

    def comb(self, n, k):
        # nCk mod p を求める
        if n < 0 or k < 0 or n < k:
            return 0
        if n == 0 or k == 0:
            return 1
        a = self.fact[n]
        b = self.fact[k]
        c = self.fact[n-k]
        return (a*self.power_func(b, self.p-2) *
                self.power_func(c, self.p-2)) % self.p

    def perm(self, n, k):
        # nPk mod p を求める
        if n < 0 or k < 0 or n < k:
            return 0
        if n == 0 or k == 0:
            return 1
        a = self.fact[n]
        b = self.fact[n-k]
        return (a * self.power_func(b, self.p-2)) % self.p


    def power_func(self, a, b):
        # a^b mod p　を繰り返し二乗法で求める
        if b == 0:
            return 1
        if b % 2 == 0:
            d = self.power_func(a, b//2)
            return d*d % self.p
        if b % 2 == 1:
            return (a*self.power_func(a, b-1)) % self.p

MOD = 10 ** 9 + 7
facts = Facts(n)

for i in range(1, k+1):
    ans = facts.comb(n-k+1, i) * facts.comb(k-1, i-1) % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
MOD = 10**9 + 7
def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k  = map(int, input().split())
ans = []
for i in range(1, k+1):
    if i % 2 == 1:
        print(combinations_count(n+1-k, i) % MOD)
    else:
        print(permutations_count(n+1-k, i) % MOD)
Problem p03041 (python)

Fixed submission:
n, k = map(int, input().split())
s = str(input())

s = s[:k-1] + s[k-1].lower() + s[k:]
print(s)

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

u = [0] * (n-1)
v = [0] * (n-1)
w = [0] * (n-1)

node = [i for i in range(n)]

group1 = []
group2 = []

for i in range(n-1):
    u[i], v[i], w[i] = map(int, input().split())
    u[i] -= 1
    v[i] -= 1
    w[i] = w[i] % 2
    # 同じなら0、違ったら1
    if w[i] == 0:
        if node[u[i]] == u[i]:
            node[u[i]] = node[v[i]]
        elif node[u[i]] != u[i]:
            node[v[i]] = node[u[i]]

for i in range(n-1):
    if w[i] == 1:
        if u[i] in group1:
            group2.append(node[v[i]])
        elif u[i] in group2:
            group1.append(node[v[i]])
        elif v[i] in group1:
            group2.append(node[u[i]])
        elif v[i] in group2:
            group1.append(node[u[i]])
        else:
            group1.append(node[v[i]])
            group2.append(node[u[i]])

for i in range(n):
    if node[i] in group1:
        node[i] = 0
    else:
        node[i] = 1

for color in node:
    print(color)
Problem p03127 (python)

Fixed submission:
# C
n = int(input()) 
a = list(map(int, input().split()))

from functools import reduce
def gcd(a,b):
    if a<b:a,b=b,a
    if a%b==0:return b
    return gcd(b,a%b)

gcd=reduce(gcd,a)
print(gcd)

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

import functools
import math

gcd = functools.reduce(math.gcd, a)
print(gcd)
Problem p03209 (python)

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

a, p = [1], [1]
for i in range(n):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

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

print(f(n, x))

Buggy submission (verdict: Runtime Error):
# D
N, X = map(int, input().split())
lv = [0]*(N+1)
lv[0] = 'P'
for i in range(1, len(lv)):
    lv[i] = 'B' + lv[i-1] + 'P' + lv[i-1] + 'B'
print(lv[N][-X:].count('P'))
Problem p03295 (python)

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

N, M = (int(i) for i in input().split())
dic = {}
cnt = 0
pos = 0
for i in range(M):
    a, b = map(int, input().split())
    if b not in dic or dic[b] < a:
        dic[b] = a

for j in sorted(dic.keys()):
    if dic[j] >= pos:
        cnt += 1
        pos = j
print(cnt)

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

left = [""] * (n - 2)
right = [""] * (n - 2)

for i in range(m):
    a, b = map(int, input().split())
    left[a - 1] = "["
    right[b - 2] = "]"

s = ""
for i in range(n):
    s += left[i]
    s += right[i]

count = 0
for i in range(len(s) - 1):
    if s[i:i+2] == "[]":
        count += 1
print(count)
Problem p03315 (python)

Fixed submission:
# A
s = str(input())
result = 0
for c in list(s):
    if c == '+':
        result += 1
    else:
        result -= 1
print(result)

Buggy submission (verdict: Runtime Error):
# C
n,k=map(int,input().split())
print((n+k-3)//(k-1))
Problem p03327 (python)

Fixed submission:
n = int(input())

if n >= 1000:
    print('ABD')
else:
    print('ABC')

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

if n >= 1000:
    print('ABD')
else:
    print('ABC')
Problem p03634 (python)

Fixed submission:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(20000000)
from collections import defaultdict
n = int(input())

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

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

# k からの距離を求める
dist = [-1 for _ in range(n+1)]
is_checked = [False for _ in range(n+1)]
def dfs(num, cur_dist):
    global dist, is_checked
    for next_num, d in edges[num]:
        if not is_checked[next_num]:
            is_checked[next_num] = True
            dist[next_num] = cur_dist + d
            dfs(next_num, cur_dist + d)
dist[k] = 0
is_checked[k] = True
dfs(k, 0)

ans = []
for _ in range(q):
    x, y = map(int, input().split())
    ans.append(str(dist[x] + dist[y]))
print("\n".join(ans))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())

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

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

# k からの距離を求める
dist = [-1 for _ in range(n+1)]
is_checked = [False for _ in range(n+1)]
def dfs(num, cur_dist):
    for next_num, d in edges[num]:
        if not is_checked[next_num]:
            is_checked[next_num] = True
            dist[next_num] = cur_dist+d
            dfs(next_num, cur_dist+d)
dist[k] = 0
is_checked[k] = True
dfs(k, 0)
# print(dist)
ans = []
for _ in range(q):
    x, y = map(int, input().split())
    ans.append(str(dist[x] + dist[y]))
print("\n".join(ans))
Problem p03804 (python)

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

a = []
b = []

for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))



for s_h in range(n - m + 1):
    for s_w in range(n - m + 1):
        flag = True
        for i in range(m):
            for j in range(m):
                if a[s_h + i][s_w + j] != b[i][j]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            break
    if flag:
        break
if not flag:
    print("No")

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

a = []
b = []

for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))

for s_h in range(n - m):
    for s_w in range(n - m):
        flag = True
        for i in range(m):
            for j in range(m):
                if a[s_h + i][s_w + j] != b[i][j]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            break
    if flag:
        break
if not flag:
    print("No")
Problem p02570 (python)

Fixed submission:
d, t, s = map(int, input().split())

c = d / s

if t>=c:
  print('Yes')
elif t<c:
  print('No')

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

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

c = 0

for i in range(N-1):
  for j in range(int(i)+1, N):
    d = A[i] % (10**9+7)
    e = A[j] % (10**9+7)
    f = (d*e) % (10**9+7)
    c += f
    

c = c % (10**9+7)

print(c)
Problem p02785 (python)

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

if N <= K:
  print(0)
  
else:
  H = list(map(int, input().split()))
  H.sort()
  H.reverse()
  
  c = 0
  for i in range(K, N):
    c += H[i]
  print(c)

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

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

H.sort()
H.reverse()


for i in range(K):
  del(H[0])
  
c = 0

for j in range(len(H)):
  c += H[j]

print(c)
Problem p02933 (python)

Fixed submission:
a = int(input())

s = input()

if a >= 3200:
  print(s)
else:
  print('red')

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

s = list(map(int, input().split()))
t = []
v = 0

for i in range(n):
  c = 1/s[i]
  t.append(c)
  
for j in range(n):
  v += t[j]
  
ans = 1/v

print(ans)
Problem p02629 (python)

Fixed submission:
N = int(input())
ans = ''
while N > 0:
  N -= 1
  ans += chr(ord('a') + N % 26)
  N //= 26
print(ans[::-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
2 ans = ''
3 while N > 0:
4 N -= 1
5 ans += chr(ord('a') + N % 26)
6 N //= 26
7 print(ans[::-1])
Problem p02701 (python)

Fixed submission:
N=int(input())
S=[]
for i in range(N):
    A=input()
    S.append(A)
print(len(set(S)))

Buggy submission (verdict: Runtime Error):
N=int(input())
S=[]
count++
for i in range(N):
    A=input()
    if A not in S:
        S.append(A)
        count+=1
print(count)
Problem p02707 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
ans=[0]*N
for i in A:
    ans[i-1]+=1
for j in ans:
    print(j)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
ans=[0]*n
for i in A:
    ans[i-1]+=1
for j in ans:
    print(j)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
ans=[]
for i in A:
    ans[i-1]+=1
for j in ans:
    print(j)
Problem p02622 (python)

Fixed submission:
s=input()
t=input()
a=0
for x in range(len(s)):
  if s[x]!=t[x]:
    a+=1
print(a)

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
a=0
for x in range(s):
  if s[x]!=t[x]:
    a+=1
print(a)
Problem p02832 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
i=1
t=0
for x in a:
  if x!=i:
    t+=1
  else:
    i+=1
if len(a)==t:
  t=-1
print(t)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.append("0")
t=0
for i in range(n):
    if a[i+1]!="0":
     if a[i + 1] - a[i] != 1:
            t+=1
            a.pop(i)
    else:
        break
print(t)
Problem p02577 (python)

Fixed submission:
def main():
    N = input()
    total = 0
    for i in range(len(N)):
        total += int(N[i])
    if total % 9 == 0:
        print('Yes')
    else:
        print('No')
main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    total = 0
    while N > 0:
        total += N % 10
        N = int(N / 10)
    if total % 9 == 0:
        print('Yes')
    else:
        print('No')
main()
Problem p02688 (python)

Fixed submission:
def main():
    N, K = map(int, input().split(' '))
    d = [0] * N
    total = 0
    for i in range(K):
        A = input()
        B = list(map(int, input().split(' ')))
        for j in B:
            d[j - 1] = 1
    for j in range(N):
        if d[j] == 0:
            total += 1
    print(total)
main()

Buggy submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split(' '))
    d = [0] * N
    total = 0
    for i in range(K):
        A = input()
        B = list(map(int, input().split(' ')))
        for j in B:
            d[j - 1] = 1
    for j in range(K):
        if d[j] == 0:
            total += 1
    print(total)
main()
Problem p02570 (python)

Fixed submission:
D, S, T = map( int, input().split() )

if D - S * T <= 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = int( input())
A = list( map( int, input().split()))
 
mod = 10 ** 9 + 7
 
total = sum( A )
ret = 0
for a in A:
  ret = ( ret + ( total - a ) * a  ) 
print( ( ret // 2 ) % mod )
Problem p02622 (python)

Fixed submission:
S = input()
T = input()
 
ret = 0
for i in range(len(S)):
  if S[i] != T[i]:
    ret += 1
print( ret )

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

ret = 0
for i in len(S):
  if S[i] != T[i]:
    ret += 1
print( ret )
Problem p02627 (python)

Fixed submission:
a = input()

if a.isupper():
  print( "A" )
else:
  print("a")

Buggy submission (verdict: Runtime Error):
n = int( input() )
 
l = []
a = 97
alp = 26
k = 1
n2 = n
while n >= k + 1:
  l.append( ( n2 - 1 ) % alp  )
  n2 = ( n2 - ( n2 - 1 ) % alp ) // alp
  k *= alp
ret = ""
for c in reversed( l ):
  ret += chr( a + c )
print( ret )
Problem p02659 (python)

Fixed submission:
a, b = input().split()

b = b.replace(".","")

a = int( a )
b = int( b )
print( a * b // 100 )

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

print( a * b // 100 )

Buggy submission (verdict: Runtime Error):
import math
a, b= map( int,input().split() )

print( math.floor( a * b ) )
Problem p02682 (python)

Fixed submission:
A, B, C, K = map( int, input().split())
ret = min( A, K )
if A < K:
  ret -= max( 0, K - A - B )
print( ret )

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

l = [1] * A
l += [0] * B
l += [-1] * C

print( sum(l[:K]) )
Problem p02769 (python)

Fixed submission:
n, k = map( int, input().split() )
mod = 10 ** 9 + 7
 
numer = [ 1 ] * ( n + 1 )
demon = [ 1 ] * ( n + 1 )
 
for i in range( 1, n + 1 ):
  numer[ i ] = numer[ i - 1 ] * i % mod

demon[ n ] = pow( numer[ n ], mod - 2, mod )
for i in range( n, 0, -1 ):
  demon[ i - 1 ] = ( demon[ i ] * i ) % mod

def nCr( n, r ):
  if r < 1:
    return 1
  return ( numer[ n ] * demon[ r ] % mod ) * demon[ n - r ] % mod
 
ans = 0
for i in range( min( k, n - 1) + 1 ):
  ans = ( ans + nCr( n, i ) * nCr( n - 1, i )) % mod
print( ans )

Buggy submission (verdict: Runtime Error):
n, k = map( int, input().split() )
mod = 10 ** 9 + 7

numer = [ 1 ] * ( n + 1 )
demon = [ 1 ] * ( n + 1 )

for i in range( 1, n + 1 ):
  numer[ i + 1 ] = ( numer[ i ] * i ) % mod

demon[ n ] = pow( numer[ n ], mod - 2, mod )
for i in range( n, 0, -1 ):
  demon[ i - 1 ] = ( demon[ i ] * i ) % mod
  
def nCr( n, r ):
  if r < 1:
    return 0
  return ( numer[ n ] * demon[ r ] % mod ) * demon[ n - r ] % mod

ans = 0
for i in range( min( k, n - 1 ) + 1 ):
  ans = ( ans + nCr( n, i ) * nCr( n -1, i ) % mod
print( ans )

Buggy submission (verdict: Runtime Error):
n, k = map( int, input().split() )
mod = 10 ** 9 + 7
 
numer = [ 1 ] * ( n + 1 )
demon = [ 1 ] * ( n + 1 )
 
for i in range( 1, n + 1 ):
  numer[ i ] = numer[ i - 1 ] * i % mod

demon[ n ] = pow( numer[ n ], mod - 2, mod )
for i in range( n, 0, -1 ):
  demon[ i - 1 ] = ( demon[ i ] * i ) % mod

def nCr( n, r ):
  if r < 1:
    return 1
  return ( numer[ n ] * demon[ r ] % mod ) * demon[ n - r ] % mod
 
ans = 0
for i in range( max( k, n - 1) + 1 ):
  ans = ans + nCr( n, i ) * nCr( n - 1, i - 1 )
print( ans )

Buggy submission (verdict: Runtime Error):
n, k = map( int, input().split() )
mod = 10 ** 9 + 7
 
numer = [ 1 ] * ( n + 1 )
demon = [ 1 ] * ( n + 1 )
 
for i in range( 1, n + 1 ):
  numer[ i ] = numer[ i - 1 ] * i % mod

demon[ n ] = pow( numer[ n ], mod - 2, mod )
for i in range( n, 0, -1 ):
  demon[ i + 1 ] = ( demon[ i - 1 ] * i ) % mod

def nCr( n, r ):
  if r < 1:
    return 1
  return ( numer[ n ] * demon[ r ] % mod ) * demon[ n - r ] % mod
 
ans = 0
for i in range( max( k, n - 1) + 1 ):
  ans = ans + nCr( n, i ) * nCr( n - 1, i - 1 )
print( ans )

Buggy submission (verdict: Runtime Error):
n, k = map( int, input().split() )
mod = 10 ** 9 + 7

numer = [ 1 ] * ( n + 1 )
demon = [ 1 ] * ( n + 1 )

for i in range( 1, n + 1 ):
  numer[ i ] = numer[ i - 1 ] * i % mod

demon[ n ] = pow( numer[ n ], mod - 2, mod )
for i in range( n, 0, -1 ):
  demon[ i + 1 ] = ( demon[ i ] * i ) % mod

def nCr( n, r ):
  if r < 1:
    return 1
  return ( numer[ n ] * demon[ r ] % mod ) * demon[ n - r ] % mod

ans = 0
for i in range( max( k, n - 1) + 1 ):
  ans = ans + nCr( n, i ) * nCr( n - 1, i - 1 )
print( ans )
Problem p02661 (python)

Fixed submission:
N = int(input())
A = list()
B = list()
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
  
A.sort()
B.sort()

if(N%2==1):
  x = A[(N-1)//2]
  y = B[(N-1)//2]
  print(y-x+1)
else:
  x = A[(N//2)-1] + A[N//2]
  y = B[(N//2)-1] + B[N//2]
  print(y-x+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list()
B = list()
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
  
A.sort()
B.sort()

if(N%2==1):
  x = A[(N-1)//2]
  y = B[(N-1)//2]
  print(y-x+1)
else:
  x = A[(N//2)+1] + A[N//2]
  y = B[(N//2)+1] + B[N//2]
  print(y-x+1)