Strange Bank

AtCoder
IDabc099_c
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
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
API Response (JSON)
{
  "problem": {
    "name": "Strange Bank",
    "description": {
      "content": "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(",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc099_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:\n\n*   $1$ yen (the currency of Japan)\n    \n*   $6$ yen, $6^2(...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments