TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
n = input()
a = 0 
b = 1 
for s in n:
    x = int(s)
    
    a = min(a + x, b + 10 - x)
    b = min(a + x + 1, b + 9 - x)
    
print(a)    


s = input()
cnt = 0
sakki5 = False
for s in a:
    if int(s) < 6:
        cnt += int(s)
        sakki6 = False
        if int(s) == 5:
            sakki5 = True
    else:
        cnt += 11 - int(s)
        if sakki6:
            cnt -= 2
        if sakki5:
            cnt -= 1
        sakki6 = True
        sakki5 = False
cnt

s = input()
state = [0, 1]
for i in s:
    n = int(i)
    state_new = [min(state[0] + n, state[1] + 10 - n), 
                 min(state[0] + n + 1, state[1] + 9 - n)]
    state = state_new
print(state[0])

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
N = list(input())
Y = [0]
for i in N:
    Y.append(int(i))
dp = [0 for i in range(len(N)+1)]
dp2 = [10 for i in range(len(N)+1)]
for i in range(1,len(N)+1):
    dp[i] = min(dp[i-1] + Y[i],dp2[i-1] + Y[i])
    dp2[i] = min(dp[i-1] + 1 + 10 - Y[i],dp2[i-1] - 1 + 10 - Y[i])
    print(str(dp[i])+":" +str(dp2[i]))
ans = min(dp[-1],dp2[-1])
#print(dp,dp2)
print(ans)

s = input()
sr = s.reverse()
count = 0
for i in range(len(sr)-1):
    if sr[i]>=5:
        count += 10-sr[i]
        sr[i+1] += 1
    else:
        count += sr[i]
if sr[len(sr)-1] >=5:
    count += 1
    count += 10- sr[len(sr)-1]
else:
    count += sr[len(sr)-1]
print(count)

N = list(input())
Y = [0]
for i in N:
    Y.append(int(i))
dp = [0 for i in range(len(N)+1)]
dp2 = [10 for i in range(len(N)+1)]
for i in range(1,len(N)+1):
    dp[i] = min(dp[i-1] + Y[i],dp2[i-1] + Y[i])
    dp2[i] = min(dp[i-1] + 1 + 10 - Y[i],dp2[i-1] - 1 + 10 - Y[i])
    #print(str(dp[i])+":" +str(dp2[i]))
ans = min(dp[-1],dp2[-1])
#print(dp,dp2)
print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
N = "0" + input()

returnDP = [0]*(len(N)+1)
payDP = [0]*(len(N)+1)
j = 1
keta = 0
for i in N[::-1]:
    i = int(i) + keta
    if i == 10:
        returnDP[j] = returnDP[j-1]
        payDP[j] = payDP[j-1]
        keta = 1
    elif i > 5:
        payDP[j] = payDP[j-1]
        returnDP[j] = returnDP[j-1] + 10 - i
        keta = 1
    else:
        payDP[j] = payDP[j-1] + i
        returnDP[j] = returnDP[j-1]
        keta = 0
    j += 1
print(payDP)
print(returnDP)
print(payDP[-1] + returnDP[-1])

N = input()[::-1]
l = len(N)
dp = [[0,0] for i in range(l+1)]

for i in range(l):
    dp[i+1][0] = min(dp[i][0] + int(N[i]), dp[i][1] + int(N[i]) + 1)
    if i == 0:
        dp[i+1][1] = 10 - int(N[i])
    else:
        dp[i+1][1] = min(dp[i][0] + 10 - int(N[i]), dp[i][1] + 9 - int(N[i]))

print(min(dp[-1][0],dp[-1][1]+1))


Verdicts: Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
S=input()
paynum=0
payout=0
change=0
changenum=0
num=0

array = list(map(int, S))
array.reverse()
print(array)
for i in array:  
    if i <= 5 :
        paynum = paynum + i
        payout = payout + i *( 10 ** num)
    else:
        if num+1 <len(S):
            array[num+1] = array[num+1]+1
        else:
            paynum = paynum + 1
            payout = payout + 1*(10**(num+1))
    num= num+1


