MOHIB - Mohib and series

Mohib (CoolWink), as we all known, is very brilliant in mathematics. His friend Bar has given him another problem to solve.

Bar gives him a sequence of distinct positive integers, whose average is (A+1).

If Bar append an integer x to the sequence, then the average of integers in the sequence will be A.

He asked the Mohib to tell him the largest possible integer in the sequence.

Input

First line contains T, the number of testcases (T <= 5000). 

Next T lines contain an integer x (1 <= x <= 49999) and A (x+1 <= A <= 50000).

Output

Print the largest possible integer in the sequence.

Example

Input:
1
1 2

Output:
3

Added by:MoHib85
Date:2015-05-17
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ADA95 ASM32-GCC ASM32 ASM64 GAWK BASH JS-MONKEY

hide comments
2016-02-28 10:21:08 Arnabjyoti Kalita
Pretty easy--focus on the fact that the initial sequence has distinct numbers...
2015-12-06 23:48:59 Jacob Plachta
In some cases, x=avg... The expected output in this case is "0".
2015-12-06 18:18:27 hmp
can any body tell what is runtime error (SIGABRT) in c++
2015-10-21 19:13:55 Arjav Patel
Instead of Positive number, it should be positive integer!
2015-08-20 21:31:15
@author
code id: 14939892
output value for all input values are correct,but still getting wrong answer
(MoHib85)==> I think you should use the spoj toolkit for corner cases and debug your code....Best Of luck.. :)

thanks :D


Last edit: 2015-12-24 23:56:37
2015-08-19 19:27:25 poojan
10 minit of paperwork needed !AC in first go! btw good que!
(MoHib85)==>thanks for your appreciation ;)

Last edit: 2015-08-26 23:40:56
2015-08-09 18:20:26
easy one..accepted in one go........
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.