Bessie Goes Moo
Time limit1sMemory limit256 MB
Count assignments of listed values to seven variables that make (B+E+S+S+I+E)(G+O+E+S)(M+O+O) a multiple of 7.
- Level
Medium4 of 10
- Topics
- Math, Brute force, Combinatorics
- Solved
- No attempts yet
Problem
Farmer John and Bessie the cow trade math puzzles whenever they have free time. The last puzzle John gave Bessie was hard enough that she could not solve it, so now she wants to hand John a hard puzzle of her own.
Bessie gives John the expression , which uses the seven variables , , , , , , . The is a variable, not a zero. For each variable Bessie lists up to 500 integer values that the variable is allowed to take. John has to count how many different assignments of values to the variables make the whole expression a multiple of 7.
The answer does not always fit in a 32-bit integer, so use a 64-bit integer type.
Input
The first line contains an integer . Each of the next lines contains a variable name and one value that variable is allowed to take. Each variable appears at least once and at most 500 times, so . The same value is never listed twice for the same variable. Every value is in the range to .
Output
Print one integer, the number of assignments of values to the variables that make the expression a multiple of 7.
Hint
In the first example the two assignments that count are
(B,E,S,I,G,O,M) = (2, 5, 7, 9, 1, 16, 19) -> 51,765
= (2, 5, 7, 9, 1, 16, 2 ) -> 34,510