ZhenlongDai/ACPR huggingface dataset:
Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k, *h = map(int,open(0).read().split())
h.sort 
if n<k:
  print(0)
else:
  a = h[0: n-k]
  print(sum(a))

Failing test case input:
8 2
4 9 8 0 3 4 11 6

Expected output:
25


Actual output:
28


Fixed submission (verdict: Accepted):
n,k= map(int,input().split())
h = list(map(int,input().split()))
h.sort()
if n<=k:
  print(0)
else:
  a = h[:n-k]
  print(sum(a))

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n,k = map(int,input().split())
tairyoku = list(map(int,input().split()))
tairyoku.sort(reverse=True)

if k == 0:
    print(sum(tairyoku))
    
else:
    del tairyoku[:k]
    print(tairyoku)
    print(sum(tairyoku))

Failing test case input:
3 1
1000000000 1000000000 1110000010

Expected output:
2000000000


Actual output:
[1000000000, 1000000000]
2000000000


Fixed submission (verdict: Accepted):

n,k = map(int,input().split())
tairyoku = list(map(int,input().split()))
tairyoku.sort(reverse=True)

if k == 0:
    print(sum(tairyoku))
    
else:
    del tairyoku[:k]
    print(sum(tairyoku))

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
H = sorted([int(x) for x in input().split()])[::-1]
print(sum(H[N:]))


Failing test case input:
3 0
1100000000 1000000000 0110000100

Expected output:
2210000100


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
H = sorted([int(x) for x in input().split()])[::-1]
print(sum(H[K:]))

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    total = sum(h)

    if k >= n:
        print(0)
    elif k == 0:
        print(total)
    else:
        print(sum(sorted(h[k + 1:], reverse=True)))


if __name__ == '__main__':
    main()


Failing test case input:
8 1
4 9 8 0 3 4 16 6

Expected output:
34


Actual output:
37


Fixed submission (verdict: Accepted):



def main():
    n, k = map(int, input().split())
    h = sorted(list(map(int, input().split())), reverse=True)
    count = 0
    ans = 0

    for hi in h:
        if count >= k:
            ans += hi

        count += 1

    print(ans)


if __name__ == '__main__':
    main()

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b = map(int,input().split())
N = list(map(int,input().split()))
N.sort()
print(sum(N))

Failing test case input:
8 1
4 9 5 2 3 6 5 6

Expected output:
31


Actual output:
40


Fixed submission (verdict: Accepted):
a,b = map(int,input().split())
N = list(map(int,input().split()))
N.sort()
for i in range(b):
    if N:
        N.pop()
print(sum(N))
Problem: p02785
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
H,N=map(int, input().split())
l=list(map(int, input().split())) 

import math




import sys
if N>=len(l):
    print(l)
    sys.exit()

    
sort_l=sorted(l)
delete_l=sort_l[:len(l)-N]
print(sum(delete_l))

Failing test case input:
8 9
7 9 3 2 3 8 4 6

Expected output:
0

Actual output:
[7, 9, 3, 2, 3, 8, 4, 6]


Fixed submission (verdict: Accepted):
H,N=map(int, input().split())
l=list(map(int, input().split())) 

import math




import sys
if N>=len(l):
    print(0)
    sys.exit()

    
sort_l=sorted(l)
delete_l=sort_l[:len(l)-N]
print(sum(delete_l))

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

if K < N:
    H_sorted = sorted(H)
    print(sum(H_sorted[:-K]))
else:
    print(0)

Failing test case input:
3 0
1000000000 1000000000 0110000000

Expected output:
2110000000


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

if K < N:
    H_sorted = sorted(H, reverse=True)
    print(sum(H_sorted[K:]))
else:
    print(0)

Problem: p02785
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
H = list(map(int, input().split()))

if N <= K:
	print(0)

H.sort()

res = 0
for i in range(N - K):
	res += H[i]
print(res)

Failing test case input:
8 9
7 9 3 2 3 8 4 6

Expected output:
0

Actual output:
0
0


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
H = list(map(int, input().split()))
 
if N <= K:
	print(0)
else:
	H.sort()
 
	res = 0
	for i in range(N - K):
		res += H[i]
	print(res)

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
H = [int(x) for x in input().split()]
H.sort()

print(sum(H[0:N-K]))

Failing test case input:
8 9
7 9 3 2 3 8 4 6

Expected output:
0

Actual output:
33


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
H = [int(x) for x in input().split()]
H.sort()

if N >= K:
    print(sum(H[0:N-K]))
else:
    print(0)

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N , K = map(int, input().split())
H = [int(i) for i in input().split()]


if N <= K:
    print(0)

elif K == 0:
    print('aaa')

else:
    H.reverse()
    print(sum(H[K:N+1]))


Failing test case input:
3 0
1100000000 1000000001 1110000000

Expected output:
3210000001


Actual output:
aaa


Fixed submission (verdict: Accepted):
N , K = map(int, input().split())
H = [int(i) for i in input().split()]


if N <= K:
    print(0)

elif K == 0:
    print(sum(H))

else:
    H.sort()
    H.reverse()
    print(sum(H[K:N]))
Problem: p02785
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K,*H = map(int,read().split())
N -= K
if N <= 0:
    print(0)
    exit()
    
H.sort()
    
print(sum(H[:N - K + 1]))

Failing test case input:
8 5
7 9 5 2 3 8 4 6

Expected output:
9


Actual output:
35


