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

It's the soccer match finals in Chefland and as always it has reached the penalty shotouts. 
Each team is given 5 shots to make and the team scoring a goal on the maximum number of shots wins the game. If both the teams' scores are equal, then the game is considered a draw and we would have 2 champions.

Given ten integers A_{1}, A_{2}, \ldots, A_{10}, where the odd indexed integers(A_{1}, A_{3}, A_{5}, A_{7}, A_{9}) represent the outcome of the shots made by team 1 and even indexed integers(A_{2}, A_{4}, A_{6}, A_{8}, A_{10}) represent the outcome of the shots made by team 2 (here A_{i} = 1 indicates that it's a goal and A_{i} = 0 indicates a miss), determine the winner or find if the game ends in a draw. 

------ 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.
- The first and only line of each test case contains ten space-separated integers A_{1}, A_{2}, \ldots, A_{10}.

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

For each test case, print a single line containing one integer - 0 if the game ends in a draw or 1 if the first team wins or 2 if the second team wins.

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

$1 ≤ T ≤ 1024$
$0 ≤ A_{i} ≤ 1$

----- Sample Input 1 ------ 
4
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
1 0 1 0 0 0 0 0 0 0 
1 1 1 1 1 1 1 1 1 0
----- Sample Output 1 ------ 
0
2
1
1
----- explanation 1 ------ 
Test case $1$: No team scores any goal, so the game ends in a draw.

Test case $2$: The second team is able to score in their final shot, while the first team has scored 0 goals and hence the second team wins.

Test case $3$: The first team is successfully able to make their first $2$ shots count and whereas the second team has not scored any goals. Therefore the first team wins.

Test case $4$: Team $2$ misses their final shot and hence team $1$ wins the game with the final score of $5 - 4$.

Difficulty: EASY
Tags: Implementation

Complete search
Skill types: Complete search

Starter code:

Solutions:
n = int(input())
for _ in range(n):
	penalty = list(map(int, input().split()))
	team_1 = 0
	team_2 = 0
	for i in range(0, len(penalty)):
		if i % 2 == 0:
			team_1 += penalty[i]
		else:
			team_2 += penalty[i]
	if team_1 > team_2:
		print(1)
	elif team_1 < team_2:
		print(2)
	else:
		print(0)


for _ in range(int(input())):
	lst = list(map(int, input().strip().split()))
	e = 0
	o = 0
	for i in range(10):
		z = i + 1
		if z % 2 == 0:
			e += lst[i]
		else:
			o += lst[i]
	if e == o:
		print('0')
	elif e < o:
		print('1')
	else:
		print('2')


for i in range(int(input())):
	l = list(map(int, input().split()))
	count = 0
	s = 0
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] == 1:
				count = count + 1
		elif l[i] == 1:
			s = s + 1
	if count == s:
		print('0')
	elif count > s:
		print('1')
	else:
		print('2')


for t in range(int(input())):
	A = 0
	B = 0
	index = 0
	score = list(map(int, input().split()))
	for i in score:
		if index % 2 == 0 and i == 1:
			A += 1
		elif index % 2 != 0 and i == 1:
			B += 1
		index += 1
	if A == B:
		print('0')
	elif A > B:
		print('1')
	elif B > A:
		print('2')


T = int(int(input()))
for i in range(T):
	A = list(map(int, input().split()))
	goalsByT1 = 0
	goalsByT2 = 0
	for i in range(0, len(A), 2):
		if A[i] == 1:
			goalsByT1 += 1
	for i in range(1, len(A) + 1, 2):
		if A[i] == 1:
			goalsByT2 += 1
	if goalsByT1 > goalsByT2:
		print(1)
	elif goalsByT1 < goalsByT2:
		print(2)
	else:
		print(0)