change = payout - N
tmp= str(change)
array2 = list(map(int, tmp))
changenum= sum(array2)
print( changenum + paynum)




S=input()[::-1]
ans=0

array = list(map(int, S))
L=len(array)
for i,n in enumerate(array):
    if n<= 5 :
        ans+=n
    elif n > 5:
        ans+= 10-n
        if i <L-1:
            array[i+1] +=1
        else:
            ans +=1
    else:
        ans+=5
        if < L-1:
            if array[i+1] >=5:
                array[i+1] +=1
                
print( ans)


N=int(input())
paynum=0
payout=0
change=0
changenum=0

for i in range(0,1001)[::-1]:
    if N >= 10**i :
        paynum = N//10**i+1
        payout = paynum *(10**i)
        break
    else:
        continue


change = payout - N
tmp= change
print(tmp)

for i in range(0,1000)[::-1]:
    if tmp >= 10**i :
        changenum = changenum + tmp//(10**i)
    else:
        continue

print(paynum + changenum)


    



    

S=input()[::-1]
ans=0

array = list(map(int, S))
L=len(array)
for i,n in enumerate(array):
    if n< 5 :
        ans+=n
    elif n > 5:
        ans+= 10-n
        if i <L-1:
            array[i+1] +=1
        else:
            ans +=1
    else:
        ans+=5
        if i < L-1:
            if array[i+1] >=5:
                array[i+1] +=1
                
print( ans)


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
from itertools import combinations
n, k = map(int, input().split())
*A, = map(int, input().split())
print(sorted(x*y for x, y in combinations(A, 2))[k])   

N = map(int, input()[::-1])
a, b = 0, 9
for n in N:
    a, b = min(n+a, n+b), min(11-n+a, 9-n+b)
print(min(a, b))

Verdicts: Runtime Error

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
if __name__ == "__main__":
    n = '0' + input()

    ans = 0
    flag = 0

    for i in range(len(n)-1, 0, -1):
        if int(n[i]) + flag == 10:
            flag = 1
        elif int(n[i]) + flag > 5 or (int(n[i]) + flag == 5 and int(n[i-1]) > 4):
            ans += 10 - int(n[i]) - flag
            flag = 1
        else:
            ans += int(n[i]) + flag
            flag = 0
        print(str(n[i]) + ' ' + str(n[i-1]) + ' ' + str(ans))

    if flag == 1:
        ans += 1

    print(ans)


if __name__ == "__main__":
    n = '0' + input()

    ans = 0
    flag = 0

    for i in range(len(n)-1, 0, -1):
        if int(n[i]) + flag == 10:
            flag = 1
        elif int(n[i]) + flag > 5 or (int(n[i]) + flag == 5 and int(n[i-1]) > 4):
            ans += 10 - int(n[i]) - flag
            flag = 1
        else:
            ans += int(n[i]) + flag
            flag = 0

    if flag == 1:
        ans += 1

    print(ans)


Verdicts: Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
import sys
input = sys.stdin.buffer.readline
S = input()
ans = 0
for s in S:
    i = int(s)
    ans += min(i, 10-i)
if S[0] == '9' or int(S[1]) >= 6:
    ans += 1
print(ans)


S = input()
dp = [0, 1]
for s in S:
    i = int(s)
    a = min(dp[0] + i,   dp[1] + 10 - i)
    b = min(dp[0] + i+1, dp[1] + 10 - (i+1))
    dp = [a, b]
    # print(dp)
print(dp[0])

Verdicts: Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
n = list(map(int,input()))[::-1]
n.append(0)
for i in range(len(n)):
	if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):
    	n[i] = 10 - n[i]
        n[i+1] += 1
print(sum(n))

n = list(map(int,input()))[::-1]
n.append(0)
for i in range(len(n)):
    if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):
        n[i] = 10 - n[i]
        n[i+1] += 1
print(sum(n))


