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

Fixed submission:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
if len(s) < 26:
    for i in range(26):
        tmp = chr(i + ord('a'))
        if not tmp in s:
            print(s + tmp)
            exit()
if len(set(s)) == 26:
    for i in reversed(range(len(s))):
        for j in range(ord(s[i]) + 1, ord('z') + 1):
            if not chr(j) in s[:i]:
                print(s[:i] + chr(j))
                exit()
    print(-1)
    exit()
ans = [i for i in s]
for i in reversed(range(len(s))):
    tmp = chr(ans[i] + 1)
    if not tmp in ans:
        ans[i] = tmp
    print(''.join(ans))

Buggy submission (verdict: Runtime Error):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
if len(s) < 26:
    for i in range(26):
        tmp = chr(i + ord('a'))
        if not tmp in s:
            print(s + tmp)
            exit()
else:
    for i in reversed(26):
        for j in range(ord(s[i]) + 1, ord('z') + 1):
            if not chr(j) in s[:i]:
                print(s[:i] + chr(j))
                exit()
    print(-1)
    exit()
Problem p03400 (python)

Fixed submission:
n = int(input())
d,x = map(int,input().split())
a = []
for i in range(n):
    a.append(int(int(input())))

num = []
for i in range(n):
    num.append(0)

for i in range(n):
    num[i] = (d - 1) // a[i] + 1
#print(num)

ans = x
for i in range(n):
    ans += num[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
d,x = map(int,input().split())
a = []
for i in range(n):
    a.append(int(int(input())))

for i in range(n):
    num.append((d - 1) // a[i] + 1)
#print(num)

ans = x
for i in range(n):
    ans += num[i]
print(ans)
Problem p03408 (python)

Fixed submission:
from collections import Counter
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t =[input() for _ in range(m)]
sc=Counter(s)
tc=Counter(t)
u=list(set(s)&set(t))
ans=0
for i in u:
    ans=max(ans,max(0,sc[i]-tc[i]))
v=list(set(s)-set(u))
for i in v:
    ans=max(ans,sc[i])
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t =[input() for _ in range(m)]
sc=Counter(s)
tc=Counter(t)
u=list(set(s)&set(t))
ans=0
for i in u:
    ans=max(ans,max(0,sc[i]-st[i]))
v=list(set(s)-set(u))
for i in v:
    ans=max(ans,sc[i])
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t =[input() for _ in range(m)]
sc=Counter(s)
tc=Counter(t)
u=list(set(s)&set(t))
ans=n
for i in u:
    ans-=sc[i]
    ans+=max(0,sc[i]-st[i])
print(ans)
Problem p03457 (python)

Fixed submission:
n = int(input())
pret = 0
prex = 0
prey = 0
flag = True
for i in range(n):
    t,x,y = map(int,input().split())
    if flag:
        tmp = t - pret - abs(x - prex) - abs(y - prey)
        #print(t, x, y, tmp)
        if tmp >= 0 and tmp % 2 == 0:
            pret = t
            prex = x
            prey = y
        else:
            flag = False
if flag:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
pret = 0
prex = 0
prey = 0
for i in range(n):
    t,x,y = map(int,input().split())
    if flag:
        tmp = t - pret - abs(x - prex) - abs(y - prey)
        #print(t, x, y, tmp)
        if tmp >= 0 and tmp % 2 == 0:
            pret = t
            prex = x
            prey = y
        else:
            print('No')
            sys.exit()
print('Yes')
Problem p03627 (python)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
b = list(set(a))
b.sort(reverse=True)
l = len(b)
c = [0 for _ in range(l)]
prei = b[0]
j = 0
for i in a:
    if i != prei:
        j += 1
    c[j] += 1
    prei = i
x = []
for i in range(l):
    if c[i] >= 2:
        x.append(b[i])
if len(x) >= 2:
    ans = x[0] * x[1]
    for i in range(len(x)):
        if c[i] >= 4:
            ans  = max(ans, x[i] ** 2)
    print(ans)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
b = Counter(a)
c = sorted(list(set(a)), reverse=True)
ans = []
for i in c:
    if b[i] >= 2:
        ans.append(i)
    if b[i] >= 4:
        ans.append(i)
    if len(ans) >= 2:
        break
debug(ans)
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)
Problem p03679 (python)

Fixed submission:
#https://atcoder.jp/contests/abc065/tasks/abc065_a

x,a,b = map(int,input().split())

if b-a > x:
    print('dangerous')
elif b-a <= x and b-a > 0:
    print('safe')
else:
    print('delicious')

Buggy submission (verdict: Runtime Error):
#https://atcoder.jp/contests/abc065/tasks/abc065_a

x,a,b = map(int,input().split()))