T = int(input())
for _ in range(T):
	lst = [int(i) for i in input().split()][0:10]
	lst1 = []
	lst2 = []
	for i in range(1, 11):
		if i % 2 != 0:
			lst1.append(lst[i - 1])
		else:
			lst2.append(lst[i - 1])
	team1_goals = lst1.count(1)
	team2_goals = lst2.count(1)
	if team1_goals == team2_goals:
		print(0)
	elif team1_goals > team2_goals:
		print(1)
	else:
		print(2)


for i in range(int(input())):
	arr = list(map(int, input().split()))
	t1_odd = []
	t2_eve = []
	for i in range(len(arr)):
		if i % 2 == 0:
			t1_odd.append(arr[i])
		else:
			t2_eve.append(arr[i])
	s1 = 0
	s2 = 0
	for i in t1_odd:
		s1 = s1 + i
	for j in t2_eve:
		s2 = s2 + j
	if s1 > s2:
		print(1)
	elif s2 > s1:
		print(2)
	else:
		print(0)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	s2 = a[1] + a[3] + a[5] + a[7] + a[9]
	s1 = a[0] + a[2] + a[4] + a[6] + a[8]
	if s1 > s2:
		print(1)
	elif s1 == s2:
		print(0)
	else:
		print(2)


for _ in range(int(input())):
	scores = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	count1 = scores[0] + scores[2] + scores[4] + scores[6] + scores[8]
	count2 = scores[1] + scores[3] + scores[5] + scores[7] + scores[9]
	if count1 > count2:
		print(1)
	elif count2 > count1:
		print(2)
	else:
		print(0)


for _ in range(int(input())):
	scores = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for i in range(10):
		if i % 2 == 0 and scores[i] == 1:
			count1 += 1
		elif i % 2 != 0 and scores[i] == 1:
			count2 += 1
	if count1 > count2:
		print(1)
	elif count2 > count1:
		print(2)
	else:
		print(0)


for _ in range(int(input())):
	(a, b, c, d, e, f, g, h, i, j) = map(int, input().split())
	x = a + c + e + g + i
	y = b + d + f + h + j
	if x > y:
		print('1')
	elif x < y:
		print('2')
	else:
		print('0')


t = int(input())
for i in range(t):
	a = list(input().split())
	n = len(a)
	s1 = s2 = 0
	for j in range(n):
		if j % 2 != 0:
			s2 += int(a[j])
		else:
			s1 += int(a[j])
	if s1 > s2:
		print(1)
	elif s2 > s1:
		print(2)
	else:
		print(0)


for _ in range(int(input())):
	A = 0
	B = 0
	C = 0
	S = list(map(int, input().split()))
	for i in S:
		if C % 2 == 0 and i == 1:
			A += 1
		elif C % 2 != 0 and i == 1:
			B += 1
		C += 1
	if A == B:
		print('0')
	elif A > B:
		print('1')
	elif B > A:
		print('2')


t = int(input())
for i in range(t):
	A = list(map(int, input().split()))
	tm1 = 0
	tm2 = 0
	for i in range(10):
		if i % 2 == 0:
			if A[i] == 1:
				tm1 += 1
		elif A[i] == 1:
			tm2 += 1
	if tm1 > tm2:
		print(1)
	elif tm1 < tm2:
		print(2)
	else:
		print(0)


T = int(input())
for i in range(T):
	n = list(map(int, input().split()))
	n1 = 0
	n2 = 0
	for i in range(0, 10, 2):
		if n[i] == 1:
			n1 += 1
	for j in range(1, 10, 2):
		if n[j] == 1:
			n2 += 1
	if n1 == n2:
		print(0)
	elif n1 > n2:
		print(1)
	else:
		print(2)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	t1 = 0
	t2 = 0
	for i in range(len(a)):
		if i % 2 == 0:
			if a[i] == 1:
				t1 += 1
		elif a[i] == 1:
			t2 += 1
	if t1 == t2:
		print(0)
	elif t1 > t2:
		print(1)
	else:
		print(2)