Fixed submission (verdict: Accepted):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K,*H = map(int,read().split())
N -= K
if N <= 0:
    print(0)
    exit()
    
H.sort()
    
print(sum(H[: N]))

Problem: p02785
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math

def main():
  N, K = map(int, input().split())
  H = list(map(int, input().split()))
  
  if K >= N:
    print(0)
    return
  
  ans = 0
  l = sorted(H, reverse=True)
  
  del l[:K]
  print(l)
  
  ans += sum(l)
  
  print(ans)
  
  
main()

Failing test case input:
3 0
1000000000 1000000100 1110000000

Expected output:
3110000100


Actual output:
[1110000000, 1000000100, 1000000000]
3110000100


Fixed submission (verdict: Accepted):
import math

def main():
  N, K = map(int, input().split())
  H = list(map(int, input().split()))
  
  if K >= N:
    print(0)
    return
  
  
  l = sorted(H, reverse=True)
  
  
  
  
  
  
  print(sum(l[K:]))
  
  
  
main()

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int,input().split())
H = list(map(int, input().split()))

if K >= N:
  print(0)
 
elif K == 0:
  print(sum(H))

else:
  H.sort
  print(sum(H[K+1:N-1]))

Failing test case input:
3 1
0 1 5

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = map(int,input().split())
H = list(map(int, input().split()))

if K >= N:
  print(0)
 
elif K == 0:
  print(sum(H))

else:
  newH = sorted(H, reverse=True)
  print(sum(newH[K:]))

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

def input1():
	return int(input())


def input2():
	return map(int,input().split())


def input_array():
	return list(map(int,input().split()))


H,K=input2()
h=input_array()

sorted_h=sorted(h)
if len(sorted_h[:-K])<1:
	print(0)
else:
	print(sum(sorted_h[:-K]))

Failing test case input:
3 0
0000000000 1000000001 0110000000

Expected output:
1110000001


Actual output:
0


Fixed submission (verdict: Accepted):

def input1():
	return int(input())


def input2():
	return map(int,input().split())


def input_array():
	return list(map(int,input().split()))


H,K=input2()
h=input_array()

if K>=H:
	print(0)
elif K<=0:
	print(sum(h))
else:
	sorted_h=sorted(h)
	print(sum(sorted_h[:-K]))

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
H = sorted(map(int, input().split()))
print(sum(H[:-K]))

Failing test case input:
8 0
4 22 5 1 3 6 7 6

Expected output:
54


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
H = sorted(map(int, input().split()))
if K != 0:
    print(sum(H[:-K]))
else:
    print(sum(H))
Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())

h = sorted(map(int, input().split()))

del h[-k:]

print(sum(h))

Failing test case input:
3 0
0000000000 1000000001 0110000000

Expected output:
1110000001


Actual output:
0


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())

h = sorted(map(int, input().split()))

if k == 0:
    print(sum(h))
    
else:
    del h[-k:]
    print(sum(h))

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    total = sum(h)

    if k >= n:
        print(0)
    elif k == 0:
        print(total)
    else:
        print(total - sum(sorted(h[:k + 1], reverse=True)))


if __name__ == '__main__':
    main()


Failing test case input:
8 1
4 9 9 2 3 4 1 7

Expected output:
30


Actual output:
26


Fixed submission (verdict: Accepted):



def main():
    n, k = map(int, input().split())
    h = sorted(list(map(int, input().split())), reverse=True)
    count = 0
    ans = 0

    for hi in h:
        if count >= k:
            ans += hi

        count += 1

    print(ans)


if __name__ == '__main__':
    main()

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
inp = input().rstrip().split(" ")
N = int(inp[0])
K = int(inp[1])
inp = input().rstrip().split(" ")
HP = [0 for i in range(N)]
for i in range(N):
  HP[i] = int(inp[i])
HP.reverse()
ans = 0
for i in range(N):
  if i >= K:
    ans += HP[i]
print(ans)

Failing test case input:
8 2
4 2 3 1 0 23 10 6

Expected output:
16


Actual output:
33


Fixed submission (verdict: Accepted):
inp = input().rstrip().split(" ")
N = int(inp[0])
K = int(inp[1])
inp = input().rstrip().split(" ")
HP = [0 for i in range(N)]
for i in range(N):
  HP[i] = int(inp[i])
HP.sort()
HP.reverse()
ans = 0
for i in range(N):
  if i >= K:
    ans += HP[i]
print(ans)

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=list(map(int,input().split()))
H=list(map(int,input().split()))
count=0
H=sorted(H,reverse=True)
if N[1]>=len(H):
    print(len(H))
else:
    while N[1]>=1:
        del(H[0])
        N[1]-=1
        count+=1
    print(sum(H))
        

Failing test case input:
8 8
7 9 3 2 3 8 4 6

Expected output:
0


Actual output:
8


Fixed submission (verdict: Accepted):
N=list(map(int,input().split()))
H=list(map(int,input().split()))
H=sorted(H,reverse=True)
if N[1]>=len(H):
    print(0)
else:
    del(H[0:N[1]])
    print(sum(H))

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n,k = map(int,input().split())
h_L = list(map(int,input().split()))

h_L.sort()

if k ==0:
    print(sum(h_L))
else:
    print(sum(h_L[k+1:]))

Failing test case input:
8 1
4 9 9 2 6 4 5 12

Expected output:
39


Actual output:
45


Fixed submission (verdict: Accepted):

