A mint stamps each coin with a serial made only of decimal digits. The serial is later decoded into letters using the fixed table 1 -> A, 2 -> B, ..., 26 -> Z. To decode a serial you split it left to right into groups, where each group is either a single digit forming 1-9, or two adjacent digits forming a number 10-26. A group may never have a leading zero (so 0, 06 are not valid groups), which means a 0 can only ever be the second digit of 10 or 20.
Count the number of distinct ways to decode the given serial. Print the count modulo 1000000007. If the serial cannot be decoded at all, the answer is 0.
A single line: the serial string, consisting only of characters 0-9.
A single integer: the number of valid decodings, taken modulo 1000000007.
0-9.Example 1
Input
226
Expected
3
Explanation
226 decodes as 2|2|6, 22|6, or 2|26, i.e. BBF, VF, or BZ. That is 3 ways.
Example 2
Input
12
Expected
2
Explanation
12 decodes as 1|2 (AB) or 12 (L), giving 2 ways.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →