The Two Dishes solution codechef- Chef prepared two dishes yesterday. Chef had assigned the tastinesstastiness T1T1 and T2T2 to the first and to the second dish respectively. The tastiness of the dishes can be any integerinteger between 00 and NN (both inclusive).

The Two Dishes solution codechef

Chef prepared two dishes yesterday. Chef had assigned the tastinesstastiness T1T1 and T2T2 to the first and to the second dish respectively. The tastiness of the dishes can be any integerinteger between 00 and NN (both inclusive).

Unfortunately, Chef has forgotten the values of T1T1 and T2T2 that he had assigned to the dishes. However, he remembers the sum of the tastiness of both the dishes – denoted by SS.

Chef wonders, what can be the maximum possible absolute difference between the tastiness of the two dishes. Can you help the Chef in finding the maximum absolute difference?

It is guaranteed that at least one pair {T1,T2}{T1,T2} exist such that T1+T2=S,0T1,T2NT1+T2=S,0≤T1,T2≤N.

Input Format

  • The first line of input contains a single integer TT, denoting the number of testcases. The description of the TT testcases follows.
  • The first and only line of each test case contains two space-separated integers NNSS, denoting the maximum tastiness and the sum of tastiness of the two dishes, respectively.

Output Format

For each testcase, output a single line containing the maximum absolute difference between the tastiness of the two dishes.

Constraints

  • 1T1031≤T≤103
  • 1N1051≤N≤105
  • 1S21051≤S≤2⋅105

Sample Input 1 

3
3 1
4 4
2 3

Sample Output 1 

1
4
1

Explanation

Test Case 11: The possible pairs of {T1,T2}{T1,T2} are {0,1}{0,1} and {1,0}{1,0}. Difference in both the cases is 11, hence the maximum possible absolute difference is 11.

Test Case 22: The possible pairs of {T1,T2}{T1,T2} are {0,4}{0,4}{1,3}{1,3}{2,2}{2,2}{3,1}{3,1} and {4,0}{4,0}. The maximum possible absolute difference is 44.

Test Case 33: The possible pairs of {T1,T2}{T1,T2} are {1,2}{1,2} and {2,1}{2,1}. Difference in both the cases is 11, and hence the maximum possible absolute difference is 11.

Leave a Comment

Your email address will not be published.