Alice has an array of N integers — A_{1}, A_{2}, \ldots, A_{N}. She wants the product of all the elements of the array to be a non-negative integer. That is, it can be either 0 or positive. But she doesn't want it to be negative.

To do this, she is willing to remove some elements of the array. Determine the  minimum number of elements that she will have to remove to make the product of the array's elements non-negative.

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

- The first line of input will contain a single integer T, denoting the number of test cases.
- The first line of each test case contains a single integer N — the number of elements in the array originally.
- The next line contains N space-separated integers — A_{1}, A_{2}, \ldots, A_{N}, which are the original array elements.

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

For each test case, output on a new line the minimum number of elements that she has to remove from the array.

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

$1 ≤ T ≤ 100$
$2 ≤ N ≤ 10000$
$-1000 ≤ A_{i} ≤ 1000$

----- Sample Input 1 ------ 
4
3
1 9 8
4
2 -1 9 100
4
2 -1 0 100
4
2 -1 -1 100

----- Sample Output 1 ------ 
0
1
0
0

----- explanation 1 ------ 
Test case $1$: The product of the elements of the array is $1 \times 9 \times 8 = 72$, which is already non-negative. Hence no element needs to be removed, and so the answer is $0$.

Test case $2$: The product of the elements of the array is $2 \times -1 \times 9 \times 100 = -1800$, which is negative. Alice can remove the element $-1$, and the product then becomes non-negative. Hence the answer is $1$.

Test case $3$: The product of the elements of the array is $2 \times -1 \times 0 \times 100 = 0$, which is already non-negative. Hence no element needs to be removed, and so the answer is $0$.

Test case $4$: The product of the elements of the array is $2 \times -1 \times -1 \times 100 = 200$, which is already non-negative. Hence no element needs to be removed, and so the answer is $0$.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
t = int(input())
for i in range(t):
	N = int(input())
	n2 = list(map(int, input().split()))
	n = 1
	for i in range(N):
		n1 = n * n2[i]
		n = n1
	if n < 0:
		print(1)
	else:
		print(0)


for i in range(int(input())):
	num = int(input())
	arr = list(map(int, input().split()))
	var = 1
	for i in range(num):
		var *= arr[i]
	if var < 0:
		print(1)
	else:
		print(0)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	m = 1
	for i in a:
		m = m * i
		if i < 0:
			x = x + 1
	if m == 0:
		print('0')
	elif x % 2 == 0:
		print('0')
	else:
		print('1')


import math
T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	b = []
	prod = math.prod(A)
	if prod < 0:
		for i in A:
			if i < 0:
				b.append(i)
		if len(b) % 2 == 0:
			print(0)
		else:
			print(1)
	else:
		print(0)


n = int(input())
for i in range(n):
	a = int(input())
	b = list(map(int, input().split()))
	w = 1
	for i in range(a):
		w = w * b[i]
	if w < 0:
		print('1')
	else:
		print('0')


for a in range(int(input())):
	s = int(input())
	d = list(map(int, input().split()))
	w = 1
	for i in range(s):
		w *= d[i]
	if w < 0:
		print('1')
	else:
		print('0')


n = int(input())
for i in range(n):
	m = 1
	a = int(input())
	x = input()
	x = list(map(int, x.split()))
	for j in x:
		m = m * j
	if m < 0:
		print('1')
	else:
		print('0')


for t in range(int(input())):
	arr = int(input())
	n = list(map(int, input().split()))[:arr]
	neg = 0
	for val in n:
		if val < 0:
			neg += 1
	print(0 if 0 in n else neg % 2)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	n = z = 0
	for j in a:
		if int(j) < 0:
			n += 1
		elif int(j) == 0:
			z += 1
	if z > 0:
		print(0)
	elif n % 2 == 0:
		print(0)
	else:
		print(1)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	neg = 0
	for i in l:
		if i == 0:
			neg = -1
			break
		if i < 0:
			neg += 1
	if neg == -1 or neg % 2 == 0:
		print(0)
	else:
		print(1)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for j in a:
		if j < 0:
			c += 1
	if c % 2 == 0 or 0 in a:
		print('0')
	else:
		print('1')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	z = neg = 0
	for i in a:
		if i == 0:
			z += 1
		elif i < 0:
			neg += 1
	if z > 0 or neg % 2 == 0:
		print('0')
	else:
		print('1')


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


for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	neg = 0
	for i in range(n):
		if ls[i] < 0:
			neg += 1
	if 0 in ls:
		print(0)
	elif neg % 2 == 1:
		print(1)
	else:
		print(0)


for i in range(int(input())):
	m = int(input())
	l = list(map(int, input().split()))
	a = 0
	b = 0
	for j in range(m):
		if l[j] == 0:
			b = b + 1
			break
		elif l[j] < 0:
			a = a + 1
	if b > 0:
		print(0)
	elif a % 2 == 0:
		print(0)
	elif a % 2 != 0:
		print(1)


