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

Fixed submission:
import math

import numpy as np
import scipy as scp

# 入力の受け取り
s,t = input().split()
a,b = map(int,input().split())
u = input()

dic = {s:a,t:b}

if u == s:
    dic[s] -= 1
else:
    dic[t] -= 1

print(dic[s],dic[t])

Buggy submission (verdict: Runtime Error):
import math

import numpy as np
import scipy as scp
import sklearn as skl

# 入力の受け取り
s,t = input().split()
a,b = map(int,input().split())
u = input()

dic = {s:a,t:b}

if u == s:
    dic[s] -= 1
else:
    dic[t] -= 1

print(dic[s],dic[t])
Problem p02891 (python)

Fixed submission:
S = input()
K = int(input())

if len(S) == 1:
    print(K//2)
    exit()

if len(set(S)) == 1:
    ans = len(S)*K//2
    print(ans)
    exit()

if S[0] != S[-1]:
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    print(ans)
    exit()
elif S[0] == S[-1]:
    A = 0
    B = 0
    for s in S:
        if s == S[0]:
            A+=1
        else:
            break
    for s in S[::-1]:
        if s == S[0]:
            B+=1
        else:
            break
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    ans = ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1)
    print(ans)
    exit()

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

if len(S) == 1:
    print(K//2)
    exit()

if len(S)%2 == 0:
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    if S[0] == tmp:
        ans += 1
    ans *= K
    print(ans)
    exit()
else:
    len1 = len(S)-1
    S = S*2
    ans = 0
    tmp = ""
    for i in range(len(S)):
        if S[i] == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = S[i]
        if i == len1:
            num = ans
    if S[0] == tmp:
        ans += 1
    d,m = divmod(K,2)
    ans = ans*d + num*m
    print(ans)
    exit()
Problem p02629 (python)

Fixed submission:
import math
n = int(input())
ls = "abcdefghijklmnopqrstuvwxyz"
cnt = 0
base = 26
while n >= base ** cnt:
    n -= base ** cnt
    cnt += 1
ans = ""
#print(cnt, n)
for i in range(cnt-1, -1, -1):
    res = n // (base ** i)
    ans += ls[res]
    n -= base ** i * res
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
ls = "abcdefghijklmnopqrstuvwxyz"
cnt = 0

while 26 ** (cnt + 1) < 25 * n / 26 + 1:
    cnt += 1
ans = ""
#print(cnt, n)
n -= 1
for i in range(cnt, -1, -1):
    if i == 0:
        res = n // (26 ** i)
    else:
        res = n // (26 ** i) - 1
    ans += ls[res]
    n -= 26 ** i * (res + 1)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
ls = "abcdefghijklmnopqrstuvwxyz"
#i = 1
cnt = math.ceil(math.log(25 * n / 26 + 1, 26)) - 1
ans = ""
#print(cnt, n)
n -= 1
for i in range(cnt, -1, -1):
    if i == 0:
        res = n // (26 ** i)
    else:
        res = n // (26 ** i) - 1
    ans += ls[res]
    n -= 26 ** i * (res + 1)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
ls = "abcdefghijklmnopqrstuvwxyz"
#i = 1
cnt = math.ceil(math.log(25 * n / 26 + 1, 26)) - 1
ans = ""
#print(cnt, n)
n -= 1
for i in range(cnt, -1, -1):
    if i == 0:
        res = n // (26 ** i)
    else:
        res = n // (26 ** i) - 1
    ans += ls[res]
    n -= 26 ** i * (res + 1)
print(ans)
Problem p02659 (python)

Fixed submission:
from decimal import *
A,B = input().split()
A = int(A)
B = Decimal(B)
print(int(A*B))

Buggy submission (verdict: Runtime Error):
import sys

a, b = [float(i) for i in sys.stdin.readline().split()]
a = int(a)
a *= int(b * 100)
print(int(str(a)[:-2]))
Problem p02763 (python)

Fixed submission:
import sys
import bisect
n = int(sys.stdin.readline().strip())
s = list(sys.stdin.readline().strip())
alpha = "abcdefghijklmnopqrstuvwxyz"
dict = {i:[] for i in alpha}
for i, _s in enumerate(s):
    dict[_s].append(i)
q = int(sys.stdin.readline().strip())
for i in range(q):
    type, first, last = [i for i in sys.stdin.readline().split()]
    if type == "2":
        first = int(first)
        last = int(last)
        first -= 1
        last -= 1
        cnt = 0
        for ls in dict.values():
            if bisect.bisect_left(ls, first) != bisect.bisect_right(ls, last):
                cnt += 1
        print(cnt)
    else:
        first = int(first)
        first -= 1
        _s = s[first]
        if _s == last:
            continue
        del dict[_s][(bisect.bisect_left(dict[_s], first))]
        s[first] = last
        bisect.insort_left(dict[last], first)

Buggy submission (verdict: Runtime Error):
import sys
import bisect
n = int(sys.stdin.readline().strip())
s = list(sys.stdin.readline().strip())
alpha = "abcdefghijklmnopqrstuvwxyz"
dict = {i:[] for i in alpha}
for i, _s in enumerate(s):
    dict[_s].append(i)
q = int(sys.stdin.readline().strip())
for i in range(q):
    type, first, last = [i for i in sys.stdin.readline().split()]
    if type == "2":
        first = int(first)
        last = int(last)
        first -= 1
        last -= 1
        cnt = 0
        for ls in dict.values():
            if bisect.bisect_left(ls, first) != bisect.bisect_right(ls, last):
                cnt += 1
        print(cnt)
    else:
        _s = s[first]
        first = int(first)
        first -= 1
        dict[_s].pop(bisect.bisect_left(dict[_s], first))
        s[first] = last
        bisect.insort_left(dict[last], first)
Problem p02834 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)

