# [Solution] Buy 2 Get 1 Free solution codechef

Buy 2 Get 1 Free solution codechef – There is a sale going on in Chefland. For every 22 items Chef pays for, he gets the third item for free (see sample explanations for more clarity).

It is given that the cost of 11 item is XX rupees. Find the minimum money required by Chef to buy at least NN items.

# Buy 2 Get 1 Free solution codechef

• First line will contain TT, number of test cases. Then the test cases follow.
• Each test case contains of a single line of input, two integers NN and XX.

### Output Format

For each test case, output the minimum money required by Chef to buy at least NN items.

### Constraints

• 1T10001≤T≤1000
• 1N,X10001≤N,X≤1000

## Buy 2 Get 1 Free solution codechef

• Subtask 1 (100 points): Original constraints.

### Sample Input 1

4
3 4
4 2
5 3
6 1


### Sample Output 1

8
6
12
4


### Buy 2 Get 1 Free solution codechef

Test Case 11: Chef wants 33 items where the cost of each item is 44 rupees. To minimise the expenditure, Chef can pay for 22 items and get the third item for free. This way, the total money required is 42=84⋅2=8 rupees.

Test Case 22: To minimise the expenditure, Chef can do the following:

• Purchase 22 items for 22=42⋅2=4 rupees and get the third one free. Thus, the total number of items is 33.
• Purchase 11 item for 21=22⋅1=2 rupees. Now Chef has total 44 items.

Thus, the minimum money required to buy 44 items is 4+2=64+2=6 rupees.

Test Case 33: To minimise the expenditure, Chef can do the following:

• Purchase 22 items for 32=63⋅2=6 rupees and get the third one free. Thus, the total number of items is 33.
• Purchase 22 items for 32=63⋅2=6 rupees. Chef gets a third item for free. Now Chef has total 66 items which is greater than his requirement of 55 items.

Chef wanted to buy at least 55 items. The minimum money required for that is 6+6=126+6=12 rupees.

Test Case 44: To minimise the expenditure, Chef can do the following:

• Purchase 22 items for 12=21⋅2=2 rupees and get the third one free. Thus, the total number of items is 33.
• Purchase 22 items for 12=21⋅2=2 rupees and get the third one free.. Now Chef has total 66 items.

Thus, the minimum money required to buy 66 items is 2+2=42+2=4 rupees.