Given an array arr[] containing N integers. In one step, any element of the array can either be increased or decreased by one. Find minimum steps required such that the product of the array elements becomes 1. 
 
Example 1:
Input:
N = 3
arr[] = {-2, 4, 0}
Output:
5
Explanation:
We can change -2 to -1, 0 to -1 and 4 to 1.
So, a total of 5 steps are required
to update the elements such that
the product of the final array is 1. 
Example 2:
Input:
N = 3
arr[] = {-1, 1, -1} 
Output :
0
Explanation:
Product of the array is already 1.
So, we don't need to change anything.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function makeProductOne() which takes an integer N and an array arr of size N as input and returns the minimum steps required.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{5}
-10^{3} ≤ arr[i] ≤ 10^{3}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Mathematics

Starter code: #User function Template for python3

class Solution:
    def makeProductOne(self, arr, N):
        # code here 

Solutions:
class Solution:

	def makeProductOne(self, arr, N):
		p = 0
		n = 0
		z = 0
		step = 0
		for i in range(len(arr)):
			if arr[i] == 0:
				z += 1
			elif arr[i] < 0:
				n += 1
				step = step + (-1 - arr[i])
			else:
				p += 1
				step = step + (arr[i] - 1)
		if n % 2 == 0:
			step = step + z
		elif z > 0:
			step = step + z
		else:
			step = step + 2
		return step


class Solution:

	def makeProductOne(self, arr, N):
		count_zero = 0
		mul = 1
		steps = 0
		for i in range(N):
			if arr[i] > 0:
				steps = steps + (arr[i] - 1)
				mul = mul * 1
			elif arr[i] < 0:
				steps = steps + (-1 - arr[i])
				mul = mul * -1
			else:
				steps += 1
				count_zero += 1
		if mul == 1 or count_zero > 0:
			return steps
		elif mul == -1:
			return steps + 2


class Solution:

	def makeProductOne(self, arr, N):
		co = 0
		zero = 0
		ste = 0
		for i in range(N):
			if abs(arr[i] - 1) < abs(arr[i] + 1):
				ste = abs(arr[i] - 1) + ste
				co = co
			if abs(arr[i] - 1) > abs(arr[i] + 1):
				ste = abs(arr[i] + 1) + ste
				co += 1
			if arr[i] == 0:
				zero += 1
		if co % 2 == 0:
			ste = ste + zero
		if co % 2 != 0:
			if zero > 0:
				ste += zero
			else:
				ste += 2
		return ste


class Solution:

	def makeProductOne(self, arr, N):
		positive = 0
		negative = 0
		zero = 0
		step = 0
		for i in range(N):
			if arr[i] == 0:
				zero += 1
			elif arr[i] < 0:
				negative += 1
				step = step + (-1 - arr[i])
			else:
				positive += 1
				step = step + (arr[i] - 1)
		if negative % 2 == 0:
			step = step + zero
		elif zero > 0:
			step = step + zero
		else:
			step = step + 2
		return step


class Solution:

	def makeProductOne(self, arr, N):
		c = 0
		s = 0
		z = 0
		for i in arr:
			if i > 0:
				c += i - 1
			elif i == 0:
				c += 1
				z += 1
			else:
				c += -i - 1
				s += 1
		if s % 2 != 0:
			if z == 0:
				c += 2
		return c


import numpy

class Solution:

	def makeProductOne(self, arr, N):
		mul = numpy.prod(arr)
		if mul == 1:
			return 0
		else:
			s = 0
			count = 0
			co = 0
			for i in arr:
				if i > 0:
					s += i - 1
				elif i < 0:
					co += 1
					s += abs(i + 1)
				else:
					s += 1
					count += 1
			if count >= 1 or co % 2 == 0:
				return s
			return s + 2


class Solution:

	def makeProductOne(self, arr, N):
		neg = zero = ans = 0
		for i in arr:
			if i > 0:
				ans += i - 1
			elif i == 0:
				zero += 1
			elif 0 > i:
				neg += 1
				ans += abs(i) - 1
		if neg % 2 == 0:
			return ans + zero
		elif zero != 0:
			return ans + zero
		else:
			return ans + 2


class Solution:

	def makeProductOne(self, arr, N):
		step = 0
		neg = 0
		zero = 0
		for i in arr:
			if i < 0:
				step += -i - 1
				neg = neg + 1
			if i == 0:
				step += 1
				zero += 1
			if i > 0:
				step += -(1 - i)
		if neg % 2 == 0 or zero > 0:
			return step
		else:
			return step + 2


