Bessie Gets Even
InterviewTime limit1sMemory limit256 MB
Count assignments of listed values to seven letters that make the product (B+E+S+S+I+E)(G+O+E+S)(M+O+O) even.
- Level
Easy3 of 10
- Topics
- Brute force, Combinatorics, Math
- 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 get even by handing him a hard one.
Bessie gives John the expression , which uses the seven variables . The is a variable, not a zero. For each variable she lists up to 20 integer values that the variable is allowed to take. John has to count the number of different ways to assign values to the variables so that the whole expression evaluates to an even number.
Input
The first line contains an integer . Each of the next lines contains a variable and one possible value for that variable, separated by a space. Every variable appears in this list at least once and at most 20 times. The same value is never listed twice for the same variable. All values are between and . So is between 7 and 140.
Output
Print, on one line, the number of ways John can assign values to the variables so that the expression evaluates to an even number.
Hint
In the example with there are six possible assignments.
(B,E,S,I,G,O,M) = (2, 5, 7, 10, 1, 16, 19) -> 53244
= (2, 5, 7, 10, 1, 16, 2 ) -> 35496
= (2, 5, 7, 9, 1, 16, 2 ) -> 34510
= (3, 5, 7, 10, 1, 16, 2 ) -> 36482
= (3, 5, 7, 9, 1, 16, 19) -> 53244
= (3, 5, 7, 9, 1, 16, 2 ) -> 35496
and give the same value, but they assign different values to the variables, so they count as two different assignments.