n,k = map(int,input().split())
h_L = list(map(int,input().split()))

h_L.sort(reverse=True)

if k ==0:
    print(sum(h_L))
else:
    print(sum(h_L[k:]))
Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
[n,k]=[int(x) for x in input().split()]
h=[int(x) for x in input().split()]
h.sort()
if n<=k:
  print("0")
else:
  print(str(sum(h[:-k])))

Failing test case input:
3 0
0100000000 1001000001 1010000000

Expected output:
2111000001


Actual output:
0


Fixed submission (verdict: Accepted):
[n,k]=[int(x) for x in input().split()]
h=[int(x) for x in input().split()]
h.sort()
if n<=k:
  print("0")
else:
  print(str(sum(h[:len(h)-k])))

Problem: p02785
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K = map(int,input().split())
H = list(map(int,input().split()))
if K==0:
    print(sum(H))
elif N>K:
    x=max(H)
    print(sum(H)-x)
else:
    print(0)

Failing test case input:
8 2
7 2 2 1 0 23 0 5

Expected output:
10


Actual output:
17


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
H = list(map(int,input().split()))
if K==0:
    print(sum(H))
else:
    print(sum(sorted(H)[:-K]))

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

bodies_count = list(map(int,input().split()))
enemy_life = list(map(int,input().split()))
count = 0

if bodies_count[1] == 0:
    print(sum(enemy_life))
else:
    enemy_life.sort(reverse=True)
    a = bodies_count[1]-1
    del enemy_life[0:a]

    if enemy_life != []:
        print(sum(enemy_life))
    
    
    
    
    
    
    
    



Failing test case input:
8 2
7 2 2 1 0 23 0 6

Expected output:
11


Actual output:
18


Fixed submission (verdict: Accepted):

bodies_count = list(map(int,input().split()))
enemy_life = list(map(int,input().split()))

if bodies_count[1] == 0:
    print(sum(enemy_life))
else:
    enemy_life.sort(reverse=True)
    if bodies_count[1] == 1:
        del enemy_life[0] 
    else:
        a = bodies_count[1]
        del enemy_life[0:a]

    if enemy_life != []:
        print(sum(enemy_life))
    else:
        print(0)

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

bodies_count = list(map(int,input().split()))
enemy_life = list(map(int,input().split()))
count = 0

if bodies_count[1] == 0:
    print(sum(enemy_life))
else:
    enemy_life.sort(reverse=True)
    if bodies_count[1] == 1:
        del enemy_life[0]
    else:
        a = bodies_count[1]-1
        del enemy_life[0:a]
        print(sum(enemy_life))

    if enemy_life != []:
        print(sum(enemy_life))
    
    
    
    
    
    
    
    



Failing test case input:
8 2
7 2 2 2 0 1 0 6

Expected output:
7


Actual output:
13
13


Fixed submission (verdict: Accepted):

bodies_count = list(map(int,input().split()))
enemy_life = list(map(int,input().split()))

if bodies_count[1] == 0:
    print(sum(enemy_life))
else:
    enemy_life.sort(reverse=True)
    if bodies_count[1] == 1:
        del enemy_life[0] 
    else:
        a = bodies_count[1]
        del enemy_life[0:a]

    if enemy_life != []:
        print(sum(enemy_life))
    else:
        print(0)
Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin


def main(inp1, inp2):
    n, k = [int(i) for i in inp1.split(sep=' ')]
    h_list = sorted([int(i) for i in inp2.split(sep=' ')])

    print(h_list)
    num_enemy = n
    enable_special = k

    if enable_special >= num_enemy:
        return 0
    elif enable_special == 0:
        return sum(h_list)
    else:
        return sum(h_list[:-enable_special])


if __name__ == '__main__':
    input1 = stdin.readline().rstrip()
    input2 = stdin.readline().rstrip()
    ret = main(input1, input2)
    print(ret)

Failing test case input:
3 0
0 1 5

Expected output:
6


Actual output:
[0, 1, 5]
6


Fixed submission (verdict: Accepted):
from sys import stdin


def main(inp1, inp2):
    n, k = [int(i) for i in inp1.split(sep=' ')]
    h_list = sorted([int(i) for i in inp2.split(sep=' ')])

    num_enemy = n
    enable_special = k

    if enable_special >= num_enemy:
        return 0
    elif enable_special == 0:
        return sum(h_list)
    else:
        return sum(h_list[:-enable_special])


if __name__ == '__main__':
    input1 = stdin.readline().rstrip()
    input2 = stdin.readline().rstrip()
    ret = main(input1, input2)
    print(ret)

Problem: p02785
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
monsters = list(map(int, input().split()))

hissatsu = n-k

if hissatsu <= 0:
  print(0)
else:
  print(sum(monsters[-hissatsu:]))

Failing test case input:
8 2
7 6 3 1 0 23 10 5

Expected output:
22


Actual output:
42


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
monsters = list(map(int, input().split()))

hissatsu = n-k

if hissatsu <= 0:
  print(0)
else:
  monsters.sort(reverse=True)
  print(sum(monsters[-hissatsu:]))
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=input()
a=[]
s=len(N)

for i in range(s-1,-1,-1):
    a.append(int(N[i]))
a.append(0)


p=sum(a)
t=0
f=0
c=0
for i in range(len(a)-1):
    if a[i] <= 5:
        t+=a[i]
        if a[i] == 5 and a[i+1]>=5:a[i+1]+=1
        f=0
        
    else:
        c+=10-a[i]
        a[i+1] += 1
        f=1
        
    print(t+f+c)

