Finding Shoes
Chef has
friends. Chef promised that he would gift a pair of shoes (consisting of one left shoe and one right shoe) to each of his friends. Chef was about to go to the marketplace to buy shoes, but he suddenly remembers that he already hadleft shoes.
What is the minimum number of extra shoes that Chef will have to buy to ensure that he is able to gift a pair of shoes to each of his
friends?
For example, if
, , then Chef already has left shoes, so he must buy extra right shoes to formpairs of shoes.
Therefore Chef must buy at least
extra shoes to ensure that he is able to getpairs of shoes.
Input Format
- The first line contains a single integer
- - the number of Chef's friends and the number of left shoes Chef has.
Output Format
For each test case, output the minimum number of extra shoes that Chef will have to buy to ensure that he is able to get
pairs of shoes.
Constraints
Sample Input 1
3
2 4
6 0
4 3
Sample Output 1
2
12
5
Explanation
Test Case 1: Discussed in the problem statement
Test Case 2: Chef initially has no left shoes. He must buy
more left shoes and more right shoes to formpairs of shoes.
Test Case 3: Chef initially has
left shoes. He must buy more left shoe and more right shoes to form pairs of shoes.
Comments
Post a Comment