#P9768. [ROIR 2021] A+B (Day 2)
[ROIR 2021] A+B (Day 2)
Background
Translated from ROIR 2021 Day 2 T4 A+B。
Problem Description
There are three integers of length , which may contain leading zeros. They are arranged into three rows and columns as follows:
a
b
c
How many different ways are there to permute the columns so that the three integers read horizontally, , satisfy , and none of the three integers has leading zeros.
The number of permutations may be large; output it .
Input Format
The first line is an integer of length .
The second line is an integer of length .
The third line is an integer of length .
Output Format
Output one integer: the number of different permutations modulo .
123
123
246
6
01
02
03
1
01211
12099
23300
4
121
214
999
0
Hint
[Sample Explanation 1]: All permutations are valid.
[Sample Explanation 2]: We only count , and we do not count , because has a leading zero.
[Sample Explanation 3]: Clearly, there are two valid equations: and . However, since there are two identical columns, each of them has two ways to obtain the answer. The total number of valid permutations is .
[Constraints]:
For all subtasks, .
| Subtask ID | Special Constraints | Score |
|---|---|---|
| , the input numbers do not contain | ||
| , the input numbers do not contain | ||
| the input numbers do not contain | ||
| no special constraints |
Translated by ChatGPT 5