You are helping your brother with his homework assignment. His teacher gave him two distinct numbers x
and y, and asked him to use those numbers to form as many different expressions as possible.
Each expression must satisfy all of the following rules:
-
The only allowed operators are '+', '-' and '*'.
-
x and y must each appear exactly twice. No other numbers are allowed.
-
The result of the expression must be equal to val.
In other words, each expression can be written in the form "a op1 b op2 c op3 d", where each of op1, op2 and op3
is '+', '-' or '*', and among the numbers a, b, c and d, exactly two are equal to x and the other two are
equal to y. Please note that the unary minus is not allowed (see example 0). Expressions are calculated from
left to right, and there is no operator precedence. For example, to calculate the result of
"2 + 2 * 3 + 3", you would first calculate 2 + 2, then multiply the result by 3, and then add 3 to get 15.
Return the total number of different expressions that can be formed. Two expressions are considered
different if their string notations (as described in the previous paragraph) are different. For example,
the expressions "2 + 3 - 2 - 3", "2 - 2 + 3 - 3" and "2 - 3 - 2 + 3" are all different.
|