n = int(input())
for i in range(n):
	l = list(map(int, input().split()))
	op = ''
	for j in l:
		op = op + str(j)
	A = 0
	B = 0
	index = 0
	for k in op:
		if index % 2 == 0 and k == '1':
			A += 1
		elif index % 2 != 0 and k == '1':
			B += 1
		index += 1
	if A == B:
		print('0')
	elif A < B:
		print('2')
	else:
		print('1')


for case in range(int(input())):
	a = list(map(int, input().split()))
	count_1 = count_2 = 0
	for i in range(len(a)):
		if i % 2 == 0 and a[i] == 1:
			count_1 += 1
		elif i % 2 != 0 and a[i] == 1:
			count_2 += 1
	if count_1 > count_2:
		print(1)
	elif count_2 > count_1:
		print(2)
	else:
		print(0)


x = int(input())
for i in range(x):
	(A, B, C, D, E, F, G, H, I, J) = list(map(int, input().split()))
	r = A + C + E + G + I
	t = B + D + F + H + J
	if r > t:
		print(1)
	elif t > r:
		print(2)
	else:
		print(0)


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	a = 0
	b = 0
	for i in range(0, 10, 2):
		if l[i] == 1:
			a += 1
	for i in range(1, 10, 2):
		if l[i] == 1:
			b += 1
	if a > b:
		print(1)
	elif a < b:
		print(2)
	else:
		print(0)


for _ in range(int(input())):
	l = list(map(int, input().split()))
	x = []
	y = []
	for i in range(0, 10):
		if i % 2 == 0:
			x.append(l[i])
		else:
			y.append(l[i])
	if x.count(1) > y.count(1):
		print(1)
	elif x.count(1) < y.count(1):
		print(2)
	else:
		print(0)


for i in range(int(input())):
	l = list(map(int, input().split()))
	n = len(l)
	c = k = 0
	for i in range(n):
		if i % 2:
			if l[i] == 1:
				c += 1
		elif l[i] == 1:
			k += 1
	if c < k:
		print(1)
	elif c > k:
		print(2)
	else:
		print(0)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	(t, y) = (0, 0)
	for i in range(10):
		if (i + 1) % 2 == 0:
			if a[i] == 1:
				t += 1
		elif a[i] == 1:
			y += 1
	if t > y:
		print(2)
	elif y > t:
		print(1)
	else:
		print(0)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = a[0] + a[2] + a[4] + a[6] + a[8]
	c = a[1] + a[3] + a[5] + a[7] + a[9]
	if b > c:
		print('1')
	elif c > b:
		print('2')
	else:
		print('0')


T = int(input())
for _ in range(T):
	A = map(int, input().split())
	(team1, team2) = (0, 0)
	for (i, j) in enumerate(A):
		if i % 2 == 0 and j == 1:
			team1 += 1
		elif j == 1:
			team2 += 1
	if team1 > team2:
		print(1)
	elif team1 < team2:
		print(2)
	else:
		print(0)


for _ in range(int(input())):
	l = list(map(int, input().split()))
	e = []
	o = []
	for i in range(0, 10):
		if i % 2 == 0:
			e.append(l[i])
		else:
			o.append(l[i])
	if e.count(1) > o.count(1):
		print(1)
	elif e.count(1) < o.count(1):
		print(2)
	else:
		print(0)


for _ in range(int(input())):
	(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) = map(int, input().split())
	if a1 + a3 + a5 + a7 + a9 > a2 + a4 + a6 + a8 + a10:
		print(1)
	elif a1 + a3 + a5 + a7 + a9 < a2 + a4 + a6 + a8 + a10:
		print(2)
	else:
		print(0)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	l1 = []
	l2 = []
	for i in range(len(l)):
		if i % 2 == 0:
			l1.append(l[i])
		else:
			l2.append(l[i])
	if l1.count(1) > l2.count(1):
		print(1)
	elif l1.count(1) < l2.count(1):
		print(2)
	else:
		print(0)