class Solution:

	def makeProductOne(self, arr, N):
		steps = 0
		product = 1
		zeros = 0
		for i in arr:
			if i > 0:
				steps = steps + (i - 1)
				product *= 1
			elif i < 0:
				steps = steps + (-1 - i)
				product *= -1
			else:
				steps = steps + 1
				zeros = zeros + 1
		if product == 1 or zeros > 0:
			return steps
		else:
			return steps + 2


class Solution:

	def makeProductOne(self, arr, N):
		nZero = 0
		nNeg = 0
		nPos = 0
		sfts = 0
		for i in arr:
			if i == 0:
				nZero = nZero + 1
			elif i < 0:
				nNeg = nNeg + 1
				sfts = sfts + (i + 1) * -1
			else:
				nPos = nPos + 1
				sfts = sfts + (i - 1)
		if nNeg % 2 == 0:
			return sfts + nZero
		elif nZero > 0:
			return sfts + nZero
		else:
			return sfts + 2


class Solution:

	def makeProductOne(self, a, n):
		positive = 0
		negative = 0
		zero = 0
		step = 0
		for i in range(n):
			if a[i] == 0:
				zero += 1
			elif a[i] < 0:
				negative += 1
				step = step + (-1 - a[i])
			else:
				positive += 1
				step = step + (a[i] - 1)
		if negative % 2 == 0:
			step = step + zero
		elif zero > 0:
			step = step + zero
		else:
			step = step + 2
		return step


class Solution:

	def makeProductOne(self, arr, N):
		steps = 0
		negs = 0
		contains_zero = False
		for num in arr:
			if num == 0:
				contains_zero = True
				steps += 1
			elif num > 0:
				steps += num - 1
			else:
				negs += 1
				steps += -1 - num
		if negs % 2 != 0 and (not contains_zero):
			steps += 2
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		zero = negative = Sum = 0
		for val in range(len(arr)):
			if arr[val] == 0:
				zero += 1
				Sum += 1
			elif arr[val] < 0:
				negative += 1
				Sum += -1 - arr[val]
			else:
				Sum += arr[val] - 1
		if negative % 2 != 0 and (not zero):
			Sum += 2
		return Sum


class Solution:

	def makeProductOne(self, arr, N):
		s = 0
		d = 0
		e = 0
		for i in arr:
			if i == 0:
				e += 1
			elif i < 0:
				d += 1
				s = s + (-1 - i)
			else:
				s = s + (i - 1)
		s = s + e
		if d % 2 != 0 and e == 0:
			s += 2
		return s


class Solution:

	def makeProductOne(self, arr, N):
		output = 0
		(zero, minus) = (0, 0)
		for n in arr:
			output += abs(abs(n) - 1)
			if n < 0:
				minus += 1
			elif n == 0:
				zero += 1
		if minus % 2 == 1 and zero == 0:
			output += 2
		return output


class Solution:

	def makeProductOne(self, arr, N):
		p = 0
		n = 0
		o = 0
		count = 0
		if N == 1 and arr[0] == -1:
			return 2
		for i in arr:
			if i <= -1:
				count += -1 * i - 1
				n += 1
			elif i > 1:
				count += i - 1
				p += 1
			elif i == 0:
				count += 1
				o += 1
		if n % 2 != 0:
			if o == 0:
				count += 2
		return count


class Solution:

	def makeProductOne(self, arr, N):
		(st, n, z) = (0, 0, 0)
		for i in arr:
			if i == 0:
				z += 1
			elif i < 0:
				n += 1
				st = st + (-1 - i)
			else:
				st = st + (i - 1)
		st = st + z
		if n % 2 != 0 and z == 0:
			st += 2
		return st


class Solution:

	def makeProductOne(self, arr, N):
		zeroes = 0
		steps = 0
		negative_numbers = 0
		for ele in arr:
			if ele == 0:
				zeroes = zeroes + 1
			elif ele > 0:
				steps = steps + (ele - 1)
			else:
				negative_numbers = negative_numbers + 1
				steps = steps + (-1 - ele)
		steps = steps + zeroes
		if negative_numbers % 2 != 0 and zeroes == 0:
			steps = steps + 2
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		neg = 0
		zeros = 0
		steps = 0
		for ele in arr:
			if ele == 0:
				zeros += 1
			elif ele > 0:
				steps += ele - 1
			else:
				neg += 1
				steps += -1 - ele
		steps += zeros
		if neg % 2 != 0 and zeros == 0:
			steps += 2
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		step = neg = zero = 0
		for il in arr:
			if il == 0:
				zero = zero + 1
			elif il > 0:
				step = step + (il - 1)
			else:
				neg += 1
				step = step + (-1 - il)
		step = step + zero
		if neg % 2 != 0 and zero == 0:
			step = step + 2
		return step


