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

Fixed submission:
import sys

# 解説カンニング済み

N = int(input())
xs = []
ys = []
hs = []
reference = None
for i in range(N):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)
    # 地面でないことが分かっている(ピラミッド内のサンプル)を1つ選ぶ
    if h > 0:
        reference = (x, y, h)

for cx in range(0, 100+1):
    for cy in range(0, 100+1):
        # サンプルの高さを求める
        rx, ry, rh = reference
        ref_H = rh + abs(rx-cx) + abs(ry-cy)
        # 他のデータも全てサンプルと合致するか検証する
        ok = True
        for i in range(N):
            calc_H = max(ref_H - abs(xs[i]-cx) - abs(ys[i]-cy), 0)
            if calc_H != hs[i]:
                ok = False
                break
        if ok:
            print(cx, cy, ref_H)
            sys.exit(0)

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())
xs = []
ys = []
hs = []
for i in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        xs.append(x)
        ys.append(y)
        hs.append(h)

for cx in range(0, 100+1):
    for cy in range(0, 100+1):
        Hs = set()
        for i in range(N):
            calcH = max(abs(xs[i]-cx) + abs(ys[i]-cy) + hs[i], 0)
            Hs.add(calcH)
        if len(Hs) == 1:
            print(cx, cy, Hs.pop())
            sys.exit(0)
Problem p03262 (python)

Fixed submission:
def gcd(a, b):
    big, small = max(a, b), min(a, b)
    if big % small == 0:
        return small
    div = None
    while big % small != 0:
        div = big % small
        big, small = small, div
    else:
        return div


N, X = map(int, input().split())
x = map(int, input().split())
x = [xi - X for xi in x]

d = x[0]
for xi in x[1:]:
    d = gcd(d, xi)
print(abs(d))

Buggy submission (verdict: Runtime Error):
import math

N, X = map(int, input().split())
x = map(int, input().split())
x = [xi - X for xi in x]

d = x[0]
for xi in x[1:]:
    d = math.gcd(d, xi)
print(d)
Problem p03698 (python)

Fixed submission:
a = input()
ls = {}
for i in range(ord('a'), ord('z') + 1):
    ls[chr(i)] = 0

for i in a:
    ls[i]+=1;

f = 1;
for i in a:
    if ls[i] > 1:
        f = 0
        break
if f:
    print("yes")
else:
    print("no")

Buggy submission (verdict: Runtime Error):
a = input()
ls = {}
for i in range(ord('a'), ord('z')):
    ls[chr(i)] = 0

for i in a:
    ls[i]+=1;

f = 1;
for i in a:
    if ls[i] > 1:
        f = 0
        break
if f:
    print("yes")
else:
    print("no")
Problem p02606 (python)

Fixed submission:
L,R,d = map(int,input().split())
i=0
for x in range (L,R+1):
    if x%d==0:
        i+=1
