Read problem statements in [Mandarin], [Bengali], and [Russian] as well.

Chef has N slippers, L of which are left slippers and the rest are right slippers. Slippers must always be sold in pairs, where each pair contains one left and one right slipper. If each pair of slippers cost X rupees, what is the maximum amount of rupees that Chef can get for these slippers? 

------ Input Format ------ 

- The first line contains T - the number of test cases. Then the test cases follow.
- The first line of each test case contains three space-separated integers N, L, and X - the total number of slippers, the number of left slippers, and the price of a pair of slippers in rupees.

------ Output Format ------ 

For each test case, output on one line the maximum amount of rupees that Chef can get by selling the slippers that are available.

------ Constraints ------ 

$1 ≤ T ≤ 10^{3}$
$0 ≤ L ≤ N ≤ 10^{3}$
$0 ≤ X ≤ 10^{3}$

----- Sample Input 1 ------ 
4
0 0 100
10 1 0
1000 10 1000
10 7 1

----- Sample Output 1 ------ 
0
0
10000
3
----- explanation 1 ------ 
- Test case $1$: Chef has no pairs to sell, so the amount obtained is $0$.
- Test case $2$: The amount earned by selling a pair is $0$, so the total amount obtained is $0$.
- Test case $3$: Chef can sell $10$ pairs of slippers, each giving $1000$ rupees, so the total amount earned is $1000 \cdot 10 = 10000$.
- Test case $4$: Chef has $10$ slippers of which $7$ are left and $3$ are right. Therefore Chef can sell a maximum of $3$ pairs and in total can get at most $3 \cdot 1 = 3$.

Difficulty: EASY
Tags: Constructive algorithms

Mathematics

Ad-hoc

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(n, l, x) = map(int, input().split())
	print(x * min(l, n - l))


for i in range(int(input())):
	(n, l, x) = map(int, input().split())
	r = n - l
	if l == r:
		print(l * x)
	elif l > r:
		print(r * x)
	else:
		print(l * x)


for _ in range(int(input())):
	(n, l, x) = map(int, input().split())
	z = n - l
	rr = l if l < z else z
	print(rr * x)


n = int(input())
for _ in range(n):
	(N, L, X) = list(map(int, input().split()))
	print(min(L, N - L) * X)


t = int(input())
for _ in range(t):
	(n, l, x) = map(int, input().split())
	if l == 0 or n - l == 0:
		print(0)
	else:
		num_pairs = min(l, n - l)
		print(num_pairs * x)


T = int(input())
for _ in range(T):
	(N, L, X) = map(int, input().split())
	R = N - L
	if R == L:
		print(L * X)
	else:
		print(min(L, R) * X)


def max_money(n, l, x):
	max_pairs = min(l, n - l)
	max_money = max_pairs * x
	return max_money
t = int(input())
for i in range(t):
	(n, l, x) = map(int, input().split())
	max_money_i = max_money(n, l, x)
	print(max_money_i)


t = int(input())
for i in range(t):
	(n, l, x) = [int(i) for i in input().split()]
	r = n - l
	if r == l:
		print(l * x)
	elif r > l:
		print(l * x)
	elif l > r:
		print(r * x)


T = int(input())
for i in range(T):
	(N, L, X) = map(int, input().split())
	if N - L == L:
		print(L * X)
	elif N - L > L:
		print(L * X)
	else:
		print((N - L) * X)


for _ in range(int(input())):
	(n, l, x) = map(int, input().split())
	y = n - l
	r = 0
	if l > n / 2:
		r = y
	else:
		r = l
	print(r * x)


n = int(input())
for i in range(n):
	(a, b, c) = list(map(int, input().split()))
	right = a - b
	mini = min(b, right)
	print(mini * c)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = min(b, a - b)
	print(x * c)


T = int(input())
for i in range(T):
	(n, l, x) = map(int, input().split())
	a = n - l
	if a <= l:
		print(a * x)
	else:
		print(l * x)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	t = abs(a - b)
	l = min(t, b)
	print(l * c)


for case in range(int(input())):
	(n, l, x) = map(int, input().split())
	print(min(l, n - l) * x)


t = int(input())
for i in range(t):
	(n, l, x) = map(int, input().split())
	if n - l >= l:
		print(l * x)
	else:
		print((n - l) * x)


t = int(input())
for i in range(t):
	(n, k, x) = map(int, input().split())
	if n - k >= k:
		print(k * x)
	elif n - k < k:
		print((n - k) * x)


for _ in range(int(input())):
	(n, l, x) = map(int, input().split())
	r = n - l
	print(min(l, r) * x)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	if a - b >= b:
		print(b * c)
	else:
		print((a - b) * c)


T = int(input())
for _ in range(T):
	(N, L, X) = map(int, input().split())
	print(min(L, N - L) * X)


for i in range(int(input())):
	(n, l, x) = map(int, input().split())
	diff = n - l
	if n == 0:
		print('0')
	elif diff < l:
		print(diff * x)
	else:
		print(l * x)


t = int(input())
for _ in range(t):
	(n, l, x) = map(int, input().split())
	b = list((n, l))
	right_slippers = n - l
	if right_slippers > n // 2:
		print(l * x)
	else:
		print(right_slippers * x)


t = int(input())
for i in range(t):
	(n, l, x) = map(int, input().split())
	r = n - l
	if n == 0 or x == 0:
		print('0')
	elif r == l:
		print(l * x)
	elif r > l:
		print(l * x)
	else:
		print(r * x)


