This page is still under construction.

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

Restore Calculation

Time limit8sMemory limit512 MB

Summary
Count ways to fill each ? in equal-length strings A, B, and C with digits, leading digits nonzero, so A plus B equals C, modulo 1,000,000,007.
Level

Medium5 of 10

Topics
Dynamic programming, Math
Solved
No attempts yet

Problem

The Animal School is a primary school for animal children. You are a fox attending this school.

One day the rabbit teacher, Hanako, hands you a problem called "Arithmetical Restorations". An arithmetical restoration looks like this.

  • You are given three positive integers AA, BB and CC.
  • Several digits in these numbers have been erased.
  • You assign a digit to each blank position so that A+B=CA + B = C holds.
  • The first digit of each number must not be zero. The same applies to a single-digit number.

You are good at mathematics, so you solved the problem right away. Then you thought of a harder one: count how many assignments a given arithmetical restoration admits. Solving that will earn you a good grade.

Shortly after starting the new task you noticed that there may be far too many assignments to enumerate by hand. Since you are also the best programmer in the school, you are now writing a program that counts the assignments.

Input

The input is a sequence of datasets. The number of datasets is less than 100. Each dataset has the following format.

A
B
C

A dataset consists of the three strings AA, BB and CC, meaning that the sum of AA and BB must be CC. Each string consists of digits (0-9) and question marks (?). A question mark marks an erased digit. The first character of each string is not 0, and every dataset contains at least one question mark.

Each string has between 1 and 50 characters, and the three strings of a dataset have the same length.

The end of the input is a line holding a single zero.

Output

For each dataset, print the number of possible assignments modulo 1,000,000,007 on its own line. Ms. Hanako is a careless rabbit, so some datasets have no assignment at all.

Hint

The first dataset of the example has 2 assignments.

  • 384 + 122 = 506
  • 394 + 122 = 516

Examples6

  1. Example 1

    Input
    3?4
    12?
    5?6
    ?2?4
    5?7?
    ?9?2
    ?????
    ?????
    ?????
    0
    
    Expected output
    2
    40
    200039979
    
  2. Example 2

    Input
    ?
    ?
    ?
    0
    
    Expected output
    36
    
  3. Example 3

    Input
    1?
    1?
    1?
    0
    
    Expected output
    0
    
  4. Example 4

    Input
    12
    34
    ??
    0
    
    Expected output
    1
    
  5. Example 5

    Input
    ?9
    ?9
    ?8
    0
    
    Expected output
    28
    
  6. Example 6

    Input
    ??
    ??
    ??
    0
    
    Expected output
    3240