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 had

left 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 form

pairs of shoes.

Therefore Chef must buy at least

extra shoes to ensure that he is able to get

pairs of shoes.

Input Format

  • The first line contains a single integer
  • - the number of test cases. Then the test cases follow.
  • The first line of each test case contains two integers
  • and
    • - 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 form

    pairs 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

    Popular posts from this blog

    Walmart Sparkplug 2022 | 150 students will be selected for summer internship | ₹1-1.1 lakh monthly

    Flipkart Runway: Season 3 | 2025 | Internship

    Python for Data Science NPTEL Assignment Solutions Week 4 2022

    GATE 2022 Answer Key Release Date Announced; Details Here