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

In a Chess match "a + b", each player has a clock which shows $a$ minutes at the start and whenever a player makes a move, $b$ seconds are added to this player's clock. Time on a player's clock decreases during that player's turns and remains unchanged during the other player's turns. If the time on some player's clock hits zero (but not only in this case), this player loses the game.

There's a 3 + 2 blitz chess match. After $N$ turns (i.e. $\lfloor \frac{N+1}{2} \rfloor$ moves made by white and $\lfloor \frac{N}{2} \rfloor$ moves made by black), the game ends and the clocks of the two players stop; they show that the players (white and black) have $A$ and $B$ seconds left respectively. Note that after the $N$-th turn, $b = 2$ seconds are still added to the clock of the player that made the last move and then the game ends.

Find the total duration of the game, i.e. the number of seconds that have elapsed from the start of the game until the end.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains three space-separated integers $N$, $A$ and $B$. 

------  Output ------
For each test case, print a single line containing one integer — the duration of the game.

------  Constraints ------
$1 ≤ T ≤ 10^{5}$
$10 ≤ N ≤ 100$
$0 ≤ A ≤ 180 + 2 \cdot \lfloor \frac{N+1}{2} \rfloor$
$0 ≤ B ≤ 180 + 2 \cdot \lfloor \frac{N}{2} \rfloor$
for $N$ odd, $A ≥ 2$
for $N$ even, $B ≥ 2$
there is at least one valid game consistent with the input

----- Sample Input 1 ------ 
3
10 0 2
11 2 1
12 192 192
----- Sample Output 1 ------ 
378
379
0
----- explanation 1 ------ 
Example case 1: The total time given to both clocks after $10$ turns is $2 \cdot (180 + 10) = 380$ seconds. The total time left at the end is $0 + 2 = 2$ seconds. The duration of the game is $380 - 2 = 378$ seconds.

Example case 3: The total time given to both clocks after $12$ turns is $2 \cdot (180 + 12) = 384$ seconds. The total time left at the end is $192 + 192 = 384$ seconds. The duration of the game is $384 - 384 = 0$ seconds.

Difficulty: EASY
Tags: Constructive algorithms

Mathematics

Ad-hoc

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	total = 360 - a - b + 2 * n
	print(total)


T = input()
a = 3 * 60
b = 2
n = 0
for n in range(int(T)):
	play = input()
	play_list = play.split()
	N = int(play_list[0])
	A = int(play_list[1])
	B = int(play_list[2])
	if 10 <= N <= 100:
		total_time = 2 * (a + N)
		time_left = A + B
		time_elapsed = total_time - time_left
		print(time_elapsed)
		n += 1
	else:
		pass


t = int(input())
for i in range(t):
	(N, A, B) = map(int, input().split())
	print(2 * (180 + N) - (A + B))


for i in range(int(input())):
	(N, A, B) = map(int, input().split())
	time = 2 * (180 + N)
	total_time = time - (A + B)
	print(total_time)


for i in range(int(input())):
	(n, a, b) = list(map(int, input().split()))
	print(2 * (180 + n) - (a + b))


for _ in range(int(input())):
	(m, x, y) = map(int, input().split())
	print(2 * (180 + m) - (x + y))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	t1 = 2 * (180 + a)
	t2 = t1 - b - c
	print(t2)


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


T = int(input())
for _ in range(T):
	(N, A, B) = map(int, input().split())
	print(2 * (180 + N) - (A + B))


T = int(input())
for i in range(T):
	(N, A, B) = map(int, input().split())
	total_time_added = N * 2
	total_time_consumed = 2 * 180 + total_time_added
	total_duration = total_time_consumed - (A + B)
	print(total_duration)


t = int(input())
for i in range(t):
	(n, a, b) = list(map(int, input().split()))
	hi = 2 * (180 + n)
	hu = a + b
	print(hi - hu)