for i in range(int(input())):
	a = list(map(int, input().split()))
	l = []
	g = []
	for i in range(0, len(a)):
		if i % 2 == 0:
			l.append(a[i])
		else:
			g.append(a[i])
	if sum(l) == sum(g):
		print(0)
	elif sum(l) > sum(g):
		print(1)
	else:
		print(2)


for _ in range(int(input())):
	a = [int(i) for i in input().split()]
	a1 = a[0::2]
	a2 = a[1::2]
	if sum(a1) > sum(a2):
		print('1')
	elif sum(a1) < sum(a2):
		print('2')
	else:
		print('0')


for i in range(int(input())):
	score_list = list(map(int, input().split()))
	team_1 = 0
	team_2 = 0
	for i in range(10):
		if i % 2 == 0:
			if score_list[i] == 1:
				team_1 += 1
		elif i % 2 != 0:
			if score_list[i] == 1:
				team_2 += 1
	if team_1 > team_2:
		print(1)
	elif team_2 > team_1:
		print(2)
	else:
		print(0)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	even_a = []
	odd_a = []
	count_team2 = 0
	count_team1 = 0
	for i in range(0, len(a)):
		if i % 2:
			even_a.append(a[i])
		else:
			odd_a.append(a[i])
	for i in range(len(even_a)):
		if even_a[i] == 1:
			count_team1 += 1
	for i in range(len(odd_a)):
		if odd_a[i] == 1:
			count_team2 += 1
	if count_team1 == count_team2:
		print('0')
	elif count_team1 > count_team2:
		print('2')
	else:
		print('1')


t = int(input())
for _ in range(t):
	arr = list(map(int, input().split()))
	c = 0
	d = 0
	for i in range(0, len(arr), 2):
		c = c + arr[i]
	for j in range(1, len(arr), 2):
		d = d + arr[j]
	if c == d:
		print('0')
	elif c > d:
		print('1')
	else:
		print('2')


for i in range(int(input())):
	list_a = list(map(int, input().split()))
	a = list_a[0::2]
	b = list_a[1::2]
	if sum(a) == sum(b):
		print('0')
	elif sum(a) > sum(b):
		print('1')
	else:
		print('2')


for q in range(int(input())):
	s = list(map(int, input().split()))
	a = 0
	b = 0
	for i in range(len(s)):
		if i % 2 == 0:
			a = s[i] + a
		else:
			b = s[i] + b
	if a > b:
		print(1)
	elif a < b:
		print(2)
	else:
		print(0)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	c = 0
	l = 0
	for i in range(len(a)):
		if i % 2 == 0:
			c += a[i]
		elif i % 2 != 0:
			l += a[i]
	if c > l:
		print('1')
	elif l > c:
		print('2')
	else:
		print('0')


for i in range(int(input())):
	l = list(map(int, input().split()))
	(count1, count2) = (0, 0)
	for j in range(len(l)):
		if j % 2 == 0:
			if l[j] == 1:
				count1 += 1
		elif l[j] == 1:
			count2 += 1
	if count1 > count2:
		print('1')
	elif count1 < count2:
		print('2')
	else:
		print('0')


t = int(input())
for i in range(t):
	a = [int(a) for a in input().split()]
	count_1 = 0
	count_2 = 0
	for i in range(len(a)):
		if i % 2 == 0:
			count_1 += a[i]
		else:
			count_2 += a[i]
	if count_1 > count_2:
		print(1)
	elif count_2 > count_1:
		print(2)
	else:
		print(0)


for i in range(int(input())):
	sumE = 0
	sumO = 0
	a = list(map(int, input().split()))
	for i in range(len(a)):
		if i % 2 == 0:
			sumE += a[i]
		else:
			sumO += a[i]
	if sumE == sumO:
		print('0')
	elif sumE > sumO:
		print('1')
	else:
		print('2')