if b-a > x:
    print('dangerous')
elif b-a <= x and b-a > 0:
    print('safe')
else:
    print('delicious')
Problem p03681 (python)

Fixed submission:
import math
mod=10**9+7
factorial=[1 for _ in range(10**5+10)]
for i in range(1, 10**5+10):
    factorial[i]=i*factorial[i-1] % mod
n,m=map(int,input().split())
if abs(n-m)>1:
    print(0)
elif abs(n-m)==0:
    print(2*factorial[n]*factorial[m]%mod)
else:
    print(factorial[n]*factorial[m]%mod)

Buggy submission (verdict: Runtime Error):
import math
mod=10**9+7
factorial=[1 for _ in range(10**5+10)]
for i in range(1, 10**5+10):
    factorial[i]=i*factorial[i-1] % mod
n,m=map(int,input().split())
if abs(n-m)>1:
    print(0)
elif abs(n-m)==0:
    print(2*factorial[n]*factorial[m])
else:
    print(factorial[n]*math.factorial[m])
Problem p03695 (python)

Fixed submission:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
a.sort()
arr = [0, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200]
r = -1
for i in range(len(arr)):
    if a[0] < arr[i]:
        r = i
        break
ans = 1 if r != -1 else 0
ans2 = 0
for i in range(n):
    if a[i] >= arr[r]:
        r = -1
        for j in range(len(arr)):
            if a[i] < arr[j]:
                r = j
                break
        if r == -1:
            ans2 += 1
        else:
            ans += 1
print(ans if ans > 0 else 1, ans + ans2)

Buggy submission (verdict: Runtime Error):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
arr = []
plus = 0
for i in range(n):
    flag = True
    for j in range(1, 9):
        if a[i] < j * 400:
            if not j in arr:
                arr.append(j)
            flag = False
            break
    if flag:
        plus += 1
debug(len(set(arr)), plus, arr)
ansmx = min(len(set(arr)) + plus, 8)
ansmn = max(1, len(set(arr)))
print(ansmn, ansmx)
Problem p03730 (python)

Fixed submission:
def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x

a,b,c = map(int,input().split())
if a == b:
    if c % a == 0:
        print('YES')
    else:
        print('NO')
else:
    if c % gcd(a, b) == 0:
        print('YES')
    else:
        print('NO')

Buggy submission (verdict: Runtime Error):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

a, b, c = MAP()
d = a % b
if c % d == 0:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

a, b, c = MAP()
d = a % b
if c % d == 0:
    print('YES')
else:
    print('NO')
Problem p03854 (python)

Fixed submission:
import sys
s = str(input())
i = 0
while i < len(s):
    if i + 5 <= len(s) and s[i:i+5] == 'dream': #now dream or dreamer
        if i + 6 < len(s) and s[i+5] == 'e' and s[i+6] == 'r': #now dreamer or now dream and next is erase or eraser
            if i + 7 < len(s) and s[i+7] == 'a': #next erase or eraser, now dream
                i += 5
            else: #now dreamer
                i += 7
        else: #now dream
            i += 5
    elif i + 5 <= len(s) and s[i:i+5] == 'erase':
        if i + 5 < len(s) and s[i+5] == 'r': #now eraser
            i += 6
        else: #now erase
            i += 5
    else:
        print('NO')
        sys.exit()