for w in range(int(input())):
	(p, l, r) = map(int, input().split())
	if p >= 2 * l:
		print(l * r)
	else:
		print((p - l) * r)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	if a == 0 or b == 0 or c == 0:
		print(0)
	elif b == a - b:
		print((a - b) * c)
	elif b > a - b:
		print((a - b) * c)
	else:
		print(b * c)


t = int(input())
for _ in range(t):
	(N, L, X) = map(int, input().split())
	R = abs(N - L)
	pairs = min(L, R)
	print(pairs * X)


import math
for t in range(int(input())):
	(n, l, p) = map(int, input().split())
	mini = n - l
	minn = min(mini, l)
	print(minn * p)


t = int(input())
for _ in range(t):
	(n, l, x) = map(int, input().split())
	if n - l == l:
		print(l * x)
	elif n - l > l:
		print(l * x)
	else:
		print((n - l) * x)


n = int(input())
for _ in range(n):
	(a, b, c) = map(int, input().split())
	if a > 0 and b > 0 and (c > 0):
		if a >= 2 * b:
			print(b * c)
		else:
			x = a - b
			print(x * c)
	else:
		print(0)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	if a - b > b:
		print(b * c)
	else:
		print((a - b) * c)


t = int(input())
for i in range(t):
	(n, l, x) = map(int, input().split())
	a = n - l
	if a > l:
		y = a - l
		s = n - y
		p = s / 2
		earn = int(p * x)
		print(earn)
	elif l > a:
		y = l - a
		s = n - y
		p = s / 2
		earn = int(p * x)
		print(earn)
	elif l == a:
		earn = int(l * x)
		print(earn)


t = int(input())
for i in range(0, t):
	(a, b, c) = map(int, input().split(' '))
	print(min(a - b, b) * c)


for _ in range(int(input())):
	(t, r, c) = map(int, input().split())
	l = t - r
	print(c * min(l, r))


for _ in range(int(input())):
	(n, x, l) = map(int, input().split())
	if n >= x * 2 and x > 0:
		print(x * l)
	elif n == 0 or x == 0:
		print('0')
	else:
		print((n - x) * l)


for t in range(int(input())):
	(n, l, x) = [int(x) for x in input().split()]
	if n == 0 or l == 0 or x == 0:
		print(0)
	else:
		right = n - l
		res = min(right, l)
		print(res * x)


for _ in range(int(input())):
	(t, r, c) = map(int, input().split())
	ans = t - r
	if ans > r:
		print(r * c)
	elif r >= ans:
		print(ans * c)
	else:
		print(0)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = abs(a[0] - a[1])
	c = 0
	if a[1] < b:
		c = a[1]
	else:
		c = b
	print(c * a[-1])


a = int(input())
for i in range(a):
	(b, c, d) = map(int, input().split())
	e = abs(c - b)
	if c < e:
		print(c * d)
	else:
		print(e * d)


for _ in range(int(input())):
	(n, l, k) = map(int, input().split())
	r = n - l
	if r == l:
		print(l * k)
	elif r < l:
		print(r * k)
	else:
		print(l * k)


for _ in range(int(input())):
	(n, l, x) = map(int, input().split())
	if l == 0 or x == 0:
		print(0)
	else:
		r = n - l
		if l < r:
			print(l * x)
		else:
			print(r * x)


try:
	t = int(input())
	for r in range(t):
		(n, l, x) = map(int, input().split())
		r = n - l
		if r <= l:
			print(r * x)
		else:
			print(l * x)
except:
	pass


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	if b == 0 or c == 0:
		print(0)
	else:
		d = a - b
		if b < d:
			print(b * c)
		else:
			print(d * c)


for i in range(int(input())):
	(slippers, left, cost_of_one) = map(int, input().split())
	print(min(left, slippers - left) * cost_of_one)


t = int(input())
for _ in range(t):
	(n, l, x) = map(int, input().split())
	max_pairs = min(l, n - l)
	max_amount = max_pairs * x
	print(max_amount)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	m = a - b
	if m == b:
		print(b * c)
	elif m < b:
		print(m * c)
	else:
		print(b * c)


T = int(input())
for o in range(T):
	(n, l, x) = map(int, input().split())
	r = n - l
	print(min(l, r) * x)


t = int(input())
while t != 0:
	(n, l, x) = list(map(int, input().split()))
	r = n - l
	if r <= l:
		print(r * x)
	else:
		print(l * x)
	t = t - 1


T = int(input())
for i in range(T):
	(N, L, X) = map(int, input().split())
	R = N - L
	pairs = min(L, R)
	print(pairs * X)


for i in range(int(input())):
	(x, y, a) = map(int, input().split())
	print(min(x - y, y) * a)


t = int(input())
for i in range(t):
	(n, l, x) = map(int, input().split())
	a = abs(n - l)
	b = min(a, l)
	print(b * x)


for t in range(int(input())):
	(total, left, cost) = map(int, input().split())
	print(min(total - left, left) * cost if total >= left else 0)


t = int(input())
for i in range(t):
	(n, l, x) = input().split()
	n = int(n)
	l = int(l)
	x = int(x)
	r = n - l
	num = min(l, r)
	print(num * x)


T = int(input())
for i in range(T):
	(a, b, c) = list(map(int, input().split()))
	d = a - b
	print(min(b, d) * c)


for t in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = min(b, a - b)
	print(d * c)


T = int(input())
for tc in range(T):
	(n, l, x) = map(int, input().split())
	r = n - l
	w = min(r, l)
	print(x * w)