t = int(input())
for i in range(t):
	count1 = 0
	count2 = 0
	l = list(map(int, input().split()))
	for i in range(10):
		if i % 2 != 0:
			if l[i] == 1:
				count2 += 1
		elif l[i] == 1:
			count1 += 1
	if count1 > count2:
		print(1)
	elif count2 > count1:
		print(2)
	else:
		print(0)


for i in range(int(input())):
	a = list(map(int, input().split()))
	(b, c) = (0, 0)
	for i in range(len(a)):
		if i % 2 == 0 and a[i] == 1:
			b += 1
		if i % 2 != 0 and a[i] == 1:
			c += 1
	if b > c:
		print('1')
	elif b < c:
		print('2')
	else:
		print('0')


t = int(input())
for tc in range(t):
	arr = list(input().split(' '))[:10]
	count1 = 0
	count2 = 0
	i = 0
	while i < len(arr):
		if i % 2 == 0:
			if arr[i] == '1':
				count1 += 1
		if i % 2 == 1:
			if arr[i] == '1':
				count2 += 1
		i += 1
	if count1 == count2:
		print(0)
	elif count1 > count2:
		print(1)
	elif count2 > count1:
		print(2)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	count = 0
	count1 = 0
	for j in range(len(a)):
		if j % 2 == 0:
			if a[j] == 1:
				count += 1
		elif a[j] == 1:
			count1 += 1
	if count > count1:
		print(1)
	elif count == count1:
		print(0)
	else:
		print(2)


for i in range(int(input())):
	a = list(map(int, input().split()))
	s1 = 0
	s2 = 0
	for i in range(0, 10, 2):
		s1 += a[i]
	for i in range(1, 10, 2):
		s2 += a[i]
	if s1 > s2:
		print(1)
	elif s1 < s2:
		print(2)
	else:
		print(0)


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	odd = []
	even = []
	for i in range(len(a)):
		if i % 2 == 1:
			odd.append(a[i])
		else:
			even.append(a[i])
	r1 = sum(odd)
	r2 = sum(even)
	if r1 == r2:
		print(0)
	elif r1 > r2:
		print(2)
	else:
		print(1)


t = int(input())
for i in range(0, t):
	l = []
	m = []
	arr = list(map(int, input().split()))
	for i in range(0, len(arr)):
		if i % 2 == 0:
			l.append(arr[i])
		else:
			m.append(arr[i])
	x = l.count(1)
	y = m.count(1)
	if x < y:
		print('2')
	elif x > y:
		print('1')
	else:
		print('0')


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	for i in range(len(a)):
		if i % 2 != 0:
			if a[i] == 1:
				c1 += 1
		elif a[i] == 1:
			c2 += 1
	if c1 > c2:
		print(2)
	elif c1 < c2:
		print(1)
	else:
		print(0)


T = int(input())
for i in range(T):
	A = list(map(int, input().split()))
	if sum(A[::2]) > sum(A[1::2]):
		print(1)
	elif sum(A[::2]) == sum(A[1::2]):
		print(0)
	else:
		print(2)