Failing test case input:
839062221003161155269205136305819742322900249929330692870287401920984942188431202470664713444

Expected output:
210


Actual output:
4
8
12
15
16
20
24
28
31
31
35
39
41
41
43
44
47
51
54
55
56
58
62
64
68
70
70
70
72
74
75
75
79
83
84
86
86
90
91
93
95
98
98
101
104
106
108
110
110
114
116
116
116
118
120
122
125
127
131
135
135
136
139
143
143
146
151
154
155
160
160
162
164
167
169
174
179
180
181
186
187
190
190
190
191
193
195
197
202
202
204
207
210


Fixed submission (verdict: Accepted):
N=input()
a=[]
s=len(N)

for i in range(s-1,-1,-1):
    a.append(int(N[i]))
a.append(0)


p=sum(a)
t=0
f=0
c=0
for i in range(len(a)-1):
    if a[i] <= 5:
        t+=a[i]
        if a[i] == 5 and a[i+1]>=5:a[i+1]+=1
        f=0
        
    else:
        c+=10-a[i]
        a[i+1] += 1
        f=1
        
print(t+f+c)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
1052886723843930404957062632108031737895681287625876308234921080294129856239950792572

Expected output:
194


Actual output:
195


Fixed submission (verdict: Accepted):
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)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = list(reversed([0]+list(map(int, input()))))
ans = 0
for i in range(len(n)):
    if n[i] < 5 or (n[i]==5 and n[i]<5):
        ans += n[i]
    else:
        ans += 10 - n[i]
        n[i+1] += 1
print(ans)

Failing test case input:
10778244626751572998201056843203243747792143146751269195602934770824379141896057649912893079276854

Expected output:
233


Actual output:
237


Fixed submission (verdict: Accepted):
n = list(reversed([0]+list(map(int, input()))))
ans = 0
for i in range(len(n)):
    if n[i] < 5 or (n[i]==5 and n[i+1]<5):
        ans += n[i]
    else:
        ans += 10 - n[i]
        n[i+1] += 1
print(ans)
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N = [int(x) for x in input()]
    dp0 = 0
    dp1 = 1
    for n in N:
        
        a = min(dp0 + n, dp1 + 10 - n)
        
        b = min(dp0 + n + 1, dp1 + 10 - (n+1))
        dp0, dp1 = a, b
        print(n, dp0, dp1)
    print(dp0)


if __name__ == '__main__':
    main()

Failing test case input:
239818233088120884498468411043636524061804551883788236263668790700484152911743168866

Expected output:
207


Actual output:
2 2 3
3 5 6
9 7 6
8 8 7
1 9 10
8 12 11
2 14 15
3 17 18
3 20 21
0 20 21
8 23 22
8 24 23
1 25 26
2 27 28
0 27 28
8 30 29
8 31 30
4 35 35
4 39 40
9 41 40
8 42 41
4 46 46
6 50 49
8 51 50
4 55 55
1 56 57
1 57 58
0 57 58
4 61 62
3 64 65
6 69 68
3 72 73
6 77 76
5 81 80
2 83 84
4 87 88
0 87 88
6 92 91
1 93 94
8 96 95
0 96 97
4 100 101
5 105 105
5 110 109
1 111 112
8 114 113
8 115 114
3 118 119
7 122 121
8 123 122
8 124 123
2 126 127
3 129 130
6 134 133
2 136 137
6 141 140
3 144 145
6 149 148
6 152 151
8 153 152
7 155 154
9 155 154
0 155 156
7 159 158
0 159 160
0 159 160
4 163 164
8 166 165
4 170 170
1 171 172
5 176 176
2 178 179
9 180 179
1 181 182
1 182 183
7 186 185
4 190 190
3 193 194
1 194 195
6 199 198
8 200 199
8 201 200
6 204 203
6 207 206
207


Fixed submission (verdict: Accepted):
def main():
    N = [int(x) for x in input()]
    dp0 = 0
    dp1 = 1
    for n in N:
        
        a = min(dp0 + n, dp1 + 10 - n)
        
        b = min(dp0 + n + 1, dp1 + 10 - (n+1))
        dp0, dp1 = a, b
        
    print(dp0)
 
 
if __name__ == '__main__':
    main()

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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] >=4:
                array[i+1] +=1
                
print( ans)


Failing test case input:
112951179209792539124037565379106363289174458264689808441706471502486080445534951144969723896577005

Expected output:
246


Actual output:
248


Fixed submission (verdict: Accepted):
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)
Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


N = input().strip()

s = 0
carry = 0
fives = 0
for c in reversed(N):
    x = int(c) + carry
    if x > 5:
        if fives > 0:
            x += 1
            s -= fives - 1
        s += 10 - x
        carry = 1
        fives = 0
    elif x == 5:
        s += x
        carry = 0
        fives += 1
    else:
        s += x
        carry = 0
        fives = 0
s += carry

print(s)


Failing test case input:
6319470984430112023155520909730723407854197212900196015122373967086541898670468068130907

Expected output:
189


Actual output:
190


Fixed submission (verdict: Accepted):


N = input().strip()

s = 0
carry = 0
five = False
for c in reversed(N):
    x = int(c) + carry
    if x == 5 and not five:
        s += x
        carry = 0
        five = True
    elif x >= 5:
        if five:
            x += 1
        s += 10 - x
        carry = 1
        five = False
    else:
        s += x
        carry = 0
        five = False
