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

Fixed submission:
s=input();print(min(s.count("0"),s.count("1"))*2)

Buggy submission (verdict: Runtime Error):
s=input()
print(2*min(s.count("0"),mins.count("1")))

Buggy submission (verdict: Runtime Error):
s=int(input())
print(2*min(s.count(0),mins.count(1)))
Problem p03208 (python)

Fixed submission:
n,k=map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort()
ans=10**9
for i in range(n-k+1):
    ans=min(ans,h[i+k-1]-h[i])
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
h = [int(input()) for i in range(N)]
h.sort()
ans=10**9
for i in range(n-k+1):
    ans=min(ans,max(h[i:i+k])-min(h[i:i+k]))
print(ans)
Problem p03315 (python)

Fixed submission:
k=[]
k=list(map(str,input()))
n=0
for i in range(4):
    if k[i]=='+':
        n+=1
    else:
        n-=1
print(n)

Buggy submission (verdict: Runtime Error):
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
print(math.ceil((n-k)/(k-1)+1))
Problem p03821 (python)

Fixed submission:
n=int(input())
A=[]
B=[]
ans=0
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(n-1,-1,-1):
    if (A[i]+ans)%B[i]!=0:
        ans+=(B[i]-(A[i]+ans)%B[i])

print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(min(b+c,a+2*b+1))
Problem p03834 (python)

Fixed submission:
a,b,c=map(str,input().split(','))
print(a,b,c)

Buggy submission (verdict: Runtime Error):
a,b,c=input().split(' ')
if b=='+':
    print(int(a)+int(c))
else:
    print(int(a)-int(c))
Problem p02933 (python)

Fixed submission:
num = int(input())
string = input()

if num>=3200:
  print(string)
else:
  print("red")

Buggy submission (verdict: Runtime Error):
num = int(input())
string = input()

if num>=3200:
  print(string):
else:
  print("red")
Problem p03011 (python)

Fixed submission:
lst = list(map(int,input().split()))
lst.sort()
print(lst[0]+lst[1])

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

def fib(n):
    return ((1+sqrt(5))**(n+1)  -  (1-sqrt(5))**(n+1)) // (2**(n+1)*sqrt(5))


def how_many_ways(lst_of_broken_steps,goal):

    for i in range(len(lst_of_broken_steps)-1):#連続しているbrokenステップがあった時
        if lst_of_broken_steps[i]+1==lst_of_broken_steps[i+1]:
            return 0
    
    #1回目のbrokenステップの処理
    ans = fib(lst_of_broken_steps[0]-1)
    ans = ans % 1000000007

    for i in range(1,len(lst_of_broken_steps)):#2回目以降のbrokenステップの処理
        ans *= fib((lst_of_broken_steps[i]-1)-(lst_of_broken_steps[i-1]+1))
        ans = ans%1000000007
    

    #最後のbrokenステップの処理の後からゴールまで
    ans *= fib(goal-(lst_of_broken_steps[-1]+1))

    return ans % 1000000007



goal,n = map(int,input().split())
lst_of_broken_steps = []
for i in range(n):
    lst_of_broken_steps.append(int(input()))

print(int(how_many_ways(lst_of_broken_steps,goal)))
Problem p02659 (python)

Fixed submission:
import heapq
from sys import stdin
from decimal import *
input = stdin.readline