n, u, v = [int(i) for i in sys.stdin.readline().split()]
u -= 1
v -= 1
graph = {i: [] for i in range(n)}
for i in range(n - 1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

distance = 0
stack = [(u, 0)]
already = set()
parent = [i for i in range(n)]
while len(stack) > 0:
    cur, dis = stack.pop(-1)
    already.add(cur)
    for _next in graph[cur]:
        if _next in already:
            continue
        parent[_next] = cur
        if _next == v:
            distance = dis + 1
            break
        stack.append((_next, dis + 1))
cur = v
path = []
while cur != u:
    path.append(cur)
    cur = parent[cur]

path_dict = {j: i for i, j in enumerate(path)}
already = set()
ls = []
stack = [(u, 0, 0)]
while len(stack) > 0:
    ind, cur_dis, minus = stack.pop(-1)
    already.add(ind)
    ls.append(cur_dis - minus)
    for _next in graph[ind]:
        parent[_next] = ind
        if _next in already:
            continue
        if _next in path:
            if path_dict[_next] <= cur_dis + 1:
                continue
            else:
                stack.append((_next, cur_dis + 1, minus + 2))
        else:
            stack.append((_next, cur_dis + 1, minus))

res = max(ls)

if res == 0:
    print(distance - 1)
else:
    print(distance + res - 1)

Buggy submission (verdict: Runtime Error):
import sys
n, u, v = [int(i) for i in sys.stdin.readline().split()]
u -= 1
v -= 1
graph = {i : [] for i in range(n)}
for i in range(n-1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

distance = 0
stack = [(u, 0)]
already = set()
parent = [i for i in range(n)]
while len(stack) > 0:
    cur, dis = stack.pop(-1)
    already.add(cur)
    for _next in graph[cur]:
        if _next in already:
            continue
        parent[_next] = cur
        if _next == v:
            distance = dis + 1
            break
        stack.append((_next, dis + 1))
cur = v
path = []
while cur != u:
    path.append(cur)
    cur = parent[cur]

path_dict = {j : i for i, j in enumerate(path)}
already = set()

def dfs(ind, cur_dis):
    res = 0
    already.add(ind)
    for _next in graph[ind]:
        parent[_next] = ind
        if _next in already:
            continue
        if _next in path:
            if path_dict[_next] <= cur_dis:
                continue
            else:
                res = max(res, dfs(_next, cur_dis + 1) - 1)
        else:
            res = max(res, dfs(_next, cur_dis + 1) + 1)
    return res

res = dfs(u, 0)
if res == 0:
    print(distance - 1)
else:
    print(distance + res - distance % 2)
Problem p02990 (python)

Fixed submission:
import sys
from math import factorial

def comb(n, k):
    return int(factorial(n)) // int(factorial(k)) // int(factorial(n-k))

def h_comb(n, k):
    return int(factorial(n+k-1)) // int(factorial(k)) // int(factorial(n - 1))

n, k =[int(i) for i in sys.stdin.readline().split()]
for i in range(1,k+1):
    if n-k-i+1 < 0:
        print(0)
    else:
        x = comb(k-1, i-1)
        y = h_comb(i+1, n-k-i+1)
        print(int( x * y )% (10**9+7))

Buggy submission (verdict: Runtime Error):
import sys
from math import factorial

def comb(n, k):
    return int(factorial(n)) / int(factorial(k)) / int(factorial(n-k))

def h_comb(n, k):
    return int(factorial(n+k-1)) / int(factorial(k)) / int(factorial(n - 1))

n, k =[int(i) for i in sys.stdin.readline().split()]
for i in range(1,k+1):
    if n-k-i+1 < 0:
        print(0)
    else:
        print(int(comb(k-1, i-1) * h_comb(i+1, n-k-i+1))% (10**9+7))

Buggy submission (verdict: Runtime Error):
import sys
from math import factorial

def comb(n, k):
    return int(factorial(n)) / int(factorial(k)) / int(factorial(n-k))

def h_comb(n, k):
    return int(factorial(n+k-1)) / int(factorial(k)) / int(factorial(n - 1))

n, k =[int(i) for i in sys.stdin.readline().split()]
bl_ls = []
red_ls = []
for i in range(1,k+1):
    if n-k-i+1 < 0:
        print(0)
    else:
        print(int(comb(k-1, i-1) * h_comb(i+1, n-k-i+1) % (10**9+7)))

Buggy submission (verdict: Runtime Error):
import sys
from math import factorial

def comb(n, k):
    return int(factorial(n)) / int(factorial(k)) / int(factorial(n-k))

def h_comb(n, k):
    return int(factorial(n+k-1)) / int(factorial(k)) / int(factorial(n - 1))

n, k =[int(i) for i in sys.stdin.readline().split()]
for i in range(1,k+1):
    print(int(comb(k-1, i-1) * h_comb(i+1, n-k-i+1) % (10**9+7)))

Buggy submission (verdict: Runtime Error):
import sys
from math import factorial

def comb(n, k):
    return int(factorial(n)) / int(factorial(k)) / int(factorial(n-k))

def h_comb(n, k):
    return int(factorial(n+k-1)) / int(factorial(k)) / int(factorial(n - 1))

n, k =[int(i) for i in sys.stdin.readline().split()]
bl_ls = []
red_ls = []
for i in range(1,k+1):
    print(int(comb(k-1, i-1) * h_comb(i+1, n-k-i+1) % (10**9+7)))
Problem p03041 (python)

Fixed submission:
N, K = [int(i) for i in input().split()]
S = input()
S = S[:K-1] + S[K-1].lower() + S[K:]
print(S)

Buggy submission (verdict: Runtime Error):
N, K = [int(i) for i in input().split()]
S = input()
S[K-1] = S[K-1].lower()
print(S)

Buggy submission (verdict: Runtime Error):
N, K = [int(i) for i in input().split()]
S = input()
S[K] = S[K].lower()
print(S)
Problem p03075 (python)

Fixed submission:
data_ls = []
for i in range(5):
  data_ls.append(int(input()))
k = int(input())
data_ls.sort()
if data_ls[-1] - data_ls[0] > k:
  print(":(")
else:
  print("Yay!")

Buggy submission (verdict: Runtime Error):
data_ls = []
for i in range(5):
  data_ls.append(int(input()))
k = int(input())
sort(data_ls)
if data_ls[-1] - data_ls[0] > k:
  print("Yay!")
else:
  print(":(")
Problem p03108 (python)

Fixed submission:
N, M = [int(i) for i in input().split()]
data_ls = list()
for i in range(M):
    data_ls.append([int(i) -1 for i in input().split()])
A_ls, B_ls = zip(*data_ls)
conv_ls = list()

par = list(range(N))
rank = [1] * N

def find(x):
    if par[x] == x:
        return x
    else:
        return find(par[x])

def unite(x, y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
        rank[y] += rank[x]
        rank[x] = rank[y]
    else:
        par[y] = x
        rank[x] += rank[y]
        rank[y] = rank[x]

def is_same(x, y):
    if find(x) == find(y):
        return True
    else:
        return False

def ranking(x):
    return rank[find(x)]

def main():
    conv_ls.append(0)
    for i, (x,y) in enumerate(data_ls[::-1]):
        N1 = ranking(x)
        N2 = ranking(y)
        if is_same(x, y):
            conv_ls.append(conv_ls[i])
        else:
            conv_ls.append(conv_ls[i] + N1 * N2)
            unite(x,y)
    for conv in conv_ls[::-1][1:]:
        print(int(N * (N - 1) / 2 - conv))

main()

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
data_ls = list()
for i in range(M):
    data_ls.append([int(i) -1 for i in input().split()])
A_ls, B_ls = zip(*data_ls)
conv_ls = list()

par = list(range(N))
rank = [1] * N

def find(x):
    if par[x] == x:
        return x
    else:
        return find(par[x])

def unite(x, y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
        rank[y] += rank[x]
        rank[x] = rank[y]
    else:
        par[y] = x
        rank[x] += rank[y]
        rank[y] = rank[x]

def is_same(x, y):
    if find(x) == find(y):
        return True
    else:
        return False

def ranking(x):
    return rank[find(x)]

def main():
    conv_ls.append(0)
    for i, (x,y) in enumerate(data_ls[::-1]):
        N1 = ranking(x)
        N2 = ranking(y)
        if is_same(x, y):
            conv_ls.append(conv_ls[i])
        else:
            conv_ls.append(conv_ls[i] + N1 * N2)
        unite(x,y)
    for conv in conv_ls[::-1][1:]:
        print(int(N * (N - 1) / 2 - conv))

main()
Problem p03135 (python)

Fixed submission:
T, X = map(int, input().split())
print(T / X)

Buggy submission (verdict: Runtime Error):
def calc(X,ls):
    _sum = 0
    for i in ls:
        _sum +=  int(bin(X^i), 0)
    return _sum


N, K = map(int, input().split())
A_ls = [int(i) for i in input().split()]
if len(A_ls) == 1:
    print(A_ls[0])
else:
    _max = 0
    for i in range(K):
        result = calc(i, A_ls)
        if _max < result:
            _max = result
    print(_max)
Problem p03209 (python)

Fixed submission:
import sys
n, x = [int(i) for i in sys.stdin.readline().split()]
cur = 1
p = 1
ls = [cur]
p_ls = [p]
for i in range(50):
    cur = cur * 2 + 3
    p = p * 2 + 1
    ls.append(cur)
    p_ls.append(p)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    if x == 1:
        return 0
    elif x <= 1 + ls[n-1]:
        return f(n-1, x-1)
    elif x == ls[n-1] + 2:
        return 1 + p_ls[n-1]
    elif x < ls[n]:
        return 1 + p_ls[n-1] + f(n-1, x - ls[n-1] - 2)
    else:
        return p_ls[n]
res = f(n, x)
print(res)

Buggy submission (verdict: Runtime Error):
import sys
n, x = [int(i) for i in sys.stdin.readline().split()]
cur = 1
ls = [cur]
for i in range(50):
    cur = cur * 2 + 3
    ls.append(cur)

def f(n, x):
    if x == 1:
        return 0
    elif x <= ls[n-1]:
        return f(n-1, x-1)
    elif x == ls[n-1] + 1:
        return 1 + ls[n-1] // 2 + 1
    elif x < ls[n]:
        return 1 + ls[n-1] // 2 + 1 + f(n-1, x - ls[n-1] - 2)
    else:
        return ls[n] // 2 + 1

res = f(n, x)
print(res)
Problem p03286 (python)

Fixed submission:
n = int(input())
res = ""
cnt = 0
div = 0
if n == 0:
    print(0)
else:
    while n != 0:
        div = n % 2**(cnt+1)
        div = 1 if div > 0 else 0
        res = str(div) + res
        if div > 0:
            n -= (-2) ** cnt
        cnt += 1
    print(res)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
if n == 0:
    print(0)
else:
    base = math.floor(math.log2(abs(n)))
    res = ""
    for i in range(base+1, -1, -1):
        if i % 2 == 0:
            if -(-2)**(i-1) <= n <= -(-2) ** (i+1):
                res += "1"
                n -= (-2) ** i
            else:
                res += "0"
        else:
            if -(-2)**(i-1) >= n >= -(-2) ** (i+1):
                res += "1"
                n -= (-2) ** i
            else:
                res += "0"
    if res[0] == "0":
        print(res[1:])
    else:
        print(res)
Problem p03107 (python)

Fixed submission:
S = list(input())
N = len(S)

c=0
i=0
f=0
while(1):
    if i+1 == N or N < 2:
        break
    if S[i] != S[i+1]:
        del S[i:i+2]
        c += 2
        N -= 2
        if i >= 1:
            i -= 2
        else:
            i -= 1
    i += 1
    #print(i,N,S,f)                                                                      
print(c)

Buggy submission (verdict: Runtime Error):
S = list(input())
N = len(S)

c=0
i=0
f=0
while(1):
    if S[i] != S[i+1]:
        del S[i:i+2]
        c+=2
        N-=2
        if i>=1:
            i-=2
        else:
            i-=1
    i+=1
    #print(i,N,S,f)                                                                      
    if i+1 == N or N < 2:
        break
print(c)

Buggy submission (verdict: Runtime Error):
S = list(input())
N = len(S)

c=0
i=0
f=0
while(1):
    if S[i] != S[i+1]:
        del S[i:i+2]
        c+=2
        N-=2
        if i>=1:
            i-=2
        else:
            i-=1
    i+=1
    #print(i,N,S,f)                                                                      
    if i+1 == N:
        break
print(c)

Buggy submission (verdict: Runtime Error):
S = list(input())
N = len(S)

c=0
i=0
f=0
while(1):
    if S[i] != S[i+1]:
        del S[i:i+2]
        c+=2
        N-=2
        i-=1
        f=1
    if N<2:
        break
    i+=1
    if i+1 == N:
        i=0
        if f==0:
            break
        f=0
print(c)

Buggy submission (verdict: Runtime Error):
S = list(input())
N = len(S)
c=0
i=0
f=0
while(1):
    if S[i] != S[i+1]:
        del S[i:i+2]
        c+=2
        N-=2
        i-=1
        f=1
    i+=1
    if i+1 == N:
        i=0
        if f==0:
            break
        f=0
print(c)

Buggy submission (verdict: Runtime Error):
S = list(input())
N = len(S)
c=0
i=0
f=0
while(1):
    if S[i] != S[i+1]:
	del S[i:i+2]
	c+=2
	N-=2
	i-=1
	f=1
    i+=1
    if i+1 == N:
	i=0
	if f==0:
            break
	f=0
print(c)
Problem p02831 (python)

Fixed submission:
import sys
input = sys.stdin.readline
import fractions

A,B = map(int, input().split())

lcm = A * B // fractions.gcd(A,B)

print(lcm)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import math

A,B = map(int, input().split())

lcm = A * B // math.gcd(A,B)

print(lcm)
Problem p02881 (python)

Fixed submission:
import math

n = int(input())
r_n = int(math.sqrt(n))
s = []

for i in range(1, r_n+1):
    if n%i == 0:
        s.append(n//i + i - 2)
print(min(s))

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
r_n = int(math.sqrt(n))
s = []

for i in range(1, r_n):
    if n%i == 0:
        s.append(n//i + i - 2)
print(min(s))
Problem p03201 (python)

Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
from collections import Counter

d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

N = d_in()
A_list = np.array(ds_in())
A_list.sort()
EPSILON = 10**(-6)

cand_A = 2 ** (np.log2(A_list + EPSILON).astype(int) + 1) - A_list
idx = np.searchsorted(A_list, cand_A)
A_count = dict(Counter(A_list))

ans = 0
for i in range(N-1, -1, -1):
    if A_count[A_list[i]] <= 0:
        continue
    A_count[A_list[i]] -= 1
    if (A_list[idx[i]] == cand_A[i]) and (A_count[cand_A[i]] > 0):
        ans += 1
        A_count[cand_A[i]] -= 1

print(ans)

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

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

N = d_in()
A_list = ds_in()

A_list.sort()

ans = 0
while len(A_list) > 1:
    max_a = A_list.pop()
    if bin(max_a)[3:].find('1') == -1:
        if max_a == A_list[-1]:
            A_list.pop()
            ans += 1
    else:
        cand = 2 ** len(bin(max_a)[2:]) - max_a
        idx = bisect_left(A_list, cand)
        if cand == A_list[idx]:
            A_list.pop(idx)
            ans += 1

print(ans)
Problem p03329 (python)

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


d_in = lambda: int(stdin.readline())  # N = d_in()


def get_order(n, m):
    order = 0
    while n > 0:
        n = n // m
        order += 1
    return order


def decimal2bit(n, m):
    """
    nのm進数表現
    """
    if n == 0:
        return []
    order = get_order(n, m)
    ans = []
    for i in range(order, -1, -1):
        ans.append(n // (m ** i))
        n -= m ** i * ans[-1]
    return ans


def search(n):
    ans = float('inf')
    for i in range(n // 9 + 1):
        nine = decimal2bit(9 * i, 9)
        six = decimal2bit(n - 9 * i, 6)
        ans = min(ans, sum(nine) + sum(six))
    print(ans)


if __name__ == '__main__':
    N = d_in()
    search(N)

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

d_in = lambda: int(stdin.readline())  # N = d_in()


def decimal2bit(n, m):
    """
    nのm進数表現
    """
    order = int(math.log(n, m))
    ans = []
    for i in range(order, -1, -1):
        ans.append(n // (m ** i))
        n -= m ** i * ans[-1]
    return ans


def search(n):
    ans = sum(decimal2bit(n, 6))
    for i in range(1, n // 9 + 1):
        nine = decimal2bit(9 * i, 9)
        six = decimal2bit(n - 9 * i, 6)
        ans = min(ans, sum(nine) + sum(six))
    print(ans)


if __name__ == '__main__':
    N = d_in()
    search(N)