Verdicts: Runtime Error

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
N = list(input())
ans = 0
temp = [0] + [int(n) for n in N]
for i in reversed(range(1, len(N)+1)):
    if temp[i] < 5 or (temp[i] == 5 and temp[i+1] < 4):
        ans += temp[i]
    else:
        temp[i+1] += 1
        ans += (10 - temp[i])
        temp[i] = 0
ans += temp[0]
print(ans)

N = list(input())
ans = 0
temp = [0] + [int(n) for n in N]
for i in reversed(range(1, len(N)+1)):
    if temp[i] < 5 or (temp[i] == 5 and temp[i-1] < 5):
        ans += temp[i]
    else:
        temp[i-1] += 1
        ans += (10 - temp[i])
        temp[i] = 0
ans += temp[0]
print(ans)

Verdicts: Runtime Error

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
import sys

n=sys.stdin.readline().rstrip()[::-1]
to=0
num=len(n)
m=0
print(n)

for i in range(num):
    k=int(n[i])
    k+=m
    if k==5:
        if int(n[i+1])>=5:
            to+=10-k
            m=1
        else:
            to+=k
            m=0
    if k<5:
        to+=k
        m=0
    elif k>5:
        to+=10-k
        m=1
        if i==num-1:
            to+=1
        
print(to)


import sys

n=sys.stdin.readline().rstrip()[::-1]
to=0

m=0
n+="0"
num=len(n)

for i in range(num):
    k=int(n[i])
    k+=m
    if k==5:
        if int(n[i+1])>=5:
            to+=10-k
            m=1
        else:
            to+=k
            m=0
    if k<5:
        to+=k
        m=0
    elif k>5:
        to+=10-k
        m=1
        
print(to+m)


Verdicts: Runtime Error

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
N_str = input()

ln = len(N_str)
ans = 0
table = [[0] * 2 for _ in range(ln)]
table[0] = [int(N_str[-1]), 11 - int(N_str[-1])]
for i in range(1, ln):
    table[i] = [int(N_str[-i]) + min(table[i - 1]),
                min(int(N_str[-i]) + table[i - 1][0], 10 - int(N_str[-i]) + table[i - 1][1])]
print(min(table[ln - 1]))


N_str = input()

ln = len(N_str)
ans = 0
no_mu, move_up = int(N_str[-1]), 11 - int(N_str[-1])
for i in range(2, ln + 1):
    n = int(N_str[-i])
    no_mu, move_up = n + min(no_mu, move_up), min(11 - n + no_mu, 9 - n + move_up)
print(min(no_mu, move_up))


Verdicts: Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
import sys
input = sys.stdin.readline


N = [0] + list(map(int, tuple(input().rstrip("\n"))))


Ncopy = N.copy()
ans = 0

flag = False
for i in range(len(N)-1, 0, -1):
    if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i-1] <= 4):
        ans += Ncopy[i]
        flag = False
    else:
        Ncopy[i-1] += 1
        
        if not flag:
            ans += 10 - N[i]
        else:
            ans += 9 - N[i]
        Ncopy[i] = 0
        flag = True
print(Ncopy)
if Ncopy[0] == 1:
    ans += 1

print(ans)

#!/usr/bin/env python3
import sys
input = sys.stdin.readline

def main():
    N = [0] + list(map(int, tuple(input().rstrip("\n"))))
    Ncopy = N.copy()
    ans = 0

    flag = False
    for i in range(len(N)-1, 0, -1):
        if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i-1] <= 4):
            ans += Ncopy[i]
            flag = False
        else:
            Ncopy[i-1] += 1
            if not flag:
                ans += 10 - N[i]
            else:
                ans += 9 - N[i]
            Ncopy[i] = 0
            flag = True

    if Ncopy[0] == 1:
        ans += 1

    print(ans)

if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
def main():
  n=list(input())
  n=[int(i) for i in reversed(n)]
  l=len(n)
  n.append(0)
  print(n)
  
  ans=0
  for i in range(l):
    if n[i]<=5:
      a=n[i]
    else:
      n[i+1]+=1
      a=10-n[i]
    print(a)
    ans+=a
  ans+=n[l]
  print(ans)  
if __name__=='__main__':
    main()


