cho.sh
Notes
Loading...

Candy Rotation

Time limit

2s

Memory limit

128 MB

Problem

Sejun has a circular candy container with N cells. The cells are arranged in a circle and numbered from 1 to N clockwise.

First, Sejun may place the candy in any one cell. After that, look at the number of the cell containing the candy, compute the sum of its decimal digits, and move the candy clockwise by that many cells. If the candy is in cell 123, it moves 1 + 2 + 3 = 6 cells clockwise. Repeat this movement until the candy reaches a cell that has already been visited. The initial cell is also counted as visited.

Given N, determine the maximum number of distinct cells that can be visited by choosing the initial cell optimally.

Input

The first line contains a natural number N. N is at most 200,000.

Output

Print the maximum number of distinct cells that can be visited.