Mathematics

Count how many starting integers, under a sequence of at most 10 add, subtract, multiply by x, or truncating divide by x operations, land on a given final result.

Medium6MathBrute forceImplementationNumber theoryNo attempts yetTime limit1sMemory limit128 MB

Problem

Igor did not practice mathematics at all over the summer holidays, and a few days before school started he realized that he no longer remembers the basic arithmetic operations. Now he keeps pestering his brother Davor to help him practice.

To make the practice interesting, Davor told Igor to think of an integer. Then he told him several times to add another integer to it, subtract one from it, multiply it by one, or divide it by one. For division Igor always uses integer division that truncates toward zero. For example, dividing 27-27 by 1010 gives 2-2. At the end of the practice Igor says the final result out loud, and it is up to Davor to guess which number Igor thought of at the start.

Write a program that determines how many different integers Igor could have thought of, given the operations and the final result.

Input

The first line contains the number of operations NN. (1N101 \le N \le 10)

Each of the next NN lines contains one operation in one of four forms.

  • DODAJ x: add xx.
  • ODUZMI x: subtract xx.
  • POMNOZI SA x: multiply by xx.
  • PODIJELI SA x: divide by xx.

Here xx is an integer with 1x91 \le x \le 9.

The last line contains the final result, an integer RR. (100R100-100 \le R \le 100)

Output

Print on the first line how many different integers Igor could have thought of. This count can exceed the 32-bit integer range.

Hint

In the first example there is no integer that gives 88 when multiplied by 55.