Farmer John and Bessie the cow enjoy exchanging math puzzles in their free time. The last puzzle FJ gave Bessie was quite difficult, and she was unable to solve it. Now she wants to get even with FJ by giving him a challenging puzzle of her own.
Bessie gives FJ the expression
which contains the seven variables B, E, S, I, G, O, and (the variable is the letter '', not the digit zero).
For each variable, she gives FJ a list of up to integer values that the variable may take. She asks FJ to count the number of different ways to assign values to the variables such that the entire expression is a multiple of .
Note that the answer can be too large to fit in a -bit integer, so you should use -bit integers (such as long~long in C or C++).
The first line contains an integer . Each of the next lines contains a variable and a possible value for that variable.
Each variable appears in the list at least once and at most times. No possible value is listed more than once for the same variable. All possible values are in the range -10^5 to 10^5.
Print one integer, representing the number of ways FJ can assign values to the variables such that the expression above is a multiple of .
The two possible assignments are
Example 1