ICODER  Instruction Decoder
Mathews uses a brand new 16bit instruction processor. (Yeah i am being sarcastic!). It has one register (say R) and it supports two instructions:
 ADD X; Impact: R = (R + X) mod 65536
 MUL X; Impact: R = (R * X) mod 65536
 [For both instructions 0 <= X <= 65535]
Input Format:
The input file consists of multiple testcases.
The first line of each testcase contains one integer, N. (1 <= N <= 100,000).
The following N lines contain one instructions each.
Input terminates with a line containing N=0, which must not be processed.
Output Format:
For each testcase print one integer in a single line, denoting the number of different values the register can take after code execution.
Sample Input:
1 ADD 3 1 MUL 0 5 MUL 3 ADD 4 MUL 5 ADD 3 MUL 2 8 ADD 32 MUL 5312 ADD 7 MUL 7 ADD 32 MUL 5312 ADD 7 MUL 7 0Sample Output:
65536 1 32768 16
hide comments
minhthai:
20160318 11:46:59
can someone explain the result "16". I thought the equation in that test is not solvable ??? 

Kishlay Raj:
20140420 05:00:37
Last edit: 20140422 16:45:24 

napster:
20130309 13:42:40
can u tell me how the 3rd test case getting 32768?? 
Added by:  Prasanna 
Date:  20071008 
Time limit:  0.476s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL JSRHINO NODEJS PERL6 VB.NET 
Resource:  NITT ACM ICPC Local Contest 2007 [Self] 