A + B = C
Time limit2sMemory limit1024 MB
Count ordered pairs of n-digit beautiful numbers (no two equal consecutive digits, nonzero leading digit) that sum to a given n-digit number C, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Math, Implementation, Combinatorics
- Solved
- No attempts yet
Problem
Practice contests at informatics olympiads often include an "A + B" problem, where the task is to find the sum of given integers and .
While preparing a city informatics olympiad, the chair of the judging committee decided to make the tests for such a problem himself. He used his own method: first choose the intended correct answers, then construct the input data that matches those answers.
Suppose the chair chose a number with decimal digits whose first digit is not zero. He now wants to find positive integers and such that their sum is , and each of them also has decimal digits with a nonzero first digit. In addition, the chair wants both and to be beautiful. In his view, a number is beautiful if its decimal representation contains no two equal consecutive digits. For example, is beautiful, while is not.
Given a positive integer , write a program that counts the pairs of beautiful positive integers and whose sum is . Since the count can be large, output the remainder of this count modulo .
Input
The input file contains a single positive integer . does not start with zero. The number of digits of is at most .
Output
The output file must contain a single integer: the remainder of the number of desired pairs of beautiful numbers and modulo .
Notes
can be written as a sum of two-digit numbers in three ways: , , . The way does not qualify because is not beautiful. Therefore the answer for is .
can be written as a sum of three-digit numbers in only one way: . This way does not qualify, so the answer for is .
cannot be written as a sum of four-digit numbers, so the answer for is also .