T = int(input())
for i in range(T):
	(N, A, B) = [int(j) for j in input().split()]
	result = 2 * (180 + N) - (A + B)
	print(result)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	e = 2 * (180 + a)
	d = b + c
	print(e - d)


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	print(2 * (180 + n) - (a + b))


T = int(input())
for i in range(T):
	(n, a, b) = map(int, input().split())
	res1 = 2 * (180 + n)
	res2 = a + b
	res3 = res1 - res2
	print(res3)


T = int(input())
for i in range(T):
	(N, A, B) = map(int, input().split())
	C = 2 * (180 + N)
	D = A + B
	if D - C >= 0:
		print(D - C)
	else:
		print(C - D)


t = int(input())
for i in range(t):
	(x, y, z) = map(int, input().split())
	Total_seconds = 2 * (180 + x)
	Seconds_remaining = y + z
	Sec_after_game = Total_seconds - Seconds_remaining
	print(Sec_after_game)


T = int(input())
1 <= T <= 100000
for _ in range(0, T):
	(N, A, B) = map(int, input().split())
	10 <= N <= 100
	C = 2 * (180 + N) - (A + B)
	print(C)


t = int(input())
for i in range(t):
	lst = list(map(int, input().split()))
	print(2 * (180 + lst[0]) - (lst[1] + lst[2]))


t = int(input())
for i in range(0, t):
	(n, a, b) = map(int, input().split())
	print(2 * (180 + n) - (a + b))


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().strip().split())
	k = 2 * (180 + n)
	c = a + b
	print(k - c)


t = int(input())
for i in range(t):
	(x, y, z) = map(int, input().split())
	ans = 2 * (180 + x)
	ans1 = y + z
	ans2 = ans - ans1
	print(ans2)


for i in range(int(input())):
	a = list(map(int, input().split()))
	res = 2 * (180 + a[0]) - (a[2] + a[1])
	print(res)


for t in range(int(input())):
	(n, a, b) = map(int, input().split())
	time = 2 * (180 + n) - (a + b)
	print(time)


def game_duration(n, a, b):
	total_time = 2 * (180 + n)
	remaining_time = total_time - a - b
	return remaining_time
t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	print(game_duration(n, a, b))


def match(x, y, z):
	h = 2 * (180 + x)
	total = y + z
	print(h - total)
t = int(input())
for c in range(t):
	(x, y, z) = input().split()
	match(int(x), int(y), int(z))


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	p = 2 * (180 + n)
	q = a + b
	print(abs(p - q))


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	c = 2 * (180 + n)
	d = a + b
	print(abs(c - d))


t = eval(input())
while t:
	(n, a, b) = [int(i) for i in input().split()]
	c = 2 * (180 + n)
	d = a + b
	e = c - d
	print(e)
	t -= 1


ans = []
for i in range(int(input())):
	z = input().split(' ')
	N = int(z[0])
	A = int(z[1])
	B = int(z[2])
	a = int((N + 1) / 2)
	b = int(N / 2)
	x = 180 + 2 * a
	y = 180 + 2 * b
	ans.append(x - A + (y - B))
for j in ans:
	print(j)


for i in range(int(input())):
	(N, A, B) = map(int, input().split(' '))
	tot1 = 2 * (180 + N)
	tot2 = A + B
	print(tot1 - tot2)


n = int(input())
for i in range(n):
	(x, y, z) = map(int, input().split())
	print(2 * (180 + x) - (y + z))


R = lambda : map(int, input().split())
testCase = int(input())
for i in range(testCase):
	(N, A, B) = R()
	totalTime = 2 * (N + 180)
	print(totalTime - A - B)


t = int(input())
for i in range(0, t):
	a = list(map(int, input().strip().split()))
	print((a[0] + 180) * 2 - (a[1] + a[2]))


t = int(input())
while t > 0:
	(n, a, b) = list(map(int, input().split()))
	print(2 * (180 + n) - (a + b))
	t -= 1


t = int(input())
for i in range(t):
	(a, s, d) = map(int, input().split())
	print(2 * (180 + a) - (s + d))


