Count Equation Solutions

Count the number of positive integer solutions to the following equation: a1x1 −a2x2 +a3x3 −a4x4 +a5x5 −a6x6 =0 where ai are integer coefficients, and xi are the variables such that 1 ≤ xi ≤ M. Input A number of of inputs (≤ 600) described as follows. The first line is M on a single line, followed by the 6 coefficients ai on the next line. Constraint is 1 ≤ M ≤ 100 and 0 < ai ≤ 1000000. Output For each input, output the number of solutions on a single line. Sample Input 2 111111 Sample Output 20