def main():
  import numpy as np
  n=list(input())
  n=[int(i) for i in n]
  l=len(n)
  
  dp=np.zeros((l+1,2),dtype=np.int64)   
  for i in range(l):
      dp[i+1][:1]=np.minimum(dp[i][:1]+n[i],dp[i][:1]+10-n[i])
      dp[i+1][1:]=np.minimum(dp[i][1:]+n[i]+1,dp[i][1:]+9-n[i])
  #print(dp)
  print(dp[l,0])

if __name__=='__main__':
    main()

def main():
  n=list(input())
  n=[int(i) for i in reversed(n)]
  l=len(n)
  n.append(0)
  
  ans=0
  for i in range(l):
    if n[i]<=4:
      a=n[i]
    elif n[i]==5:
      if n[i+1]<=4:
        a=n[i]
      else:
        a=10-n[i]
        n[i+1]+=1
    else:
      n[i+1]+=1
      a=10-n[i]
    ans+=a
  ans+=n[l]
  print(ans)  
if __name__=='__main__':
    main()


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
class Solution:

    def solve(self, N: str) -> int:

        L = len(N)
        D = []
        for l in range(L-1, -1, -1):
            D.append(int(N[l]))

        D.append(0)

        ans = 0
        for l in range(L+1):

            # carry over
            if D[l] == 10:
                D[l+1] += 1
                D[l] = 0

            if D[l] <= 5:
                ans += D[l]
            else:
                ans += 10-D[l]
                D[l+1] += 1

            print(D[l], ans)

        return ans


if __name__ == '__main__':

    # standard input
    N = input()

    # solve
    solution = Solution()
    print(solution.solve(N))


class Solution:

    def solve(self, N: str) -> int:

        L = len(N)
        D = []
        for l in range(L-1, -1, -1):
            D.append(int(N[l]))

        D.append(0)

        ans = 0
        for l in range(L+1):

            # carry over
            if D[l] == 10:
                D[l+1] += 1
                D[l] = 0

            if D[l] < 5:
                ans += D[l]
            elif D[l] == 5:
                if D[l+1] >= 5:
                    D[l+1] += 1
                ans += 5
            else:
                ans += 10-D[l]
                D[l+1] += 1

#            print(D[l], ans)

        return ans


if __name__ == '__main__':

    # standard input
    N = input()

    # solve
    solution = Solution()
    print(solution.solve(N))


Verdicts: Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
n = list(map(int, list(input())))
ans = 0
c_in = 0
q = 0


def carry(x, i, q):
    if x[i] <= 8:
        x[i] += 1
    else:
        x[i] = 0
        if x[i] == x[0]:
            x[i] = 0
            q += 1
        else:
            carry(x, i-1, q)


while len(n) > 0:
    s = n.pop()
    if 0 <= s <= 5:
        ans += s
        if c_in:
            c_in = 0
    elif 6 <= s <= 9:
        ans += 10 - s
        c_in = 1
        carry(n, -1, q)
    print(s, ans)

ans += q
print(ans)



n = [0] + list(map(int, list(input())))
ans = 0
c_in = 0

while n:
    s = n.pop()
    s += c_in
    if 0 <= s <= 4:
        ans += s
        c_in = 0
    elif 6 <= s:
        ans += abs(10 - s)
        c_in = 1
    else:
        ans += 5
        if 5 <= n[-1]:
            c_in = 1
        else:
            c_in = 0

print(ans)


Verdicts: Runtime Error

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
n = str(input().rstrip())

def solve1(n):
    ans = 0

    a = list(map(int, list(n)))
    a = a[::-1]
    a.append(0)
    for i in range(len(a) - 1):
        c = a[i]
        if c < 5:
            ans += c
        else:
            if c == 5 and a[i+1] < 5:
                ans += 5
            else:
                a[i+1] += 1
                ans += 10 - c
    ans += n_list[-1]

    print(ans)