for i in range(int(input())):
	m = int(input())
	l = list(map(int, input().split()))[:m]
	s = 1
	for i in l:
		s = s * i
	if s < 0:
		print(1)
	else:
		print(0)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	neg = 0
	flag = 1
	for i in range(n):
		if a[i] < 0:
			neg = neg + 1
		elif a[i] == 0:
			flag = 0
	if neg % 2 == 0:
		flag = 0
	print(flag)


n = int(input())
for i in range(n):
	w = int(input())
	a = list(map(int, input().split()))
	neg = 0
	for j in a:
		if j < 0:
			neg = neg + 1
		else:
			continue
	if 0 in a:
		print('0')
	elif neg % 2 == 0:
		print('0')
	else:
		print('1')


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	b = [int(i) for i in a]
	mul = 1
	for i in range(len(b)):
		mul *= b[i]
	if mul < 0:
		print(1)
	else:
		print(0)


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


for i in range(int(input())):
	n = input()
	l = list(map(int, input().split()))
	count = 0
	for j in l:
		if j == 0:
			count = 0
			break
		if j < 0:
			count += 1
	if count % 2 == 0:
		print(0)
	else:
		print(1)


x = int(input())
for c in range(x):
	cz = 0
	cn = 0
	b = int(input())
	a = list(map(int, input().split()))
	for c in a:
		if c == 0:
			cz += 1
		if c < 0:
			cn += 1
	if cn % 2 == 0 or cz > 0:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	z = neg = 0
	for i in A:
		if i == 0:
			z += 1
		elif i < 0:
			neg += 1
	if z > 0 or neg % 2 == 0:
		print('0')
	else:
		print('1')


T = int(input())
for i in range(T):
	negCount = 0
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	if 0 in A:
		print('0')
	else:
		for j in A:
			if j < 0:
				negCount += 1
			else:
				break
		print('0' if negCount % 2 == 0 else '1')


t = int(input())
for x in range(t):
	count = 0
	n = int(input())
	arr = list(map(int, input().split()))
	if 0 in arr:
		print(0)
		continue
	for i in range(n):
		if arr[i] < 0:
			count += 1
	if count % 2 == 0:
		print(0)
	else:
		print(1)


t = int(input())
for i in range(t):
	n = int(input())
	m = input()
	l = [i for i in m.split()]
	c = 0
	p = 1
	for i in l:
		if int(i) == 0:
			p = 0
			print('0')
			break
		if int(i) < 0:
			c = c + 1
		else:
			pass
	if c % 2 == 1 and p == 1:
		print('1')
	elif p == 1:
		print('0')


n = int(input())
while n:
	t = int(input())
	ip1 = input().split()
	l1 = [int(i) for i in ip1]
	mul = 1
	count = 1
	for i in range(0, t):
		mul *= l1[i]
		if l1[i] < 0:
			count = 0
	if mul < 0:
		print(1)
	else:
		print(0)
	n -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	if a.count(0) > 0:
		print(0)
	else:
		for i in a:
			if i < 0:
				c += 1
		if c % 2 == 0:
			print(0)
		else:
			print(1)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt = 1
	for i in range(n):
		cnt = cnt * arr[i]
	if cnt >= 0:
		print('0')
	else:
		print('1')


t = int(input())
for x in range(t):
	ctr = 0
	size = int(input())
	A = list(map(int, input().split()))
	for i in range(len(A)):
		if A[i] < 0:
			ctr += 1
		elif A[i] == 0:
			ctr = 0
			break
	if ctr % 2 == 0:
		print(0)
	else:
		print(ctr % 2)


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


t = int(input())
for i in range(t):
	n = int(input())
	list1 = list(map(int, input().split()))
	negative_list = []
	result = False
	for i in range(0, len(list1)):
		if list1[i] < 0:
			negative_list.append(i)
		if list1[i] == 0:
			result = True
	if result == True:
		print(0)
	elif len(negative_list) == 1:
		print(1)
	else:
		print(len(negative_list) % 2)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	flag = 1
	for i in range(0, n):
		if a[i] < 0:
			count += 1
		if a[i] == 0:
			flag = 0
	if flag == 0 or count % 2 == 0:
		print(0)
	elif count % 2 != 0:
		print(1)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for j in range(n):
		if a[j] < 0:
			c += 1
		elif a[j] == 0:
			c = 0
			break
	print(c % 2)


T = int(input())
for tc in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	k = 0
	p = 1
	for i in range(n):
		p = p * A[i]
	if p >= 0:
		print('0')
	else:
		print('1')


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


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


T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	count = 0
	for x in range(N):
		if A[x] == 0:
			count = 0
			break
		elif A[x] < 0:
			count += 1
	if count % 2 == 1:
		print('1')
	else:
		print('0')


t = int(input())
while t > 0:
	num = int(input())
	arr = list(map(int, input().split()))
	flag = 0
	count = 0
	for i in range(num):
		if arr[i] < 0:
			count = count + 1
		if arr[i] == 0:
			count = 0
			break
	if count % 2 == 0:
		print(0)
	else:
		print(1)
	t = t - 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = 1
	for i in range(n):
		z = a[i]
		x = x * z
	if x >= 0:
		print('0')
	else:
		print('1')