#arc147f. [arc147_f]Again ABC String
[arc147_f]Again ABC String
Problem Statement
Consider strings of length consisting of A
, B
, and C
. Among them, find the number of strings that satisfy the following condition, modulo :
- Let be the string formed by the first characters of . Also let , , and be the numbers of
A
's,B
's, andC
's in , respectively. For all such that , the following holds:
You have test cases to solve.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Each case is in the following format:
Output
For each case, print the answer.
Sample Input 1
1
3 2 1 0
Sample Output 1
0
strings satisfy the condition: AAB
,AAC
,ABA
,ABC
,ACA
,ACB
,BAA
,BAC
. Therefore the answer is .
Sample Input 2
10
1 22 9 92
14 7 74 39
23 50 8 6
93 40 9 60
68 8 47 64
11 68 18 24
3 26 54 8
46 17 90 86
86 76 45 55
80 68 79 62
Sample Output 2
1
0
0
0
1
1
1
0
1
0