def solve2(n):
    INF = 10**9
    n = n[::-1]
    n += '0'
    n_len = len(n)
    dp = [INF for _ in range(2)]
    dp[0] = 0

    for i in range(n_len):
        pre_dp = [INF, INF]
        for i in range(2):
            pre_dp[i] = dp[i]
        dp = [INF, INF]
        for j in range(2):
            x = int(n[i])
            x += j
            if x < 10:
                dp[0] = min(dp[0], pre_dp[j]+x)
            if x > 0:
                dp[1] = min(dp[1], pre_dp[j]+(10-x))
    print(dp[0])

solve2(n)

n = str(input().rstrip())

ans = 0

a = list(map(int, list(n)))
a = a[::-1]
a.append(0)
for i in range(len(a) - 1):
    c = a[i]
    if c < 5:
        ans += c
    else:
        if c == 5 and a[i+1] < 5:
            ans += 5
        else:
            a[i+1] += 1
            ans += 10 - c
ans += a[-1]

print(ans)



Verdicts: Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
tmp=input()
n=int(tmp)
l=len(tmp)
rev=tmp[::-1]
pay_rev=""
next_bit=0
for i in range(l):
    val=int(rev[i])+next_bit
    if val>5:
        val=0
        next_bit=1
    else:
        next_bit=0
    pay_rev+=str(val)
if pay_rev[-1]=="0":
    pay_rev+="1"
pay=pay_rev[::-1]

print(pay)
zankin=int(pay)-n
print(zankin)
ans=0
for i in pay:
    ans+=int(i)
for i in str(zankin):
    ans+=int(i)

print(ans)


tmp="9"*(10**6)
#tmp=input()
#tmp="78164062862089986280348253421170"
#tmp="314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170"
#tmp="846"
#tmp="253421170"
l=len(tmp)
#print(l)
rev=tmp[::-1]+"0"
seq_flag=False
ans=0
debug=[]
ans_arr=[]
next_bit=0
for i in range(l-1):
    num=int(rev[i])+next_bit
    next_num=int(rev[i+1])
    if not seq_flag:
        if (num<5) or (num==5 and next_num<5):
            ans+=num
            ans_arr.append(ans)
            next_bit=0
            kuri_cal=0
            continue
        seq_s=i
        seq_flag=True
        kuri_cal=10-num
        next_bit+=1
        continue
    
    if num<5:
        ans+=(kuri_cal+num)
        next_bit=0
        seq_flag=False
    elif num>5:
        kuri_cal+=10-num
    else:
        if next_num<5:
            ans+=(kuri_cal+num)
            next_bit=0
            seq_flag=False
        else:
            kuri_cal+=10-num
        

#print(ans)
last=int(tmp[0])+next_bit
#print(last)

ans+=kuri_cal+min(last,11-last)
ans_arr.append(ans)
print(ans)

def y_solver(tmp):
    l=len(tmp)
    rev=[int(i) for i in tmp[::-1]+"0"]
    ans=0
    for i in range(l):
        num=rev[i]
        next_num=rev[i+1]
        if (num>5) or (num==5 and next_num>=5):
            rev[i+1]+=1
        ans+=min(num,10-num)  
    last=rev[l]
    ans+=min(last,10-last)
    return ans
s=input()
ans=y_solver(s)
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
# -*- coding: utf-8 -*-
def solve():
    N = input()[::-1]+'0'
    res = 0
    c = 0
    for i in range(len(N)-1):
        r = int(N[i])+c
        c = r//10
        r %= 10
        r_ = (int(N[i+1])+c)%10
        if r < 5 or (r==5 and r_ < 5):
            res += r
        else:
            res += 10-r
    return str(res)

if __name__ == '__main__':
    print(solve())



# -*- coding: utf-8 -*-
def solve():
    N = input()[::-1]+'00'
    res = 0
    c = 0
    for i in range(len(N)-1):
        print(N[i],c)
        r = int(N[i])+c
        c = r//10
        r %= 10
        r_ = (int(N[i+1])+c)%10
        if r < 5 or (r==5 and r_ < 5):
            res += r
        else:
            res += 10-r
            c += 1
    return str(res)

if __name__ == '__main__':
    print(solve())



# -*- coding: utf-8 -*-
def solve():
    N = input()[::-1]+'00'
    res = 0
    c = 0
    for i in range(len(N)-1):
        r = int(N[i])+c
        c = r//10
        r %= 10
        r_ = (int(N[i+1])+c)%10
        if r < 5 or (r==5 and r_ < 5):
            res += r
        else:
            res += 10-r
            c += 1
    return str(res)

if __name__ == '__main__':
    print(solve())



Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
s = input()[::-1]
size = len(s)
s += "9"

ans = 0
bef = 0

for i in range(size):
    v1 = int(s[i])
    v2 = int(s[i+1])
    if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0

ans += (v+bef)//10
print(ans)

s = input()[::-1]
size = len(s)
s += "4"

ans = 0
bef = 0

for i in range(size):
    v1 = int(s[i])
    v2 = int(s[i+1])
    if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0

ans += bef
print(ans)

Verdicts: Runtime Error

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
N = str(input())
L = len(N)
ans = 0
s = list(N)
for i in range(L):
    n = int(s[i])
    ans += min(n,10-n)

print(ans)


N = str(input())
L = len(N)
ans = 0
dp = [[0,0] for _ in range(L)]
s = list(map(int,N))
dp[0] = [s[0],11-s[0]]
for i in range(1,L):
    n = s[i]
    dp[i][0] = min(dp[i-1][0]+n,dp[i-1][1]+n)
    dp[i][1] = min(dp[i-1][1]+9-n,dp[i-1][0]+11-n)
print(min(dp[-1]))

Verdicts: Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
N = input().strip()

d = len(N)
culc = [0] * (d+1)

for i, digit in enumerate(N):
  digit = int(digit)
  if digit < 6:
    culc[i+1] = digit
  else:
    culc[i] += 1
    culc[i+1] -= (10 - digit) 
    if culc[i+1] > 5:
      culc[i+1] = (10 - culc[i+1])

ans = 0
for i in culc:
  ans += abs(i)
    
print(culc)
print(ans)


N = input().strip()

d = len(N)
culc = [0] * (d+1)

for i, digit in enumerate(N):
  digit = int(digit)
  if digit < 6:
    culc[i+1] = digit
  else:
    culc[i] += 1
    culc[i+1] -= (10 - digit) 

ans = 0
for i in culc:
  ans += abs(i)
    
print(culc)
print(ans)


n = input()
digit = [int(n[-(i + 1)]) for i in range(len(n))]
digit.append(0)

ans = 0
for i in range(len(digit)):
  if digit[i] > 5 or (digit[i] == 5 and digit[i + 1] >= 5):
    ans += 10 - digit[i]
    digit[i] = 0
    digit[i + 1] += 1
  else:
    ans += digit[i]
    digit[i] = 0

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
n = list(map(int, input()))
n = n[::-1]
#print(n)

b0 = [0]*(len(n)+1)
b1 = [0]*(len(n)+1)

for i in range(0, len(n)):
  num = n[i]
  b0[i+1] = min(b0[i]+num, b1[i]+num+1)
  b1[i+1] = min(b0[i]+10-num, b1[i]+10-(num+1))

print(min(b0[-1], b1[-1]+1))

n = [0] + list(map(int, input())) + [0]
n = n[::-1]
#print(n)

b0 = [0]*len(n)
b1 = [0]*len(n)

for i in range(1, len(n)):
  num = n[i]
  b0[i] = min(b0[i-1]+num, b1[i-1]+num+1)
  b1[i] = min(b0[i-1]+10-num, b1[i-1]+10-(num+1))

print(min(b0[-1], b1[-1]))

n = list(map(int, input())) + [0]
n = n[::-1]
#print(n)

b0 = [0]*len(n)
b1 = [0]*len(n)

for i in range(1, len(n)):
  num = n[i]
  #print(num)
  b0[i] = min(b0[i-1]+num, b1[i-1]+num+1)
  b1[i] = min(b0[i-1]+10-num, b1[i-1]+10-(num+1))

  
