A+B
Time limit1sMemory limit512 MB
Count the column permutations of three n-digit rows that make a+b=c hold with no leading zeros, modulo 10^9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
Let , , and be non-negative integers written in decimal. They all have the same length , and each may start with zeros. The numbers are written one below another, so the digits form three rows and columns. Here is an example of such a notation:
01211
12099
23300
You need to permute the columns of this notation so that holds. In the resulting notation, leading zeros are already forbidden. Count the number of different ways to do this.
Two column permutations are considered different even if the resulting notations are the same. For example, swapping the last two columns in the notation above gives a different permutation, even though the digits in those columns match.
Since the answer can be large, print it modulo .
Input
The input contains the integers , , and , one per line. Each number consists of decimal digits and may start with zeros ().
Output
Print the number of suitable column permutations modulo .
Hint
In the first example, every column permutation is suitable.
In the second example, the only suitable permutation gives . The case does not count because of the leading zeros.
In the third example, there are two possible results, and . Each of them can be obtained by two different permutations.