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

Fixed submission:
n = input()
if "7" in n:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = input()
if 7 in n:
    print("Yes")
else:
    print("No")
Problem p02781 (python)

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    K = int(input())
    L = len(N)

    # dp[i][j][k]
    # i 桁目まで決めて
    # j 個の非0を使って
    # k = 0 : そこまでの桁はNと一致
    # k = 1 : そこまでの桁でN未満であることが確定
    dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(L + 1)]
    dp[0][0][0] = 1

    from pprint import pprint
    for i, x in enumerate(N):
        for k in range(K + 1):
            # 桁ごと数え上げ
            if x == 0:
                # x == 0
                dp[i + 1][k][0] += dp[i][k][0]
            else:
                # x == 0
                dp[i + 1][k][1] += dp[i][k][0]
                # 0 < n < x
                dp[i + 1][k + 1][1] += dp[i][k][0] * (x - 1)
                # n == x
                dp[i + 1][k + 1][0] += dp[i][k][0]
            # N未満で次の桁に1~9を入れる
            dp[i + 1][k + 1][1] += dp[i][k][1] * 9
            # N未満で次の桁に0を入れる
            dp[i + 1][k][1] += dp[i][k][1]

    print(sum(dp[L][K]))  

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    K = int(input())

    if len(N) < K:
        print(0)

    if K == 1:
        print(N[0] + 9 * (len(N)-1))
    elif K == 2:
        count = 0
        for i in range(1, len(N)-1):
            count += 81 * i
        count += (N[0]-1) * 9 * (len(N)-1)

        count += 9 * (len(N)-2)

        count += N[1]
        print(count)
    else:
        count = 0
        for i in range(2, len(N)-1):
            count += 729 * i*(i-1)//2
        count += (N[0]-1) * 81 * (len(N)-1) * (len(N)-2) // 2

        count += 81 * (len(N)-2) * (len(N)-3) // 2

        count += (N[1]-1) * 9 * (len(N)-2)

        count += 9 * (len(N)-3)

        count += N[2]
        print(count)

main()
Problem p02785 (python)

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
if n <= k:
    print(0)
    exit()
h.sort()
for i in range(k):
    h.pop()
print(sum(h))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
for i in range(k):
    h.pop()
print(sum(h))
Problem p02912 (python)

Fixed submission:
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

if n == 1:
    while m > 0:
        a[0] //= 2
        m -= 1
    print(a[0])
    exit()

while m > 0:
    a.sort(reverse = True)
    mid = a[0] // 2
    i = 0
    while a[i] >= mid:
        if m > 0:
            a[i] //= 2
            m -= 1
            i += 1
        else:
            break
        if i == len(a):
            break
print(sum(a))

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

if n == 1:
    while m > 0:
        a[0] //= 2
        m -= 1
    print(a[0])
    exit()

while m > 0:
    a.sort(reverse = True)
    mid = a[0] // 2
    i = 0
    while a[i] >= mid:
        if i == n:
            break
        if m > 0:
            a[i] //= 2
            m -= 1
            i += 1
        else:
            break
print(sum(a))
Problem p02990 (python)

Fixed submission:
mod = 1000000007