print(min(b0[-1], b1[-1]))

n = [0] + list(map(int, input())) + [0]
n = n[::-1]
#print(n)

b0 = [0]*len(n)
b1 = [0]*len(n)
b1[0] = 1
for i in range(1, len(n)):
  num = n[i]
  b0[i] = min(b0[i-1]+num, b1[i-1]+num+1)
  b1[i] = min(b0[i-1]+10-num, b1[i-1]+10-(num+1))

print(min(b0[-1], b1[-1]))
#print(b0[-1], b1[-1])

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):

#    0, 1, 2, 3, 4, 5, 6, 7, 8, 9
P = [0, 1, 2, 3, 4, 0, 0, 0, 0, 0]
C = [0, 0, 0, 0, 0, 5, 4, 3, 2, 1]
X = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1]
import sys
def solve(N):
    N = [int(c) for c in N]
    N = N[::-1]
    p = 0
    b = 0
    s = []
    for i in range(len(N)):
        c = N[i]
        c += b
        if c == 10:
            c = 0
            b = 1
            p += X[c]
            s.append(P[c])
        elif c == 5:
            if i == len(N)-1:
                p += 5
                s.append(5)
                b = 0
            else:
                if N[i+1] < 5:
                    p += 5
                    b = 0
                    s.append(5)
                else:
                    p += 5    
                    b = 1
                    s.append(0)
        elif c > 5:
            b = 1
            p += X[c]
            s.append(P[c])
        else:
            b = 0
            p += X[c]
            s.append(P[c])
    if b:
        s.append(b)
    #print(b, file=sys.stderr)
    return p + b, s[::-1]

def count(n):
    return sum([int(x) for x in str(n)])

def test(N):
    m = 10e10
    p = 0
    for P in range(N, N*10):
        n = count(P) + count(P - N)
        if n < m:
            p = P
            m = n
    e,s = solve(str(N))
    if e != m:
        print("N=%d"%N, "expected=%d"%m, p, "actual=%d"%e, "".join(str(c) for c in s))

N = [int(x) for x in input()]
a,_ = solve(N)
print(a)
if 1==1:
    for i in range(1, 1000):
        test(i)
    test(159)
    test(149)
    test(449)
    test(959)
    test(949)
    test(939)
    test(539)
    test(569)



X = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]
def solve(N):
    N = [int(c) for c in N][::-1]
    p = 0
    b = 0
    for i in range(len(N)):
        c = N[i] + b
        p += X[c]
        if c == 5:
            b = 0 if i == len(N)-1 or N[i+1] < 5 else 1
        elif c > 5:
            b = 1
        else:
            b = 0
    return p + b

print(solve(input()))


Verdicts: Time Limit Exceeded

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
Ns = [int(s) for s in input()]
total = 0
kuri = 0
for n in Ns[::-1]:
  print(n)
  if kuri + n == 10:
    kuri = 1
  else:
    n += kuri
    if n <= 5:
      total += n
      kuri = 0
    else:
      total += (10 - n)
      kuri = 1
if kuri > 0:
  total += kuri
    
print(total)

Ns = [int(s) for s in input()]
order = len(Ns)

dp_just = [0 for _ in range(order + 1)]
dp_plus = [0 for _ in range(order + 1)]

dp_just[0] = 0
dp_plus[0] = 1

for o in range(order):
  n = Ns[o]
  dp_just[o+1] = min(dp_just[o] + n, dp_plus[o] + (10 - n))
  dp_plus[o+1] = min(dp_just[o] + n + 1, dp_plus[o] + (9 -n))
  
print(dp_just[-1])


Verdicts: Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
n=list(input())
lis=[]
for k in range(len(n)):
  lis.append(int(n[len(n)-1-k]))
             
t=0
print(lis)
for k in range(len(lis)):
  if lis[k]==10:
    if k==len(lis)-1:
      t+=1
      break
    else:
      lis[k]=0
      lis[k+1]+=1
  if lis[k]<5:
    t+=lis[k]
  elif lis[k]>5:
    t=t+10-lis[k]
    if k==len(lis)-1:
        t+=1
        break
    else:
        
      lis[k+1]+=1
  elif lis[k]==5:
    if k==len(lis)-1:
      t+=5
    else:
      t+=5
      if lis[k+1]<5:
        pass
      else:
        lis[k+1]+=1
