Count how many starting values from 1 to 100 turn negative or fractional when the given operations are applied in order.
Easy2SimulationBrute forceNo attempts yetTime limit2sMemory limit256 MBYour friend shows you a calculation and calls it an amazing math trick. You ask how it works, and your friend explains it.
First you pick any integer k between 1 and 100. Then your friend reads out n operations in order. One operation is one of ADD, SUBTRACT, MULTIPLY, or DIVIDE, together with an integer operand x.
You apply the operations in the given order. You do not like dealing with fractions or negative numbers, so if the value ever becomes a fraction or a negative number along the way, you tell your friend that he messed up. In other words, if the value right after some operation is not an integer or is less than 0, you stop there and say he messed up. A value of exactly 0 is fine.
You already know the n operations your friend will read out. How many of the integers from 1 to 100, taken as the starting value, make you tell your friend that he messed up?
The first line contains the integer n (1≤n≤10).
Each of the next n lines contains one operation and one operand, separated by a space. The operation is one of ADD, SUBTRACT, MULTIPLY, or DIVIDE, and the operand is a positive integer not exceeding 5.
Print on a single line how many of the integers from 1 to 100 make you tell your friend that he messed up.