Problem:


Score : 300 points

Problem Statement

To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:

1 yen (the currency of Japan)

6 yen, 6^2(=36) yen, 6^3(=216) yen, ...

9 yen, 9^2(=81) yen, 9^3(=729) yen, ...

At least how many operations are required to withdraw exactly N yen in total?

It is not allowed to re-deposit the money you withdrew.

Constraints

1 \leq N \leq 100000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If at least x operations are required to withdraw exactly N yen in total, print x.

Sample Input 1

127

Sample Output 1

4

By withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.

Sample Input 2

3

Sample Output 2

3

By withdrawing 1 yen three times, we can withdraw 3 yen in three operations.

Sample Input 3

44852

Sample Output 3

16



Sample input:
127


Sample output:
4

Submission status: Wrong Answer

Solution code:
import math

def calc(N):
    V = 0
    by_6 = 0
    while(V < N):
        log6 = int(math.log(N - V, 6))

        by_6 += (N - V) // (6 ** log6)
        V += (6 ** log6) * ((N - V) // (6 ** log6))

    V = 0
    by_9 = 0
    while(V < N):
        log9 = int(math.log(N - V, 9))

        by_9 += (N - V) // (9 ** log9)
        V += (9 ** log9) * ((N - V) // (9 ** log9))

    return min(by_6, by_9) - abs(by_6 - by_9)

if __name__ == "__main__":
    N = int(input())

    print(calc(N))

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = N
for i in range(N):
    c = 0
    t = i
    while t > 0:
        c += t % 6
        t //= 6
    
    t = N - i
    while t > 0:
        c += t % 9
        t //= 9
    
    ans = min(ans, c)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def calc(N):
    count = 0
    V = 0

    while(V < N):
        log9 = int(math.log(N - V, 9))
        log6 = int(math.log(N - V, 6))

        V += max(6 ** log6, 9 ** log9)
        count += 1

    return count

if __name__ == "__main__":
    N = int(input())

    print(calc(N))

Submission status: Wrong Answer

Solution code:
n=int(input())

ans=n
for i in range(n):
    count=0
    pow6=6
    while pow6<=i:
        count+= (i%(pow6*6))//pow6
        pow6*=6
    pow9=9
    while pow9<=n-i:
        count+= ((n-i)%(pow9*9))//pow9
        pow9*=9
    count+= (i%6)+((n-i)%9)
    ans=min(ans,count)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
numlist = []
n, m = 1, 1
ans = N

while 6**n < N:
  numlist.append(6**n)
  n += 1
while 9**m < N:
  numlist.append(9**m)
  m += 1
  
l = len(numlist)
for i in range(2**l):
  tmp = 0
  count = 0
  for j in range(l):
    if (i>>j) & 1:
      tmp += numlist[j]
      count += 1
  if tmp < N:
    count += N - tmp
    ans = min(count, ans)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N, = map(int, input().split())
si = []
ni = []
p = [1]

s = 1
while s < N:
    s *= 6
    
    if s < N:
        si.append(s)

s = 1
while s < N:
    s *= 9
    
    if s < N:
        ni.append(s)

p.extend(si)
p.extend(ni)
p.sort()

ans = 0
for v in reversed(p):
    if N >= v:
        ans += N // v
        N = N % v
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
def f(n):
    li = []
    ans = 0
    last = 0
    for i in range(100000):
        if 9**(i+1) <= n:
            li.append(9**(i+1))
        else:break
    
    for i in range(100000):
        if 6**(i+1) <= n:
            li.append(6**(i+1))
        else:break
    
    while n >= 6:
        cost = []
        for i in li:
            if n >= i:
                cost.append([i,n//i+n%i])
        ans += 1
        cost_sort = sorted(cost,key=lambda x:x[1])
        n -= cost_sort[0][0]
        print(cost_sort[0][0])

    return ans + n

print(f(n))

Submission status: Wrong Answer

Solution code:
n = int(input())
def f(n):
    li = []
    ans = 0
    last = 0
    for i in range(100000):
        if 9**(i+1) <= n:
            li.append(9**(i+1))
        else:break
    
    for i in range(100000):
        if 6**(i+1) <= n:
            li.append(6**(i+1))
        else:break
    
    li_sort = sorted(li,reverse= True)
    for i in li_sort:
        while True:
            if i <= n:
                n -= i
                ans += 1
                last = i
            else:
                break
    if last == 9 and n >= 3:
        return ans + n - 2
    else:
        return ans+n

print(f(n))

Submission status: Wrong Answer

Solution code:
n = int(input())
li = []
ans = 0
for i in range(100000):
    if 9**(i+1) <= n:
        li.append(9**(i+1))
    else:
        break
for i in range(100000):
    if 6**(i+1) <= n:
        li.append(6**(i+1))
    else:
        break

li_sort = sorted(li,reverse= True)
for i in li_sort:
    while True:
        if i <= n:
            n -= i
            ans += 1
        else:
            break

print(ans+n)

Submission status: Wrong Answer

Solution code:
n=int(input())

dp=[0]*100010
dp[0]=0


for i in range(1,100010):
  n6=0
  n9=0
  li=[]
  while 6**(n6+1)<i:
    n6+=1
  while 9**(n9+1)<i:
    n9+=1
  for j in range(n6+1):
    li.append(dp[i-6**n6])
  for jj in range(n9+1):
    li.append(dp[i-9**n9])
  dp[i]=min(li)+1
print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())

def hikidashi(x):
    ind6 = 0
    while 6 ** (ind6 + 1) <= x:
        ind6 += 1
    ind9 = 0
    while 9 ** (ind9 + 1) <= x:
        ind9 += 1
    return min(x-1,min(x-6**ind6,x-9**ind9))

cnt = 0
while n > 14:
    n = hikidashi(n)
    cnt += 1
if n == 14:
    print(cnt + 4)
if n == 13:
    print(cnt + 3)
if n == 12:
    print(cnt + 2)
if n == 11:
    print(cnt + 3)
if n == 10:
    print(cnt + 2)
if n == 9:
    print(cnt + 1)
if n == 8:
    print(cnt + 3)
if n == 7:
    print(cnt + 2)
if n == 6:
    print(cnt + 1)
if 0 <= n and n <=5:
    print(cnt + n)

Submission status: Wrong Answer

Solution code:
n = int(input())

def hikidashi(x):
    ind6 = 0
    while 6 ** (ind6 + 1) <= x:
        ind6 += 1
    ind9 = 0
    while 9 ** (ind9 + 1) <= x:
        ind9 += 1
    return min(x-1,min(x-6**ind6,x-9**ind9))

cnt = 0
while n != 0:
    n = hikidashi(n)
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=n
for i in range(n+1):
  ni,si=i,n-i
  m=0
  while ni!=0:m+=ni%6;ni//=6
  while si!=0:m+=si%6;si//=6
  a=min(a,m)
print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())

large = []

def listup(base):
	global large
	for n in range(2, 10):
		t = base ** n
		if t < 100000:
			large += [t]
		else:
			return

listup(6)
listup(9)
large.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	if hi < lo:
		return lo
	mi = (hi + lo) // 2
	if a[mi] < v:
		return bsr(a, v, mi + 1, hi)
	else:
		return bsr(a, v, lo, mi - 1)

c, n = 0, N
index = bsr(large, n)
while 0 < index:
	c += 1
	n -= large[index - 1]
	index = bsr(large, n)

sc = []
for n9 in range(6):
	for n6 in range(6):
		t = n9 * 9 + n6 * 6
		if n < t:
			break
		sc += [n9 + n6 + (n - t)]

print(c + min(sc))

Submission status: Wrong Answer

Solution code:
N = int(input())
M = 100

ans = 0
dp = [99999] * 100010

dp[0] = 0
for i in range(1,100000):
    power = 1
    while (power <= N):
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 6
    power = 1
    while (power <= N):
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 9
print(dp[N])

Submission status: Wrong Answer

Solution code:
def solve(N: int):
    coins = set()
    coins.add(1)
    i = 1
    while 6**i < N:
        coins.add(6**i)
        i += 1
    i = 1
    while 9**i < N:
        coins.add(9**i)
        i += 1
         

    dp = [float('inf')] * (N + 1)
    dp[0] = 0
    
    for n in range(1, N + 1):
        for coin in coins:
            if n - coin >= 0:
                dp[n] = min(dp[n - coin] + 1, dp[n])
                
    return dp[N]
N = int(input())
print(solve(N))

Submission status: Wrong Answer

Solution code:
def smaller(x, y):
	if x < y: return x
	return y

nine = []
six = []
a = 9
while a <= 100000:
	nine.append(a)
	a *= 9
a = 6
while a <= 100000:
	six.append(a)
	a *= 6

dp = [0]
for i in range(1, 100001):
	min = dp[i-1]+1
	for j in range(0, len(nine)):
		if i < nine[j]: break
		min = smaller(min, dp[i-nine[j]])
	for j in range(0, len(six)):
		if i < six[j]: break
		min = smaller(min, dp[i-six[j]])
	dp.append(min)
print dp[int(raw_input())]

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = N

for i in range(N):
    cnt = 0
    t1 = i
    t2 = N - i
    while t1 > 0:
        cnt += t1 % 6
        t1 //= 6

    while t2 > 0:
        cnt += t2 % 9
        t2 //= 9
        
    ans = min(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = N

for i in range(N):
    cnt = 0
    t = i
    while t > 0:
        cnt += int(t % 6)
        t /= 6
    
    t = N - i
    while t > 0:
        cnt += int(t % 9)
        t /= 9
        
    if ans > cnt:
        ans = cnt

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

dp = [10**6] *(n+1)
dp[0] = 0
power = 1

while power <= n:
    for i in range(1,n+1):
        dp[i] = min(dp[i], dp[i-power] + 1)
    power *= 6

power = 1
while power <= n:
    for i in range(1,n+1):
        dp[i] = min(dp[i], dp[i-power] + 1)
    power *= 9
    
print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [531441, 59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
ans = 0
cnt = 0

while ans != n:
    for i in l:
        if (n-ans) >= i:
            cnt += 1
            ans += i
            break
        
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = sorted([1, 6, 6 ** 2, 6 ** 3, 6 ** 4, 6 ** 5, 6 ** 6, 9, 9 ** 2, 9 ** 3, 9 ** 4, 9 ** 5])[:: -1]
ans = 0
while N > 0:
	i = 0
	while c[i] > N:
		i += 1
	ans += 1
	N -= c[i]
	print(N, c[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n
for i in range(n):
    c = 0
    t = i
    while(t > 0):
        c += t%6
        t //= 6
    t = n-i
    while(t > 0):
        c += t%9
        t //= 9
    if ans > c:
        ans = c
print(ans)

Submission status: Wrong Answer

Solution code:
def log(x, y):
    i = 0
    while(y ** i <= x):
        i += 1
    return i - 1

N = int(input())
if N < 6:
    ans = N
else:
    a = log(N, 6)
    b = log(N, 9)
    m = [6**i for i in range(1, a + 1)] + [9**j for j in range(1, b + 1)]
    m.sort(reverse=True)
    nn = N
    i = 0
    ans = 0
    while(True):
        ans += nn // m[i]
        nn = nn % m[i]
        i += 1
        if i == len(m):
            ans += nn
            break
print(ans)

Submission status: Wrong Answer

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()

    ans = n

    for i in range(n // 6):
        count = 0

        s6 = i * 6
        ii = i
        for j in range(1, n + 1):
            scount = ii % 6
            count += scount
            ii = ii // 6
            s6 -= (6**j) * scount
            if not s6:
                break

        s9 = n - i * 6
        ii = s9
        for j in range(0, n + 1):
            scount = ii % 9
            count += scount
            ii = ii // 9
            s9 -= (9**j) * scount
            if not s9:
                break

        ans = min(ans, count)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())

prices = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]

times = 0
while True:
    if N < 6:
        times += N
        break
    else:
        N = N - prices[bisect.bisect_left(prices,N) - 1]
        #print(N,prices[bisect.bisect_left(prices,N) - 1])
        times += 1

print(times)

Submission status: Wrong Answer

Solution code:
## TLEなのはわかっておる...

import numpy as np
from collections import deque

N = int(input())

# 6^6 < 1e5 < 6^7
# 9^5 < 1e5 < 9^6
# に注目すると大きい金額から引き出してみる全探索で良さそう


drawable = [6, 6**2, 6**3, 6**4, 6**5, 6**6, 9, 9**2, 9**3, 9**4, 9**5, 9**6]
drawable = sorted(drawable, reverse=True)
ans = -1

def main():
    dq = deque()
    dq.append((N,0))
    while dq:
        rest, cnt = dq.popleft()
        for draw in drawable:
          rest_afterdraw = rest - draw
          if rest_afterdraw >= 0 and rest_afterdraw < 6:
              global ans
              ans = cnt + rest_afterdraw + 1 
              return
          if rest_afterdraw > 0:
              dq.append((rest_afterdraw,cnt+1))
     

main()
print(ans)

Submission status: Wrong Answer

Solution code:
def lessNum(num, v):
  
  i = 0
  n = 1
  while True:
    if num < pow(v,n):
      i = n - 1
      break
    n += 1
  if num >= v:
    #print(num,  pow(v,i), i)
    num = pow(v,i)
  else:
    num = 0
  return num
  
a=int(input())

ans = 0

while True:
  #print(lessNum(a, 9),lessNum(a, 6))
  s = max(lessNum(a, 9),lessNum(a, 6))
  #print(a, s)
  if s != 0:
    a -= s
    ans += 1
  if s == 0:
      
      break

#print(ans,a)
print(ans + a)

Submission status: Wrong Answer

Solution code:
def lessNum(num, v):
  i = 0
  n = 1
  while True:
    if num <= pow(v,n):
      i = n - 1
      break
    n += 1
  num = num - pow(v,i)
  return (num, i)
  
a=int(input())

ans = 0

while True:
  (a, i) = lessNum(a, 9)
  if 1 != 0:
    ans += 1
  (a, k) = lessNum(a, 6)
  if 1 != 0:
    ans += 1
  if a >= 9:
    a -= 9
    ans += 1
  elif a >= 6:
    a -= 6
    ans += 1
  break

print(ans + a)

Submission status: Wrong Answer

Solution code:
N = int(input())
INF = 10 ** 6
six = [[6 ** i * j for j in range(1, 6)] for i in range(1, 7)]
nin = [[9 ** i * j for j in range(1, 9)] for i in range(1, 6)]
dp = [INF] * (100010)
dp[0] = 0
for p in [6, 9]:
    for n in range(1, 10 ** 5):
        power = 1
        while power <= n:
            dp[n] = min(dp[n], dp[n - power] + 1)
            power *= p
print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
c = []
for i in [9, 6]:
	Nt = N
	count = 0
	while Nt >= i:
		Nt = Nt // i
		count += 1
	c.append(count)
lt = [9 ** i for i in range(c[0]+1)] + [6 ** i for i in range(c[1]+1)]
lt = list(set(lt))
lt.sort(reverse=True)

count = 0
i = 0
while (N >= 216) & (i <= len(lt)):
	count += (N // lt[i])
	N = N % lt[i]
	i += 1

add = 999
for i1 in range(N // 81, -1, -1):
	N1 = N - 81 * i1
	for i2 in range(N1 // 36, -1, -1):
		N2 = N1 - 36 * i2
		for i3 in range(N2 // 9, -1, -1):
			N3 = N2 - 9 * i3
			add = min(add, sum(divmod(N3, 6)) + i1 + i2 + i3)
print(count + add)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = []
for i in [9, 6]:
	Nt = N
	count = 0
	while Nt >= i:
		Nt = Nt // i
		count += 1
	c.append(count)
lt = [9 ** i for i in range(c[0]+1)] + [6 ** i for i in range(c[1]+1)]
lt = list(set(lt))
lt.sort(reverse=True)

count = 0
i = 0
while (N >= 36) & (i <= len(lt)):
	count += (N // lt[i])
	N = N % lt[i]
	i += 1

add = 999
for i in range(N // 9, -1, -1):
	add = min(add, sum(divmod(N - 9 * i, 6)) + i)
print(count + add)

Submission status: Wrong Answer

Solution code:
n=int(input())
dp=[0]*n
l69=sorted([1]+[6**i for i in range(1,7)]+[9**i for i in range(1,6)])
g=0
for i in range(n):
    for j in range(len(l69)):
        if i-l69[j]>=0:
            g=j
    dp[i]=min(dp[i-p]+1 for p in l69[:g+1])
print(dp[n-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
Inf = float("inf")
dp = [Inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
        still1 = 1
        while still1 <= N:
                dp[i] = min(dp[i],1+dp[i-still1])
                still1 *= 6
        still2 = 1
        while still2 <= N:
                dp[i] = min(dp[i],1+dp[i-still2])
                still2 *= 9
for i in range(N+1):
        print(dp[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
L1 = [1]
L2 = [6**i for i in range(1,10) if 6**i < 100000]
L3 = [9**i for i in range(1,10) if 9**i < 100000]
L = L1 + L2 + L3
L.sort(reverse = True)
def paypay(N):
        if N < 6:
                return N
        else:
                ans = 0
                while N > 0:
                      for i in L:
                            if N >= i:
                                  N = N - i
                                  ans += 1
                                  break
        return ans


print(min(paypay(N),paypay(N-6)+1,paypay(N-9)+1) if N > 6 else N)

Submission status: Wrong Answer

Solution code:
N = int(input())
L1 = [1]
L2 = [6**i for i in range(1,10) if 6**i < 100000]
L3 = [9**i for i in range(1,10) if 9**i < 100000]
L = L1 + L2 + L3
L.sort(reverse = True)
def paypay(N):
        if N < 6:
                return N
        else:
                ans = 0
                while N > 0:
                      for i in L:
                            if N >= i:
                                  N = N - i
                                  ans += 1
                                  break
        return ans


print(min(paypay(N),paypay(N-6)+1) if N > 6 else N)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=10**10
dp=[0]*100001
for i in range(1,n+1):
  tmp=[dp[i]+1]
  if i>=6**1:
    tmp.append(dp[i-6**1]+1)
  if i>=9**1:
    tmp.append(dp[i-9**1]+1)
  if i>=6**2:
    tmp.append(dp[i-6**2]+1)
  if i>=9**2:
    tmp.append(dp[i-9**2]+1)
  if i>=6**3:
    tmp.append(dp[i-6**3]+1)
  if i>=9**3:
    tmp.append(dp[i-9**3]+1)
  if i>=6**4:
    tmp.append(dp[i-6**4]+1)
  if i>=9**4:
    tmp.append(dp[i-9**4]+1)
  if i>=6**5:
    tmp.append(dp[i-6**5]+1)
  if i>=9**5:
    tmp.append(dp[i-9**5]+1)
  if i>=6**6:
    tmp.append(dp[i-6**6]+1)
  if i>=9**6:
    tmp.append(dp[i-9**6]+1)
  dp[i]=min(tmp)
print(dp[n])

Submission status: Wrong Answer

Solution code:
N=int(input())
ss=[]
i = 1
while 6**i < 100000:
    ss.append(6**i)
    i += 1
ns=[]
i = 1
while 9**i < 100000:
    ns.append(9**i)
    i += 1
ans = 0
nsss=sorted(ns+ss+[1])
def sol(v,i):
    if i == 0:
        return v
    elif i < 7:
        return min([sol(v-j*nsss[i],i-1)+j for j in range(v//nsss[i]+1)])
    else:
        j = v//nsss[i]
        return sol(v-j*nsss[i],i-1)+j
print(sol(N,len(nsss)-1))

Submission status: Wrong Answer

Solution code:
N=int(input())
ss=[]
i = 1
while 6**i < 100000:
    ss.append(6**i)
    i += 1
ns=[]
i = 1
while 9**i < 100000:
    ns.append(9**i)
    i += 1
ans = 0
nsss=sorted(ns+ss+[1])
def sol(v,i):
    if i == 0:
        return v
    elif i < 3:
        return min([sol(v-j*nsss[i],i-1)+j for j in range(v//nsss[i]+1)])
    else:
        j = v//nsss[i]
        return sol(v-j*nsss[i],i-1)+j
print(sol(N,len(nsss)-1))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = 0
list = []
for i in range(1,6):
  list.append(9**i)
for j in range(1,7):
  list.append(6**j)
list.sort(reverse=True)

for x in list:
  if N <= 5:
    a += N
    break
  elif x <= N:
    a += 1
    N -= x
print(a)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
dp=[100000 for i in range(n+1)]
dp[0]=0
dp[1]=1
for i in range(1,n+1):
  dp[i]=dp[i-1]+1
  j,k=int(math.log(i)/math.log(6)),int(math.log(i)/math.log(9))
  for jj in range(j+2):
    dp[i]=min(dp[i],dp[max(0,i-6**jj)]+1)
  for kk in range(k+1):
    dp[i]=min(dp[i],dp[i-9**kk]+1) 
print(dp[n])

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
dp=[100000 for i in range(n+1)]
dp[0]=0
dp[1]=1
for i in range(1,n+1):
  dp[i]=dp[i-1]+1
  j,k=int(math.log(i)/math.log(6)),int(math.log(i)/math.log(9))
  for jj in range(j+1):
    dp[i]=min(dp[i],dp[i-6**jj]+1)
  for kk in range(k+1):
    dp[i]=min(dp[i],dp[i-9**kk]+1) 
print(dp[n])

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
dp=[100000 for i in range(n+1)]
dp[0]=0
dp[1]=1
for i in range(1,n+1):
  dp[i]=dp[i-1]+1
  j,k=int(math.log(i)/math.log(6)),int(math.log(i)/math.log(9))
  dp[i]=min(dp[i],dp[i-6**j]+1)
  dp[i]=min(dp[i],dp[i-9**k]+1) 
print(dp[n])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
cnt = 0
while n > 0:
    cnt += 1
    tmp = math.log(n, 9)
    if float(tmp).is_integer():
        n -= (9 ** tmp)
        continue
    tmp = math.log(n, 3)
    if float(tmp).is_integer():
        n -= (3 ** tmp)
        continue
    n -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
# 解説
N=int(input())
r=N
for i in range(N):
  c=0;t=i
  while t>0:c+=t%6;t//=6
  t=N-i
  while t>0:c+=t%9;t//=9
  r=min(r,c)
print(r)

Submission status: Wrong Answer

Solution code:
S6=set([1])
S9=set([1])
i=0
while max(S6) <= 100000 :
  S6.add(6**i)
  i+=1
i=0
while max(S9) <= 100000 :
  S9.add(9**i)
  i+=1
L=list(S6|S9)
L.sort(reverse=True)
N=int(input())
M=0
for i in L :
  if N >= i :
    while N >= i :
      M+=1
      N-=i   
print(M)

Submission status: Wrong Answer

Solution code:
S6=set([1])
S9=set([1])
i=0
while max(S6) <= 100000 :
  S6.add(6**i)
  i+=1
i=0
while max(S9) <= 100000 :
  S9.add(9**i)
  i+=1
L=list(S6|S9)
L.sort(reverse=True)
print(L)
N=int(input())
M=0
for i in L :
  if N >= i :
    while N >= i :
      M+=1
      N-=i   
print(M)

Submission status: Wrong Answer

Solution code:
S6=set([1])
S9=set([1])
i=0
while max(S6) <= 100000 :
  S6.add(6**i)
  i+=1
i=0
while max(S9) <= 100000 :
  S9.add(9**i)
  i+=1
L=list(S6|S9)
L.sort(reverse=True)
N=int(input())
M=0
for i in L :
  if N > i :
    while N > i :
      M+=1
      N-=i   
print(M+N)

Submission status: Wrong Answer

Solution code:
S6=set([1])
S9=set([1])
i=0
while max(S6) <= 100000 :
  S6.add(6**i)
  i+=1
i=0
while max(S9) <= 100000 :
  S9.add(9**i)
  i+=1
L=list(S6|S9)
L.sort(reverse=True)
print(L)
N=int(input())
M=0
for i in L :
  if N > i :
    while N > i :
      M+=1
      N-=i   
print(M+N)

Submission status: Wrong Answer

Solution code:
import math
inf = 10 ** 9
n = int(input())
dp = [inf] * (n+1)
dp[0] = 0
dp[1] = 1
for i in range(1, n+1):
    d6 = math.floor(math.log(i)/math.log(6))
    if d6 != 0:
        e6 = i // (6 ** d6)
        dp[i] = min(dp[i - e6 * (6 ** d6)] + e6, dp[i])
    d9 = math.floor(math.log(i)/math.log(9))
    if d9 != 0:
        e9 = i // (9 ** d9)
        dp[i] = min(dp[i - e9 * (9 ** d9)] + e9, dp[i])
    dp[i] = min(dp[i-1] + 1, dp[i])
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import math
inf = 10 ** 9
n = int(input())
dp = [inf] * (n+1)
dp[0] = 0
dp[1] = 1
for i in range(1, n+1):
    d6 = math.floor(math.log(i)/math.log(6))
    if d6 != 0:
        e6 = i // (6 ** d6)
    else:
        e6 = 0
    dp[i] = min(dp[i - e6 * (6 ** d6)] + e6, dp[i])
    d9 = math.floor(math.log(i)/math.log(9))
    if d9 != 0:
        e9 = i // (9 ** d9)
    else:
        e9 = 0
    dp[i] = min(dp[i - e9 * (9 ** d9)] + e9, dp[i])
    dp[i] = min(dp[i-1] + 1, dp[i])
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import math
inf = 10 ** 9
n = int(input())
dp = [inf] * (n+1)
dp[1] = 1
for i in range(1, n+1):
    d6 = math.floor(math.log(i)/math.log(6))
    d9 = math.floor(math.log(i)/math.log(9))
    dp[i] = min(dp[i - 6 ** d6] + 1, dp[i])
    dp[i] = min(dp[i - 9 ** d9] + 1, dp[i])
    dp[i] = min(dp[i-1] + 1, dp[i])
print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
INF = float('inf')
dp = [INF] * 100010
dp[0] = 0

for i in range(1, N):
    power = 1
    while power <= i:
        dp[i] = min(dp[i], dp[i-power] + 1)
        power *= 6
    power = 1
    while power <= i:
        dp[i] = min(dp[i], dp[i-power] + 1)
        power *= 9
print(dp[N-1]+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = N

for i in range(N):
    count = 0
    tmp = i
    while tmp > 0:
        count += tmp%6
        tmp //= 6
    tmp = N - i
    while tmp > 0:
        count += tmp % 9
        tmp //= 9
    ans = min(count, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
	N= int(input())
	dp = [0]*(N+1)
	dp[1]=1

	for i in range(2, N+1):
		ans = dp[i-1]+1
		tmp6 = 6
		while tmp6 < i:
			ans = min(ans, dp[i-tmp6]+1)
			tmp6 *= 6

		tmp9 = 9
		while tmp9 < i:
			ans = min(ans, dp[i-tmp9]+1)
			tmp9 *= 9

		dp[i] = ans

	print(dp[N])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

l1 = 2 ** 30
p6 = [1] * 6
p9 = [1] * 5
for i in range(1,6):
    p6[i] = p6[i-1] * 6
    if i < 5 : p9[i] = p9[i-1] * 9

dp = [l1] * (N+1)
dp[0] = 0

for i in range(1,N+1):
    for j in p6:
        if j>i: break
        dp[i] = min(dp[i],dp[i-j]+1)
        
    for j in p9:
        if j>i: break
        dp[i] = min(dp[i],dp[i-j]+1)
        
print(dp[N])

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=1000000000
for i in range(0,n+1,6):
  j=n-i
  while j:
    a=j%9
    j//=9
  while i:
    a+=i%6
    i//=6
  ans=min(a,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
list6,list9 = [6],[9]
i = 2
while list6[-1] <= 100000:
    list6.append(6**i)
    i += 1
i = 2
while list9[-1] <= 100000:
    list9.append(9**i)
    i += 1
ans = 0
def f(N,ans):
    if N < 6:
        return ans + N
    if N < 9:
        return ans + (N-6)+1

    max6 = max(y for y in list6 if N >= y)
    max9 = max(z for z in list9 if N >= z)

    a6 = N-max6
    a9 = N-max9
    return min(f(a6,ans+1),f(a9,ans+1))

Submission status: Wrong Answer

Solution code:
N = int(input())

M = set([1])
n = 1
while N > 6**n:
    M.add(6**n)
    n += 1

n = 1
while N > 9**n:
    M.add(9**n)
    n += 1

ml = sorted(M, reverse=True)

ans = 0
while N > 18:
    for i in range(len(ml)):
        if N >= ml[i]:
            N -= ml[i]
            ans += 1
            break

if N % 9 < N % 6:
    ans += N % 9 + 1
else:
    if N > 12:
        ans += N % 6 + N // 6
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0

while(1):
 if(N < 6):
  count += N
  break
 for i in range(7):
   i= 7-i
   if(9**i<=N<9**(i+1)): 
    N -= 9**i
    count += 1
    break
   elif(6**i<=N<9**(i+1)): 
    N -= 6**i
    count += 1
    break
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0

while(1):
 if(N < 6):
  count += N
  break
 for i in range(7):
   i= 7-i
   if(9**i<=N<9**(i+1)): 
    N -= 9**i
    count += 1
   elif(6**i<=N<9**(i+1)): 
    N -= 6**i
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0

while(1):
 if(N < 6):
  count += N
  break
 for i in range(6):
   i= 6-i
   if(9**i<=N<9**(i+1)): 
    N -= 9**i
    count += 1
   elif(6**i<=N<9**(i+1)): 
    N -= 6**i
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0

while(1):
 if(N < 6):
  count += N
  break
 for i in range(7):
   i= 6-i
   if(9**i<=N<9**(i+1)): 
    N -= 9**i
    count += 1
   elif(6**i<=N<9**(i+1)): 
    N -= 6**i
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
num = 0
j = 0
while N > 0:
    i = 0
    while i <= N**0.5:
        num = i
        i += 1
    N = N - num ** 2
    j += 1
print(j)

Submission status: Wrong Answer

Solution code:
import math


N=int(input())
a=[0]*(N+1)

for i in range(1,N+1):
    p,q=math.floor(math.log(i,6)), math.floor(math.log(i,9))
    b=[ a[i-(6**j)] for j in range(1,p+1) ]
    c=[ a[i-(9**j)] for j in range(1,q+1) ]
    a[i]=min([a[i-1]] + b + c )+1
print(a[N])

Submission status: Wrong Answer

Solution code:
import math

a=[0]*1000001

for i in range(1,100001):
    p,q=math.floor(math.log(i,6)), math.floor(math.log(i,9))
    b=[ a[i-(6**j)] for j in range(1,p+1) ]
    c=[ a[i-(9**j)] for j in range(1,q+1) ]
    a[i]=min([a[i-1]] + b + c )+1

print(a[int(input())])

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [1] + [6**i for i in range(1,7)] + [9**j for j in range(1,6)]
x.sort()
ans = 0
while n >= 1:
  for i in x[::-1]:
    if n >= i:
      n -= i
      ans += 1
      break
print(ans)

Submission status: Wrong Answer

Solution code:
# not solved only by myself
N = int(input())

def get_nums(wa,ar):
    ar = sorted(ar,reverse=True)
    tmp = 0
    for a in ar:
        tmp += wa // a
        wa %= a
    return tmp + wa


nines = []
tmp = 9
while tmp <= N:
    nines.append(tmp)
    tmp *= 9

sixes = []
tmp = 6
while tmp <= N:
    sixes.append(tmp)
    tmp *= 6



res = N
for t in range(0,N):
    hoge = get_nums(t,sixes) + get_nums(N - t,nines)
    res = min(res,hoge)

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())

ts = [1]
tmp = 9
while tmp <= N:
    ts.append(tmp)
    tmp *= 9

tmp = 6
while tmp <= N:
    ts.append(tmp)
    tmp *= 6

ts = sorted(list(set(ts)),reverse=True)

nums = 0
for t in ts:
    nums += N // t
    N %= t
    if N == 0:
        break

print(nums)

Submission status: Wrong Answer

Solution code:
l=[1]
for i in range(1,6):
  l.append(9**i)
for i in range(1,7):
  l.append(6**i)
l=sorted(l)
l=l[::-1]
i=int(input())
c=0
for j in l:
  if i>=j:
    c+=i//j
    i=i%j
print(c)

Submission status: Wrong Answer

Solution code:
l=[1]
for i in range(1,6):
  l.append(9**i)
for i in range(1,7):
  l.append(6**i)
l=sorted(l)
i=int(input())
c=0
for j in range(1,len(l)+1):
  if i>=l[-j]:
    i=i%l[-j]
    c+=i//l[-j]
  elif i==0:
    break
print(c)