class combination():
    def __init__(self, n):
        self.fact = [1] * (n+1)
        self.ifact = [1] * (n+1)
        for i in range(1, n+1):
            self.fact[i] = self.fact[i-1]*i % mod
        self.ifact[n] = pow(self.fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            self.ifact[i-1] = self.ifact[i]*i % mod
    def comb(self, n, k):
        if k < 0 or k > n: return 0
        comb = self.fact[n]*self.ifact[k]*self.ifact[n-k] %mod
        return comb

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

comb = combination(n)
for i in range(1, k+1):
    print(comb.comb(n-k+1, i) * comb.comb(k-1, i-1) % mod)

Buggy submission (verdict: Runtime Error):
mod = 1000000007

class combination():
    def __init__(self, n):
        self.fact = [1] * (n+1)
        self.ifact = [1] * (n+1)
        for i in range(1, n+1):
            self.fact[i] = self.fact[i-1]*i % mod
        self.ifact[n] = pow(self.fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            self.ifact[i-1] = self.ifact[i]*i % mod
    def comb(self, n, k):
        if k < 0 or k > n: return 0
        comb = self.fact[n]*self.ifact[k]*self.ifact[n-k] %mod
        return comb

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

comb = combination(n-k+5)
for i in range(1, k+1):
    print(comb.comb(n-k+1, i) * comb.comb(k-1, i-1) % mod)

Buggy submission (verdict: Runtime Error):
mod = 1000000007

class combination():
    def __init__(self, n):
        self.fact = [1] * (n+1)
        self.ifact = [1] * (n+1)
        for i in range(1, n+1):
            self.fact[i] = self.fact[i-1]*i % mod
        self.ifact[n] = pow(self.fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            self.ifact[i-1] = self.ifact[i]*i % mod
    def comb(self, n, k):
        if k < 0 or k > n: return 0
        comb = self.fact[n]*self.ifact[k]*self.ifact[n-k] %mod
        return comb

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

comb = combination(n-k+1)
for i in range(1, k+1):
    print(comb.comb(n-k+1, i) * comb.comb(k-1, i-1) % mod)
Problem p03013 (python)

Fixed submission:
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def iif(n): return [int(input()) for _ in range(n)]
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    mod = 1000000007

    F = [1, 1]
    for i in range(100000):
        F.append(F[i] + F[i+1])

    N, M = mi()

    if M == 0:
        print(F[N] % mod)
        return

    A = iif(M)
    DA = []
    left = 0
    for i in range(M):
        da = A[i] - left
        if da == 0 and left != 0:
            print(0)
            return
        else:
            DA.append(da-1)
        left = A[i] + 1
    if A[-1] != N:
        DA.append(N - A[-1] - 1)


    ans = 1
    for i in DA:
        ans *= F[i]

    print(ans % mod)

    return

main()

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

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def iif(n): return [int(input()) for _ in range(n)]
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    mod = 1000000007

    N, M = mi()
    A = iif(M)
    DA = []
    left = 0
    for i in range(M):
        da = A[i] - left
        if da == 0 and left != 0:
            print(0)
            return
        else:
            DA.append(da-1)
        left = A[i] + 1
    if A[-1] != N:
        DA.append(N - A[-1] - 1)

    F = [1, 1]
    for i in range(100000):
        F.append(F[i] + F[i+1])

    ans = 1
    for i in DA:
        ans *= F[i]

    print(ans % mod)

    return

main()

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

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def iif(n): return [int(input()) for _ in range(n)]
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    mod = 1000000007

    N, M = mi()
    A = iif(M)
    DA = []
    left = 0
    for i in range(M):
        da = A[i] - left
        if da == 1 and left != 0:
            print(0)
            return
        else:
            DA.append(da-1)
        left = A[i] + 1
    if A[-1] != N:
        DA.append(N - A[-1] - 1)

    F = [1, 1]
    for i in range(100000):
        F.append(F[i] + F[i+1])

    ans = 1
    for i in DA:
        ans *= F[i]

    print(ans % mod)

    return

main()
Problem p03013 (python)

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

dan=[]

for i in range(m):
    b=list(map(int, input().split()))
    dan.append(b[0])

fib=[0 for i in range(n+2)]
fib[1]=1
fib[2]=2

for ii in range(n-1):
    i=ii+3
    fib[i]=(fib[i-1]+fib[i-2])%1000000007
    
#print(fib,dan)

eachans=[]

if(m==0):
    print(fib[n])

if(m>=1):
    if(dan[0]!=1):
        eachans.append(fib[dan[0]-1])

    for i in range(m-1):
        if(dan[i+1]-dan[i]-2 == 0):
            eachans.append(1)
        elif(dan[i+1]-dan[i]-2 == -1):
            eachans.append(0)
        else:
            eachans.append(fib[dan[i+1]-dan[i]-2])
        #print(dan[i+1]-dan[i]-1)

if(m>=1):
    if(dan[-1]!=n-1):
        eachans.append(fib[n-dan[-1]-1])
    
if(m>=1):
    #print(eachans)
    ans=1
    for i in range(len(eachans)):
        ans = ans*eachans[i]%1000000007

    print(ans)

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

dan=[]

for i in range(m):
    b=list(map(int, input().split()))
    dan.append(b[0])

fib=[0 for i in range(n+2)]
fib[1]=1
fib[2]=2

for ii in range(n-1):
    i=ii+3
    fib[i]=(fib[i-1]+fib[i-2])%1000000007
    
#print(fib,dan)

eachans=[]

if(m==0):
    print(fib[n])

if(m>=1):
    if(dan[0]!=1):
        eachans.append(fib[dan[0]-1])

    for i in range(m-1):
        if(dan[i+1]-dan[i]-2 == 0):
            eachans.append(1)
        elif(dan[i+1]-dan[i]-2 == -1):
            eachans.append(0)
        else:
            eachans.append(fib[dan[i+1]-dan[i]-2])
        #print(dan[i+1]-dan[i]-1)

if(m>=1):
    if(dan[-1]!=n-1):
        eachans.append(fib[n-dan[-1]-1])
    
if(m>=1):
    #print(eachans)
    ans=1
    for i in range(len(eachans)):
        ans = ans*eachans[i]%1000000007

print(ans)

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

dan=[]

for i in range(m):
    b=list(map(int, input().split()))
    dan.append(b[0])

fib=[0 for i in range(n+2)]
fib[1]=1
fib[2]=2

for ii in range(n-1):
    i=ii+3
    fib[i]=(fib[i-1]+fib[i-2])%1000000007
    
#print(fib,dan)

eachans=[]

if(m==0):
    print(fib[n])

if(m>=1):
    if(dan[0]!=1):
        eachans.append(fib[dan[0]-1])

for i in range(m-1):
    if(dan[i+1]-dan[i]-2 == 0):
        eachans.append(1)
    elif(dan[i+1]-dan[i]-2 == -1):
        eachans.append(0)
    else:
        eachans.append(fib[dan[i+1]-dan[i]-2])
    #print(dan[i+1]-dan[i]-1)

if(m>=1):
    if(dan[-1]!=n-1):
        eachans.append(fib[n-dan[-1]-1])
    
if(m>=1):
    #print(eachans)
    ans=1
    for i in range(len(eachans)):
        ans = ans*eachans[i]%1000000007

print(ans)
Problem p03038 (python)

Fixed submission:
import math

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

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

n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc=[]
for i in range(m):
    temp=list(map(int, input().split()))
    bc.append(temp)

a.sort()

bc.sort(key=lambda x:x[1],reverse=True)
#print(a)
#print(bc)

now=0
for i in range(n):
    if(a[i] < bc[now][1]):
        a[i] = bc[now][1]
        bc[now][0] -= 1
    else:
        break
    if(bc[now][0]==0):
        now+=1
    if(now>=m):
        break
    
print(sum(a))
#print(a)

Buggy submission (verdict: Runtime Error):
import math

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

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

n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc=[]
for i in range(m):
    temp=list(map(int, input().split()))
    bc.append(temp)

a.sort()

bc.sort(key=lambda x:x[1],reverse=True)
#print(a)
#print(bc)

now=0
for i in range(n):
    if(a[i] < bc[now][1]):
        a[i] = bc[now][1]
        bc[now][0] -= 1
    else:
        break
    if(bc[now][0]==0):
        now+=1
    
print(sum(a))
#print(a)

Buggy submission (verdict: Runtime Error):
import math


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

bc=[]

for i in range(m):
    l,r=list(map(int, input().split()))
    bc.append([l,r])
    
list.sort(a)
list.sort(bc, key=lambda x:x[0])

count=0

for i in range(m):
    for j in range(min(bc[m-i-1][0],len(a))):
        if(a[count]<bc[m-i-1][1]):
            a[count]=bc[m-i-1][1]
            count+=1

print(sum(a))
Problem p02832 (python)

Fixed submission:
n = int(input())
a = input().split( )

b = []
j = 0
k = 1

for i in range(n):
  if k == int(a[i]):
    b.append(int(a[i]))
    j += 1
    k += 1

if 0 == len(b):
  print(-1)
else:
  print(int(n)-len(b))

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

b = []
j = 0
k = 1

for i in range(n):
	if k == int(a[i]):
	b.append(int(a[i]))
	j += 1
	k += 1

if 0 == len(b):
	print(-1)
else:
	print(int(n)-len(b))

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

b = []
j = 0
k = 1

for i in range(n):
	if k == int(a[i]):
	b.append(int(a[i]))
	j += 1
	k += 1

if 0 == len(b):
	print(-1)
else:
	print(int(n)-len(b))

Buggy submission (verdict: Runtime Error):
n = input()
a = input().split( )

b = []
j = 0
k = 1

for i in range(int(n)):
    if k == int(a[i]):
	b.append(a[i])
	j += 1
	k += 1

if 0 == len(b):
    print(-1)
else:
    print(int(n)-len(b))
Problem p02711 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#N, K, C = map(int, readline().split())  int
#S = read().rstrip().decode()  string
# N =int(read())
#print(C,A,B)

x=read().rstrip().decode()

if '7' in x:
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#N, K, C = map(int, readline().split())  int
#S = read().rstrip().decode()  string
# N =int(read())
#print(C,A,B)

x=read()
if '7' in x:
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#N, K, C = map(int, readline().split())  int
#S = read().rstrip().decode()  string
# N =int(read())
#print(C,A,B)

x=read()
if ''7' in x:
	print("Yes")
else:
	print("No")
Problem p03295 (python)

Fixed submission:
n,m=map(int,input().split())
mx =[-1 for i in range(0,n)]
for z in range(0,m):
  a,b=map(int,input().split())
  mx[b-1]=max(mx[b-1],a-1)
cut=-1
cn=0
for z in range(0,n):
	if cut<mx[z]:
		cut=z-1
		cn=cn+1
print(cn)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
mx =[0 for i in range(0,n)]
for z in range(0,m):
  a,b=map(int,input().split())
  mx[b-1]=max(mx[b-1],a-1)
cut=0
cn=0
for z in range(0,n):
  if cut<mx[z]:
   	cut=z
    cn=cn+1
print(cn)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
mx =[0 for i in range(0,n)]
for z in range(0,m):
  a,b=map(int,input().split())
  mx[b]=max(mx[b],a)
cnt=0
cn=0
for z in range(0,n):
  if cut<mx[z]:
   	cut=z
    cn=cn+1
print(cn)
Problem p02597 (python)

Fixed submission:
N = int(input())
c = input()
W = c.count('W')
R = c.count('R')
print(c[:R].count('W'))

Buggy submission (verdict: Runtime Error):
N = int(input())
c = input()
W = c.count('W')
print(c[:R].count('W'))
Problem p03127 (python)

Fixed submission:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
flag = 0
#mi = min(A)
Q = np.array(A)
an = 1
def toku(Q):
    mi = min(Q)
    R1 = Q % mi
    if any(R1) == 0:
        flag = 1
        an = mi
        return flag, an, R1
    else:
        flag = 0
        an = 1
        ind = np.argmin(Q)
        R1[ind] = mi
        R = R1[R1!=0]
        return flag, an, R

while flag == 0:
    flag,an,PP = toku(Q)
    Q = PP

print(an)

Buggy submission (verdict: Runtime Error):
import functools
import math
N = int(input())
A = list(map(int,input().split()))

gcd = functools.reduce(math.gcd, A)
print(gcd)
Problem p03286 (python)

Fixed submission:
N = int(input())
ans = [0]*36

def bit(inp,ans):
    if inp == 0:
        ans[0] = 0
        inp2 = 0
    
    if inp > 0:
        b = [1,5,21,85,341,1365,5461,21845,87381,349525,1398101,5592405,22369621,89478485,357913941,1431655765]
        pcount = 0
        for ii in range(len(b)):
            if inp <= b[ii]:
                inp2 = inp - 4**ii
                break
            pcount = pcount + 1
        ans[pcount*2] = 1
        
    if inp < 0:
        b2 = [-2,-10,-42,-170,-682,-2730,-10922,-43690,-174762,-699050,-2796202,-11184810,-44739242,-178956970,-715827882,-2863311530]
        pcount = 0
        for ii in range(len(b2)):
            if inp >= b2[ii]:
                inp2 = inp + 2 * (4**ii)
                break
            pcount = pcount + 1
        ans[pcount*2+1] = 1
        
    return inp2,ans

    
while N != 0:
    N,ans = bit(N,ans)

fi = ans[::-1]
fistr = [str(n) for n in fi]
m = ''.join(fistr)
mm = int(m)

print(mm)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = [0]*36

def bit(inp,ans):
    if inp == 0:
        ans[0] = 0
        inp2 = 0
    
    if inp > 0:
        b = [1,5,21,85,341,1365,5461,21845,87381,349525,1398101,5592405,22369621,89478485,357913941,1431655765]
        pcount = 0
        for ii in range(len(b)):
            if inp <= b[ii]:
                inp2 = inp - 4**ii
                break
            pcount = pcount + 1
        ans[pcount*2] = 1
        
    if inp < 0:
        b2 = [-2,-10,-42,-170,-682,-2730,-10922,-43690,-174762,-699050,-2796202,-11184810,-44739242,-178956970,-715827882]
        pcount = 0
        for ii in range(len(b2)):
            if inp >= b2[ii]:
                inp2 = inp + 2 * (4**ii)
                break
            pcount = pcount + 1
        ans[pcount*2+1] = 1
        
    return inp2,ans

    
while N != 0:
    N,ans = bit(N,ans)

fi = ans[::-1]
fistr = [str(n) for n in fi]
m = ''.join(fistr)
mm = int(m)

print(mm)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = [0]*32

def bit(inp,ans):
    if inp == 0:
        ans[0] = 0
        inp2 = 0
    
    if inp > 0:
        b = [1,5,21,85,341,1365,5461,21845,87381,349525,1398101,5592405,22369621,89478485,357913941]
        pcount = 0
        for ii in range(len(b)):
            if inp <= b[ii]:
                inp2 = inp - 4**ii
                break
            pcount = pcount + 1
        ans[pcount*2] = 1
        
    if inp < 0:
        b2 = [-2,-10,-42,-170,-682,-2730,-10922,-43690,-174762,-699050,-2796202,-11184810,-44739242,-178956970]
        pcount = 0
        for ii in range(len(b2)):
            if inp >= b2[ii]:
                inp2 = inp + 2 * (4**ii)
                break
            pcount = pcount + 1
        ans[pcount*2+1] = 1
        
    return inp2,ans


while N != 0:
    N,ans = bit(N,ans)

fi = ans[::-1]
fistr = [str(n) for n in fi]
m = ''.join(fistr)
mm = int(m)

print(mm)
Problem p02723 (python)

Fixed submission:
s = input()

if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')

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

n = int(input())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
mod = 10 ** 9 + 7
def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

N = 10 ** 5 + 10
fact = [0] * (N)
fact[0] = 1
for i in range(1, N):
    fact[i] = (fact[i-1] * i) % mod

def comb(a, b):
    return moddiv(moddiv(fact[a], fact[a-b]), fact[b])

connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

d = [{} for _ in range(n)]

def dfs(v, p):
    if p in d[v]:
        return d[v][p]
    num, count = 0, 1
    for next in connect[v]:
        if next != p:
            i, c = dfs(next, v)
            num += i
            count *= c
            count %= mod
            count *= comb(num, i)
            count %= mod
    num += 1
    d[v][p] = num, count
    return num, count

for i in range(n):
    dfs(i, -1)
    print(d[i][-1][1])
Problem p02781 (python)

Fixed submission:
n = list(map(int, list(input())))
k = int(input())

# 上の桁からDP
# 大きさが微妙な場合は分ける
# dp[桁][0の個数]

def solve(n, k):
    if k == 0:
        return 1
    if n == []:
        return 0
    dp = [[0 for _ in range(k+1)] for _ in range(len(n))]
    dp[0][0] = 1
    dp[0][1] = n[0] - 1
    for i in range(len(n) - 1):
        for j in range(k + 1):
            if j == 0:
                dp[i+1][0] = dp[i][0]
            else:
                dp[i+1][j] = dp[i][j-1] * 9 + dp[i][j]
    # first non-0
    i = 1
    while i < len(n) and n[i] == 0:
        i += 1
    return dp[len(n) - 1][k] + solve(n[i:], k-1)

print(solve(n, k))

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

# 上の桁からDP
# 大きさが微妙な場合は分ける
# dp[桁][0の個数]

def solve(n, k):
    if k == 0:
        return 1
    dp = [[0 for _ in range(k+1)] for _ in range(len(n))]
    dp[0][0] = 1
    dp[0][1] = n[0] - 1
    for i in range(len(n) - 1):
        for j in range(k + 1):
            if j == 0:
                dp[i+1][0] = dp[i][0]
            else:
                dp[i+1][j] = dp[i][j-1] * 9 + dp[i][j]
    # first non-0
    i = 1
    while i < len(n) and n[i] == 0:
        i += 1
    return dp[len(n) - 1][k] + solve(n[i:], k-1)

print(solve(n, k))
Problem p02834 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2*10**5)

n, u, v = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
u -= 1
v -= 1

connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

du = [0] * n
dv = [0] * n

def dfs(v, dis, ng, d):
    d[v] = dis
    ng.add(v)
    for w in connect[v]:
        if w not in ng:
            dfs(w, dis+1, ng, d)

dfs(u, 0, set(), du)
dfs(v, 0, set(), dv)

ans = 0
for i in range(n):
    if du[i] < dv[i]:
        ans = max(ans, dv[i]-1)
print(ans)

Buggy submission (verdict: Runtime Error):
n, u, v = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
u -= 1
v -= 1

connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

du = [0] * n
dv = [0] * n

def dfs(v, dis, ng, d):
    d[v] = dis
    ng.add(v)
    for w in connect[v]:
        if w not in ng:
            dfs(w, dis+1, ng, d)

dfs(u, 0, set(), du)
dfs(v, 0, set(), dv)

print(du)
print(dv)
ans = 0
for i in range(n):
    if du[i] < du[i]:
        ans = max(ans, du[v]-1)
print(ans)
Problem p02847 (python)

Fixed submission:
s = input()
if s == 'SUN':
    print(7)
if s == 'MON':
    print(6)
if s == 'TUE':
    print(5)
if s == 'WED':
    print(4)
if s == 'THU':
    print(3)
if s == 'FRI':
    print(2)
if s == 'SAT':
    print(1)

Buggy submission (verdict: Runtime Error):
s = input()
if s == 'SUN':
    return 7
if s == 'MON':
    return 1
if s == 'TUE':
    return 2
if s == 'WED':
    return 3
if s == 'THU':
    return 4
if s == 'FRI':
    return 5
if s == 'SAT':
    return 6
Problem p03041 (python)

Fixed submission:
n, k = map(int, input().split())
s = input()
for i in range(n):
    if i == k - 1:
        print(s[i].lower(), end = '')
    else:
        print(s[i], end = '')

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
color = [-1] * n
neighbor = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = tuple(map(int, input().split()))
    neighbor[u - 1].append((v-1, w))
    neighbor[v - 1].append((u-1, w))
def col(u, c):
    color[u] = c
    for v, w in neighbor[u]:
        if color[v] < 0:
            col(v, (c + w) % 2)
col(0, 0)
for i in range(n):
    print(color[i])