print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(int,map(input().split())
i = 0
for z in range(N)         
	for x,y in enumerate a:
         b=x+1
		 if b%2!=0 and y%2!=0:
    		i+=1
print(i)

Buggy submission (verdict: Runtime Error):
N = input()
a = list(map(input(),range(1,N+1)))
i = 0
for x,b in enumerate(a):
	x=x+1  
	if x%2!=0 and b%2!=0:
    	i+==1
     
    print(i)

Buggy submission (verdict: Runtime Error):
L = int(input())
R = int(input())
d = int(input())
i=0
for x in range (L,R+1):
    if x%2==0:
        i+=1
print(i)
Problem p02607 (python)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
i=0
for x,y in enumerate (a):
    b=x+1
    if b%2!=0 and y%2!=0:
        i+=1
print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(int,map(input().split())
i = 0
for z in range(N)         
	for x,y in enumerate a:
         b=x+1
		if b%2!=0 and y%2!=0:
    		i+=1
print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(int,map(input().split())
i = 0       
	for x,y in enumerate a:
         b=x+1
		if b%2!=0 and y%2!=0:
    		i+=1
print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(int,map(input().split())
i = 0       
	for x,y in enumerate a:
         b=x+1
		if b%2!=0 and a%2!=0:
    		i+=1
print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(int,map(input().split())
i = 0       
	for x,a in enumerate a:
         b=x+1
		if b%2!=0 and a%2!=0:
    		i+=1
print(i)

Buggy submission (verdict: Runtime Error):
N = input()
a = list(map(input().split())
i = 0
for x,a in enumerate a:
	if x%2!=0 and a%2!=0:
    	i+=1
     
    print(i)

Buggy submission (verdict: Runtime Error):
N = input()
a = list(map(input().split())
i = 0
for x in a:
	if x%2!=0 and a[x]%2!=0:
    	i+==1
     
    print(i)

Buggy submission (verdict: Runtime Error):
N = input()
a = list(map(input().split(N+1))
i = 0
for x in a:
	if x%2!=0 and a[x]%2!=0:
    	i+=1
     
    print(i)

Buggy submission (verdict: Runtime Error):
N = input()
a = list(map(input().split(N+1))
i = 0
for x in a:
	if x%2!=0 and a[x]%2!=0:
    	i+==1
     
    print(i)

Buggy submission (verdict: Runtime Error):
N = input()
a = list(map(input(),range(1,N+1)))
i = 0
for x in a:
	if x%2!=0 and a[x]%2!=0:
    	i+==1
     
    print(i)

Buggy submission (verdict: Runtime Error):
N = input()
a = list(map(input(),range(1,N+1)))
i = 0
for x in a:
	if x%2!=0 and a[x]%2!=0:
    	i+==1
     
    print(i)
Problem p02608 (python)

Fixed submission:
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n = x*x+y*y+z*z+x*y+y*z+z*x
            d[n]+=1
for i in range(1,N+1):
    print(d[i])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n = x*x+y*y+z*z+x*y+y*z+z*x
                d[n]+=1
for i in range(1,N+1):
    print(d[i])
Problem p03951 (python)

Fixed submission:
n=input()
s=raw_input()
t=raw_input()
for i in xrange(0,n+1):
	if s[i:n]==t[0:n-i]:
		print n+i
		break

Buggy submission (verdict: Runtime Error):
n=input()
s=raw_input()
t=raw_input()
for i in xrange(0, n + 1):
	if s[i : n] == t[0 : n - i]:
		print n + i
		break

Buggy submission (verdict: Runtime Error):
n=input()
s=raw_input()
t=raw_input()
for i in xrange(0, n + 1):
	if s[i : n] == t[0 : n - i]:
		print n + i
		break
Problem p02973 (python)

Fixed submission:
from collections import deque
import bisect
N = int(input())
A = deque()
for _ in range(N):
    x = int(input())
    i = bisect.bisect_left(A,x)
    if i == 0:
        A.appendleft(x)
    else:
        A[i-1] = x

print(len(A))

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
A = deque()
for _ in range(N):
    x = int(input())
    i = bisect.bisect_left(A,x)
    j = bisect.bisect_right(A,x)
    if len(A) == 0:
        A.append(x)
    elif i > 0:
        if x <= A[i-1]:
            A.insert(i-1, x)
        else:
            A[i-1] = x
    elif x <= A[i]:
        A.insert(i, x)
    elif x > A[i]:
        A[i] = x

print(len(A))

Buggy submission (verdict: Runtime Error):
from collections import deque
import bisect
N = int(input())
A = deque()
for _ in range(N):
    x = int(input())
    i = bisect.bisect_left(A,x)
    j = bisect.bisect_right(A,x)
    if len(A) == 0:
        A.append(x)
    elif i > 0:
        if x <= A[i-1]:
            A.insert(i-1, x)
        else:
            A[i-1] = x
    elif x <= A[i]:
        A.insert(i, x)
    elif x > A[i]:
        A[i] = x

print(len(A))
Problem p02985 (python)

Fixed submission:
MOD = 1000000007
N, K = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

C = [False for _ in range(N)]
F = [0]
C[0] = True
r = K
while F:
    n = F.pop()
    if n == 0:
        c = K-1
    else:
        c = K-2
    for e in G[n]:
        if C[e]:
            continue
        C[e] = True
        r = (r * c) % MOD
        c -= 1
        F.append(e)

print(r)

Buggy submission (verdict: Runtime Error):
MOD = 1000000007
N, K = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

def dfs(K, G, now, parent):
    can_use_color_num = K-2
    if parent == -1:
        can_use_color_num = K-1
    if K < len(G[now]):
        return 0
    else:
        case_num = 1
        for e in G[now]:
            if e == parent:
                continue
            case_num *= can_use_color_num
            can_use_color_num -= 1
            case_num %= MOD
        for e in G[now]:
            if e == parent:
                continue
            case_num *= dfs(K, G, e, now)
            case_num %= MOD
        return case_num

ans = K * dfs(K, G, 0, -1)
print(ans % MOD)

Buggy submission (verdict: Runtime Error):
MOD = 1000000007
N, K = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

def dfs(K, G, now, parent):
    can_use_color_num = K-2
    if parent == -1:
        can_use_color_num = K-1
    if K < len(G[now]):
        return 0
    else:
        case_num = 1
        for e in G[now]:
            if e == parent:
                continue
            case_num *= can_use_color_num
            can_use_color_num -= 1
            case_num %= MOD
        for e in G[now]:
            if e == parent:
                continue
            case_num *= dfs(K, G, e, now)
            case_num %= MOD
        return case_num

ans = K * dfs(K, G, 0, -1)
print(ans % MOD)

Buggy submission (verdict: Runtime Error):
MOD = 1000000007
N, K = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

def dfs(K, G, now, parent):
    can_use_color_num = K-2
    if parent == -1:
        can_use_color_num = K-1
    if K < len(G[now]):
        return 0
    else:
        case_num = 1
        for e in G[now]:
            if e == parent:
                continue
            case_num *= can_use_color_num
            can_use_color_num -= 1
            case_num %= MOD
        for e in G[now]:
            if e == parent:
                continue
            case_num *= dfs(K, G, e, now)
            case_num %= MOD
        print("now:{},num:{}".format(now, case_num))
        return case_num

ans = K * dfs(K, G, 0, -1)
print(ans % MOD)
Problem p03043 (python)

Fixed submission:
N, K = map(int,input().split())

ans = 0
for i in range(1, N+1):
    cnt = 0
    while i * (2 ** cnt) < K:
        cnt += 1
    ans += (0.5 ** cnt) / N

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())

dic = {}
i = 0
while (2 ** i) <= (10 ** 5):
    dic[i] = 0
    i += 1

for i in range(1, N+1):
    cnt = 0
    while i * (2 ** cnt) < K:
        cnt += 1
    dic[cnt] += 1

ans = 0
for k, v in dic.items():
    if v > 0:
        ans += v * (0.5 ** k) / N

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())

dic = {}
i = 0
while (2 ** i) <= (10 ** 5):
    dic[i] = 0
    i += 1

for i in range(1, N+1):
    cnt = 0
    while i * (2 ** cnt) < K:
        cnt += 1
    dic[cnt] += 1

ans = 0
for k, v in dic.items():
    if v > 0:
        ans += v * (0.5 ** k)

ans /= N
print(ans)
Problem p03061 (python)

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

L = [0]
g = 0
for i in range(N-1):
    g = gcd(g, A[i])
    L.append(g)

R = []
g = 0
for i in range(N-1):
    g = gcd(g, A[N-1-i])
    R.append(g)
R.reverse()
R.append(0)

ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i],R[i]))

print(ans)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = list(map(int,input().split()))

L = [0]
g = 0
for i in range(N-1):
    g = math.gcd(g, A[i])
    L.append(g)

R = []
g = 0
for i in range(N-1):
    g = math.gcd(g, A[N-1-i])
    R.append(g)
R.reverse()
R.append(0)

ans = 0
for i in range(N):
    ans = max(ans, math.gcd(L[i],R[i]))

print(ans)
Problem p03076 (python)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

L = [A, B, C, D, E]
S = [10]
for l in L:
    if l % 10 != 0:
        S.append(l % 10)
min_s = min(S)

s = 0
flag = True
for l in L:
    if flag and min_s == l % 10:
        s += l
        flag = False
    elif 0 == l % 10:
        s += l
    else:
        s += 10 * (l // 10) + 10
print(s)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

L = [A, B, C, D, E]
S = []
for l in L:
    if l % 10 != 0:
        S.append(l % 10)
min_s = min(S)

s = 0
flag = True
for l in L:
    if flag and min_s == l % 10:
        s += l
        flag = False
    elif 0 == l % 10:
        s += l
    else:
        s += 10 * (l // 10) + 10
print(s)
Problem p03240 (python)

Fixed submission:
N = int(input())
X = []
Y = []
H = []
xc = None
yc = None
hc = None
for _ in range(N):
    x, y, h = map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
    if h > 0:
        xc = x
        yc = y
        hc = h

for pos_x in range(101):
    for pos_y in range(101):
        center_h = hc + abs(xc - pos_x) + abs(yc - pos_y)

        flag = True
        for n in range(N):
            if H[n] != max(center_h - abs(X[n] - pos_x) - abs(Y[n] - pos_y), 0):
                flag = False
                break
        if flag:
            print(pos_x, pos_y, center_h)
            exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
X = []
Y = []
H = []
for _ in range(N):
    x, y, h = map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)

for pos_x in range(101):
    for pos_y in range(101):
        need_h = -1
        for n in range(N):
            if H[n] > 0:
                tmp = H[n] + abs(X[n]-pos_x) + abs(Y[n]-pos_y)
            if need_h == -1:
                need_h = tmp
            else:
                if need_h != tmp:
                    need_h = -2
                    break
        if need_h == -2:
            continue

        for n in range(N):
            if H[n] == 0:
                tmp = H[n] + abs(X[n]-pos_x) + abs(Y[n]-pos_y)
                if need_h > tmp:
                    need_h = -2
                    break
        if need_h == -2:
            continue

        print(pos_x, pos_y, need_h)
        exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
X = []
Y = []
H = []
for _ in range(N):
    x, y, h = map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)

C = [[-1 for _ in range(101)] for _ in range(101)]
for i in range(101):
    for j in range(101):

        need = -1
        for n in range(N):
            if H[n] > 0:
                tmp = H[n] + abs(X[n]-i) + abs(Y[n]-j)
            if need == -1:
                need = tmp
            else:
                if need != tmp:
                    need = -2
                    break
        if need == -2:
            continue

        for n in range(N):
            if H[n] == 0:
                tmp = H[n] + abs(X[n] - i) + abs(Y[n] - j)
                if need > tmp:
                    need = -2
                    break
        if need == -2:
            continue

        print(i, j, need)
        exit()
Problem p03262 (python)

Fixed submission:
N, X = map(int,input().split())
A = list(map(int,input().split()))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

ans = abs(A[0]-X)
for a in A:
    ans = gcd(ans, abs(a-X))


print(ans)

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

X.append(x)
X.sort()

ans = X[1] - X[0]
for i in range(1, N+1):
    t = X[i+1] - X[i]
    if t < ans:
        ans = t
print(ans)
Problem p03533 (python)

Fixed submission:
def main():
    S = input()

    check = []
    for i in ["A", ""]:
        for j in ["A", ""]:
            for k in ["A", ""]:
                for l in ["A", ""]:
                    check.append(i + "KIH" + j + "B" + k + "R" + l)

    for C in check:
        if C == S:
            print("YES")
            exit()

    print("NO")
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    S = input()
    len_s = len(S)
    check = "AKIHABARA"
    idx = 0
    len_check = len(check)

    i = 0
    while i < len_s:
        s = S[i]
        if check[idx] == s:
            idx += 1
        elif idx+1 < len_check and s == check[idx+1] and "A" == check[idx]:
            idx += 2
        else:
            print("NO")
            exit()
        i += 1
    if idx >= 7:
        print("YES")
    else:
        print("NO")
if __name__ == '__main__':
    main()
Problem p03651 (python)

Fixed submission:
N, K = map(int,input().split())
A = list(map(int,input().split()))

def get_gcd(a,b):
    if b > a:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

gcd  = A[0]
max_a = A[0]
for i in range(1, N):
    a = A[i]
    if a == K:
        print("POSSIBLE")
        exit()
    if a > max_a:
        max_a = a
    gcd = get_gcd(gcd, a)

if max_a < K:
    print("IMPOSSIBLE")
    exit()
else:
    if K % gcd == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

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

A.sort()
max_a = -1
min_diff = K
for i in range(N):
    a = A[i]
    if a == K:
        print("POSSIBLE")
        exit()
    if a > max_a:
        max_a = a
    if i < N-1:
        diff = A[i+1]-A[i]
        if diff < min_diff:
            min_diff = diff

if max_a < K:
    print("IMPOSSIBLE")
    exit()
else:
    for a in A:
        if (K-a) % min_diff == 0:
            print("POSSIBLE")
            exit()

print("IMPOSSIBLE")
Problem p02698 (python)

Fixed submission:
import bisect
import sys
sys.setrecursionlimit(10**9)

N = int(input())
A = list(map(int,input().split()))

Edge = [[] for _ in range(N)]
for _ in range(N-1):
    u,v = map(int,input().split())
    Edge[u-1].append(v-1)
    Edge[v-1].append(u-1)

visited = [False]*N
visited[0] = True
answer = [1]*N

def dfs(v, dp):
    for nv in Edge[v]:
        if visited[nv]:
            continue
        
        visited[nv] = True
        if len(dp)==0 or A[nv]>dp[-1]:
            dp.append(A[nv])
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp.pop()
        else:
            idx = bisect.bisect_left(dp, A[nv])
            temp = dp[idx]
            dp[idx] = A[nv]
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp[idx] = temp
        
    return 

dfs(0, [A[0]])
answer[0] = 1
for a in answer:
    print(a)

Buggy submission (verdict: Runtime Error):
import bisect

N = int(input())
A = list(map(int,input().split()))

Edge = [[] for _ in range(N)]
for _ in range(N-1):
    u,v = map(int,input().split())
    Edge[u-1].append(v-1)
    Edge[v-1].append(u-1)

visited = [False]*N
visited[0] = True
answer = [1]*N

def dfs(v, dp):
    for nv in Edge[v]:
        if visited[nv]:
            continue
        
        visited[nv] = True
        if len(dp)==0 or A[nv]>dp[-1]:
            dp.append(A[nv])
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp.pop()
        else:
            idx = bisect.bisect_left(dp, A[nv])
            temp = dp[idx]
            dp[idx] = A[nv]
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp[idx] = temp
        
    return 

dfs(0, [A[0]])
answer[0] = 1
for a in answer:
    print(a)

Buggy submission (verdict: Runtime Error):
import bisect

N = int(input())
A = list(map(int,input().split()))

Edge = [[] for _ in range(N)]
for _ in range(N-1):
    u,v = map(int,input().split())
    Edge[u-1].append(v-1)
    Edge[v-1].append(u-1)

visited = [False]*N
visited[0] = True
answer = [1]*N

def dfs(v, dp):
    for nv in Edge[v]:
        if visited[nv]:
            continue
        
        visited[nv] = True
        if A[nv]>dp[-1]:
            dp.append(A[nv])
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp.pop()
        else:
            idx = bisect.bisect_left(dp, A[nv])
            temp = dp[idx]
            dp[idx] = A[nv]
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp[idx] = temp
        
    return 

dfs(0, [A[0]])
answer[0] = 1
for a in answer:
    print(a)
Problem p02721 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys

N,K,C = map(int,input().split())
S = input()
#%%
assign_t = [False]*N
assign_b = [False]*N


i = 0
num = 0
while i<N:
    if S[i]=='o':
        assign_t[i]=True
        num += 1
        i += C+1
    else:
        i += 1

if num>K:
    print()
    sys.exit()

i = N-1
num = 0
while i>=0 and num<K:
    if S[i]=='o':
        assign_b[i]=True
        num += 1
        i -= C+1
    else:
        i -=1


for i in range(N):
    if assign_t[i] and assign_b[i]:
        print(i+1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys

N,K,C = map(int,input().split())
S = input()
#%%
assign_t = [False]*N
assign_b = [False]*N

i = 0
num = 0
while i<N and num<K:
    if S[i]=='o':
        assign_t[i]=True
        num += 1
        i += C+1
    else:
        i += 1

i = N-1
num = 0
while i>=0 and num<K:
    if S[i]=='o':
        assign_b[i]=True
        num += 1
        i -= C+1
    else:
        i -=1

tot = 0
for s in S:
    if s=='o':
        tot += 1

if tot//(K-1)>1.4*(C+1):
    print()
    sys.exit()

for i in range(N):
    if assign_t[i] and assign_b[i]:
        print(i+1)
Problem p02775 (python)

Fixed submission:

N = list(input())

N.reverse()

ans = 0
flag = False
L = len(N)
for i,s in enumerate(N):
    n = int(s)
    
    if flag:
        n += 1
    
    if n<5:
        ans += n
        flag = False
    elif n>5:
        ans += 10-n
        flag = True
    else:
        if i==L-1:
            ans += n
            flag = False
            break
            
        if int(N[i+1])<5:
            ans += n
            flag = False
        else:
            ans += 10-n
            flag = True

if flag:
    ans += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):

N = list(input())

N.reverse()

ans = 0
flag = False
L = len(N)
for i,s in enumerate(N):
    n = int(s)
    
    if flag:
        n += 1
    
    if n<5:
        ans += n
        flag = False
    elif n>5:
        ans += 10-n
        flag = True
    else:
        if i==L-1:
            ans += n
            flag = False
            
        if int(N[i+1])<5:
            ans += n
            flag = False
        else:
            ans += 10-n
            flag = True

if flag:
    ans += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):

N = list(input())

N.reverse()

ans = 0
flag = False

for i,s in enumerate(N):
    n = int(s)
    
    if flag:
        n += 1
    
    if n<5:
        ans += n
        flag = False
    elif n>5:
        ans += 10-n
        flag = True
    else:
        if i==N-1:
            ans += n
            flag = False
            
        if int(N[i+1])<5:
            ans += n
            flag = False
        else:
            ans += 10-n
            flag = True

if flag:
    ans += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):

N = list(input())

N.reverse()

ans = 0
flag = False

for i,s in enumerate(N):
    n = int(s)
    
    if flag:
        n += 1
    
    if n<5:
        ans += n
        flag = False
    elif n>5:
        ans += 10-n
        flag = True
    else:
        if int(N[i+1])<5:
            ans += n
            flag = False
        else:
            ans += 10-n
            flag = True

if flag:
    ans += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):

N = list(input())

N.reverse()

ans = 0
flag = False

for i,s in enumerate(N):
    n = int(s)
    
    if flag:
        n += 1
    
    if n<5:
        ans += n
        flag = False
    elif n>5:
        ans += 10-n
        flag = True
    else:
        if int(N[i+1])<5:
            ans += n
            flag = False
        else:
            ans += 10-n
            flag = True

if flag:
    ans += 1
    
print(ans)