Problem H
Hunter x Communication
Having passed the Hunter Exam, Gon is now officially a Hunter! Gon is now saying goodbye to his best friend, Killua, as Gon wants to visit his home in ‘While Island’.
Gon and Killua plan to use the online chat application, Olaz, to keep in touch. However, they are not confident with Olaz’s security: some imposters may be able to login to Gon’s account and send messages to Killua! To prevent this, they have decided to use the following method:
-
Before starting a conversation, Gon must send Killua a number
with exactly digits. -
Killua must reply with an integer
with exactly digits, where and form a best friend pair. -
Each time they start a conversation, they must use a different best friend pair. This would avoid imposters from simply reusing the previous best friend pairs.
To define a best friend pair, first we define a friendly
operation on a number
-
Select two adjacent digits of
. -
Either add
to both digits, or subtract from both digits. -
It is forbidden to add
to digit , or subtract from digit . -
It is also forbidden to subtract
from the first digit of , if the first digit of is .
Note that the last two conditions guarantee that the new number is valid and does not have leading zero. The new and old numbers will also have the same length.
Two numbers
For example,
Now Gon is wondering how many conversation can they have, before running out of best friend pairs.
Input
The input contains exactly one integer
Output
The output contains exactly one integer — the number of
pairs of best friend numbers with exactly
Sample Input 1 | Sample Output 1 |
---|---|
1 |
10 |
Sample Input 2 | Sample Output 2 |
---|---|
2 |
570 |