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
import numpy as np


def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p)


try:
    sys.winver
    N = np.array([int(_) for _ in input()])
    from numba import jit
    solve = jit(solve, '(i8[:])')
    solve(N)
except:
    if sys.argv[-1] == 'ONLINE_JUDGE':
        import numba
        from numba.pycc import CC
        cc = CC('my_module')
        cc.export('solve', '(i8[:])')(solve)
        
        cc.compile()
    else:
        from my_module import solve
        N = np.array([int(_) for _ in input()])
        solve(N)


import sys
import numpy as np


def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p)


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i8[:])')(solve)
    
    cc.compile()
else:
    from my_module import main
    N = np.array([int(_) for _ in input()])
    solve(N)


import sys
import numpy as np



def main(N, dp):
    dp=np.zeros((2,len(N)),dtype=np.int64)
    dp[0, 0] = min(N[0], 11 - N[0])
    dp[0, 1] = min(N[0] + 1, 10 - N[0])
    for i in range(1, len(N)):
        dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])
        dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])
    print(dp[-1][0])


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8,i8[:],)')(main)
    
    cc.compile()
else:
    #from my_module import main
    N = np.array([int(_) for _ in input()])
    main(N)


N = [int(s) for s in input()][::-1] + [0]
ans = 0
for i in range(len(N)):
    if N[i] == 10:
        N[i + 1] += 1
    elif N[i] < 6:
        ans += N[i]
    else:
        ans += 10 - N[i]
print(ans)


import sys
import numpy as np



def main(N,dp):
    dp[0, 0] = min(N[0], 11 - N[0])
    dp[0, 1] = min(N[0] + 1, 10 - N[0])
    for i in range(1, len(N)):
        dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])
        dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])
    print(dp[-1][0])


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8[:],i8[:,:])')(main)
    
    cc.compile()
else:
    from my_module import main
    N = np.array([int(_) for _ in input()])
    dp=np.zeros((2,len(N)),dtype=np.int64)
    main(N,dp)


import sys
import numpy as np


def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p)


try:
    sys.winver
    N = np.array([int(_) for _ in input()])
    from numba import jit
    solve = jit(solve, '(i8[:])')
    solve(N)
except:
    if sys.argv[-1] != 'ONLINE_JUDGE':
        import numba
        from numba.pycc import CC
        cc = CC('my_module')
        cc.export('solve', '(i8[:])')(solve)
        
        cc.compile()
    else:
        from my_module import solve
        N = np.array([int(_) for _ in input()])
        solve(N)


import sys
import numpy as np


def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p)


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i8[:])')(solve)
    
    cc.compile()
else:
    from my_module import solve
    N = np.array([int(_) for _ in input()])
    solve(N)


import sys
import numpy as np


def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p)


try:
    sys.winver
    N = np.array([int(_) for _ in input()])
    from numba import jit
    solve = jit(solve, '(i8[:])')
    solve(N)
except:
    if sys.argv[-1] != 'ONLINE_JUDGE':
        import numba
        from numba.pycc import CC
        cc = CC('my_module')
        cc.export('solve', '(i8[:])')(solve)
        
        cc.compile()
    else:
        #from my_module import solve
        #N = np.array([int(_) for _ in input()])
        solve(N)


import numpy as np
from numba import njit

N = np.array([int(_) for _ in input()])


def solve(N):
    p, q = 0, 1
    for x in N:
        p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
    print(p)


solve(N)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted