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

Fixed submission:
mod=998244353
k,n=map(int,input().split())

def modinv(n):
    return pow(n,mod-2,mod)
m=n+k
Fact=[1]
for i in range(1,m+1):
    Fact.append(Fact[i-1]*i%mod)
Finv=[0]*(m+1)
Finv[-1]=modinv(Fact[-1])
for i in range(m-1,-1,-1):
    Finv[i]=Finv[i+1]*(i+1)%mod
def comb(n,r):
    if r<0 or n<r:
        return 0
    return Fact[n]*Finv[r]*Finv[n-r]%mod
def hcomb(n,r):
    return comb(n+r-1,r)
Pow=[1]*(k+1)
for i in range(k):
    Pow[i+1]=Pow[i]*2%mod
def solve(x):
    ret=0
    if x%2:
        p=x//2
        for q in range(p+1):
            ret+=Pow[q]*comb(p,q)*hcomb(k-2*p+q,n-q)
            ret%=mod
    else:
        p=x//2-1
        for q in range(p+1):
            ret+=Pow[q]*comb(p,q)*(hcomb(k-2*p+q-1,n-q)+hcomb(k-2*p+q-1,n-q-1))
            ret%=mod
    return ret
Ans=[]
for i in range(2,k+2):
    Ans.append(solve(i))
print(*Ans,sep='\n')
print(*reversed(Ans[:k-1]),sep='\n')

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

def modinv(n):
    return pow(n,mod-2,mod)
m=n+k
Fact=[1]
for i in range(1,m+1):
    Fact.append(Fact[i-1]*i%mod)
Finv=[0]*(m+1)
Finv[-1]=modinv(Fact[-1])
for i in range(m-1,-1,-1):
    Finv[i]=Finv[i+1]*(i+1)%mod
def comb(n,r):
    if n<r:
        return 0
    return Fact[n]*Finv[r]*Finv[n-r]%mod
def hcomb(n,r):
    return comb(n+r-1,r)
Pow=[1]*(n+1)
for i in range(n):
    Pow[i+1]=Pow[i]*2%mod
def solve(x):
    ret=0
    if x%2:
        p=x//2
        for q in range(p+1):
            ret+=Pow[q]*comb(p,q)*hcomb(k-2*p+q,n-q)
            ret%=mod
    else:
        p=x//2-1
        for q in range(p+1):
            ret+=Pow[q]*comb(p,q)*(hcomb(k-2*p+q-1,n-q)+hcomb(k-2*p+q-1,n-q-1))
            ret%=mod
    return ret

Ans=[]
for i in range(2,k+2):
    Ans.append(solve(i))
print(*Ans, sep="\n")
print(*reversed(Ans[:-1]),sep="\n")
Problem p03363 (python)

Fixed submission:
from itertools import accumulate
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
S=list(accumulate(A))
C=Counter(S)

def num(m):
    return m*(m-1)//2

ans=0
for k,v in C.items():
    if k==0:
        ans+=v
    if v>1:
        ans+=num(v)
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
S=list(accumulate(A))
C=Counter(S)

def num(m):
    return m*(m-1)//2

ans=0
for k,v in C.items():
    if k==0:
        ans+=v
    if v>1:
        ans+=comb(v)
print(ans)
Problem p03428 (python)

Fixed submission:
import sys
input=sys.stdin.readline
from math import atan2,pi

def InnerProduct(V0,V1):
    x0,y0=V0
    x1,y1=V1
    return x0*x1+y0*y1
def CrossProduct(V0,V1):
    x0,y0=V0
    x1,y1=V1
    return x0*y1-x1*y0
def clockwise(P0,P1,P2):
    V0,V1=(P1[0]-P0[0],P1[1]-P0[1]),(P2[0]-P0[0],P2[1]-P0[1])
    return CrossProduct(V0,V1)<0

