output_description: If at least x operations are required to withdraw exactly N yen in total,
  print x.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
attempt: N = int(input())
  B = [pow(6, i) for i in range(1, 10) if pow(6, i) <= N]
  C = [pow(9, i) for i in range(1, 10) if pow(9, i) <= N]
  A = sorted(B + C + [1])
  L = len(A)
  DP = [[N] * (N + 1) for i in range(L)]
  DP[0] = [i for i in range(N + 1)]
  for l in range(1, L):
      k = A[l]
      for n in range(0, k):
          DP[l][n] = DP[l - 1][n]
      for n in range(k, N + 1):
          DP[l][n] = min(DP[l - 1][n - k] + 1, DP[l][n - k] + 1, DP[l - 1][n])
  print(DP[L - 1][N])
  
problem_description: 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.
samples: [{"input": "127", "output": "4\n    \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n    \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]