The *fuel economy* of a car is the distance which it can travel on one litre of fuel.

The base fuel economy (i.e, its fuel economy when there is only one person - the driver - in the car) of a certain car is M kilometres per litre. It was also observed that every extra passenger in the car *decreases* the fuel economy by 1 kilometre per litre.

P people want to take this car for a journey. They know that the car currently has V litres of fuel in its tank.

What is the maximum distance this car can travel under the given conditions, assuming that all P people always stay in the car and no refuelling can be done?

Note that among the P people is also a driver, i.e, there are exactly P people in the car.

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

- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, containing three space-separated integers P, M, and V - the number of people, base fuel economy, and amount of fuel present in the car, respectively.

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

For each test case, output a single line containing one integer - the maximum distance that the car can travel.

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

$1 ≤ T ≤ 3 \cdot 10^{4}$
$1 ≤ P ≤ 5$
$6 ≤ M ≤ 56$
$1 ≤ V ≤ 100$

----- Sample Input 1 ------ 
3
5 10 20
1 6 10
4 6 1
----- Sample Output 1 ------ 
120
60
3
----- explanation 1 ------ 
Test Case $1$: 
There are $5$ people in the car, and its base fuel economy is $10$. Thus, its effective fuel economy is $10 - 4 = 6$, since there are $4$ people present other than the driver.
There are $20$ litres of fuel in the car, so the maximum distance that can be travelled is $6\cdot 20 = 120$.

Test Case $2$: 
The effective fuel economy is $6$, and the maximum distance that can be travelled is $6\cdot 10 = 60$.

Test Case $3$: 
The effective fuel economy is $3$, and the maximum distance that can be travelled is $3\cdot 1 = 3$.

Difficulty: EASY
Tags: Constructive algorithms

Mathematics

Ad-hoc

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(p, m, v) = map(int, input().split())
	print(abs(p - m - 1) * v)


T = int(input())
for i in range(T):
	(P, M, T) = map(int, input().split())
	n1 = P - 1
	print((M - n1) * T)


for i in range(int(input())):
	(P, M, V) = map(int, input().split())
	print((M - (P - 1)) * V)


for testcases in range(int(input())):
	(people, economy, litres) = map(int, input().split())
	total = economy - (people - 1)
	print(total * litres)


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


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


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


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


T = int(input())
for _ in range(T):
	(P, M, V) = map(int, input().split())
	persons_in_car = 0 if P == 1 else P - 1
	print((M - persons_in_car) * V)


for _ in range(int(input())):
	(p, m, v) = map(int, input().split())
	print((m - (p - 1)) * v)


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


t = int(input())
for i in range(t):
	(p, v, m) = map(int, input().split())
	if p > 1:
		v = v - (p - 1)
		print(v * m)
	else:
		print(v * m)


t = int(input())
for i in range(t):
	(p, m, v) = [int(i) for i in input().split()]
	eco = m - (p - 1)
	output = v * eco
	print(output)


t = int(input())
for x in range(t):
	(p, m, v) = map(int, input().split())
	cm = m - (p - 1)
	print(cm * v)


T = int(input())
for i in range(T):
	(P, M, V) = map(int, input().split())
	if P <= 1:
		res1 = M * V
		print(res1)
	else:
		res1 = (M - (P - 1)) * V
		print(res1)


def cr(x, y, z):
	if x > 1:
		ans = (y - (x - 1)) * z
		print(ans)
	else:
		print(y * z)
t = int(input())
for i in range(0, t):
	(a, b, c) = map(int, input().split())
	ans = cr(a, b, c)


def cr(x, y, z):
	g = x - 1
	h = y - g
	i = h * z
	print(i)
t = int(input())
for i in range(0, t):
	(a, b, c) = map(int, input().split())
	ans = cr(a, b, c)


for i in range(int(input())):
	(p, m, v) = map(int, input().split())
	base_ec = m
	base_dist = m * v
	if p == 1:
		print(base_dist)
	if p > 1:
		net_ec = m - p + 1
		print(net_ec * v)


for i in range(int(input())):
	(p, m, v) = map(int, input().split())
	res = v * (m - p + 1)
	print(res)


T = int(input())
for _ in range(T):
	(P, M, V) = map(int, input().split())
	print((M - (P - 1)) * V)


test = int(input())
for i in range(test):
	(a, b, c) = map(int, input().split())
	persons = a - 1
	reminds = b - persons
	print(c * reminds)


T = int(input())
for i in range(T):
	milage = input().split()
	P = int(milage[0]) - 1
	M = int(milage[1])
	V = int(milage[2])
	fuel_economy = M - P
	range_car = fuel_economy * V
	print(int(range_car))


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


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


for _ in range(int(input())):
	(p, m, v) = map(int, input().split())
	if p == 1:
		print(m * v)
	else:
		f = p - 1
		k = m - f
		print(k * v)


try:
	t = int(input())
	for r in range(t):
		(p, m, v) = map(int, input().split())
		d = p - 1
		c = m - d
		if p == 1:
			print(m * v)
		else:
			print(c * v)
except:
	pass


t = int(input())
for i in range(t):
	(p, m, v) = map(int, input().split())
	a = m - p + 1
	b = a * v
	print(b)


for i in range(int(input())):
	(members, kmltr, fuelinltr) = map(int, input().split())
	print((kmltr - members + 1) * fuelinltr)


t = int(input())
for _ in range(t):
	(p, m, v) = list(map(int, input().split()))
	effective_f_economy = m - p + 1
	print(effective_f_economy * v)


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


for _ in range(int(input())):
	(P, M, V) = [int(i) for i in input().split()]
	if P == 1:
		print(M * V)
	else:
		print((M - P + 1) * V)


T = int(input())
for i in range(T):
	(People, BaseFuelEconomy, FuelPresent) = map(int, input().split())
	NewPeople = People - 1
	NewTargetCovered = BaseFuelEconomy - NewPeople
	MaxDistanceCovered = FuelPresent * NewTargetCovered
	print(MaxDistanceCovered)


for _ in range(int(input())):
	(p, m, v) = map(int, input().split())
	if p > 1:
		p -= 1
		s = m - p
		print(s * v)
	elif p == 1:
		print(m * v)
	else:
		print(0)


T = int(input())
for i in range(T):
	input_values = input().split()
	if len(input_values) != 3:
		print('Invalid input for test case', i + 1)
		continue
	(P, M, V) = map(int, input_values)
	if not (1 <= P <= 5 and 6 <= M <= 56 and (1 <= V <= 100)):
		print('Invalid input for test case', i + 1)
		continue
	fuel_economy = M - (P - 1)
	max_distance = fuel_economy * V
	print(max_distance)


t = int(input())
for i in range(t):
	(p, m, v) = map(int, input().split())
	q = p - 1
	r = m - q
	print(r * v)


for i in range(int(input())):
	(x, y, z) = map(int, input().split())
	d1 = x - 1
	d2 = y - d1
	print(d2 * z)