s += carry

print(s)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=input()
m=list(n)
l=[int(i) for i in m]
l.reverse()
l.append(0)
k=l
ans=0
for i in range(len(l)):
  if k[i]<=5:
    ans+=k[i]
  else:
    ans+=10-k[i]
    k[i+1]+=1
print(ans)

Failing test case input:
314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170

Expected output:
243

Actual output:
249


Fixed submission (verdict: Accepted):
n=input()
m=list(n)
l=[int(i) for i in m]
l.reverse()
l.append(0)
k=l
ans=0
for i in range(len(l)):
  if k[i]<5:
    ans+=k[i]
  elif k[i]==5:
    if k[i+1]>=5:
      k[i+1]+=1
    ans+=5
  else:
    ans+=10-k[i]
    k[i+1]+=1
print(ans)

Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect

S=input()
dig=len(S)

ans=0

b=0
for i in range(dig):
    a=int(S[dig-i-1])
    if a<=4:
        ans+=a
        b=0
    elif a>=6:
        ans+=(10-a)
        b=1
    else:
        if i==dig-1:
            ans+=5
            b=0
        else:
            if int(S[dig-i-2])>=5:
                b=1
            else:
                b=0
            ans+=5


        

if b==1:
    ans+=1

    
print(ans)
    
    

Failing test case input:
625194062587274125366911666694365620157285295199873104572635325193885831421199703585

Expected output:
219


Actual output:
226


Fixed submission (verdict: Accepted):
import bisect

S=input()
dig=len(S)

ans=0

b=0
for i in range(dig):
    a=int(S[dig-i-1])+b
    if a<=4:
        ans+=a
        b=0
    elif a>=6:
        ans+=(10-a)
        b=1
    else:
        if i==dig-1:
            ans+=5
            b=0
        else:
            if int(S[dig-i-2])>=5:
                b=1
            else:
                b=0
            ans+=5


        

if b==1:
    ans+=1

    
print(ans)
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = [0] + list(map(int, input())) + [0]
n = n[::-1]


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]))

Failing test case input:
407504418419319404483892872412128726502323410021882982269821146488442578928668339812974822005526619

Expected output:
230


Actual output:
229


Fixed submission (verdict: Accepted):
n = [0] + list(map(int, input())) + [0]
n = n[::-1]


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]))

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = list(map(int, list(input())))

x = 0
for i, k in enumerate(n):
    if i == len(n) - 1:
        q = 10
    else:
        q = 9
    if q - k + 1 + (i == 0) > k:
        x += k
    else:
        x += q - k + 1 + (i == 0)
print(x)


Failing test case input:
58927111396610822503999113526436588746143189811872145889707861286500815214872909760

Expected output:
180


Actual output:
188


Fixed submission (verdict: Accepted):
n = list(map(int, list(input())))
n = n[::-1] + [0]
d = len(n)

ans = 0
for i, k in enumerate(n):
    if k < 5:
        ans += k
    elif k == 5 and n[i + 1] < 5:
        ans += k
    else:
        ans += 10 - k
        n[i + 1] += 1
print(ans)

Problem: p02775
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=[int(x) for x in list(input()[::-1])]+[0]
ans = 0
step = 0
for i in range(len(n)-1):
  x = n[i]+step
  if x < 5 or (x==5 and n[i+1]<5):
    ans += x
    step = 0
  else:
    ans += 10 - x
    step = 1
print(ans)

Failing test case input:
6970937589065021770894270413067430155521391358278764894400209153369561375191611174323036054379

Expected output:
226


Actual output:
225


Fixed submission (verdict: Accepted):
n=[int(x) for x in list(input()[::-1])]+[0]
ans = 0
step = 0
for i in range(len(n)-1):
  x = n[i]+step
  if x < 5 or (x==5 and n[i+1]<5):
    ans += x
    step = 0
  else:
    ans += 10 - x
    step = 1
print(ans+step)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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

print(ans)


Failing test case input:
92169365473264969401297139600904300050133382153532281049570118403532801256585380413832810657140025

Expected output:
228


Actual output:
227


Fixed submission (verdict: Accepted):
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)
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = reversed("0" + input())
digit = next(N)
total = 0
carry = 0
for nextdigit in N:
    digit = int(digit) + carry
    if digit < 1:
        carry = 0
    elif digit < 5:
        total += digit
        carry = 0
    elif digit == 5:
        if int(nextdigit) < 5:
            total += digit
            carry = 0
        else:
            total += 10 - digit
            carry = 1
    elif digit < 10:
        total += 10 - digit
        carry = 1
    else:
        carry = 1
    digit = nextdigit

print(total)


Failing test case input:
95708211113760965440887073802791175012976779786011249825704430349998074877261347106

Expected output:
177


Actual output:
176


Fixed submission (verdict: Accepted):
N = reversed("0" + input())
digit = next(N)
total = 0
carry = 0
for nextdigit in N:
    digit = int(digit) + carry
    if digit < 5:
        total += digit
        carry = 0
    elif digit == 5:
        if int(nextdigit) < 5:
            total += digit
            carry = 0
        else:
            total += 10 - digit
            carry = 1
    else:
        total += 10 - digit
        carry = 1
    digit = nextdigit

