AtCoder Beginner Contest 099
C
Strange Bank
AtCoder
⌀ 1101
原题
← BD →
翻译中…

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$.

翻译中…

样例

Input #1
127
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.
Input #2
3
Output #2
3
By withdrawing $1$ yen three times, we can withdraw $3$ yen in three operations.
Input #3
44852
Output #3
16
题目信息
题号
abc099_c
时间限制
2 s
内存限制
256 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。