def MonotoneChain(V):
    upper,lower=[],[]
    P=sorted(V)
    for p in P:
        while len(lower)>1 and (not clockwise(lower[-2],lower[-1],p)):
            lower.pop()
        lower.append(p)
    for p in P[::-1]:
        while len(upper)>1 and (not clockwise(upper[-2],upper[-1],p)):
            upper.pop()
        upper.append(p)
    return lower[:-1]+upper[:-1]

n=int(input())
P=[tuple(map(int,input().split())) for _ in range(n)]
d={p: i for i,p in enumerate(P)}
ans=[0]*n
CH=MonotoneChain(P)
CH+=[CH[0],CH[1]]
for (x0,y0),(x1,y1),(x2,y2) in zip(CH,CH[1:],CH[2:]):
    V0,V1=(x0-x1,y0-y1),(x2-x1,y2-y1)
    ans[d[(x1,y1)]]=(pi-atan2(CrossProduct(V0,V1),InnerProduct(V0,V1)))/(2*pi)
for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
#021-B
import sys
input=sys.stdin.readline
from math import atan2,pi
from operator import itemgetter

def InnerProduct(V0,V1):
    x0,y0=V0
    x1,y1=V1
    return x0*x1+y0*y1
def CrossProduct(V0,V1):
    x0,y0=V0
    x1,y1=V1
    return x0*y1-x1*y0
def angle(P0,P1):
    x0,y0=P0
    x1,y1=P1
    return atan2(y1-y0,x1-x0)
def counterclockwise(P0,P1,P2):
    V0,V1=(P1[0]-P0[0],P1[1]-P0[1]),(P2[0]-P0[0],P2[1]-P0[1])
    return CrossProduct(V0,V1)>0

def GrahamScan(P):
    V=sorted(P,key=itemgetter(1))
    V0=V[0]
    V=sorted(V[1:], key=lambda p: angle(p,V0))+V[:1]
    convex=V[-1:]+V[:1]
    last_x,last_y=convex[-1]
    for p in V[1:]:
        while not counterclockwise(convex[-2],convex[-1],p):
            convex.pop()
        convex.append(p)
        last_x,last_y=p
    return convex[:-1]

n=int(input())
P=[tuple(map(int,input().split())) for _ in range(n)]
d={p: i for i,p in enumerate(P)}
ans=[0]*n
CH=GrahamScan(P)*2
for (x0,y0),(x1,y1),(x2,y2) in zip(CH,CH[1:],CH[2:]):
    V0,V1=(x0-x1,y0-y1),(x2-x1,y2-y1)
    ans[d[(x1,y1)]]=(pi+atan2(CrossProduct(V0,V1),InnerProduct(V0,V1)))/(2*pi)
for a in ans:
    print(a)
Problem p03597 (python)

Fixed submission:
print(int(input())**2-int(input()))

Buggy submission (verdict: Runtime Error):
print(input()**2-input())

Buggy submission (verdict: Runtime Error):
n,a=map(int,input().split())
print(n**2-a)
Problem p03612 (python)

Fixed submission:
n=int(input())
P=list(map(int,input().split()))
cnt=0
for i in range(n-1):
    if P[i]==i+1:
        tmp=P[i]
        P[i]=P[i+1]
        P[i+1]=tmp
        cnt+=1
if P[n-1]==n:
    cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
n=int(input())
P=list(map(int,input().split()))
cnt=0
for i in range(n-1):
    if P[i]==i+1:
        tmp=P[i]
        P[i]=P[i+1]
        P[i+1]=tmp
        cnt+=1
if P[n]==n+1:
    cnt+=1
print(cnt)
Problem p03633 (python)

Fixed submission:
n=int(input())
t=list(map(int,[input() for i in range(n)]))

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)

if n==1:
    print(t[0])
else:
    ans=lcm(t[0],t[1])
    for i in range(n-1):
        ans=lcm(ans,lcm(t[i],t[i+1]))
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
t=list(map(int,[input() for i in range(n)]))

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)

ans=lcm(t[0],t[1])
for i in range(n-1):
    ans=lcm(ans,lcm(t[i],t[i+1]))
