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

Fixed submission:
from collections import Counter
n, m, *d = map(int, open(0).read().split())
a = Counter(d[:n])
for b, c in zip(d[n::2], d[n+1::2]):
    a[c] += b
ans = 0
for k, v in sorted(a.items())[::-1]:
    if n < v:
        exit(print(ans + k * n))
    n -= v
    ans += k * v

Buggy submission (verdict: Runtime Error):
from collections import*
I=lambda:map(int,input().split())
n,m=I()
a=Counter(I())
exec("b,c=I();a[c]+=b"*m)
s=0
for k,v in sorted(a.items())[::-1]:
 if n<v:exit(print(s+k*n))
 n-=v;s+=k*v

Buggy submission (verdict: Runtime Error):
from collections import＊
n,m,*d=map(int,open(0).read().split())
a=Counter(d[:n])
for b,c in zip(d[n::2],d[n+1::2]):a[c]+=b
s=0
for k, v in sorted(a.items())[::-1]:
 if n<v:exit(print(s+k*n))
 n-=v
 s+=k*v
Problem p03041 (python)

Fixed submission:
k = int(input()[2:])
s = list(input())
s[k-1] = chr(ord(str(s[k-1])) + 32)
print("".join(s))

Buggy submission (verdict: Runtime Error):
_, k, s = map(int, open(0).read().split())
s[k-1] = chr(ord(s[k-1])+26)
print(s)

Buggy submission (verdict: Runtime Error):
_, k, s = map(int, open(0).read().split())
s[k-1] ==chr(ord(s[k-1])+26)
print(s)

Buggy submission (verdict: Runtime Error):
_, k, s = map(int, open(0).read().split())
s[k-1] == chr(ord(s[k-1])+26)
print(s)
Problem p03242 (python)

Fixed submission:
print(1110 - int(input()))

Buggy submission (verdict: Runtime Error):
from collections import*
n, *v = map(int, open(0).read().split())
a, b = [Counter(v[i::2]).most_common() + [(0,0)] for i in (0,1)]
s, x = a[0]
t, y = b[0]
print(n - [x+y, max(x+b[1][1], y+a[1][1])][s==t])
Problem p03634 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())

dis = [ 0 for _ in range(n)]  # 距離
adj = [[] for _ in range(n)] # 隣接リスト

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

# v; 現在の頂点
# p; vの親
# d; 現在の距離
def dfs(v, p, d):
    dis[v] = d
    for i, c in adj[v]:
        if i == p:
            continue
        dfs(i, v, d+c)

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

dfs(k, -1, 0)

for _ in range(q):
    x, y = map(int, input().split())
    x -= 1;y -= 1
    print(dis[x] + dis[y])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6);l=lambda:map(int, input().split());n=int(input());s=[0for _ in[0]*n];j=[[]for _ in[0]*n]
for _ in range(n-1):a,b,c=l();j[a-1].append([b-1,c]);j[b-1].append([a-1,c])
def f(v,p,d):
 s[v]=d
 for i,c in j[v]:
  if i==p:
   continue
  f(i,v,d+c)
q,k=l()
dfs(k-1,-1,0)
for _ in [0]*q:x,y=l();print(s[x-1]+s[y-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6);l=lambda:map(int, input().split());n=int(input()):s=[0for _ in[0]*n];j=[[]for _ in[0]*n]
for _ in range(n-1):a,b,c=l();j[a-1].append([b-1,c]);j[b-1].append([a-1,c])
def f(v,p,d):
 s[v]=d
 for i,c in j[v]:
  if i==p:
   continue
  f(i,v,d+c)
q,k=l()
dfs(k-1,-1,0)
for _ in [0]*q:x,y=l();print(s[x-1]+s[y-1])
Problem p03724 (python)

Fixed submission:
c = [0]*10**5
for i in open(0).read().split()[2:]: c[int(i)-1] ^= 1
print("NO" if any(c) else "YES")

Buggy submission (verdict: Runtime Error):
c = [0]*10**5
for i in open(0).read().split()[2::]: c[int(i)] ^= 1
print("NO" if any(c) else "YES")

Buggy submission (verdict: Runtime Error):
c = [0]*10**5
for i in open(0).read().split()[::2]: c[int(i)] ^= 1
print("NO" if any(c) else "YES")
Problem p03775 (python)

Fixed submission:
n, m = int(input()), 0
for i in range(1, int(n**.5)+1):
    if not n%i:
        m = max(m, i)
print(len(str(n//m)))

Buggy submission (verdict: Runtime Error):
n, m = int(input()), 0
for i in range(1, n**.5 + 1):
  if n%i == 0:
    m = max(m, i)
print(len(str(n // m)))

Buggy submission (verdict: Runtime Error):
n, m = int(input()), 0
for i in range(1, **.5 + 1):
  if n%i == 0:
    m = max(m, i)
print(len(str(n // m)))
Problem p02549 (python)

Fixed submission:
p=998244353
n,k=map(int,input().split())
kukan=[]
for i in range(k):
    l,r=map(int,input().split())
    kukan.append((l,r))
dp=[0]*n
sdp=[0]*(n+1)
dp[0]=1
sdp[1]=1
for i in range(1,n):
    for l,r in kukan:
        left=max(0,i-r)
        right=max(0,i-l+1)
        dp[i]=(dp[i]+sdp[right]-sdp[left])%p
    sdp[i+1]=(sdp[i]+dp[i])%p
print(dp[-1])

Buggy submission (verdict: Runtime Error):
import heapq
n,k=map(int,input().split())
can=[]
you=[0]*(n+1)
for i in range(k):
    l,r=map(int,input().split())
    you[l],you[r+1]=1,-1
for i in range(n):
    you[i+1]+=you[i]
for i in range(n):
    if you[i]:
        can.append(i)
table=[0]*n
table[0]=1
ka=[0]*(n+1)
ka[0]=1
que=[0]
heapq.heapify(que)
can.sort()
while que:
    now=heapq.heappop(que)
    ka[now]=0
    for j in can:
        if now+j>=n:
            break
        table[now+j]=(table[now+j]+table[now])%998244353
        if ka[now+j]==0:
            heapq.heappush(que,now+j)
            ka[now+j]=1
print(table[-1]%998244353)

Buggy submission (verdict: Runtime Error):
import heapq
n,k=map(int,input().split())
can=[]
for i in range(k):
    l,r=map(int,input().split())
    for j in range(l,r+1):
        can.append(j)
table=[0]*n
table[0]=1
que=[0]
heapq.heapify(que)
can.sort()
while que:
    now=heapq.heappop(que)
    for j in can:
        if now+j>n:
            break
        table[now+j]=(table[now+j]+table[now])%998244353
        if now+j in set(que):
            continue
        heapq.heappush(que,now+j)
print(table[-1]%998244353)
Problem p02580 (python)

Fixed submission:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w+1):
    if bm==b[i]:
        wmax[i]+=1
ans=am+bm #基本解
k=sum(hmax)*sum(wmax)
if k>m: #鳩ノ巣原理
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=set([i for i, x in enumerate(a) if x==am])
bb=set([i for i, x in enumerate(b) if x==bm])
c=[0 for i in range(m)]
d=[0 for i in range(m)]
for x in bomb:
        c[x[0]-1]+=1
        d[x[1]-1]+=1
cm=max(c)
dm=max(d)
aaa=len(aa)
bbb=len(bb)
if cm<bbb or dm<aaa:
    print(am+bm)
else:
    print(am+bm-1)

Buggy submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=[i for i, x in enumerate(a) if x==am]
bb=[i for i, x in enumerate(b) if x==bm]
for i in aa:
    for j in bb:
        if not [i,j] in set(bomb):
            continue
        else:
            print(am+bm)
            exit()
print(am+bm-1)
Problem p02623 (python)

Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa,bb=[0],[0]
for i in range(n):
    aa.append(aa[-1]+a[i])
for i in range(m):
    bb.append(bb[-1]+b[i])
ans,j=0,m
for i in range(n+1):
    if aa[i]>k:
        break
    while bb[j]>k-aa[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa,bb=[0],[0]
for i in range(n):
    aa.append(aa[-1]+a[i])
for i in range(m):
    bb.append(bb[-1]+b[i])
ans,j=0,m
for i in range(n+1):
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)
Problem p02659 (python)

Fixed submission:
A,B=input().split()
a=int(A)
b=B[0]+B[2]+B[3]
print(a*int(b)//100)

Buggy submission (verdict: Runtime Error):
from math import ceil
a,b=map(int,input().split())
print(ceil(a*b))
Problem p02711 (python)

Fixed submission:
n=input()
if n[0]=="7" or n[1]=="7" or n[2]=="7":
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n=input()
if n[0]=="7" or n[1]=="7" or n[2]=="7"
    print("Yes")
else:
    print("No")
Problem p02859 (python)

Fixed submission:
r=int(input())
print(r**2)

Buggy submission (verdict: Runtime Error):
def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
if len(f)=<r:
    print("0")
    exit()
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)
Problem p02862 (python)

Fixed submission:
def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
if x==0 and y>0:
    print("0")
    exit()
if y/x>2 or y/x<0.5:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)

Buggy submission (verdict: Runtime Error):
def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
if y/x>2 or y/x<0.5:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)

Buggy submission (verdict: Runtime Error):
def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
if len(f)<=r:
    print("0")
    exit()
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)

Buggy submission (verdict: Runtime Error):
def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
if len(f)>=r:
    print("0")
    exit()
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)

Buggy submission (verdict: Runtime Error):
def inv(a,p):
    if a==1:
        return 1
    elif a==0:
        return 0
    else:
        return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return(a)
f=fact(n,p)
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)

Buggy submission (verdict: Runtime Error):
def inv(a,p):
    if a==1:
        return 1
    else:
        return p-(inv(p%a,p)*(p//a))%p
x,y=map(int,input().split())
if (x+y)%3!=0:
    print("0")
    exit()
n=(x+y)//3
r=(2*x-y)//3
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return(a)
f=fact(n,p)
c=f[-1]
d=f[r]
e=f[n-r]
dd=inv(d,p)
ee=inv(e,p)
ans=(c*dd*ee)%p
print(ans)
Problem p02990 (python)

Fixed submission:
n,k=map(int,input().split())
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
invf=[]
for i in f:
    invf.append(pow(i,-1,p))
ans=[]
for i in range(1,k+1):
    if i>n-k+1:
        ans.append(0)
        continue
    ans.append(((f[n-k+1]*invf[n-k+1-i])%p)*((invf[i]*f[k-1])%p)*((invf[i-1]*invf[k-i]))%p)
for i in ans:
    print(i%p)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n-k+1,p)
invf=[]
for i in f:
    invf.append(pow(i,-1,p))
ans=[]
for i in range(1,k+1):
    if i>n-k+1:
        ans.append(0)
        continue
    ans.append(((f[n-k+1]*invf[n-k+1-i])%p)*((invf[i]*f[k-1])%p)*((invf[i-1]*invf[k-i]))%p)
for i in ans:
    print(i%p)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=10**9+7
def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n-k+1,p)
invf=[]
for i in f:
    invf.append(pow(i,-1,p))
ans=[]
for i in range(1,k+1):
    ans.append(f[n-k+1]*invf[n-k+1-i]*invf[i]*i**(k-i))
for i in ans:
    print(i%p)
Problem p03013 (python)

Fixed submission:
n,m=map(int,input().split())
a=set([int(input()) for j in range(m)])
dp=[0]*(n+1)
dp[0]=1
if not 1 in a:
    dp[1]=1
else:
    dp[1]=0
for i in range(n-1):
    if i+2 in a:
        dp[i+2]=0
    else:
        dp[i+2]=(dp[i+1]+dp[i])%(10**9+7)
print(dp[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=set([int(input()) for j in range(m)])
dp=[0]*(n+1)
dp[0]=1
if not a[0]==1:
    dp[1]=1
else:
    dp[1]=0
for i in range(n-1):
    if i+2 in a:
        dp[i+2]=0
    else:
        dp[i+2]=(dp[i+1]+dp[i])%(10**9+7)
print(dp[n])
Problem p03075 (python)

Fixed submission:
a=[int(input()) for i in range(5)]
k=int(input())
for i in range(4):
    for j in range(i+1,5):
        if a[j]-a[i]>k:
            print(":(")
            exit()
print("Yay!")

Buggy submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
b=sorted(list(map(int,input().split())),reverse=True)
c=sorted(list(map(int,input().split())),reverse=True)
ab=[]
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort(reverse=True)
ans=[]
for i in range(min(k,x*y)):
    for j in range(z):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])
Problem p02552 (python)

Fixed submission:
print(int(input())^1)

Buggy submission (verdict: Runtime Error):
import time
print((time.time()%10)^int(input()))
Problem p02557 (python)

Fixed submission:
# Rotationによる解。
from collections import Counter

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

elem_max_count = max((Counter(As) + Counter(Bs)).values())
if elem_max_count > N:
    print("No")
    exit()

# Bs[-index:] > As[:index] を満たすようなindexを二分探索
# 参考: https://twitter.com/catupper/status/1305163805802917889?s=20

ok = 0
ng = N + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    isok = True
    for b, a in zip(Bs[-mid:], As[:mid]):
        if b <= a:
            isok = False
            break
    
    if isok:
        ok = mid
    else:
        ng = mid

print("Yes")
print(*(Bs[-ok:] + Bs[:-ok]))

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

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

As_counter = Counter(As)
Bs_counter = Counter(Bs)

A_indices = dict()
for i, A in enumerate(As):
    if A in A_indices:
        A_indices[A].append(i)
    else:
        A_indices[A] = [i]
B_indices = dict()
for i, B in enumerate(Bs):
    if B in B_indices:
        B_indices[B].append(i)
    else:
        B_indices[B] = [i]

all_count = sorted((As_counter + Bs_counter).items(), key=lambda t: t[1], reverse=True)

if all_count[0][1] > N:
    print("No")
else:
    print("Yes")
    filling_order = []
    for elem, count in all_count[1:]:
        filling_order += A_indices[elem]
    filling_order += A_indices[all_count[0][0]]

    index = 0
    ans = [0] * N
    for elem, _ in all_count:
        count = Bs_counter[elem]
        for i in range(index, index + count):
            ans[filling_order[i]] = elem
        index += count

    print(*ans)
    assert not any(a == b for a, b in zip(ans, As))
Problem p02570 (python)

Fixed submission:
D, T, S = map(int, input().split())
print("Yes" if T * S >= D else "No")

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

if not __debug__:
	print("Yes" if D < T * S else "No")
else:
    1/0

Buggy submission (verdict: Runtime Error):
import sys

assert sys.argv[1] == "ONLINE_JUDGE"

Buggy submission (verdict: Runtime Error):
import sys

print(sys.argv[2])

Buggy submission (verdict: Runtime Error):
import sys

print(sys.argv[3])
Problem p02572 (python)

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

sA = sum(As) % (10 ** 9 + 7)
print((sA * sA - sum( (A * A % (10 ** 9 + 7) for A in As) ) ) * pow(2, -1, 10 ** 9 + 7) % (10 ** 9 + 7))

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

sA = sum(As) % (10 ** 9 + 7)
print((sA * sA - sum( (A * A % (10 ** 9 + 7) for A in As) ) ) * pow(2, -1, 10 ** 9 + 7) % (10 ** 9 + 7))
Problem p02693 (python)

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

flg = False
for i in range(a, b+1):
    if i % k == 0:
        flg = True
        break

if flg:
    print("OK")
else:
    print("NG")

Buggy submission (verdict: Runtime Error):
import bisect

INF = 10 ** 10

N = int(input())
As = list(map(int, input().split()))
edges = [tuple(map(int, input().split())) for _ in range(N-1)]

dfs_stack = [1]
ans = [-1] * N
lis = [INF] * (N+1)
rewinder = []

while dfs_stack:
    pos = dfs_stack.pop()
    for u, v in edges:
        if u == pos:
            if ans[v-1] == -1:
                dfs_stack.append(v)
            else:
                parent = v
        elif v == pos:
            if ans[u-1] == -1:
                dfs_stack.append(u)
            else:
                parent = u
    
    while rewinder:
        i, before, after = rewinder.pop()
        if after == As[parent-1]:
            rewinder.append( (i, before, after) )
            break
        else:
            lis[i] = before

    index = bisect.bisect_left(lis, As[pos-1])
    rewinder.append( (index, lis[index], As[pos-1]) )
    lis[index] = As[pos-1]
    ans[pos-1] = lis.index(INF)

print(*ans, sep = '\n')
Problem p02769 (python)

Fixed submission:
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

@lru_cache(None)
def combination(n, k):
    if k == 0:
        return 1
    else:
        return ((combination(n, k-1) * (n-k+1) % MOD) * pow(k, MOD-2, MOD)) % MOD

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

s = 0
for m in range(0, min(k+1, n)):
    s += combination(n, min(m, n - m)) * combination(n - 1, min(m, n - m - 1))
    s %= MOD

print(s)

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

@lru_cache
def combination(n, k):
    if k == 0:
        return 1
    else:
        return ((combination(n, k-1) * (n-k+1) % MOD) * pow(k, MOD-2, MOD)) % MOD

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

s = 0
for m in range(0, min(k+1, n)):
    s += combination(n, min(m, n - m)) * combination(n - 1, min(m, n - m - 1))
    s %= MOD

print(s)
Problem p02771 (python)

Fixed submission:
A, B, C = map(int, input().split())
if A == B == C:
  print("No")
elif A == B or B == C or C == A:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
if A == B == C:
  print("No")
elif A == B or B == C or C == A:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right

N, K = map(int, input().split())
As = sorted(map(int, input().split()))
        
l = - (10 ** 18 + 10)
r = 10 ** 18 + 10
while True
    mid = (l + r) // 2
    count = 0
    for i, A in enumerate(As):
        if A > 0:
            count += bisect_right(As, mid//A, lo = i+1) - (i+1)
        elif A < 0:
            count += N - bisect_left(As, -((-mid)//A), lo = i+1)
        else:
            if mid >= 0:
                count += N - i - 1
    if count < K:
        l = mid
    else:
        r = mid
    if r - l == 1:
        break

print(r)
Problem p02832 (python)

Fixed submission:
N = int(input())
ls = list(map(int, input().split()))
counter = 1
for elem in ls:
    if elem == counter:
        counter += 1
if counter == 1:
    print(-1)
else:
    print(N - counter + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
ls = list(map(int, input().split())
counter = 1
for elem in ls:
    if elem == counter:
        counter += 1
print(N - counter)
Problem p02948 (python)

Fixed submission:
from operator import itemgetter
import heapq

N, M = map(int, input().split())
pairs = [tuple(map(int, input().split())) for _ in range(N)]
pairs.sort(key = itemgetter(0))

heap = []
reward = 0
index_of_pairs = 0   
for i in range(1, M+1):
    while index_of_pairs < N and pairs[index_of_pairs][0] <= i:
        heapq.heappush(heap, -pairs[index_of_pairs][1])
        index_of_pairs += 1
    if heap:
        reward -= heapq.heappop(heap)

print(reward)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

N, M = map(int, input().split())
pairs = [tuple(map(int, input().split())) for _ in range(N)]
pairs.sort(key = itemgetter(1), reverse = True)

A_max = M
schedule = [0] * (M+1)
for A, B in pairs:
    for i in range(A, A_max+1):
        if schedule[i] == 0:
            schedule[i] = B
            break
    else:
        A_max = A
    


print(sum(schedule))
Problem p03003 (python)

Fixed submission:
MOD = 10 ** 9 + 7

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

dp = [[1] * (M+1) for _ in range(N+1)]

for i, s in enumerate(S):
    for j, t in enumerate(T):
        dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]
        if s != t:
            dp[i+1][j+1] -= dp[i][j]
        dp[i+1][j+1] %= MOD

print(dp[N][M])

Buggy submission (verdict: Runtime Error):
from numba import njit

MOD = 10 ** 9 + 7

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

@njit
def solve(N, M, S, T):
    dp = [[1] * (M+1) for _ in range(N+1)]
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]
            if s != t:
                dp[i+1][j+1] -= dp[i][j]
            dp[i+1][j+1] %= MOD
    return dp[M][N]
    
print(solve(N, M, S, T))
Problem p03839 (python)

Fixed submission:
from itertools import accumulate
N, K = map(int, input().split())
As = list(map(int, input().split()))

csum = list(accumulate(As, initial = 0))
csum_of_positives = list(accumulate([max(A, 0) for A in As], initial = 0))

#[i, i+K) will be all white/black.
max_score = 0
for i in range(N-K+1):
    score = 0
    all_black = csum[i+K] - csum[i]
    if all_black > 0: # if [i, i+K) is worth painting with black 
        score += all_black
    score += csum_of_positives[i] #[0, i)
    score += csum_of_positives[N] - csum_of_positives[i+K] #[i+K, N)    
    max_score = max(max_score, score)

print(max_score)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
N, K = map(int, input().split())
As = list(map(int, input().split()))

csum = list(accumulate(As, initial = 0))
csum_of_positives = list(accumulate([max(A, 0) for A in As], initial = 0))

#[i, i+K) will be all white/black.
max_score = 0
for i in range(N-K+1):
    score = 0
    all_black = csum[i+K] - csum[i]
    if all_black > 0: # if [i, i+K) is worth painting with black 
        score += all_black
    score += csum_of_positives[i] #[0, i)
    score += csum_of_positives[N] - csum_of_positives[i+K] #[i+K, N)    
    max_score = max(max_score, score)

print(max_score)