Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc155/submissions/10175015

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

Fixed submission:
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 int(n[i + 1]) < 5):
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)

Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc155/submissions/10175015

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


Fixed submission:
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 int(n[i + 1]) < 5):
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)

Buggy python submission (verdict: Runtime Error):
import sys
n = list(map(int, sys.stdin.readline().strip()))
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)


Fixed submission:
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 int(n[i + 1]) < 5):
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)

Buggy python submission (verdict: Runtime Error):
import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)


Fixed submission:
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 int(n[i + 1]) < 5):
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)

Buggy python submission (verdict: Runtime Error):
import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)

print(s)


Fixed submission:
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 int(n[i + 1]) < 5):
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)

Buggy python submission (verdict: Runtime Error):
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)


Fixed submission:
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 int(n[i + 1]) < 5):
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)

Buggy python submission (verdict: Runtime Error):
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)


Fixed submission:
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 int(n[i + 1]) < 5):
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)