class Solution:

	def makeProductOne(self, arr, N):
		neg = 0
		pos = 0
		zero = 0
		for i in range(N):
			if arr[i] < 0:
				neg += 1
			elif arr[i] > 0:
				pos += 1
			else:
				zero += 1
		step = 0
		if neg % 2 == 0 or (neg % 2 == 1 and zero > 0):
			for elem in arr:
				if elem < 0:
					step += -1 - elem
				elif elem > 0:
					step += elem - 1
				else:
					step += 1
		elif neg % 2 == 1:
			for elem in arr:
				if elem < 0:
					step += -1 - elem
				elif elem > 0:
					step += elem - 1
				else:
					step += 1
			step += 2
		return step


class Solution:

	def makeProductOne(self, arr, N):
		negative = 0
		steps = 0
		zero = 0
		for i in arr:
			if i == 0:
				zero = zero + 1
			elif i > 1:
				steps = steps + (i - 1)
			elif i < 1:
				negative = negative + 1
				steps = steps + (-1 - i)
		steps = steps + zero
		if negative % 2 != 0 and zero == 0:
			steps = steps + 2
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		counter = 0
		negatives = 0
		zeros = 0
		for i in range(N):
			if arr[i] > 0:
				counter += arr[i] - 1
				arr[i] = 1
			elif arr[i] < 0:
				counter += -1 * (arr[i] + 1)
				arr[i] = -1
				negatives += 1
			else:
				zeros += 1
		if negatives % 2 == 0:
			counter += zeros
		elif zeros > 0:
			counter += zeros
		else:
			counter += 2
		return counter


class Solution:

	def makeProductOne(self, arr, N):
		minimumSteps = 0
		(neg, zero) = (0, 0)
		for val in arr:
			if val > 0:
				minimumSteps += val - 1
			elif val < 0:
				neg += 1
				minimumSteps += -1 - val
			else:
				zero += 1
		if neg % 2 == 0:
			minimumSteps += zero
		elif zero > 0:
			minimumSteps += zero
		else:
			minimumSteps += 2
		return minimumSteps


class Solution:

	def makeProductOne(self, arr, N):
		count = 0
		product = 1
		neg = 0
		zeroes = 0
		for ele in arr:
			if ele > 1:
				count += ele - 1
				ele = 1
			elif ele < -1:
				count += -1 - ele
				ele = -1
				neg += 1
			elif ele == 0:
				zeroes += 1
				if neg % 2 == 0:
					ele = 1
				else:
					ele = -1
				count += 1
			product *= ele
		if product == -1:
			if zeroes == 0:
				count += 2
		return count


class Solution:

	def makeProductOne(self, arr, N):
		cnt_0 = 0
		cnt_m1 = 0
		cnt_1 = 0
		step = 0
		for i in arr:
			if i == 0:
				cnt_0 += 1
			elif i < 0:
				cnt_m1 += 1
				step += -i - 1
			else:
				cnt_1 += 1
				step += i - 1
		if cnt_m1 % 2 == 0:
			step += cnt_0
		elif cnt_0 > 0:
			step += cnt_0
		else:
			step += 2
		return step


class Solution:

	def makeProductOne(self, arr, N):
		count = 0
		negative = 0
		for item in arr:
			if item < 0:
				count += -item - 1
				negative += 1
			else:
				count += abs(item - 1)
		if negative % 2 and (not 0 in arr):
			count += 2
		return count


class Solution:

	def makeProductOne(self, arr, N):
		count_0 = arr.count(0)
		count_neg = 0
		sum_neg = 0
		sum_pos = 0
		count_pos = 0
		for i in arr:
			if i < 0:
				sum_neg += i
				count_neg += 1
			elif i > 0:
				count_pos += 1
				sum_pos += i
		if sum_pos == 1 & count_pos == 1:
			return 0
		if count_0 != 0:
			x = sum_pos + abs(sum_neg) + count_0 - (count_pos + count_neg)
			return x
		elif count_neg % 2 == 1:
			x = sum_pos + abs(sum_neg) - (count_pos + count_neg) + 2
			return x
		else:
			x = sum_pos + abs(sum_neg) - (count_pos + count_neg)
			return x


import numpy as np

class Solution:

	def makeProductOne(self, a, n):
		pos = 0
		neg = 0
		zero = 0
		step = 0
		for i in range(n):
			if a[i] == 0:
				zero += 1
			elif a[i] < 1:
				neg += 1
				step = step + (-1 - a[i])
			else:
				pos += 1
				step += a[i] - 1
		if neg % 2 == 0:
			step += zero
		elif zero > 0:
			step += zero
		else:
			step += 2
		return step


class Solution:

	def makeProductOne(self, arr, N):
		neg = 0
		ze = 0
		res = 0
		for i in range(N):
			if arr[i] < 0:
				neg = neg + 1
				res += abs(arr[i]) - 1
			elif arr[i] == 0:
				ze = ze + 1
				res = res + 1
			else:
				res += arr[i] - 1
		if neg % 2 == 1 and ze == 0:
			res += 2
		return res


class Solution:

	def makeProductOne(self, arr, N):
		(s, zc, nc) = (0, 0, 0)
		for i in range(N):
			if arr[i] > 0:
				s += arr[i] - 1
			elif arr[i] < 0:
				s += abs(arr[i]) - 1
				nc += 1
			else:
				zc += 1
				s += 1
		if nc % 2 == 1 and zc == 0:
			s += 2
		return s


class Solution:

	def makeProductOne(self, arr, N):
		(n, z, r) = (0, 0, 0)
		for i in range(N):
			if arr[i] < 0:
				n += 1
				r += abs(arr[i]) - 1
			elif arr[i] == 0:
				z += 1
				r += 1
			else:
				r += arr[i] - 1
		if n % 2 == 1 and z == 0:
			r += 2
		return r


class Solution:

	def makeProductOne(self, arr, N):
		sum = 0
		prod = 0
		zero = 0
		for i in range(N):
			if arr[i] < 0:
				x = -(arr[i] + 1)
				prod += 1
			elif arr[i] == 0:
				x = 1
				zero += 1
			else:
				x = arr[i] - 1
			sum += x
		if prod % 2 == 1 and zero == 0:
			sum += 2
		return sum


class Solution:

	def makeProductOne(self, arr, N):
		n = False
		z = 0
		c = 0
		for i in range(N):
			x = arr[i]
			if x == 1:
				continue
			if x < 0:
				c = c + (-1 - x)
				n = not n
			if x > 0:
				c = c + (x - 1)
			if x == 0:
				z = z + 1
				c = c + 1
		if n and z == 0:
			c = c + 2
		return c


class Solution:

	def makeProductOne(self, arr, N):
		neg_num = 0
		is_zero = False
		for elem in arr:
			if elem < 0:
				neg_num += 1
			elif elem == 0:
				is_zero = True
		sum = 0
		for elem in arr:
			if elem > 0:
				sum += elem - 1
			elif elem == 0:
				sum += 1
			else:
				sum += abs(elem) - 1
		if neg_num % 2 != 0 and (not is_zero):
			sum += 2
		return sum


class Solution:

	def makeProductOne(self, arr, N):
		zeros = 0
		ones = 0
		minus = 0
		total = 0
		for i in arr:
			if i < 0:
				minus += 1
				total += -1 - i
			elif i == 0:
				zeros += 1
			else:
				ones += 1
				total += i - 1
		if minus % 2 == 0:
			if zeros > 0:
				total += zeros
			return total
		else:
			if zeros > 0:
				total += 1
				total += zeros - 1
			else:
				total += 2
			return total


class Solution:

	def makeProductOne(self, arr, N):
		step = 0
		prd = 1
		for i in arr:
			if i > 0:
				step += i - 1
				prd *= 1
			elif i < 0:
				step += abs(i + 1)
				prd *= -1
		zero = arr.count(0)
		if zero == 0:
			if prd == 1:
				return step
			else:
				return step + 2
		if prd == -1 and zero > 0:
			prd = 1
			zero -= 1
			step += 1
		while zero > 0:
			step += 1
			zero -= 1
		return step


class Solution:

	def makeProductOne(self, arr, N):
		count = 0
		zeroCount = 0
		negCount = 0
		for i in range(N):
			if arr[i] == 0:
				zeroCount += 1
			elif arr[i] > 0:
				count += arr[i] - 1
			else:
				count += abs(arr[i]) - 1
				negCount += 1
		if negCount % 2 != 0 and zeroCount == 0:
			return count + 2
		count += zeroCount
		return count


class Solution:

	def makeProductOne(self, arr, N):
		count = 0
		a = list()
		for i in range(N):
			if arr[i] == 0:
				count = count + 1
			elif arr[i] < 0:
				count = count + (-1 - arr[i])
				a.append(-1)
			else:
				count = count + arr[i] - 1
				a.append(1)
		product = 1
		for i in range(len(a)):
			product = product * a[i]
		if 0 in arr:
			return count
		elif product == -1:
			return count + 2
		else:
			return count


class Solution:

	def makeProductOne(self, arr, N):
		step = 0
		zero = 0
		neg = 0
		for i in range(N):
			if arr[i] > 0:
				step += arr[i] - 1
			elif arr[i] < 0:
				step += abs(arr[i]) - 1
				neg += 1
			else:
				zero += 1
		if neg % 2 != 0 and zero == 0:
			step += 2
		step += zero
		return step


class Solution:

	def makeProductOne(self, arr, N):
		steps = 0
		neg = []
		zero = 0
		for i in arr:
			if i > 0:
				steps += i - 1
			elif i == 0:
				zero += 1
			else:
				neg += [i]
		if len(neg) > 0:
			if len(neg) % 2 == 0:
				for i in neg:
					steps += -1 - i
			else:
				for i in range(len(neg) - 1):
					steps += -1 - neg[i]
				if zero > 0:
					zero -= 1
					steps += -1 - neg[-1] + 1
				else:
					steps += -1 - neg[-1] + 2
		steps += zero
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		steps = 0
		z = 0
		negative_numbers = 0
		for i in range(len(arr)):
			if arr[i] == 0:
				z += 1
			elif arr[i] < 0:
				negative_numbers += 1
				steps += -arr[i] - 1
			else:
				steps += arr[i] - 1
		steps += z
		if negative_numbers % 2 != 0 and z == 0:
			steps += 2
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		step = 0
		negative_number = 0
		zero = 0
		for ele in arr:
			if ele == 0:
				zero = zero + 1
			elif ele > 0:
				step = step + (ele - 1)
			else:
				negative_number += 1
				step = step + (-1 - ele)
		step = step + zero
		if negative_number % 2 != 0 and zero == 0:
			step = step + 2
		return step


class Solution:

	def makeProductOne(self, arr, N):
		steps = 0
		for i in range(N):
			if arr[i] >= 1:
				steps += arr[i] - 1
			elif arr[i] <= -1:
				steps += -1 * arr[i] - 1
			else:
				steps += 1
		product = 1
		for x in arr:
			if x == 0:
				return steps
			else:
				product *= x
		if product < 0:
			steps += 2
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		steps = 0
		count = 0
		count_zero = 0
		for ele in arr:
			if ele == 0:
				count_zero = count_zero + 1
				steps = steps + 1
			elif ele > 0:
				steps = steps + (ele - 1)
			else:
				steps = steps + (-1 - ele)
				count = count + 1
		if count % 2 != 0 and count_zero == 0:
			steps = steps + 2
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		step = 0
		count_neg = 0
		count_zero = 0
		for i in range(N):
			if arr[i] < 0:
				count_neg += 1
				step = step + abs(arr[i] + 1)
			elif arr[i] == 0:
				count_zero += 1
			else:
				step = step + (arr[i] - 1)
		if count_neg % 2 == 0:
			step = step + count_zero
		elif count_zero > 0:
			step = step + count_zero
		else:
			step = step + 2
		return step


class Solution:

	def makeProductOne(self, arr, N):
		Steps = 0
		Negative_numbers = 0
		Zeroes = 0
		for ele in arr:
			if ele == 0:
				Zeroes = Zeroes + 1
			elif ele > 0:
				Steps = Steps + (ele - 1)
			else:
				Negative_numbers = Negative_numbers + 1
				Steps = Steps + (-1 - ele)
		Steps = Steps + Zeroes
		if Negative_numbers % 2 != 0 and Zeroes == 0:
			Steps = Steps + 2
		return Steps


class Solution:

	def makeProductOne(self, arr, N):
		negative = 0
		steps = 0
		zeros = 0
		for el in arr:
			if el == 0:
				zeros = zeros + 1
			elif el > 0:
				steps = steps + (el - 1)
			else:
				negative = negative + 1
				steps = steps + (-1 - el)
		steps = steps + zeros
		if negative % 2 != 0 and zeros == 0:
			steps = steps + 2
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		count_neg = 0
		ans = 0
		flag = False
		for i in arr:
			if i > 1:
				ans += i - 1
			elif i < -1:
				ans += -1 - i
				count_neg += 1
			if i == -1:
				count_neg += 1
			if i == 0:
				flag = True
				ans += 1
		if flag == True:
			return ans
		if count_neg & 1:
			ans += 2
		return ans


class Solution:

	def makeProductOne(self, arr, N):
		steps = 0
		minus_1 = 0
		zero_count = arr.count(0)
		for i in arr:
			if i < 0:
				steps += -1 - i
				minus_1 += 1
			elif i > 0:
				steps += i - 1
		if zero_count == 0:
			if minus_1 % 2 != 0:
				steps += 2
		else:
			steps += zero_count
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		zero = 0
		negative = 0
		count = 0
		for i in arr:
			if i == 0:
				zero += 1
			elif i < 0:
				count += -1 - i
				negative += 1
			else:
				count += i - 1
		if negative % 2 != 0:
			if zero == 0:
				count += 2
		return count + zero


class Solution:

	def makeProductOne(self, arr, N):
		step = 0
		neg = 0
		count = 0
		for i in range(0, N):
			if arr[i] == 0:
				step += 1
			elif arr[i] < 0:
				neg += 1
				step += abs(arr[i]) - 1
			else:
				step += abs(arr[i]) - 1
		if neg % 2 != 0:
			for j in range(N):
				if arr[j] == 0:
					count = 1
					break
			if count != 1:
				step += 2
		return step
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		arr = list(map(int, input().split()))
		ob = Solution()
		print(ob.makeProductOne(arr, N))


class Solution:

	def makeProductOne(self, arr, N):
		p = 0
		n = 0
		z = 0
		step = 0
		for i in range(len(arr)):
			if arr[i] == 0:
				z += 1
			elif arr[i] < 0:
				n += 1
				step = step + (-1 - arr[i])
			else:
				p += 1
				step = step + (arr[i] - 1)
		if n % 2 == 0:
			step = step + z
		elif z > 0:
			step = step + z
		else:
			step = step + 2
		return step
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		arr = list(map(int, input().split()))
		ob = Solution()
		print(ob.makeProductOne(arr, N))


class Solution:

	def makeProductOne(self, arr, N):
		pos = 0
		neg = 0
		zero = 0
		step = 0
		for elem in arr:
			if elem == 0:
				zero += 1
			elif elem > 0:
				pos += 1
				step += elem - 1
			elif elem < 0:
				neg += 1
				step += -1 - elem
		if neg % 2 == 1 and zero > 0:
			step += zero
		elif neg % 2 == 1 and zero == 0:
			step += 2
		elif zero > 0:
			step += zero
		return step
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		arr = list(map(int, input().split()))
		ob = Solution()
		print(ob.makeProductOne(arr, N))


class Solution:

	def makeProductOne(self, arr, N):
		negC = 0
		posC = 0
		zC = 0
		maxNeg = -999999999
		for i in arr:
			if i > 0:
				posC += 1
			elif i < 0:
				maxNeg = max(maxNeg, i)
				negC += 1
			else:
				zC += 1
		if negC % 2 == 0:
			res = zC
			for i in arr:
				if i != 0:
					res += min(abs(i + 1), abs(i - 1))
		elif zC > 0:
			res = zC
			for i in arr:
				if i != 0:
					res += min(abs(i + 1), abs(i - 1))
		else:
			j = arr.index(maxNeg)
			res = abs(maxNeg - 1)
			for i in range(len(arr)):
				if i != j:
					res += min(abs(arr[i] + 1), abs(arr[i] - 1))
		return res
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		arr = list(map(int, input().split()))
		ob = Solution()
		print(ob.makeProductOne(arr, N))


class Solution:

	def makeProductOne(self, arr, N):
		steps = 0
		neg_no = 0
		zero = 0
		for ele in arr:
			if ele > 0:
				steps = steps + (ele - 1)
			elif ele == 0:
				zero = zero + 1
			else:
				neg_no = neg_no + 1
				steps = steps + (-1 - ele)
		steps = steps + zero
		if neg_no % 2 != 0 and zero == 0:
			steps = steps + 2
		return steps


class Solution:

	def makeProductOne(self, arr, N):
		steps = 0
		negatives = 0
		zeroes = 0
		for n in arr:
			if n > 0:
				steps += n - 1
			elif n < 0:
				steps += -1 - n
				negatives += 1
			else:
				zeroes += 1
		if negatives % 2 != 0 and zeroes is 0:
			steps += 2
			return steps
		steps += zeroes
		return steps