import math
t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split(' '))
	duration1 = math.floor((n + 1) / 2) * 2 + (180 - a)
	duration2 = math.floor(n / 2) * 2 + (180 - b)
	total_duration = duration1 + duration2
	print(total_duration)


for i in range(int(input())):
	x = [int(x) for x in input().split()]
	print(2 * (180 + x[0]) - (x[1] + x[2]))


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	if n % 2 == 0:
		c = n // 2
		d = n // 2
	else:
		c = (n + 1) // 2
		d = n - c
	t1 = 180 - a + c * 2
	t2 = 180 - b + d * 2
	print(t1 + t2)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	x = 2 * (180 + n)
	y = a + b
	z = x - y
	print(z)


t = int(input())
for i in range(t):
	(n, A, B) = map(int, input().split())
	if n % 2 == 0:
		b_sec = 3 * 60
		a_sec = 2 * (n // 2)
		total_sec = 2 * (b_sec + a_sec)
		final_time = total_sec - A - B
	else:
		b_sec = 3 * 60
		a_sec = (n + 1) // 2 + n // 2
		total_sec = 2 * (a_sec + b_sec)
		final_time = total_sec - A - B
	print(final_time)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	n = 2 * (180 + n)
	print(n - (m + k))


Match = int(input())
for k in range(Match):
	(c, b, n) = input().split()
	(c, b, n) = (int(c), int(b), int(n))
	print(2 * (180 + c) - (b + n))


def check_input(t, n, a, b):
	if t >= 1 and t <= pow(10, 5):
		if n >= 10 and n <= 100:
			if n % 2 == 1:
				if a >= 0 and a <= 180 + 2 * ((n + 1) / 2) and (a >= 2):
					return True
			elif b >= 0 and b <= 180 + 2 * (n / 2) and (b >= 2):
				return True
T = int(input())
list_final = []
list_output = []
i = 0
proceed = True
while i < T and proceed:
	input_value = input()
	list_a = input_value.split()
	check_constraint = check_input(T, int(list_a[0]), int(list_a[1]), int(list_a[2]))
	if check_constraint:
		list_final.append(list_a)
		var1 = 2 * (180 + int(list_a[0]))
		var2 = int(list_a[1]) + int(list_a[2])
		list_output.append(var1 - var2)
	else:
		proceed = False
	i += 1
for item in list_output:
	print(item)


x = int(input())
for i in range(x):
	(a, b, c) = map(int, input().split())
	k = (180 + a) * 2
	l = b + c
	print(k - l)


n = int(input(''))
res = 0
for i in range(n):
	(a, b, c) = map(int, input().split(' '))
	res += (180 + a) * 2
	res -= b + c
	print(res)
	res = 0


T = int(input())
for i in range(T):
	(N, A, B) = map(int, input().split())
	a = 2 * (N + 180)
	b = A + B
	c = a - b
	print(c)


n_cases = int(input())
for i in range(n_cases):
	(n, a, b) = map(int, input().split(' '))
	start_time = 180
	n_player = n / 2
	time_player_a = start_time - a + 2 * n_player
	time_player_b = start_time - b + 2 * n_player
	print(int(time_player_a + time_player_b))


t = int(input())
for i in range(t):
	(turns, total_time1, total_time2) = map(int, input().split())
	both_clock_time = 2 * (180 + turns)
	the_duration_of_the_game = both_clock_time - (total_time1 + total_time2)
	print(the_duration_of_the_game)


a = int(input())
for i in range(a):
	b = input()
	c = b.split()
	s = (int(c[0]) + 180) * 2 - int(c[1]) - int(c[2])
	print(s)


T = int(input())
for i in range(T):
	N = input()
	N = N.split()
	x = 2 * (180 + int(N[0]))
	y = int(N[1]) + int(N[2])
	print(x - y)


t = int(input())
while t > 0:
	(n, a, b) = input().split()
	total = 2 * (180 + int(n))
	print(total - int(a) - int(b))
	t = t - 1