Buggy python submission (verdict: Runtime Error):
N = input()

for i in range(len(N) - 1, -1, -1):
    t = int(N[i])
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
print(min(a, b + 1))


Fixed submission:
N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)

Buggy python submission (verdict: Runtime Error):
N = input()

a = 0  # not carried
b = 0  # carried
t = int(N[-1])
a, b = a + t, a + (10 - t)

for i in range(1, len(N))
    t = int(N[-i])
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
print(min(a, b + 1))


Fixed submission:
N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N = input()

a = 0  # not carried
b = 0  # carried
t = int(N[-1]) % 10
a, b = a + t, a + (10 - t)
N = N[:-1]
while len(N) != 0:
    t = int(N[-1]) % 10
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
    N = N[:-1]
print(min(a, b + 1))


Fixed submission:
N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)

Buggy python submission (verdict: Runtime Error):
N = input()

a = 0  # not carried
b = 0  # carried
t = int(N[:-1]) % 10
a, b = a + t, a + (10 - t)
N = N[:-1]
while N != 0:
    t = int(N[:-1]) % 10
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
    N = N[:-1]
print(min(a, b + 1))


Fixed submission:
N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

a = 0  # not carried
b = 0  # carried
t = N % 10
a, b = a + t, a + (10 - t)
N //= 10
while N != 0:
    t = N % 10
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
    N //= 10
print(min(a, b + 1))


Fixed submission:
N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)

Buggy python submission (verdict: Runtime Error):
def main():
    from builtin import min
    N = int(input())

    a = 0  # not carried
    b = 0  # carried
    t = N % 10
    a, b = a + t, a + (10 - t)
    N //= 10
    while N != 0:
        t = N % 10
        a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
        N //= 10
    print(min(a, b + 1))


main()


Fixed submission:
N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)

Buggy python submission (verdict: Runtime Error):
def main():
    from builtin import min
    N = int(input())

    a = 0  # not carried
    b = 0  # carried
    while N != 0:
        t = N % 10
        a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
        N //= 10
    print(min(a, b + 1))


main()


Fixed submission:
N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)

Buggy python submission (verdict: Runtime Error):
def main():
    from builtin import min
    N = int(input())

    a = 0 // carried
    b = 0 // not carried
    while N != 0:
        t = N % 10
        a = min(a + t + 1, b + t)
        b = min(a + 9 - t, a + 10 - t)
        n //= 10
    print(min(a + 1, b))


main()


Fixed submission:
N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)