#入力
# s = input()[0:-1]
# n = int(input())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]
# n = int(input())
# a,b = map(float, input().split())
# ab=[]
# for i in range():
#     a,b = map(int, input().split())
#     ab.append([a,b])


     
def main():
    a,b = map(Decimal, input().split())

    print(int(a*b//1))
if __name__ == '__main__':
    main()

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

#入力
# s = input()[0:-1]
# n = int(input())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]
# n = int(input())
a,b = map(float, input().split())
# ab=[]
# for i in range():
#     a,b = map(int, input().split())
#     ab.append([a,b])


     
def main():
    b = int(b*100)
    a= int(a)
    print(a*b//100)
if __name__ == '__main__':
    main()
Problem p02790 (python)

Fixed submission:
a,b= map(str, input().split())
ab = a*int(b)
ba = b*int(a)
if ab < ba:
    print(ab)
else:
    print(ba)
# p = list(map(int,input().split()))

# count = 0
# val = sum(p[0:k])
# val_lis = [val]
# mx_val = val
# index = 0
# mx_index = 0
# for i,j in enumerate(p[k:]):
#     val = val - p[index] + j
#     val_lis.append(val)
#     index +=1
#     if val > mx_val:
#         mx_index = index
#         mx_val = val 
    
# ans = 0
# for i in range(k):
#     ans += ((p[mx_index + i]+1.0)*(p[mx_index+i]))/ (p[mx_index+i] *2.0)
# print(ans)  




# h = sorted(h,reverse = True)
# print(sum(h[k:]))

# s,t= map(str, input().split())
# a,b= map(int, input().split())
# u = input()
# print("x"*len(u))

# if(u == s):
#     print(a-1,b)
# else:
#     print(a,b-1)

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

if a < b:
    print(a)
else:
    print(b)
# p = list(map(int,input().split()))

# count = 0
# val = sum(p[0:k])
# val_lis = [val]
# mx_val = val
# index = 0
# mx_index = 0
# for i,j in enumerate(p[k:]):
#     val = val - p[index] + j
#     val_lis.append(val)
#     index +=1
#     if val > mx_val:
#         mx_index = index
#         mx_val = val 
    
# ans = 0
# for i in range(k):
#     ans += ((p[mx_index + i]+1.0)*(p[mx_index+i]))/ (p[mx_index+i] *2.0)
# print(ans)  




# h = sorted(h,reverse = True)
# print(sum(h[k:]))

# s,t= map(str, input().split())
# a,b= map(int, input().split())
# u = input()
# print("x"*len(u))

# if(u == s):
#     print(a-1,b)
# else:
#     print(a,b-1)
Problem p02860 (python)

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

if n % 2 != 0 :
    print("No")
else:
    mae = s[0:int(n/2)]
    usi = s[int(n/2):]
    if mae == usi :
        print("Yes")
    else:
        print("No")

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

if n % 2 != 0 :
    print("No")
else:
    mae = s[0:int(n/2)]
    usi = s[int(n/2):]
    if mae == usi :
        print("Yes")
    else:
        print("No")
Problem p03011 (python)

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

mn = 200
for i in range(2):
    for j in range(i+1,3):
        if (p[i]+p[j] < mn):
            mn = p[i]+p[j]

print(mn)

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

mn = 200
for i in p[:-2]:
    for j in p[i+1:]
    if (i+j < mn):
        mn = i+j

print(mn)
Problem p03013 (python)

Fixed submission:
n,m = map(int, input().split())
a = set([int(input()) for _ in range(m)])

mod = 10**9+7
dp = [0]*(n+1)
dp[0]=1
if 1 not in a:
    dp[1]=1
for i in range(2,n+1):
    if i in a :
        continue
    else:
        dp[i]= dp[i-1] + dp[i-2]
        dp[i]%= mod


print(dp[n])

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
a = [int(input()) for _ in range(m)]

large = 10**9 +7
count = [0]*(n+1)
itr = 0
count[0] = 1
if a[0] != 1 :
    count[1] = 1
else:
    count[1] = 0
    itr = 1

for i in range(2,n+1):
    if itr<len(a) and a[itr] == i:
        itr +=1
        continue
    else:
        count[i] = (count[i-1] + count[i-2])%large

print(count[n])
Problem p03038 (python)

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

bc = []

for i in range(m):
    b,c=map(int,input().split())
    bc.append([b,c])

bc = sorted(bc, key=lambda x: x[1],reverse=True)
a = sorted(a)

itr = 0 
for i in bc:
    b, c = i[0], i[1]
    for j in range(b):
        if a[itr]>=c:
            print(sum(a))
            exit()
        else:
            a[itr]=c
            itr +=1
            if itr == n:
                print(sum(a))
                exit()
print(sum(a))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n,m= map(int, input().split())
a = list(map(int, input().split()))
d = []
for i in range(m):
    b,c = map(int, input().split())
    d.append([b,c])
d = sorted(d, key=lambda x:x[1], reverse=True)
a = sorted(a)
itr = 0
for i in range(len(d)):
    change = d[i]

    for j in range(change[0]):
        if a[itr] > change[1]:
            print(sum(a))
            exit()
        else:
            a[itr] = change[1]
        itr+=1
        if itr == n:
            break
print(sum(a))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n,m= map(int, input().split())
a = list(map(int, input().split()))
d = []
for i in range(m):
    b,c = map(int, input().split())
    d.append([b,c])
d = sorted(d, key=lambda x:x[1], reverse=True)
a = sorted(a)
itr = 0
for i in range(len(d)):
    change = d[i]

    for j in range(change[0]):
        if a[itr] > change[1]:
            print(sum(a))
            exit()
        else:
            a[itr] = change[1]
        itr+=1
print(sum(a))

Buggy submission (verdict: Runtime Error):
n,m= map(int, input().split())
a = list(map(int, input().split()))
d = []
for i in range(m):
    b,c = map(int, input().split())
    d.extend([c]*b)
d = sorted(d,reverse=True)
k = max(len(d),n)
d = d[0:k]

a = sorted(a)

for i in range(n):
    if i >=k-1:
        break 
    if a[i] > d[i]:
        break
    else:
        a[i] = d[i]

print(sum(a))
Problem p02659 (python)

Fixed submission:
a,b = input().split()
a = int(a)
b = int(b.replace('.',''))
print(a*b//100)

Buggy submission (verdict: Runtime Error):
a,b = input().split()
a = int(a)
b = int(b.replace('.','')
print(a*b//100)
Problem p02735 (python)

Fixed submission:
from collections import deque
H,W = map(int,input().split())
s = []
for i in range(H):
    s.append(list(input()))

que = deque()
alr = [[float('inf') for i in range(W)] for j in range(H)]
if s[0][0] == '.':
    alr[0][0] = 0
else:
    alr[0][0] = 1
que.append((0,0))
while que:
    h,w = que.popleft()
    if s[h][w] == '#':
        flag = True
    else:
        flag = False

    if h < H-1:
        if s[h+1][w] == '.':
            if alr[h+1][w] > alr[h][w]:
                alr[h+1][w] = alr[h][w]
                que.append((h+1,w))
        else:
            if flag:
                if alr[h+1][w] > alr[h][w]:
                    alr[h+1][w] = alr[h][w]
                    que.append((h+1,w))
            else:
                if alr[h+1][w] > alr[h][w]+1:
                    alr[h+1][w] =alr[h][w]+1
                    que.append((h+1,w))            
    if w < W-1:
        if s[h][w+1] == '.':
            if alr[h][w+1] > alr[h][w]:
                alr[h][w+1] =alr[h][w]
                que.append((h,w+1))
        else:
            if flag:
                if alr[h][w+1] > alr[h][w]:
                    alr[h][w+1] =alr[h][w]
                    que.append((h,w+1))
            else:
                if alr[h][w+1] > alr[h][w]+1:
                    que.append((h,w+1))
                    alr[h][w+1] = alr[h][w] + 1
print(alr[-1][-1])

Buggy submission (verdict: Runtime Error):
5 5
.#.#.
#.#.#
.#.#.
#.#.#
.#.#.
Problem p02834 (python)

Fixed submission:
from collections import deque
N,ppl,oni = map(int,input().split())
ppl -= 1
oni -= 1
AB = [ []for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    AB[a-1].append(b-1)
    AB[b-1].append(a-1)

def dfs(start):
    dist = [-1 for i in range(N)]
    dist[start] = 0
    que = deque()
    que.append(start)
    while que:
        q = que.popleft()
        for nextr in AB[q]:
            if dist[nextr] == -1:
                dist[nextr] = dist[q] +1
                que.append(nextr)
    return dist
    
if len(AB[ppl]) == 1 and oni in AB[ppl]:
    print(0)
else:
    ppldist = dfs(ppl)
    onidist = dfs(oni)
    maxa = max(onidist)
    ans = 0
    for i in range(N):
        if ppldist[i] < onidist[i]:
            ans = max(ans,onidist[i]-1)
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
N,ppl,oni = map(int,input().split())
ppl -= 1
oni -= 1
AB = [ []for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    AB[a-1].append(b-1)
    AB[b-1].append(a-1)

def dfs(start):
    dist = [-1 for i in range(N)]
    dist[start] = 0
    que = deque()
    que.append(start)
    while que:
        q = que.popleft()
        for nextr in AB[q]:
            if dist[nextr] == -1:
                dist[nextr] = dist[q] +1
                que.append(nextr)
    return dist
    
if len(AB[ppl]) == 1 and oni in AB[ppl]:
    print(0)
else:
    ppldist = dfs(ppl)
    onidist = dfs(oni)
    maxa = max(onidist)
    for i in range(max(onidist),-1,-1):
        for j in [k for k in range(len(onidist)) if onidist[k] == maxa]:
            if maxa >= ppldist[j]:
                if maxa&ppldist[j] == 1:
                    ans = maxa
                else:
                    ans = maxa-1
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
N,ppl,oni = map(int,input().split())
ppl -= 1
oni -= 1
AB = [ []for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    AB[a-1].append(b-1)
    AB[b-1].append(a-1)

def dfs(start):
    dist = [-1 for i in range(N)]
    dist[start] = 0
    que = deque()
    que.append(start)
    while que:
        q = que.popleft()
        for nextr in AB[q]:
            if dist[nextr] == -1:
                dist[nextr] = dist[q] +1
                que.append(nextr)
    return dist
    
if len(AB[ppl]) == 1 and oni in AB[ppl]:
    print(0)
else:
    ppldist = dfs(ppl)
    onidist = dfs(oni)
    maxa = max(onidist)
    for i in range(max(onidist),-1,-1):
        for j in [k for k in range(len(onidist)) if onidist[k] == maxa]:
            if maxa >= ppldist[j]:
                if maxa&ppldist[j] == 1:
                    ans = maxa
                else:
                    ans = maxa-1
    print(ans)
Problem p02873 (python)

Fixed submission:
S = input()
snum = len(S)
N = snum +1
Nar = [0 for i in range(N)]

for i in range(snum):
    if S[i] == '<':
        Nar[i+1] = Nar[i] + 1

for i in reversed(range(N-1)):
    if S[i] == '>':
        Nar[i] = max(Nar[i],Nar[i+1]+1)
sum = 0
for i in Nar:
    sum += i
print(sum)

Buggy submission (verdict: Runtime Error):
S = input()
ans = 0
a = []
up = True
count = 0
for i in S:
    if up:
        if i == '>':
            a.append(count)
            count = 1
            up = False
        else:
            count += 1
    else:
        if i == '<':
            a.append(count)
            count = 1
            up = True
        else:
            count += 1
a.append(count)
a.append(0)
for i in range(0,len(a),2):
    u,d = max(a[i],a[i+1]), min(a[i],a[i+1])-1
    ans += u*(u+1)//2 + d*(d+1)//2
print(ans)
Problem p02891 (python)

Fixed submission:
from collections import Counter
s = input()
N = len(s)
K = int(input())
if s[0] != s[-1]:
    count = 1
    ans = 0
    now = s[0]
    for i in range(1,len(s)):
        if now == s[i]:
            count += 1
        else:
            now = s[i]
            ans += count//2
            count = 1
    if count != 1:
        ans += count//2
    print(ans*K)
elif len(Counter(s).values()) == 1:
    print(K*len(s)//2)
else:
    ans = 0
    fcount = 1
    bcount = 1
    now = s[0]
    start = N
    for i in range(1,N):
        if s[i] == now:
            fcount += 1
        else:
            start = i
            break
    now = s[-1]
    end= 0
    for i in range(N-2,-1,-1):
        if s[i] == now:
            bcount += 1
        else:
            end = i
            break   
    ans = fcount//2 + bcount//2 + ((fcount+bcount)//2)*(K-1)
    now = s[start]
    count = 1
    mcount = 0
    for i in range(start+1,end+1):
        if s[i] == now:
            count += 1
        else:
            mcount += count//2
            count = 1
            now = s[i]
    if count != 1:
        mcount += count//2
    print(ans + mcount*K)

Buggy submission (verdict: Runtime Error):
S = list(input())
K = int(input())
count = 0
if S[0] != S[-1]:
    flag = False
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = 1
            count += 1
    print(K*count)
else:
    if len(S) == 2:
        print(K)
    else:
        if S[0] == S[1] and S[-1] != S[-2]:
            S[0] = 1
            count += 1
        elif S[0] != S[1] and S[-1] == S[-2]:
            S[-1] = 1
            count += 1
        elif S[0] == S[1] and S[-1] == S[-2]:
            S[0] = 1
            count += 1
        elif S[0] != S[1] and S[-1] != S[-2]:
            S[0] = 1
            count += 1
        
        
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = 1
                count += 1
        print(K*count)

Buggy submission (verdict: Runtime Error):
S = list(input())
K = int(input())
count = 0
if S[0] != S[-1]:
    flag = False
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = 1
            count += 1
    print(K*count)
else:
    if len(S) == 2:
        print(K)
    else:
        if S[0] == S[1]:
            S[0] = 1
            count += 1
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = 1
                count += 1
        print(K*count)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
count = 0
if S[0] != S[-1]:
    flag = False
    for i in range(len(S)-1):
        if not flag and S[i] == S[i+1]:
            count += 1
            flag = True
        if flag:
            flag = False
    print(K*count)
else:
    if len(S) == 2:
        print(K)
    else:
        if S[-1] == S[-2]:
            S = S[:-1]+'X'
            count = 1
        flag = False
        for i in range(len(S)-1):
            if not flag and S[i] == S[i+1]:
                count += 1
                flag = True
            if flag:
                flag = False
        print(K*count)
Problem p02912 (python)

Fixed submission:
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)
while M > 0:
    A[0] //= 2
    for i in range(1,M):
        if i < N and A[i] >= A[0]:
            A[i] //= 2
        else:
            M -= i
            A.sort(reverse = True)
            break
    else:
        break
print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)
while M > 0:
    A[0] //= 2
    for i in range(1,M):
        if A[i] >= A[0]:
            A[i] //= 2
        else:
            M -= i
            A.sort(reverse = True)
            break
    else:
        break
print(sum(A))
Problem p02948 (python)

Fixed submission:
import heapq
from collections import defaultdict
N,M = map(int,input().split())
AB = defaultdict(list)
for i in range(N):
    a,b = list(map(int,input().split()))
    if a not in AB:
        AB[a] = [-b]
    else:
        AB[a] += [-b]
work = 0
AB2 = []
heapq.heapify(AB2)
for i in range(1,M+1):
    for j in AB[i]:
        heapq.heappush(AB2,j)
    if not AB2:
        continue
    b = heapq.heappop(AB2)
    work += -b
print(work)

Buggy submission (verdict: Runtime Error):
import heapq
N,M = map(int,input().split())
AB = [[] for i in range(M+1)]
for i in range(N):
    a,b = list(map(int,input().split()))
    AB[a].append(-b)
work = 0
AB2 = []
for i in range(1,M+1):
    AB2 += AB[i]
    heapq.heapify(AB2)
    if not AB2:
        continue
    b = heapq.heappop(AB2)
    work += -b
print(work)
Problem p02951 (python)

Fixed submission:
A,B,C = map(int,input().split())
if C-(A-B) >= 0:
  print(C-(A-B))
else:
  print(0)

Buggy submission (verdict: Runtime Error):
A,B,C = map(int,input())
print(C-(A-B))
Problem p02987 (python)

Fixed submission:
import collections
S = input()
S2 = collections.Counter(S)
c = True
for i,v in S2.items():
  if v == 2:
    continue
  else:
    c = False
if c:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
import collections
S = input()
S2 = collections.counter(S)
c = True
for i,v in S2.items():
  if v == 2:
    continue
  else:
    c = False
if c:
  print('Yes')
else:
  print('No')
Problem p03013 (python)

Fixed submission:
N,M = map(int,input().split())
array = [0 for i in range(N+1)]
c = 0
for i in range(M):
    a = int(input())
    if array[a-1] == 0:
        array[a] = 1
    else:
        c = 1
        break
if c == 1:
    print(0)
else:
    dp = [0 for i in range(N+1)]
    dp[0] = 1
    for i in range(N-1):
        if array[i+1] == 0:
            dp[i+1] += dp[i]%(10**9+7)
        if array[i+2] == 0:
            dp[i+2] += dp[i]%(10**9+7)
    if array[N-1] == 0:
        dp[N] += dp[N-1]%(10**9+7)
    print(dp[-1]%(10**9+7))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
array = []
c = 0
for i in range(M):
    a = int(input())
    if a-1 not in array:
        array.append(a)
    else:
        c = 1
        break
if c == 1:
    print(0)
else:
    dp = [0 for i in range(N+1)]
    dp[0] = 1
    for i in range(N-1):
        if i+1 not in array:
            dp[i+1] += dp[i]%(10**9+7)
        if i+2 not in array:
            dp[i+2] += dp[i]%(10**9+7)
if N-1 not in array:
    dp[N] += dp[N-1]%(10**9+7)
print(dp[-1]%(10**9+7))
Problem p03041 (python)

Fixed submission:
N,K = map(int,input().split())
S = input()
S[K-1].lower()
print(S[:K-1]+ S[K-1].lower() + S[K:])

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()
S[K-1] = S[K-1].lower()
print(S)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()
S[K-1] = S[K-1].upper()
print(S)
Problem p03329 (python)

Fixed submission:
N = int(input())
dp = [float('inf') for i in range(N+1)]
dp[0] = 0
if N >= 6:
    dp[6] = 1
def below_power(n,a):
    "n以下になるa**xのxの最大値を求める"
    x = 0
    while n >= a**x:
        x += 1
    return x-1
nine = below_power(N,9)
six = below_power(N,6)
for i in range(six,0,-1):
    for j in range(N+1):
        if j - 6**i >= 0:
            dp[j] = min(dp[j],dp[j-6**i]+1)
for i in range(nine,0,-1):
    for j in range(N+1):
        if j - 9**i >= 0:
            dp[j] = min(dp[j],dp[j-9**i]+1)       
ans = dp[N]
for i in range(1,min(N+1,6)):
    ans = min(ans,dp[N-i]+i)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
dp = [[float('inf') for i in range(N+1)] for j in range(4)]
dp[0][0] = 0
dp[3] = [i for i in range(N+1)]
def below_power(n,a):
    "n以下になるa**xのxの最大値を求める"
    x = 0
    while n >= a**x:
        x += 1
    return x-1
nine = below_power(N,9)
six = below_power(N,6)
for i in range(nine,0,-1):
    dp[1][9**i] = 1
    x= (9**i)
    for j in range(x,N+1):
        dp[1][j] = min(dp[1][j],dp[1][j-x]+1)
for i in range(1,six+1):
    dp[2][6**i] = 1
    x= (6**i)
    for j in range(N+1):
        if j >= 9:
            dp[2][j] = min(dp[2][j],dp[2][j-x]+1)
        if j >= x:
            dp[2][j] = min(dp[2][j],dp[1][j-x]+1)
for i in range(1,6):
    dp[3][-1] = min(dp[3][-1],dp[2][N-i]+i)
print(dp[-1][-1])
Problem p02682 (python)

Fixed submission:
A,B, C,K=map(int,input().split())
if K<= A:
    print(K)
elif K<=A+B:
    print(A)
else:
    print(2*A+B-K)

Buggy submission (verdict: Runtime Error):
A,B, C,K=map(int,input().split())
if K<= A:
    prin(K)
elif K<=A+B:
    print(A)
else:
    print(2*A+B-K)