This page is still under construction.

Parts of this page are still being built. What you see may change.

A+B

Time limit1sMemory limit512 MB

Summary
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 aa, bb, and cc be non-negative integers written in decimal. They all have the same length nn, and each may start with zeros. The numbers are written one below another, so the digits form three rows and nn columns. Here is an example of such a notation:

01211
12099
23300

You need to permute the columns of this notation so that a+b=ca+b=c 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 109+710^9+7.

Input

The input contains the integers aa, bb, and cc, one per line. Each number consists of nn decimal digits and may start with zeros (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5).

Output

Print the number of suitable column permutations modulo 109+710^9+7.

Hint

In the first example, every column permutation is suitable.

In the second example, the only suitable permutation gives 10+20=3010+20=30. The case 01+02=0301+02=03 does not count because of the leading zeros.

In the third example, there are two possible results, 10121+21909=3203010121+21909=32030 and 12101+20919=3302012101+20919=33020. Each of them can be obtained by two different permutations.

Examples4

  1. Example 1

    Input
    123
    123
    246
    
    Expected output
    6
    
  2. Example 2

    Input
    01
    02
    03
    
    Expected output
    1
    
  3. Example 3

    Input
    01211
    12099
    23300
    
    Expected output
    4
    
  4. Example 4

    Input
    121
    214
    999
    
    Expected output
    0