Sequence Sum

5

1 votes
Problem

Bob has 2 types of sequences S1 and S2. They are defined as follows

S1 = 1, 2, 3, 4, 5, 6...

S2 = 1, -2, 3, -4, 5, -6...

Bob wants you to find the sum of the first N terms of the sequence.

Input Format

There T test cases, and the first line contains a single integer T.

The next T lines contains 2 integers each (type, N), denoting whether its S1 or S2, and the number N.

Constraints

1 T 105

type is either 1 or 2

1 N 109

Output Format

For each test case, output a new line, the required sum

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first test case, the answer is 1 + 2 + 3 = 6.

For the second test case, the answer is 1 - 2 + 3 = 2.

Editor Image

?