print(total + carry)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
L = len(N)
ans = 0
t = 0
for i in range(L-1,-1,-1):
    n = int(N[i])+t
    if n <= 5:
        ans += n
        t = 0
    else:
        t = 1
        ans += 10-n
if t==1:
    ans += 1
print(ans)

Failing test case input:
1330006711630442707717890285579038615422527217209570711462647791260096589616039973056164784724079

Expected output:
224


Actual output:
227


Fixed submission (verdict: Accepted):
N = input()
L = len(N)
ans = 0
t = 0
for i in range(L-1,-1,-1):
    n = int(N[i])+t
    if n == 5:
        if i > 0 and int(N[i-1]) >= 5:
            ans += 10-n
            t = 1
            continue
    if n <= 5:
        ans += n
        t = 0
    else:
        t = 1
        ans += 10-n
if t==1:
    ans += 1
print(ans)

Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = list(input())
n = [int(i) for i in n]
n.reverse()
l = len(n)
ans = 0
for i in range(l):
    if n[i]>5:
        if i!=l-1:
            n[i+1] += 1
        else:
            ans += 1
        ans += 10-n[i]
    else:
        ans += n[i]
print(ans)

Failing test case input:
3029165028855265861064957503518699141718370197384262165027208857833010479

Expected output:
171


Actual output:
177


Fixed submission (verdict: Accepted):
n = list(input())
n = [int(i) for i in n]
n.reverse()
l = len(n)
ans = 0
for i in range(l-1):
    if (n[i]==5 and n[i+1]>=5) or n[i]>5:
        n[i+1] += 1
        ans += 10-n[i]
    else:
        ans += n[i]
ans += 11-n[-1] if n[-1]>5 else n[-1]
print(ans)
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = list(map(int, list(input())))
ans = 0
c_in = 0

while n:
    s = n.pop()

    if 0 <= s <= 4:
        ans += s + c_in
        c_in = 0
    elif s == 5:
        if c_in:
            ans += 4
        else:
            ans += s
    elif 6 <= s <= 9:
        ans += 10 - s - c_in
        c_in = 1


ans += c_in
print(ans)



Failing test case input:
3662752567870943894500519117429600511362501728702138430022877893213312628318030925892120

Expected output:
196


Actual output:
197


Fixed submission (verdict: Accepted):
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)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
count = 0
prev = 0
for i in range(len(N)):
  if 0 <= int(N[i]) + prev < 6:
    count += int(N[i]) + prev
    prev = 0
  elif 6 <= int(N[i]) + prev <= 9:
    count += 10 - (int(N[i]) + prev)
    prev = 1
  else:
    prev = 1
count = count + prev
print(count)

Failing test case input:
23176382616528747370066658017543196046021467459861679562986783430104667575603656483991005432205633

Expected output:
253


Actual output:
258


Fixed submission (verdict: Accepted):
N = input()
count = 0
prev = 0
for i in range(len(N)):
  if 0 <= int(N[i]) + prev < 5:
    count += int(N[i]) + prev
    prev = 0
  elif 6 <= int(N[i]) + prev <= 9:
    count += 10 - (int(N[i]) + prev)
    prev = 1
  elif int(N[i]) + prev == 10:
    prev = 1
  else:
    if (i < (len(N) - 1) and int(N[i+1]) < 5) or i == len(N) - 1:
      count += 5
      prev = 0
    else:
      count += 5
      prev = 1
count = count + prev
print(count)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
L = len(N)
ans = 0
t = 0
for i in range(L-1,-1,-1):
    n = int(N[i])+t
    if n <= 5:
        ans += n
        t = 0
    else:
        t = 1
        ans += 10-n
if n == 10:
    ans += 1
print(ans)

Failing test case input:
15406457055638114443779945037629915854686048560792750012085185646189696449917675473572101534845973

Expected output:
257


Actual output:
266


Fixed submission (verdict: Accepted):
N = input()
L = len(N)
ans = 0
t = 0
for i in range(L-1,-1,-1):
    n = int(N[i])+t
    if n == 5:
        if i > 0 and int(N[i-1]) >= 5:
            ans += 10-n
            t = 1
            continue
    if n <= 5:
        ans += n
        t = 0
    else:
        t = 1
        ans += 10-n
if t==1:
    ans += 1
print(ans)
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = input()
n = n[::-1]
n += '0'
cnt = 0
tmp = 0
print(n)
for i in range(len(n)):
    a = int(n[i])
    a += tmp
    if a == 5:
        cnt += a
        if int(n[i + 1]) >= 5:
            tmp = 1
        else:
            tmp = 0
    elif a < 5:
        cnt += a
        tmp = 0
    else:
        cnt += 10 - a
        tmp = 1
print(cnt)

Failing test case input:
3662752567870943894500519117429600511362501728702138430022877893213312628318030925892120

Expected output:
196


Actual output:
02129852903081382621331239877822003483120782710526311500692471191500549834907876525726630
196


Fixed submission (verdict: Accepted):
n = input()
n = n[::-1]
n += '0'
cnt = 0
tmp = 0
for i in range(len(n)):
    a = int(n[i])
    a += tmp
    if a == 5:
        cnt += a
        if int(n[i + 1]) >= 5:
            tmp = 1
        else:
            tmp = 0
    elif a < 5:
        cnt += a
        tmp = 0
    else:
        cnt += 10 - a
        tmp = 1
print(cnt)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



def solve(*args: str) -> str:
    n = int(args[0])

    count = 0
    c = 0
    for i in map(int, reversed(str(n))):
        count += min(i+c, 10-i-c)
        c = 1 if 10-i-c < i+c else 0
    count += c
    return str(count)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Failing test case input:
476640020082194381531155118436783393866726953614433851622190777875571135215042541028243752681838573

Expected output:
259


Actual output:
262


Fixed submission (verdict: Accepted):



def solve(*args: str) -> str:
    N = list(map(int, args[0]))

    a, b = 0, 1
    for n in N:
        a, b = min(b+(10-n), a+n), min(b+(9-n), a+n+1)
    return str(a)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = list(input())
ans = 0
upped = False

for num in reversed(N):
    num = int(num)
    if upped:
        if num + 1 >5:
            ans += ((10-num))
            upped = True
        else:
            ans += num - 1
            upped = False
    else:
        if num >5:
            ans += (1+(10-num))
            upped = True
        else:
            ans += num
            upped = False
            
print(ans)

Failing test case input:
92169365473264969401297139600904300050133382153532281049570118403532801256585380413832810657140025

Expected output:
228


Actual output:
226


Fixed submission (verdict: Accepted):

N = list(input())
N = [int(n) for n in N]
N.insert(0, 0)
len_N = len(N)
ans = 0

for i in reversed(range(len_N)):
    num = int(N[i])
    if num == 10:
        N[i-1] += 1
    
    elif num==5:
        if int(N[i-1])>=5:
            ans += 5
            N[i-1] += 1
        else:
            ans += 5
    
    elif num >5:
        ans += (10-num)
        N[i-1] += 1
    else:
        ans += num

print(ans)
Problem: p02775
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    S = list( map( int, list( input())))
    N = len(S)
    dp = [[0,0] for _ in range(N+1)]
    dp[0][1] = 1
    for i in range(N):
        s = S[i]
        dp[i+1][0] = min(dp[i][0] + s, dp[i][1]+s)
        dp[i+1][1] = min(dp[i][0] + 11-s, dp[i][1]+9-s)
        
        
    print( min(dp[N][0], dp[N][1]))
if __name__ == '__main__':
    main()


Failing test case input:
6970937589065021770894270413067430155521391358278764894400209153369561375191611174323036054379

Expected output:
226


Actual output:
225


Fixed submission (verdict: Accepted):
def main():
    S = list( map( int, list( input())))
    N = len(S)
    dp = [[0,0] for _ in range(N+1)]
    dp[0][1] = 2
    for i in range(N):
        s = S[i]
        dp[i+1][0] = min(dp[i][0] + s, dp[i][1]+s)
        dp[i+1][1] = min(dp[i][0] + 11-s, dp[i][1]+9-s)
        
        
        
    print( min(dp[N][0], dp[N][1]))
if __name__ == '__main__':
    main()

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = list(map(int, input())) + [0]
n = n[::-1]


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]))

Failing test case input:
95708211113760965440887073802791175012976779786011249825704430349998074877261347106

Expected output:
177


Actual output:
175


Fixed submission (verdict: Accepted):
n = [0] + list(map(int, input())) + [0]
n = n[::-1]


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]))

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
21859110864590199198540714463744578129645949823640150386511332904564103343275159478837648186452280

Expected output:
248


Actual output:
249


Fixed submission (verdict: Accepted):
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)
Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()

count = 0
for i in range(len(N)-1, -1, -1):
    if int(N[i]) <= 4:
        count += int(N[i])
    else:
        count += 10 - int(N[i])

if int(N[-1]) == 0:
    count -= 1
print(count + 1)


Failing test case input:
7080342512965218976697912729659556758411438217421806030246142237833070455171621700559274830690093

Expected output:
231


Actual output:
234


Fixed submission (verdict: Accepted):
N = list(input())
N.insert(0, '0')
count = 0
for i in range(len(N)-1, -1, -1):
    if int(N[i]) <= 4:
        count += int(N[i])
    elif int(N[i]) == 5 and int(N[i-1]) <= 4:
        count += int(N[i])
    else:
        count += 10 - int(N[i])
        N[i-1] = str(int(N[i-1]) + 1)

print(count)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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] >=4:
                array[i+1] +=1
                
print( ans)


Failing test case input:
108928980065873105078814085813029433701360267947813051577719632838904263506056818405

Expected output:
187


Actual output:
188


Fixed submission (verdict: Accepted):
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)

Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
N = list(str(N))
N = tuple(map(int, N))

ans = 0
flag = False
flag5 = False
for i, x in enumerate(reversed(N)):
    x = N[i]
    if flag or (flag5 and x >= 5):
        x += 1
    flag5 = False
    flag = False
    if x > 5:
        ans += (10 - x)
        flag = True
        if i == 0:
            ans += 1
    else:
        ans += x
    if x == 5:
        flag5 = True
print(ans)


Failing test case input:
35777234074262543307164356835532933969592337023223887910148926519144342235064759911912928955956958

Expected output:
249


Actual output:
248


Fixed submission (verdict: Accepted):
N = tuple(input())
N = tuple(map(int, N))

ans = 0
flag = False
flag5 = False
i = len(N)-1


for x in reversed(N):
    if flag or (flag5 and x >= 5):
        x += 1
    flag5 = False
    flag = False
    if x > 5:
        ans += (10 - x)
        flag = True
        if i == 0:
            ans += 1
    else:

        ans += x
    if x == 5:
        flag5 = True
    i -= 1