print('YES')

Buggy submission (verdict: Runtime Error):
import sys
s = str(input())
i = 0
while i < len(s):
    if i + 5 <= len(s) and s[i:i+5] == 'dream': #now dream or dreamer
        if i + 6 < len(s) and s[i+5] == 'e' and s[i+6] == 'r': #now dreamer or now dream and next is erase or eraser
            if s[i+7] == 'a': #next erase or eraser, now dream
                i += 5
            else: #now dreamer
                i += 7
        else: #now dream
            i += 5
    elif i + 5 <= len(s) and s[i:i+5] == 'erase':
        if i + 5 < len(s) and s[i+5] == 'r': #now eraser
            i += 6
        else: #now erase
            i += 5
    else:
        print('NO')
        sys.exit()
print('YES')

Buggy submission (verdict: Runtime Error):
import sys
s = str(input())
i = 0
while i < len(s):
    if i + 5 <= len(s) and s[i:i+5] == 'dream': #now dream or dreamer
        if i + 6 <= len(s) and s[i+5] == 'e' and s[i+6] == 'r': #now dreamer or now dream and next is erase or eraser
            if s[i+7] == 'a': #next erase or eraser, now dream
                i += 5
            else: #now dreamer
                i += 7
        else: #now dream
            i += 5
    elif i + 5 <= len(s) and s[i:i+5] == 'erase':
        if i + 5 <= len(s) and s[i+5] == 'r': #now eraser
            i += 6
        else: #now erase
            i += 5
    else:
        print('NO')
        sys.exit()
print('YES')
Problem p02609 (python)

Fixed submission:
def modpow(val, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = (ret * val) % mod
        val = (val * val) % mod
        n = n >> 1
    return ret


def calc(val, my_dict, cnt):
    num_one = bin(val).count('1')
    if val in my_dict:
        return cnt + my_dict[val]
    else:
        if num_one == 0:
            return cnt
        nex = val % num_one
        ret = calc(nex, my_dict, cnt+1)
        my_dict[val] = ret - cnt
        return ret


n = int(input())
x = input()
tmp = list(x)
my_dict = dict()

num_one = tmp.count('1')
num_one_plus = num_one + 1
num_one_minus = num_one - 1

modsum_plus = 0
modsum_minus = 0
for i in range(1, n+1):
    if tmp[-i] == '1':
        modsum_plus += modpow(2, i-1, num_one_plus) % num_one_plus
        if num_one_minus != 0:
            modsum_minus += modpow(2, i-1, num_one_minus) % num_one_minus

for i in range(n):
    if num_one == 1 and tmp[i] == '1':
        print(0)
        continue
    if tmp[i] == '0':
        val = (modsum_plus + modpow(2, n-i-1, num_one_plus)) % num_one_plus
    else:
        if num_one_minus != 0:
            val = (modsum_minus - modpow(2, n-i-1, num_one_minus)) % num_one_minus
        else:
            val = 0
    if val != 0:
        print(calc(val, my_dict, 1))
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
def modpow(val, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = (ret * val) % mod
        val = (val * val) % mod
        n = n >> 1
    return ret


def calc(val, my_dict, cnt):
    num_one = bin(val).count('1')
    if val in my_dict:
        return cnt + my_dict[val]
    else:
        if num_one == 0:
            return cnt
        nex = val % num_one
        ret = calc(nex, my_dict, cnt+1)
        my_dict[val] = ret - cnt
        return ret


n = int(input())
x = input()
tmp = list(x)
my_dict = dict()

num_one = tmp.count('1')
num_one_plus = num_one + 1
num_one_minus = num_one - 1

modsum_plus = 0
modsum_minus = 0
for i in range(1, n+1):
    if tmp[-i] == '1':
        modsum_plus += modpow(2, i-1, num_one_plus) % num_one_plus
        modsum_minus += modpow(2, i-1, num_one_minus) % num_one_minus

for i in range(n):
    if tmp[i] == '0':
        val = (modsum_plus + modpow(2, n-i-1, num_one_plus)) % num_one_plus
    else:
        val = (modsum_minus - modpow(2, n-i-1, num_one_minus)) % num_one_minus
    print(calc(val, my_dict, 1))
Problem p02642 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

cand = set(a)

exist = set()
dup = set()
for item in a:
    if item in exist:
        dup.add(item)
    else:
        exist.add(item)

dame_set = set()

a.sort()
ret = 0

for val in a:
    if val in dup:
        if val in dame_set:
            continue
        else:
            i = 1
            cnt = 10 ** 6 // val
            while i <= cnt:
                tmp = i * val
                if tmp in cand:
                    dame_set.add(tmp)
                i += 1
    else:
        if val in dame_set:
            continue
        else:
            ret += 1
            i = 1
            cnt = 10 ** 6 // val
            while i <= cnt:
                tmp = i * val
                if tmp in cand:
                    dame_set.add(tmp)
                i += 1

print(ret)

Buggy submission (verdict: Runtime Error):
import sympy

n = int(input())
a = list(map(int, input().split()))
cand = set(a)

exist = set()
dup = set()
for item in a:
    if item in exist:
        dup.add(item)
    else:
        exist.add(item)

ret = 0

for i in range(n):
    is_ok = True
    val = a[i]
    if val in dup:
        continue
    divs = sympy.divisors(val)
    for item in divs:
        if item == val:
            continue
        elif item in cand:
            is_ok = False
            break
    if is_ok:
        ret += 1

print(ret)
Problem p02690 (python)

Fixed submission:
x = int(input())

my_dict = dict()

for i in range(1000):
    my_dict[i**5] = i

for i in range(-1000, 1000):
    target = x + (i ** 5)
    if (- target) in my_dict:
        print(-my_dict[-target], i)
        exit()
    elif target in my_dict:
        print(my_dict[target], i)
        exit()

Buggy submission (verdict: Runtime Error):
x = int(input())

my_dict = dict()

for i in range(1000):
    my_dict[i**5] = i

for i in range(-1000, 1000):
    target = x + (i ** 5)
    if (- target) in my_dict:
        print(-my_dict[target], i)
        exit()
    elif target in my_dict:
        print(my_dict[target], i)
        exit()

Buggy submission (verdict: Runtime Error):
x = int(input())

my_dict = dict()

for i in range(10 ** 6):
    my_dict[i**5] = i

for i in range(-10 ** 4, 10 ** 4):
    target = x + (i ** 5)
    if (- target) in my_dict:
        print(-my_dict[target], i)
        exit()
    elif target in my_dict:
        print(my_dict[target], i)
        exit()

Buggy submission (verdict: Runtime Error):
x = int(input())

my_dict = dict()

for i in range(10 ** 6):
    my_dict[i**5] = i

for i in range(-10**2, 10 ** 2):
    target = x + (i ** 5)
    if (- target) in my_dict:
        print(-my_dict[target], i)
        exit()
    elif target in my_dict:
        print(my_dict[target], i)
        exit()

Buggy submission (verdict: Runtime Error):
x = int(input())

my_dict = dict()

for i in range(10 ** 5):
    my_dict[i**5] = i

for i in range(-10 ** 5, 10 ** 5):
    target = x + (i ** 5)
    if (- target) in my_dict:
        print(-my_dict[target], i)
        exit()
    elif target in my_dict:
        print(my_dict[target], i)
        exit()

Buggy submission (verdict: Runtime Error):
x = int(input())

my_dict = dict()

for i in range(10 ** 5):
    my_dict[i**5] = i

for i in range(-10 ** 5, 10 ** 5):
    target = x + (i ** 5)
    if target in my_dict:
        print(my_dict[target], i)
        exit()
    elif (- target) in my_dict:
        print(-my_dict[target], i)
        exit()

Buggy submission (verdict: Runtime Error):
x = int(input())

my_dict = dict()

for i in range(10 ** 5):
    my_dict[i**5] = i

for i in range(-10 ** 5, 10 ** 5):
    target = x + (i ** 5)
    if target in my_dict:
        print(my_dict[target], i)
        exit()
    elif (- target) in my_dict:
        print(-my_dict[target], i)
        exit()

Buggy submission (verdict: Runtime Error):
x = int(input())

my_dict = dict()

for i in range(10 ** 5):
    my_dict[i**5] = i

for i in range(-10 ** 5, 10 ** 5):
    target = x + (i ** 5)
    if target in my_dict:
        print(my_dict[target], i)
        exit()
    elif - target in my_dict:
        print(-my_dict[target], i)
        exit()
Problem p02722 (python)

Fixed submission:
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


n = int(input())

tmp = n - 1
ret = len(make_divisors(tmp)) - 1

tmplen = make_divisors(n)

for item in tmplen:
    if item == 1:
        continue
    val = n
    while True:
        if val % item == 0:
            val = val // item
        else:
            if val % item == 1:
                ret += 1
            break

print(ret)

Buggy submission (verdict: Runtime Error):
import sympy

n = int(input())

tmp = n - 1
ret = len(sympy.divisors(tmp)) - 1

tmplen = sympy.divisors(n)

for item in tmplen:
    if item == 1:
        continue
    val = n
    while True:
        if val % item == 0:
            val = val // item
        else:
            if val % item == 1:
                ret += 1
            break

print(ret)
Problem p02775 (python)

Fixed submission:
n = input()

dp = [[0] * 2 for _ in range(2)]

digit = int(n[-1])

dp[0][0] = 10 - digit
dp[0][1] = digit

for i in range(1, len(n) + 1):
    if i == len(n):
        digit = 0
    else:
        digit = int(n[-i-1])

    if i % 2 == 0:
        dp[0][0] = min(dp[1][0] + 10 - digit - 1, dp[1][1] + 10 - digit)
        dp[0][1] = min(dp[1][0] + digit + 1, dp[1][1] + digit)
    else:
        dp[1][0] = min(dp[0][0] + 10 - digit - 1, dp[0][1] + 10 - digit)
        dp[1][1] = min(dp[0][0] + digit + 1, dp[0][1] + digit)


print(min(dp[0][1], dp[1][1]))

Buggy submission (verdict: Runtime Error):
n = input()

dp = [[0] * 2 for _ in range(100000)]

digit = int(n[-1])

dp[0][0] = 10 - digit
dp[0][1] = digit

for i in range(1, len(n) + 1):
    if i == len(n):
        digit = 0
    else:
        digit = int(n[-i-1])
    dp[i][0] = min(dp[i-1][0] + 10 - digit - 1, dp[i-1][1] + 10 - digit)
    dp[i][1] = min(dp[i-1][0] + digit + 1, dp[i-1][1] + digit)


print(min(dp[len(n)][1], dp[len(n)-1][1]))

Buggy submission (verdict: Runtime Error):
n = input()

dp = [[0] * 2 for _ in range(101)]

digit = int(n[-1])

dp[0][0] = 10 - digit
dp[0][1] = digit

for i in range(1, len(n) + 1):
    if i == len(n):
        digit = 0
    else:
        digit = int(n[-i-1])
    dp[i][0] = min(dp[i-1][0] + 10 - digit - 1, dp[i-1][1] + 10 - digit)
    dp[i][1] = min(dp[i-1][0] + digit + 1, dp[i-1][1] + digit)


print(min(dp[len(n)][1], dp[len(n)-1][1]))