A Sequence of Numbers
You are given a sequence of N integers (each within the range [0, 216 − 1]) along with P operations and
in order to solve this problem you need to process the operations instructed as follows. There are two kinds of operations that you will be instructed to perform:
- Modification - Given a non-negative number T, you need to increase the value of every number in the sequence by T. If the value of any number in the sequence is larger than 216 - 1 after the operation, you should divide its value by 216 and take the remainder as its value;
- Query - Given a non-negative number T, query how many numbers in the sequence satisfies the condition that its bitwise and result with 2T is greater than zero.
For simplicity, all you need to do here is to output the sum (sum < 10, 000, 000, 000) of the answers to all queries.
Input
There are multiple test cases in the input file. Each test case starts with one integer N (N ≤ 105), the number of integers in the sequence. The following N line consists of one integer P (0 ≤ P ≤ 216 − 1), the value on i-th line being the value of the i-th number in the sequence.
Each of the following lines is either of the format ‘C delta’ (0 ≤ delta), meaning that you should increase the value of every number by delta, or ‘Q i’ (0 ≤ i ≤ 15), meaning that you should calculate the answer to the query (as explained in the problem description). Every test case ends with one character ‘E’ on a single line, followed by a blank line.
N = −1 indicates the end of input file and should not be processed by your program. It is guaranteed that the total number of operations in each test case does not exceed 200,000.
Output
For each test case, print the sum of answers to queries on one separate line in the format as indicated in the sample output.
Sample Input
3
1
2
4 Q1 Q2 C1 Q1 Q2 E
-1
2/2
Sample Output
Case 1: 5