print(ans)
Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = list(input())
n = [int(i) for i in n]
n.reverse()
l = len(n)
ans = 0
for i in range(l-1):
    if (n[i]==5 and n[i+1]>=5) or n[i]>5:
        n[i+1] += 1
        ans += 10-n[i]
    else:
        ans += n[i]
ans += 9-n[-1] if n[-1]>5 else n[-1]
print(ans)


Failing test case input:
774047226080128130891487643004606511507698191084132904950256971520940546016417

Expected output:
181


Actual output:
179


Fixed submission (verdict: Accepted):
n = list(input())
n = [int(i) for i in n]
n.reverse()
l = len(n)
ans = 0
for i in range(l-1):
    if (n[i]==5 and n[i+1]>=5) or n[i]>5:
        n[i+1] += 1
        ans += 10-n[i]
    else:
        ans += n[i]
ans += 11-n[-1] if n[-1]>5 else n[-1]
print(ans)

Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

list_n=[0]+list(map(int,input()))
l = len(list_n)

pay=0
back=0
for i in range(l-1,-1,-1):
    
    now = list_n[i]
    if now <=5:
        pay+=now
        list_n[i]=0
    elif now==10:
        list_n[i]=0
        list_n[i-1] +=1
    else:
        back+=10-now
        list_n[i]=0
        list_n[i-1] +=1
print(pay+back)

Failing test case input:
95708211113760965440887073802791175012976779786011249825704430349998074877261347106

Expected output:
177


Actual output:
180


Fixed submission (verdict: Accepted):
list_n=[0]+list(map(int,input()))
l = len(list_n)

pay=0
back=0
for i in range(l-1,-1,-1):
    
    now = list_n[i]
    if now in [0,1,2,3,4] or (now == 5 and list_n[i-1]<5):
        pay+=now
        list_n[i]=0
    elif now in [6,7,8,9] or (now == 5 and list_n[i-1]>=5):
        back+=10-now
        list_n[i]=0
        list_n[i-1] +=1
    elif now==10:
        list_n[i]=0
        list_n[i-1] +=1
print(pay+back)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = input()
a = 0
b = 0
for s in n:
  v = int(s)
  a_ = min(a + v, b + v)
  b_ = min(a + 10 - v + 1, b + 10 - v + 1 - 2)
  a = a_
  b = b_
  
print(min(a, b))

Failing test case input:
55281069069669140036096567167987803917949900262269041019580432304146529155237957819637499367

Expected output:
204


Actual output:
202


Fixed submission (verdict: Accepted):
n = input()
a = 0
b = 2
for s in n:
  v = int(s)
  a_ = min(a + v, b + v)
  b_ = min(a + 10 - v + 1, b + 10 - v + 1 - 2)
  a = a_
  b = b_
  
print(min(a, b))
Problem: p02775
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = tuple(input())
N = tuple(map(int, N))

ans = 0
flag = False
flag5 = False
for i, x in enumerate(reversed(N)):
    x = N[i]
    if flag or (flag5 and x >= 5):
        x += 1
    flag5 = False
    flag = False
    if x > 5:
        ans += (10 - x)
        flag = True
        if i == 0:
            ans += 1
    else:
        ans += x
    if x == 5:
        flag5 = True
print(ans)

Failing test case input:
407504418419319404483892872412128726502323410021882982269821146488442578928668339812974822005526619

Expected output:
230


Actual output:
229


Fixed submission (verdict: Accepted):
N = tuple(input())
N = tuple(map(int, N))

ans = 0
flag = False
flag5 = False
i = len(N)-1


for x in reversed(N):
    if flag or (flag5 and x >= 5):
        x += 1
    flag5 = False
    flag = False
    if x > 5:
        ans += (10 - x)
        flag = True
        if i == 0:
            ans += 1
    else:

        ans += x
    if x == 5:
        flag5 = True
    i -= 1

print(ans)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = list(input())
n.insert(0, '0')

ans = 0
for i in range(len(n)-1, -1, -1):
    if n[i] == '0':
        pass
    elif int(n[i]) <= 5:
        ans += int(n[i])
    else:
        ans += 10 - int(n[i])
        n[i-1] = str(int(n[i-1]) + 1)

print(ans)



Failing test case input:
10778244626751572998201056843203243747792143146751269195602934770824379141896057649912893079276854

Expected output:
233


Actual output:
238


Fixed submission (verdict: Accepted):
n = list(input())
n.insert(0, '0')

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

print(ans)

Problem: p02775
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
l = len(s)
cnt = 0
ls = []
ls.append(0)
ls.append(0)
for i in range(l):
    ls.append(int(s[i]))
for i in range(l+1):
    if 6<= ls[-i-1] <=10:
        ls[-i-1] = 10 -ls[-i-1] 
        ls[-i-2] += 1 
print(sum(ls))


Failing test case input:
476640020082194381531155118436783393866726953614433851622190777875571135215042541028243752681838573

Expected output:
259


Actual output:
262


Fixed submission (verdict: Accepted):
s = input()
l = len(s)
cnt = 0
ls = []
ls.append(0)
ls.append(0)
for i in range(l):
    ls.append(int(s[i]))
for i in range(l+1):
    if 6<= ls[-i-1] or (ls[-i-1] ==5 and ls[-i-2] >=5):
        ls[-i-1] = 10 -ls[-i-1] 
        ls[-i-2] += 1 
print(sum(ls))