Hill Numbers
Time limit5sMemory limit256 MB
Given N with up to 70 digits, count hill numbers smaller than N, or print -1 when N is not one.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
A hill number is an integer whose digits may rise and then fall, but never fall and then rise again.
- 12321 is a hill number.
- 101 is not a hill number.
- 1111000001111 is not a hill number.
Two neighboring digits may be equal, before the top or after it. Only integers of 0 or more are counted, and 0 is a hill number.
An integer is given. If is a hill number, print how many hill numbers are smaller than . If it is not, print .
Input
The first line has the number of test cases ().
Each of the next lines has one integer . is at least 1 and has at most 70 digits. The answer always fits in a signed 64-bit integer.
Output
Print the answer for each test case on its own line.