for i in range(int(input())):
	a = list(map(int, input().split()))
	sum1 = 0
	sum2 = 0
	for j in range(len(a) // 2):
		sum2 = sum2 + a[2 * j + 1]
	for j in range(len(a) // 2):
		sum1 = sum1 + a[2 * j]
	if sum1 == sum2:
		print('0')
	if sum1 > sum2:
		print('1')
	if sum1 < sum2:
		print('2')


for i in range(int(input())):
	(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) = list(map(int, input().split()))
	A = a1 + a3 + a5 + a7 + a9
	B = a2 + a4 + a6 + a8 + a10
	if A == B:
		print(0)
	elif A > B:
		print(1)
	else:
		print(2)


for i in range(int(input())):
	a = list(map(int, input().split()))
	c = 0
	m = 0
	for i in range(0, 10):
		if i % 2 == 0:
			if a[i] == 1:
				c += 1
		elif a[i] == 1:
			m += 1
	if c == m:
		print(0)
	elif c > m:
		print(1)
	else:
		print(2)


try:
	t = int(input())
	for r in range(t):
		a = list(map(int, input().split()))
		ad = a[0] + a[2] + a[4] + a[6] + a[8]
		bd = a[1] + a[3] + a[5] + a[7] + a[9]
		if ad == bd:
			print(0)
		elif ad > bd:
			print(1)
		elif ad < bd:
			print(2)
except:
	pass


for i in range(int(input())):
	lis = list(map(int, input().split()))
	(a_team, b_team) = (lis[::2], lis[1::2])
	print(1 if a_team.count(1) > b_team.count(1) else 2 if a_team.count(1) < b_team.count(1) else 0)


T = int(input())
for i in range(0, T):
	A = list(map(int, input().split()))
	team1_sum = A[0] + A[2] + A[4] + A[6] + A[8]
	team2_sum = sum(A) - team1_sum
	if team1_sum == team2_sum:
		ans = 0
	elif team1_sum > team2_sum:
		ans = 1
	elif team2_sum > team1_sum:
		ans = 2
	print(ans)


T = int(input())
for i in range(T):
	(A, B, C, D, E, F, G, H, I, J) = map(int, input().split())
	r = A + C + E + G + I
	k = B + D + F + H + J
	if r > k:
		print('1')
	elif k > r:
		print('2')
	else:
		print('0')


t = int(input())
for test in range(t):
	t1 = 0
	t2 = 0
	pen = list(map(int, input().split()))
	for p in range(len(pen)):
		if p % 2 == 0:
			t1 += pen[p]
		else:
			t2 += pen[p]
	if t1 > t2:
		print(1)
	elif t2 > t1:
		print(2)
	else:
		print(0)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	x = 0
	y = 0
	m = len(l)
	for i in range(m):
		if i % 2 == 0:
			if l[i] == 1:
				x += 1
		elif l[i] == 1:
			y += 1
	if x > y:
		print('1')
	elif x < y:
		print('2')
	else:
		print('0')


for i in range(int(input())):
	x = input().split()
	(f, s) = (0, 0)
	for i in range(1, len(x) + 1):
		if i % 2 == 0:
			s += int(x[i - 1])
		else:
			f += int(x[i - 1])
	if s > f:
		print(2)
	elif f > s:
		print(1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	a = [int(x) for x in input().split()]
	t1 = [a[i] for i in range(0, len(a), 2)]
	t2 = [a[i] for i in range(1, len(a), 2)]
	if t1.count(1) > t2.count(1):
		print(1)
	elif t1.count(1) < t2.count(1):
		print(2)
	else:
		print(0)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for j in range(10):
		if j % 2 == 0 and a[j] == 1:
			count1 += 1
		elif j % 2 != 0 and a[j] == 1:
			count2 += 1
	if count1 > count2:
		print('1')
	elif count2 > count1:
		print('2')
	else:
		print(0)


for t in range(int(input())):
	shots = list(map(int, input().split()))
	team_a = shots[::2]
	team_b = shots[1::2]
	if team_a.count(1) > team_b.count(1):
		print(1)
	elif team_a.count(1) < team_b.count(1):
		print(2)
	else:
		print(0)


for i in range(int(input())):
	l = [int(x) for x in input().split()]
	(a, b) = (0, 0)
	for i in range(len(l)):
		if i % 2 != 0:
			b = b + l[i]
		else:
			a = a + l[i]
	if a == b:
		print(0)
	elif a > b:
		print(1)
	else:
		print(2)


for t in range(int(input())):
	(a, b, c, d, e, f, g, h, i, j) = map(int, input().split())
	m = a + c + e + g + i
	n = b + d + f + h + j
	if m == n:
		print(0)
	elif m > n:
		print(1)
	else:
		print(2)