Task
The two Runtime Terror teams met up in a fierce robot match-up, which is going to decide who is the best Runtime Terror team!
In order to quickly settle the fight, the members of the two teams decided to test these robots in a somewhat unusual event, namely summing numbers up! Now you are helping the members of the 22105 Runtime Terror team win this fight, but there is a catch -- you have to get this done fast.
Namely, you are given an array of integers and queries. In each of the queries, you will have to find the sum of the following values, depending on the type:
- -- find the sum of the bitwise AND for all unordered pairs of integers in that given subarray. In other words, find .
- -- find the sum of the bitwise XOR for all unordered pairs of integers in that given subarray. In other words, find .
- -- find the sum of the bitwise OR for all unordered pairs of integers in that given subarray. In other words, find .
Help your favorite team win the round so that they can show the world they are the best Runtime Terrors out there.
Input data
On the first line you will find , the number of integers in the array. On the next line you will find the integers forming the array .
On the third line you will have , the number of queries. On each of the next lines you will have three integers , where is the type of the query, and are the ends of the subarray in question.
Output data
The output will contain lines, representing the answers for each query.
Constraints and clarifications
- ;
- ;
- ;
- ;
# | Score | Constraints |
---|---|---|
0 | 0 | Example |
1 | 14 | |
2 | 12 | |
3 | 16 | |
4 | 21 | |
5 | 37 | No additional constraints |
Example
stdin
9
8 1 9 4 7 9 4 9 3
14
1 7 8
2 1 4
1 5 6
3 1 7
2 2 8
3 2 3
2 3 6
3 5 7
1 1 9
2 1 9
3 1 9
1 2 5
2 2 9
1 4 6
stdout
0
48
1
210
166
9
57
35
77
278
355
7
216
5