print(t)

n=list(input())
lis=[]
for k in range(len(n)):
  lis.append(int(n[len(n)-1-k]))
             
t=0

for k in range(len(lis)):
  if lis[k]==10:
    if k==len(lis)-1:
      t+=1
      break
    else:
      lis[k]=0
      lis[k+1]+=1
  if lis[k]<5:
    t+=lis[k]
  elif lis[k]>5:
    t=t+10-lis[k]
    if k==len(lis)-1:
        t+=1
        break
    else:
        
      lis[k+1]+=1
  elif lis[k]==5:
    if k==len(lis)-1:
      t+=5
    else:
      t+=5
      if lis[k+1]<5:
        pass
      else:
        lis[k+1]+=1
print(t)

Verdicts: Wrong Answer

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)

print(s)


import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)


import sys



import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)
if (n[0] > 5 and n[1] < 6) or (n[0] <= 5 and n[1] >= 6):
  s += 1
print(s)


import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)
if (n[0] > 5 and n[1] < 6) or (n[0] <= 5 and n[1] >= 6):
  s += 1
print(s)


def main():
    n = list(map(int, input()[::-1])) + [0]
    s = 0
    res = 0
    for i, ni in enumerate(n[:-1]):
        k = ni + s
        if k < 5 or (k == 5 and n[i + 1] < 5):
            res += k
            s = 0
        else:
            res += 10 - k
            s = 1
    res += s
    print(res)


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
def solve():
    from sys import stdin
    #f_i = stdin
    f_i = open('test_in_3')#
    
    N = f_i.readline().rstrip()
    N = N[::-1] + '0'
    
    INF = 10 ** 32
    
    import numpy as np
    dp = np.full((len(N), 2), INF)
    dp[0][0] = 0
    
    for i, x in enumerate(int(n) for n in N[:-1]):
        ni = i + 1
        dp[ni][0] = min(dp[i] + x)
        dp[ni][1] = min(dp[i][0] + 11 - x, dp[i][1] + 9 - x)
    
    ans = min(dp[-1])
    
    print(ans)

solve()

def solve():
    N = input()
    
    INF = 10 ** 32
    
    dp = [[INF, INF] for i in range(len(N) + 1)]
    dp[0][0] = 0
    
    for i, x in enumerate(int(n) for n in N[::-1]):
        ni = i + 1
        dp[ni][0] = min(dp[i][0] + x, dp[i][1] + x)
        dp[ni][1] = min(dp[i][0] + 11 - x, dp[i][1] + 9 - x)
    
    ans = min(dp[-1])
    
    print(ans)

solve()

Verdicts: Runtime Error

Accepted
Problem: In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_  To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.  What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?  Assume that you have sufficient numbers of banknotes, and so does the clerk.

Submission attempts (in order):
#

import sys
input=sys.stdin.readline

def main():
    N=input().strip("\n")
    ans=0
    for i in range(len(N)):
        d=int(N[i])
        if d<=5:
            ans+=d
        else:
            ans+=10-d
            if i==0:
                ans+=1
    print(ans)
    
if __name__=="__main__":
    main()


#

import sys
input=sys.stdin.readline

def main():
    NS=(input().strip("\n"))[::-1]
    dp=[[0]*2 for i in range(len(NS))]
    
    dp[0][0]=int(NS[0])
    dp[0][1]=10-int(NS[0])
    for i in range(1,len(NS)):
        d=int(NS[i])
        dp[i][0]=min(dp[i-1][0]+d,dp[i-1][1]+d+1)
        dp[i][1]=min(dp[i-1][0]+10-d,dp[i-1][1]-1+10-d)
    dp[-1][1]+=1
    print(min(dp[-1]))
    
if __name__=="__main__":
    main()


Verdicts: Wrong Answer

Accepted