print(ans)
Problem p03761 (python)

Fixed submission:
import string
import collections
n=int(input())
A=list(string.ascii_lowercase)
d={}
for _ in range(n):
    s=input()
    c=collections.Counter(s)
    for i in A:
        if i in c.keys():
            if i not in d:
                d[i]=c[i]
            else:
                d[i]=min(d[i],c[i])
        else:
            d[i]=0
ans=[]
for i in d:
    ans+=i*d[i]
ans.sort()
print(*ans,sep='')

Buggy submission (verdict: Runtime Error):
import string
from collections
n=int(input())
A=list(string.ascii_lowercase)
d={}
for _ in range(n):
    s=input()
    c=collections.Counter(s)
    for i in A:
        if i in c.keys():
            if i not in d:
                d[i]=c[i]
            else:
                d[i]=min(d[i],c[i])
        else:
            d[i]=0
ans=[]
for i in d:
    ans+=i*d[i]
ans.sort()
print(*ans,sep='')
Problem p03797 (python)

Fixed submission:
n,m=map(int,input().split())
m//=2
print((n+(m-n)//2) if n<m else m)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
print((n+m//2)//2)n,m=map(int,input().split())
m//=2
print((n+(m-n)//2) if n<m else m)
Problem p02730 (python)

Fixed submission:
S = input()
N = len(S)

if S == S[::-1]:
  if S[:(N-1)//2] == S [(N+1)//2:]:
    print("Yes")
  else:
    print("No")
else:
  print("No")

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

if S == S[::-1]:
  if S[:(n-1)//2] == S [(n+1)//2:]:
    print("Yes")
  else:
    print("No")
else:
  print("No")

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

if S = S[::-1]:
  if S[:(n-1)//2] == S [(n+1)//2:]:
    print("Yes")
  else:
    print("No")
else:
  print("No")
Problem p02911 (python)

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

if K > Q:
	for i in range(N):
		print("Yes")
	exit()

T = [0 for i in range(N)]
t = Q - K

for i in range(Q):
    a = int(input())
    T[a-1] += 1

for i in range(N):
    if T[i] > t:
         print("Yes")
    else:
        print("No")

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

if K > Q:
    ans = ["Yes" for i in range(N)]
print(ans)
exit()

T = [0 for i in range(N)]
t = Q - K

for i in range(Q):
    a = int(input())
    T[a] += 1

for i in range(N):
    if T[i] > t:
         print("Yes")
    else:
        print("No")
Problem p03076 (python)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

if A % 10 == 0:
    a = 0
else:
    a = 10 - A % 10

if B % 10 == 0:
    b = 0
else:
    b = 10 - B % 10

if C % 10 == 0:
    c = 0
else:
    c = 10 - C % 10

if D % 10 == 0:
    d = 0
else:
    d = 10 - D % 10

if E % 10 == 0:
    e = 0
else:
    e = 10 - E % 10

sum = A + B + C + D + E + a + b + c + d + e - max(a,b,c,d,e)

print(sum)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

if A % 10 == 0:
    a = 0
else:
    a = 10 - A % 10

if B % 10 == 0:
    b = 0
else:
    b = 10 - B % 10

if C % 10 == 0:
    c = 0
else:
    c = 10 - C % 10

if D % 10 == 0:
    d = 0
else:
    d = 10 - D % 10

    if E % 10 == 0:
        e = 0
    else:
        e = 10 - E % 10

sum = A + B + C + D + E + a + b + c + d + e - max(a,b,c,d,e)

print(sum)
Problem p03544 (python)

Fixed submission:
N = int(input())

if N == 1:
  print(1)
  exit()

for i in range(N+1):
    if i == 0:
        L_0 = 2
    elif i == 1:
        L_1 = 1
    else:
        L_2 = L_0 + L_1
        L_0 = L_1
        L_1 = L_2
        
print(L_2)

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

for i in range(N+1):
    if i == 0:
        L_1 = 2
    elif i == 1:
        L_2 = 1
    else:
        L_3 = L_1 + L_2
        L_1 = L_2
        L_2 = L_3
        
print(L_3)
Problem p04030 (python)

Fixed submission:
s = list(map(str,input()))

ans = []

for i in range(len(s)):
    if s[i] == '0':
        ans.append('0')
    elif s[i] == '1':
        ans.append('1')
    else:
        if ans == []:
            continue
        else:
            ans.pop(-1)

print(''.join(ans))

Buggy submission (verdict: Runtime Error):
s = list(map(str,input()))

ans = []

for i in range(len(s)):
    if s[i] == '0':
        ans.append('0')
    elif s[i] == '1':
        ans.append('1')
    else:
        ans.pop(-1)

print(''.join(ans))
Problem p02900 (python)

Fixed submission:
from fractions import gcd

a,b = [int(x) for x in input().split()]

def prime_factor(n):
    x = int(n**0.5)
    res = [1]
    for i in range(2,x+1):
        if n%i==0:
            while n%i==0:
                n //= i
            res.append(i)
    if n!=1:
        res.append(n)
    return res

z = gcd(a,b)
print(len(prime_factor(z)))

Buggy submission (verdict: Runtime Error):
import math
import fractions
import sys

sys.setrecursionlimit(10**8)
a,b = [int(x) for x in input().split()]
x = fractions.gcd(a,b)

is_prime = [1]*(x+1)
is_prime[0] = 0
is_prime[1] = 0
ans = 1
for i in range(2,x+1):
    if is_prime[i]:
        if x%i==0:
            ans += 1
        for j in range(2*i,x+1,i):
            is_prime[j] = 0
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import fractions

a,b = [int(x) for x in input().split()]
x = fractions.gcd(a,b)

is_prime = [1]*(x+1)
is_prime[0] = 0
is_prime[1] = 0
ans = 1
for i in range(2,x+1):
    if is_prime[i]:
        if x%i==0:
            ans += 1
        for j in range(2*i,x+1,i):
            is_prime[j] = 0
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import fractions

a,b = [int(x) for x in input().split()]
x = fractions.gcd(a,b)

is_prime = [1]*(x+1)
is_prime[0] = 0
is_prime[1] = 0
ans = 1
for i in range(2,x+1):
    if is_prime[i]:
        if x%i==0:
            ans += 1
        for j in range(2*i,x+1,i):
            is_prime[j] = 0
print(ans)
Problem p02918 (python)

Fixed submission:
n,k = [int(x) for x in input().split()]
s = input()
count = 1
for i in range(n-1):
    if s[i]!=s[i+1]:
        count += 1
print(n-max(1,count-2*k))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = list(input())
R = []
L = []
flag = 1 #1...R 0...L
lf = 1
rf = 1
if s[0]=="L":
    flag = 0
    lf = 0
if s[-1]=="L":
    rf = 0
count = 1
for i in range(n):
    if i==n-1:
        if flag==1:
            R.append(count*(-1))
            break
        else:
            L.append(count*(-1))
            break
    if s[i]==s[i+1]:
        count += 1
    elif flag==1:
        R.append(count*(-1))
        flag = 0
        count = 1
    else:
        L.append(count*(-1))
        flag = 1
        count = 1

import heapq
ans = 0
if s.count("R")>s.count("L"):
    ans += sum(R)*(-1)-len(R)
    copy_L = [x for x in L]
    heapq.heapify(L)
    for i in range(k):
        x = heapq.heappop(L)
        if lf==0 and x==copy_L[0] and copy_L.count(x)==1:
            ans += x*(-1)
        elif rf==0 and x==copy_L[-1] and copy_L.count(x)==1:
            ans += x*(-1)
        else:
            ans += x*(-1) +1
else:
    ans += sum(L)*(-1)-len(L)
    copy_R = [x for x in R]
    heapq.heapify(R)
    for i in range(k):
        x = heapq.heappop(R)
        if lf==1 and x==copy_R[0] and copy_R.count(x)==1:
            ans += x*(-1)
        elif rf==1 and x==copy_R[-1] and copy_R.count(x)==1:
            ans += x*(-1)
        else:
            ans += x*(-1) + 1 

print(ans)
Problem p03161 (python)

Fixed submission:
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float("inf")]*n
dp[0] = 0
for i in range(1,n):
    for j in range(1,k+1):
        if i>=j:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(x) for x in input().split()]
dp = [float("inf")]*(n+10)
dp[0] = 0
for i in range(n):
    if i<n-1:
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
    if i<n-2:      
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
print(dp[n-1])
Problem p02554 (python)

Fixed submission:
N = int(input())
a=(10**N)%(10**9+7)
b=(9**N)%(10**9+7)
c=(8**N)%(10**9+7)
print((a+c-2*b)%(10**9+7))

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

if N<(10**6):
	a=(10**N)%(10**9+7)
	b=(9**N)%(10**9+7)
	c=(8**N)%(10**9+7)
	print((a+c-2*b)%(10**9+7))
else:
	print((a+c-2*b)%(10**9+7))
Problem p02678 (python)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
to = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    to[a].append(b)
    to[b].append(a)

ans = [-1 for _ in range(n)]
d = deque()
d.append(0)
while len(d) > 0:
    now = d.popleft()
    for v in to[now]:
        if ans[v] > -1:
            continue
        ans[v] = now
        d.append(v)

print("Yes")
for i in range(1, len(ans)):
    print(ans[i]+1)

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

n, m = map(int, input().split())
to = [[] for _ in range(m)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    to[a].append(b)
    to[b].append(a)

visited = [False for _ in range(n)]

visited[0] = True
ans = [-1 for _ in range(n)]
d = deque()
d.append(0)
while len(d) > 0:
    now = d.popleft()
    for v in to[now]:
        if ans[v] > -1:
            continue
        ans[v] = now
        d.append(v)

print("Yes")
for i in range(1, len(ans)):
    print(ans[i]+1)
Problem p02697 (python)

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

ans = []
if M%2 == 0:
    for i in range(1, M//2+1):
        ans.append([i, M+1-i])
        ans.append([M+i, 2*M+2-i])
else:
    for i in range(1, M//2+1):
        ans.append([i, M+1-i])
    for i in range(1, (M+1)//2+1):
        ans.append([M+i, 2*M+2-i])

for i in range(len(ans)):
    print(*ans[i])

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

N, M = map(int, input().split())
candi = [True for _ in range(101010)]
for d in make_divisors(N):
    if d > 1:
        candi[d] = False

ans = []
l, r = 1, N
for i in range(M):
    if not candi[r-l]:
        while not candi[r-l]:
            r -= 1
    ans.append([l, r])
    l += 1
    r -= 1

for i in range(M):
    print(" ".join(map(str, ans[i])))
Problem p02698 (python)

Fixed submission:
import sys
import copy
import bisect

sys.setrecursionlimit(202020)

INF = 10**12
MAX_N = 202020

N = int(input())
a = list(map(int, input().split()))
to = [[] for _ in range(N)]
for i in range(N-1):
    u, v = map(int, input().split())
    u -= 1; v -= 1
    to[u].append(v)
    to[v].append(u)

dp = [INF for _ in range(MAX_N)]
ans = [0 for _ in range(N)]

def dfs(v, p=-1):
    i = bisect.bisect_left(dp, a[v])
    old = dp[i]
    dp[i] = a[v]
    ans[v] = i
    if p != -1:
        ans[v] = max(ans[v], ans[p])
    for u in to[v]:
        if u == p:
            continue
        dfs(u, v)
    dp[i] = old

dp[0] = -INF
dfs(0)
print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
import copy
import bisect

sys.setrecursionlimit(202020)

N = int(input())
a = list(map(int, input().split()))
to = [[] for _ in range(N)]
for i in range(N-1):
    u, v = map(int, input().split())
    u -= 1; v -= 1
    to[u].append(v)
    to[v].append(u)

ans = [1 for _ in range(N)]

def dfs(u, p, L, length):
    print(u)
    ans[u] = length
    for v in to[u]:
        if v == p:
            continue
        L_copy = copy.deepcopy(L)
        if L[-1] < a[v]:
            L_copy.append(a[v])
            dfs(v, u, L_copy, length+1)
        else:
            p = bisect.bisect_left(L_copy, a[v])
            L_copy[p] = a[v]
            dfs(v, u, L_copy, length)

dfs(0, -1, [a[0]], 1)
for i in range(N):
    print(ans[i])
Problem p02747 (python)

Fixed submission:
S=input()
ans="Yes"
if len(S)%2==1:
    ans="No"
else:
    for i in range(len(S)):
        if i%2==0:
            if S[i]!="h":
                ans="No"
                break
        if i%2==1:
            if S[i]!="i":
                ans="No"
                break
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
ans="Yes"
if len(S)%2==1:
    ans="No"
else:
for i in range(len(S)):
    if i%2==0:
        if S[i]!="h":
            ans="No"
            break
    if i%2==1:
        if S[i]!="i":
            ans="No"
            break
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
ans="Yes"
if S%2==1:
    ans="No"
else:
    for i in range(len(S)):
        if i%2==0:
            if S[i]!="h":
                ans="No"
                break
        if i%2==1:
            if S[i]!="i":
                ans="No"
                break
print(ans)
Problem p02761 (python)

Fixed submission:
N, M =map(int, input().split())
sc=[list(map(int, input().split())) for _ in range(M)]
sc.sort(key=lambda x:x[0])

ans=0
for i in range(M):
    s1, c1 = sc[i]
    if s1>N:
        ans=-1
        break
    for j in range(i+1, M):
        s2, c2 = sc[j]
        if s1==s2 and c1!=c2:
            ans=-1
            break
if M>0 and N>1 and sc[0][0]==1 and sc[0][1]==0:
    ans=-1

if ans!=-1:
    ans_={1:1, 2:0, 3:0}
    for i in range(M):
        s, c = sc[i]
        ans_[s]=c
    for i in range(1, N+1):
        ans=ans*10+ans_[i]

if N==1 and M==0:
    ans=0

print(ans)

Buggy submission (verdict: Runtime Error):
N, M =map(int, input().split())
sc=[list(map(int, input().split())) for _ in range(M)]
sc.sort(key=lambda x:x[0])

ans=0
if M>N:
    ans=-1
for i in range(M):
    s1, c1 = sc[i]
    if s1>N:
        ans=-1
        break
    for j in range(i+1, M):
        s2, c2 = sc[j]
        if s1==s2 and c1!=c2:
            ans=-1
            break
if len(sc)!=1 and sc[0][0]==1 and sc[0][1]==0:
    ans=-1

if ans!=-1:
    ans_={1:1, 2:0, 3:0}
    for i in range(M):
        s, c = sc[i]
        ans_[s]=c
    for i in range(1, N+1):
        ans=ans*10+ans_[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N, M =map(int, input().split())
sc=[list(map(int, input().split())) for _ in range(M)]
sc.sort(key=lambda x:x[0])

ans=0
for i in range(M):
    s1, c1 = sc[i]
    if s1>N:
        ans=-1
        break
    for j in range(i+1, M):
        s2, c2 = sc[j]
        if s1==s2 and c1!=c2:
            ans=-1
            break
if sc[0][0]==1 and sc[0][1]==0:
    ans=-1

if ans!=-1:
    ans_={1:1, 2:0, 3:0, 4:0, 5:0}
    for i in range(M):
        s, c = sc[i]
        ans_[s]=c
    for i in range(1, N+1):
        ans=ans*10+ans_[i]

print(ans)
Problem p02768 (python)

Fixed submission:
def comb2(n, r):
    if r<0 or r>n:
        return 0
    r=min(r, n-r)
    res=1
    for i in range(r):
        res=res*(n-i)%MOD*pow(i+1, MOD-2, MOD)%MOD
    return res

MOD=10**9+7

N, A, B=map(int, input().split())
ans=pow(2, N, MOD)-comb2(N, A)-comb2(N, B)-1
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
def comb(n, r):
    if r<0 or r>n:
        return 0
    r=min(r, n-r)
    return g1[n]*g2[r]*g2[n-r]%MOD

MOD=10**9+7
MAXN=200000+10
g1=[1, 1]
g2=[1, 1]
inverse=[0, 1]

for i in range(2, MAXN+1):
    g1.append((g1[-1]*i)%MOD)
    inverse.append(-inverse[MOD%i]*(MOD//i)%MOD)
    g2.append((g2[-1]*inverse[-1])%MOD)

def binary(n):
    return bin(n)[2:]

def pow_by_binary_exponentiation(a, x):
    x=[int(b) for b in binary(x)]
    y=a
    for i in range(1, len(x)):
        y=(y**2)%MOD
        if x[i]==1:
            y=(y*a)%MOD
    return y

N, A, B=map(int, input().split())
ans=pow_by_binary_exponentiation(2, N)-comb(N, A)-comb(N, B)-1
print(ans)
Problem p02782 (python)

Fixed submission:
def comb(n, r):
    if r<0 or r>n:
        return 0
    r=min(r, n-r)
    return g1[n]*g2[r]*g2[n-r]%MOD

MOD=10**9+7
MAXN=2000000+10
g1=[1, 1]
g2=[1, 1]
inverse=[0, 1]

for i in range(2, MAXN+1):
    g1.append((g1[-1]*i)%MOD)
    inverse.append(-inverse[MOD%i]*(MOD//i)%MOD)
    g2.append((g2[-1]*inverse[-1])%MOD)

r1, c1, r2, c2=map(int, input().split())
s1=comb(r2+c2+2, r2+1)-1
s2=comb(r1+c2+1, r1)-1
s3=comb(r2+c1+1, r2+1)-1
s4=comb(r1+c1, r1)-1
print((s1-s2-s3+s4)%MOD)

Buggy submission (verdict: Runtime Error):
r1, c1, r2, c2 = map(int, input().split())

MOD=10**9+7
MAXN=400000+10
g1=[1, 1]
g2=[1, 1]
inverse=[0, 1]

for i in range(2, MAXN+1): 
    g1.append((g1[-1]*i)%MOD)
    inverse.append(-inverse[MOD%i]*(MOD//i)%MOD)
    g2.append((g2[-1]*inverse[-1])%MOD)

def comb(n, r): 
    if r<0 or r>n: 
        return 0
    r=min(r, n-r)
    return g1[n]*g2[r]*g2[n-r]%MOD

ans = comb(r2+c2+2, r2+1)-1
ans -= comb(r2+1+c1, c1)-1
ans -= comb(r1+c2+1, r1)-1
ans += comb(r1+c1, r1)-1

print(ans%MOD)

Buggy submission (verdict: Runtime Error):
def comb(n, r):
    if r<0 or r>n:
        return 0
    r=min(r, n-r)
    return g1[n]*g2[r]*g2[n-r]%MOD

MOD=10**9+7
MAXN=100000*2+10
g1=[1, 1]
g2=[1, 1]
inverse=[0, 1]

for i in range(2, MAXN+1):
    g1.append((g1[-1]*i)%MOD)
    inverse.append(-inverse[MOD%i]*(MOD//i)%MOD)
    g2.append((g2[-1]*inverse[-1])%MOD)

r1, c1, r2, c2=map(int, input().split())
s1=comb(r2+c2+2, r2+1)
s2=comb(r1+c2+1, r1)
s3=comb(r2+c1+1, r2+1)
s4=comb(r1+c1, r1)
print(s1-s2-s3+s4)