Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.

One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.

Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.

Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 10^3) — the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id_1, id_2, ..., id_{n} (0 ≤ id_{i} ≤ 10^9). Number id_{i} equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise.

Consider the secretaries indexed from 1 to n in some way.


-----Output-----

Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.


-----Examples-----
Input
6
0 1 7 1 7 10

Output
2

Input
3
1 1 1

Output
-1

Input
1
0

Output
0



-----Note-----

In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.

In the second test sample the described situation is impossible as conferences aren't allowed.

Difficulty: EASY
Tags: Sorting

Implementation
Skill types: Sorting

Starter code:

Solutions:
n = int(input())
li = list(map(int, input().rstrip().split()))
li.sort()
cnt = 0
i = 0
while i < n:
	if li[i] == 0:
		i += 1
	else:
		p = li[i]
		cnt1 = 1
		j = i + 1
		while j < n and li[j] == p:
			cnt1 += 1
			j += 1
		if cnt1 > 2:
			print(-1)
			exit()
		elif cnt1 == 2:
			cnt += 1
		i = i + cnt1
print(cnt)


n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(n):
	if a[i] != 0:
		a = a[i:n]
		break
l = len(a)
c = [0] * l
c[0] = 1
for i in range(1, l):
	if a[i] != a[i - 1]:
		c[i] = 1
	else:
		c[i] = c[i - 1] + 1
if l == a.count(0):
	print(0)
elif c.count(1) + c.count(2) != l:
	print(-1)
else:
	print(c.count(2))


n = int(input())
d = {}
k = 0
l1 = list(map(int, input().split()))
for x in l1:
	if x:
		d[x] = d.get(x, 0) + 1
		if d[x] == 2:
			k += 1
		if d[x] == 3:
			print(-1)
			exit()
print(k)


from collections import *
from sys import *
input = stdin.readline
n = int(input())
ll = list(map(int, input().split()))
l = [i for i in ll if i != 0]
c = Counter(l)
cc = 0
d = list(c.values())
for i in d:
	if i == 2:
		cc = cc + 1
	elif i > 2:
		cc = -1
		break
print(cc)


t = int(input())
sec = list(map(int, input().split()))
total = 0
m = set(sec)
for i in m:
	if i == 0:
		continue
	if sec.count(i) > 2:
		print(-1)
		exit(0)
	if sec.count(i) == 2:
		total += 1
print(total)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = ii()
d = collections.Counter(li())
d[0] = 0
if any((v > 2 for v in d.values())):
	print(-1)
else:
	print(list(d.values()).count(2))


n = int(input())
calls = list(map(int, input().split()))
people = {}
for x in calls:
	if x != 0:
		if not x in people:
			people[x] = 0
		people[x] += 1
a = 0
for x in people.values():
	if x > 2:
		print(-1)
		break
	if x == 2:
		a += 1
else:
	print(a)


def cocktail_sort(a):
	n = len(a)
	swapped = True
	start = 0
	end = n - 1
	while swapped == True:
		swapped = False
		for i in range(start, end):
			if a[i] > a[i + 1]:
				(a[i], a[i + 1]) = (a[i + 1], a[i])
				swapped = True
		if swapped == False:
			break
		swapped = False
		end = end - 1
		for i in range(end - 1, start - 1, -1):
			if a[i] > a[i + 1]:
				(a[i], a[i + 1]) = (a[i + 1], a[i])
				swapped = True
		start = start + 1
n = int(input())
x = list(map(int, input().split()))
ans = 0
cocktail_sort(x)
for i in range(len(x) - 1):
	if i + 2 >= n:
		if x[i] == x[i + 1] and x[i] != 0:
			ans = ans + 1
			i = i + 1
	elif x[i] == x[i + 1] and x[i] != 0 and (x[i] != x[i + 2]):
		ans = ans + 1
		i = i + 1
	elif x[i] == x[i + 1] and x[i] != 0 and (x[i] != 0):
		ans = -1
		break
print(ans)


n = int(input())
s = 0
l = input().split()
for i in range(n):
	l[i] = int(l[i])
r = 0
for i in range(n - 1):
	r = 0
	if l[i] != 0:
		for j in range(i + 1, n):
			if l[i] == l[j]:
				r += 1
		if r == 1:
			s += 1
		elif r > 1:
			print(-1)
			break
if r <= 1:
	print(s)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def summarizeList(l):
	sl = sorted(l)
	a = sl[0]
	c = 1
	res = []
	for x in sl[1:]:
		if x == a:
			c += 1
		else:
			res.append([a, c])
			a = x
			c = 1
	res.append([a, c])
	return res

def main():
	n = I()
	l = LI()
	sl = summarizeList(l)
	ans = 0
	for (x, c) in sl:
		if x != 0 and c > 2:
			return -1
		if x != 0 and c == 2:
			ans += 1
	return ans
print(main())


__copyright__ = ''
__author__ = 'Son-Huy TRAN'
__email__ = 'sonhuytran@gmail.com'
__doc__ = ''
__version__ = '1.0'

def count_sessions(sessions: list) -> int:
	session_dict = {}
	for session in sessions:
		if session == 0:
			continue
		session_count = session_dict.get(session, 0)
		if session_count >= 2:
			return -1
		session_dict[session] = session_count + 1
	count = 0
	for value in session_dict.values():
		if value >= 2:
			count += 1
	return count

def main() -> int:
	n_calls = int(input())
	sessions = [int(word) for word in input().split()]
	print(count_sessions(sessions))
	return 0

def __starting_point():
	exit(main())
__starting_point()


n = int(input())
l = [int(x) for x in input().split()]
ans = 0
g = list(set(l))
for i in g:
	c = l.count(i)
	if i != 0:
		if c == 2:
			ans += 1
		elif c > 2:
			ans = -1
			break
print(ans)


def spyke_talks(spyke):
	connected = 0
	sort_spyke = sorted(spyke)
	for i in range(1, len(sort_spyke)):
		if sort_spyke[i] != 0 and sort_spyke[i] == sort_spyke[i - 1]:
			connected += 1
			if i + 1 < len(spyke) and sort_spyke[i] == sort_spyke[i + 1]:
				connected = -1
				print(connected)
				return
	print(connected)
n = input()
spyke = list(map(int, input().split()))
spyke_talks(spyke)


n = int(input())
arr = list(map(int, input().split()))
cnt = 0
(clast, llast) = (-1, -1)
arr = sorted(arr)
bad = False
for i in arr:
	if i > 0:
		if i == clast:
			cnt += 1
			if clast == llast:
				bad = True
		llast = clast
		clast = i
if bad == False:
	print(cnt)
else:
	print(-1)


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
N = int(input())
A = [int(x) for x in input().split()]
wc = collections.Counter([v for v in A if v != 0])
if any([c > 2 for c in wc.values()]):
	print(-1)
else:
	print(len([c for c in wc.values() if c == 2]))


n = int(input())
id = sorted(list(map(int, input().split())))
prev = -1
count = 1
output = 0
for i in id[id.count(0):]:
	if i == 0:
		continue
	if prev == i:
		count += 1
	else:
		count = 1
	if count == 2:
		output += 1
	elif count >= 3:
		output = -1
		break
	prev = i
print(output)


n = int(input())
a = sorted([int(i) for i in input().split()])
i = 0
ans = 0
while i < n:
	if i < n - 2 and a[i] == a[i + 1] and (a[i] != a[i + 2]) and (a[i] != 0):
		ans += 1
		i += 2
	elif i < n - 2 and a[i] == a[i + 1] and (a[i] == a[i + 2]) and (a[i] != 0):
		ans = -1
		break
	elif i < n - 1 and a[i] == a[i + 1] and (a[i] != 0):
		ans += 1
		i += 1
	else:
		i += 1
print(ans)


n = int(input())
nums = [int(i) for i in input().split()]
nums.sort()
ans = 0
eq = 0
if n > 1:
	for i in range(1, n):
		if nums[i] == 0:
			eq = 0
			continue
		if nums[i] == nums[i - 1]:
			eq += 1
			ans += 1
			if eq == 2:
				ans = -1
				break
		else:
			eq = 0
print(ans)


nenuzhnayadich = input()
arr = list(map(int, input().split()))
(meowcount, x) = (0, 0)

def meow(x, arr, meowcount):
	if x == len(arr):
		print(meowcount)
		return meowcount
	elif arr.count(arr[x]) == 2 and arr[x] != 0:
		meowcount += 1
		arr.pop(x)
		return meow(x, arr, meowcount)
	elif arr.count(arr[x]) > 2 and arr[x] != 0:
		print(-1)
		return -1
	elif arr[x] == 0 or arr.count(arr[x]) < 2:
		x += 1
		return meow(x, arr, meowcount)
meow(0, arr, 0)


n = int(input())
a = list(map(int, input().split()))
d = {0: 0}
for x in a:
	if x > 0:
		d[x] = d.get(x, 0) + 1
if max(d.values()) > 2:
	print(-1)
else:
	ans = list(d.values()).count(2)
	print(ans)


n = int(input())
cons = list(map(int, input().split()))
cons.sort()
i = 0
while i < len(cons) and cons[i] == 0:
	i += 1
r = 0
if i != len(cons):
	old = 0
	for j in range(i, len(cons)):
		if cons[j] == old:
			r += 1
			if flag:
				r = -1
				break
			flag = True
		else:
			flag = False
		old = cons[j]
print(r)


n = int(input())
c = 0
l = list(map(int, input().split()))
s = list(set(l))
for i in s:
	if i == 0:
		continue
	elif l.count(i) == 2:
		c += 1
	elif l.count(i) > 2:
		print(-1)
		quit()
print(c)


input()
lst = map(int, input().split())
dct = {}
for i in lst:
	if i > 0:
		dct[i] = dct.get(i, 0) + 1
total = 0
for v in dct.values():
	if v == 2:
		total += 1
	elif v > 2:
		total = -1
		break
print(total)


n = int(input())
l = list(map(int, input().split()))
l.sort()
r = 0
bad = False
for i in range(n - 1):
	if l[i] == 0:
		continue
	if l[i] == l[i + 1]:
		r += 1
	if i < n - 2 and l[i + 2] == l[i]:
		print(-1)
		bad = True
		break
if not bad:
	print(r)


(n, calls) = (int(input()), list(map(int, input().split())))
res = 0
for x in set(calls):
	if calls.count(x) == 2 and x != 0:
		res += 1
	if calls.count(x) >= 3 and x != 0:
		res = -1
		break
print(res)


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
cc = Counter(l)
del cc[0]
vals = list(cc.values())
if len(vals) > 0 and max(vals) > 2:
	print(-1)
else:
	print(vals.count(2))


n = int(input())
a = sorted(list(map(int, input().split())))
(m, i) = (0, 0)
if n == 1:
	print(0)
else:
	while i < n:
		x = a.count(a[i])
		if a[i] != 0 and x == 2:
			m += 1
		elif a[i] != 0 and x > 2:
			m = -1
			break
		i += x
	if m:
		print(m)
	else:
		print(0)


n = int(input())
C = {}
L = list(map(int, input().split()))
for i in range(n):
	item = L[i]
	if item in C:
		C[item].append(i)
	else:
		C[item] = [i]
valid = True
ans = 0
for item in C:
	if item == 0:
		continue
	if len(C[item]) > 2:
		valid = False
		ans = -1
		break
	if len(C[item]) == 2:
		ans += 1
print(ans)


from collections import Counter
n = int(input())
l = sorted(list(map(int, input().split())))
s = list(set(l))
d = Counter(l)
(c, f) = (0, 0)
for x in s:
	if x != 0 and d[x] > 2:
		f = 1
		break
	elif x != 0 and d[x] == 2:
		c += 1
print([c, -1][f == 1])


n = int(input())
l = list(map(int, input().split()))
l.sort()
s = list(set(l))
c = 0
x3 = 0
for i in range(len(s)):
	if int(s[i]) == 0:
		i = i + 1
	else:
		x = l.count(s[i])
		if x > 2:
			x3 = 1
			break
		elif x == 2:
			c = c + 1
if x3 == 1:
	print('-1')
else:
	print(c)


n = int(input())
b = input().split()
l1 = [int(x) for x in b if int(x) and b.count(x) >= 2]
done = 0
for x in l1:
	if l1.count(x) > 2:
		done = 1
if not done:
	print(len(set(l1)))
else:
	print(-1)


from math import ceil
a = int(input())
b = list(map(int, input().split()))
c = []
cnt = 0
for i in range(a):
	if b.count(b[i]) == 2 and b[i] > 0:
		cnt += 1
	elif b.count(b[i]) > 2 and b[i] > 0:
		print('-1')
		quit()
	else:
		cnt += 0
print(ceil(cnt / 2))


n = int(input())
d = {}
l = list(map(int, input().split()))
ans = 0
for x in l:
	d[x] = d.get(x, 0) + 1
for x in d:
	if x == 0:
		continue
	if d[x] == 2:
		ans += 1
	if d[x] > 2:
		print(-1)
		break
else:
	print(ans)


from collections import Counter

def main():
	n = int(input())
	d = Counter(map(int, input().split()))
	d[0] = 0
	if max(d.values()) < 3:
		print(sum((_ == 2 for _ in d.values())))
	else:
		print(-1)
main()


from collections import Counter

def main():
	n = int(input())
	d = Counter(map(int, input().split()))
	d[0] = 0
	if max(d.values()) < 3:
		print(Counter(d.values())[2])
	else:
		print(-1)
main()


def shellSort(arr):
	gap = n // 2
	while gap > 0:
		for i in range(gap, n):
			temp = arr[i]
			j = i
			while j >= gap and arr[j - gap] > temp:
				arr[j] = arr[j - gap]
				j -= gap
			arr[j] = temp
		gap //= 2
n = int(input())
secretaryID = [int(x) for x in input().split()]
shellSort(secretaryID)
ans = 0
if n == 1:
	print(0)
	quit()
else:
	for i in range(n - 2):
		if secretaryID[i] == 0:
			continue
		if secretaryID[i] == secretaryID[i + 1]:
			if secretaryID[i + 1] == secretaryID[i + 2]:
				ans = -1
				break
			else:
				ans += 1
if ans == -1:
	print(ans)
else:
	print(ans if secretaryID[n - 2] != secretaryID[n - 1] or secretaryID[n - 2] == 0 else ans + 1)


n = int(input())
s = [int(x) for x in input().split(' ')]
ones = set()
twos = set()
answer = 0
for id in s:
	if id == 0:
		pass
	elif id in twos:
		answer = -1
		break
	elif id in ones:
		answer += 1
		ones.remove(id)
		twos.add(id)
	else:
		ones.add(id)
print(answer)


n = int(input())
arr = list(map(int, input().split()))
d = {}
for i in arr:
	if i != 0:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
v = list(d.values())
f = 0
c = 0
for i in v:
	if i > 2:
		f = 1
		break
	else:
		c += int(i / 2)
if f:
	print(-1)
else:
	print(c)


n = int(input())
ids = list(map(int, input().split()))
ids.sort()
ids = [ids.count(x) for x in {*ids} - {0}]
if max(ids + [0]) > 2:
	print(-1)
else:
	print(ids.count(2))


a = int(input())
t = list(map(int, input().split()))
y = list(set(t))
h = 0
u = 0
if y == [0]:
	print(0)
else:
	for k in y:
		if k == 0:
			pass
		elif t.count(k) == 2:
			u += 1
		elif t.count(k) > 2:
			print(-1)
			h += 1
			break
	if h == 0:
		print(u)


from collections import Counter
n = int(input())
cnt = Counter((int(x) for x in input().split()))
ans = 0
for (a, b) in cnt.items():
	if a:
		if b == 2:
			ans += 1
		if b > 2:
			print(-1)
			exit(0)
print(ans)


n = int(input())
id = list(map(int, input().split()))
ans = 0
for char in id:
	if id.count(char) == 2 and char != 0:
		ans += 1
	elif id.count(char) > 2 and char != 0:
		ans = -1
		break
if ans != -1:
	print(ans // 2)
else:
	print(ans)


import sys
n = int(input())
callers = sorted(map(int, input().split()))
if n == 1:
	print(0)
elif n == 2:
	if callers[0] == callers[1]:
		print(1)
	else:
		print(0)
else:
	first = 0
	for i in range(n):
		if callers[i] != 0:
			first = i
			break
	else:
		print(0)
		sys.exit(0)
	stack = [callers[first]]
	ans = 0
	couple = 1
	for i in range(first + 1, n):
		if stack[-1] == callers[i] and couple == 1:
			couple += 1
		elif stack[-1] == callers[i] and couple != 1:
			couple += 1
			if couple > 2:
				print(-1)
				break
		else:
			stack[-1] = callers[i]
			if couple == 2:
				ans += 1
			couple = 1
	else:
		if couple == 2:
			print(ans + 1)
		else:
			print(ans)


n = int(input())
ci = list(map(int, input().split()[:n]))
d = {}
for i in ci:
	if i in d:
		d[i] += 1
	elif i != 0:
		d[i] = 1
b = []
for i in d:
	b.append(d[i])
b.append(-1)
count = 0
for i in b:
	if len(ci) == 1:
		print(0)
		break
	elif i >= 3:
		print(-1)
		break
	elif i == 2:
		count += 1
	elif i == -1:
		print(count)


n = int(input())
x = [int(w) for w in input().split()]
y = set(x)
a = 0
for i in y:
	if i == 0:
		continue
	b = x.count(i)
	if b >= 3:
		a = -1
		break
	if b == 2:
		a += 1
print(a)


n = int(input())
d = list(map(int, input().split()))
calls = dict()
invalid = False
c = 0
for i in range(n):
	if d[i] > 0:
		if d[i] in calls.keys():
			calls[d[i]] += 1
		else:
			calls[d[i]] = 1
		if calls[d[i]] == 2:
			c += 1
		elif calls[d[i]] == 3:
			invalid = True
			break
if invalid:
	print(-1)
else:
	print(c)


n = map(int, input().split())
a = list(map(int, input().split()))
b = set(a) - {0}
result = 0
for i in b:
	if a.count(i) > 2:
		print(-1)
		exit(0)
	elif a.count(i) == 2:
		result += 1
print(result)


a = [*open(0)][1].split()
a = [a.count(x) for x in {*a} - {'0'}]
print([a.count(2), -1][max(a + [0]) > 2])


n = int(input())
sessions = {}
counter = 0
for i in input().split():
	i = int(i)
	if i == 0:
		continue
	if i not in sessions:
		sessions[i] = 0
	sessions[i] += 1
	if sessions[i] == 2:
		counter += 1
	elif sessions[i] == 3:
		counter = -1
		break
print(counter)


secretaryCount = int(input())
callSessionIDs = list(map(int, input().split(' ')))
callsHashMap = {}
for i in range(secretaryCount):
	if callSessionIDs[i] == 0:
		continue
	key = callSessionIDs[i]
	if key in callsHashMap:
		callsHashMap[key] = callsHashMap[key] + 1
	else:
		callsHashMap[callSessionIDs[i]] = 1
(pairCount, callIDCounts) = (0, list(callsHashMap.values()))
(found, index) = (False, 0)
while not found and index < len(callIDCounts):
	if callIDCounts[index] > 2:
		found = not found
	elif callIDCounts[index] == 2:
		pairCount = pairCount + 1
	index = index + 1
print('-1') if found else print(pairCount)


input()
l = list(map(int, input().split()))
a = [l.count(i) for i in set(l) if i > 0]
print([a.count(2), -1][max(a + [0]) > 2])


n = int(input())
l = list(map(int, input().split()))
ans = 0
repeat = {}
for i in l:
	if i in repeat:
		repeat[i] += 1
		if i == 0:
			pass
		elif repeat[i] > 2:
			ans = -1
			break
		else:
			ans += 1
	else:
		repeat[i] = 1
print(ans)


def main(n, nums):
	data = {}
	Rn = range(n)
	answer = 0
	for i in Rn:
		item = str(nums[i])
		if item != '0':
			if item not in data:
				data[item] = 0
			data[item] += 1
	for item in data.keys():
		val = data[item]
		if val == 2:
			answer += 1
		elif val > 2:
			return -1
	return answer

def init():
	n = int(input())
	nums = list(map(int, input().split()))
	print(main(n, nums))
init()


d = {'dummy': 0}
n = int(input())
a = list(map(str, input().split()))
for i in range(n):
	k = False
	p = list(d.keys())
	for j in p:
		if a[i] == j:
			k = True
			break
	if k:
		d[a[i]] += 1
	else:
		d[a[i]] = 1
count = 0
neg = 0
k = list(d.items())
for (i, j) in k:
	if i != '0' and i != 'dummy':
		if j == 2:
			count += 1
		elif j > 2:
			neg += 1
if count >= 0 and neg > 0:
	print(-1)
else:
	print(count)


n = int(input())
l = list(map(int, input().split()))
s = set(l)
a = [0] * 1005
i = 0
for x in s:
	if x != 0:
		a[i] = l.count(x)
	else:
		a[i] = 0
	i += 1
if max(a) > 2:
	print('-1')
else:
	print(a.count(2))


T_ON = 0
DEBUG_ON = 0
MOD = 998244353

def solve():
	n = read_int()
	A = read_ints()
	G = Counter(A)
	del G[0]
	count = 0
	for v in G.values():
		if v > 2:
			print(-1)
			return
		elif v == 2:
			count += 1
	print(count)

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def First():
	print('First')

def Second():
	print('Second')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def is_even(x):
	return x % 2 == 0

def is_odd(x):
	return x % 2 == 1

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	(ct, ctm) = (1, 0)
	l.append(-1)
	for i in range(0, n):
		if l[i] == l[i + 1] and l[i] > 0:
			ct += 1
		elif l[i] != l[i + 1] and ct == 2:
			ctm += 1
			ct = 1
		elif l[i] != l[i + 1] and ct > 2:
			ctm = -1
			break
	print(ctm)
solve()


n = int(input())
s = list(map(int, input().split()))
pair = 0
freq = {}
for item in s:
	if item in freq:
		freq[item] = freq[item] + 1
	else:
		freq[item] = 1
for (key, value) in freq.items():
	if key > 0 and value == 2:
		pair = pair + value // 2
	elif key > 0 and value > 2:
		pair = -1
		break
print(pair)


n = int(input())
a = input().split()
k = 0
for i in set(a):
	if a.count(i) == 2 and i != '0':
		k += 1
	elif a.count(i) > 2 and i != '0':
		print(-1)
		quit()
print(k)


n = int(input())
l = list(map(int, input().split(' ')))
dict = {}
cnt = 0
for i in l:
	if i == 0:
		continue
	if i in dict:
		if dict[i] == 2:
			cnt = -1
			break
		dict[i] += 1
		cnt += 1
	else:
		dict[i] = 1
print(cnt)


d = {'dummy': 0}
n = int(input())
a = list(map(str, input().split()))
for i in range(n):
	if a[i] not in d:
		d[a[i]] = 1
	else:
		d[a[i]] += 1
count = 0
neg = 0
k = list(d.items())
for (i, j) in k:
	if i != '0' and i != 'dummy':
		if j == 2:
			count += 1
		elif j > 2:
			neg += 1
			break
if count >= 0 and neg > 0:
	print(-1)
else:
	print(count)


import sys
import math
n = int(sys.stdin.readline())
id = [int(x) for x in sys.stdin.readline().split() if x != '0']
if len(id) == 0:
	print(0)
	exit()
res = 0
id.sort()
v = id[0]
k = 1
for x in id[1:]:
	if x == v:
		k += 1
	else:
		if k == 2:
			res += 1
		elif k > 2:
			print(-1)
			exit()
		v = x
		k = 1
if k == 2:
	res += 1
elif k > 2:
	print(-1)
	exit()
print(res)


input()
d = input().split()
ans = 0
for i in d:
	if d.count(i) > 2 and i != '0':
		print(-1)
		break
	elif d.count(i) == 2 and i != '0':
		ans += 1
else:
	print(ans // 2)


from collections import Counter
useless = input()

def pairs(secretaries):
	counted_secretaries = Counter(secretaries)
	del counted_secretaries['0']
	while len(counted_secretaries.most_common()) > 0 and counted_secretaries.most_common()[-1][1] == 1:
		del counted_secretaries[counted_secretaries.most_common()[-1][0]]
	if len(counted_secretaries.most_common()) == 0:
		return 0
	return -1 if counted_secretaries.most_common()[0][1] > 2 else len(counted_secretaries.most_common())
print(pairs(input().split(' ')))


n = int(input())
s = input().split()
for i in range(n):
	s[i] = int(s[i])
ans = 0
done = False
for i in range(n):
	if s[i] == 0:
		continue
	n = s[i + 1:].count(s[i])
	if n == 1:
		ans += 1
	elif n > 1:
		print(-1)
		done = True
		break
if not done:
	print(ans)


n = int(input())
id = [int(i) for i in input().split() if i != '0']
id.sort()
ans = 0
while id:
	tmp = id.pop()
	if id and tmp == id[-1]:
		ans += 1
		id.pop()
	if id and tmp == id[-1]:
		ans = -1
		break
print(ans)


def getNextGap(gap):
	gap = gap * 10 // 13
	if gap < 1:
		return 1
	return gap

def combSort(arr):
	n = len(arr)
	gap = n
	swapped = True
	while gap != 1 or swapped == 1:
		gap = getNextGap(gap)
		swapped = False
		for i in range(0, n - gap):
			if arr[i] > arr[i + gap]:
				(arr[i], arr[i + gap]) = (arr[i + gap], arr[i])
				swapped = True
answer = 0
possible = True
input()
arr = [int(x) for x in input().split()]
combSort(arr)
for i in range(0, len(arr) - 2):
	if arr[i] == 0:
		continue
	if arr[i] == arr[i + 1]:
		if arr[i] == arr[i + 2]:
			possible = False
			break
		else:
			answer += 1
if arr[len(arr) - 2] == arr[len(arr) - 1] and len(arr) != 1 and (arr[len(arr) - 1] != 0):
	answer += 1
if possible == False:
	answer = -1
print(answer)


n = int(input())
s = input().split()
d = {}
for i in s:
	d[i] = d.get(i, 0) + 1
ans = 0
for i in d:
	if i == '0':
		continue
	if d[i] == 2:
		ans += 1
	elif d[i] > 2:
		print('-1')
		break
else:
	print(ans)


from collections import Counter
input()
c = Counter(map(int, input().split()))
c[0] = 0
if any((c[i] > 2 for i in c)):
	print(-1)
else:
	print(sum((1 for i in c if c[i] == 2)))


n = int(input())
k = 0
lst = []
n1 = list(map(int, input().split()))
if n == 1:
	print(0)
else:
	for i in n1:
		if i != 0 and n1.count(i) == 2:
			lst.append(i)
		elif i != 0 and n1.count(i) >= 3:
			print(-1)
			k = k + 1
			break
	if k == 0:
		print(len(lst) // 2)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
n = int(input())
a = sorted([*map(int, input().split())])
ca = Counter(a)
ans = 0
for i in ca:
	if i == 0:
		continue
	if ca[i] == 2:
		ans += 1
	elif ca[i] > 2:
		print(-1)
		exit()
print(ans)


def read_tokens():
	return input().strip().split(' ')

def read_ints():
	return [int(s) for s in read_tokens()]
n = int(input())
arr = read_ints()

def solve(arr: list) -> int:
	n = len(arr)
	d = {}
	for el in arr:
		if el == 0:
			continue
		if el in d:
			d[el] += 1
		else:
			d[el] = 1
	cnt = 0
	for (k, v) in d.items():
		if v > 2:
			return -1
		if v == 2:
			cnt += 1
	return cnt
print(solve(arr))


n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a) - {0}
b = list(b)
c = 0
d = 0
for i in b:
	if a.count(i) == 2:
		c = c + 1
	elif a.count(i) > 2:
		d = d + 1
if d > 0:
	print(-1)
else:
	print(c)


from collections import Counter
(N, Answer) = (int(input()), 0)
X = Counter(list(map(int, input().split())))
for key in X:
	if key != 0:
		if X[key] == 2:
			Answer += 1
		elif X[key] > 2:
			print(-1)
			exit()
print(Answer)


def solve():
	n = int(input())
	id = list(map(int, input().split()))
	duplicate_id = set()
	unique_id = set()
	score = 0
	for i in range(len(id)):
		if id[i] != 0 and id[i] not in duplicate_id:
			if id[i] not in unique_id:
				unique_id.add(id[i])
			else:
				duplicate_id.add(id[i])
				score += 1
		elif id[i] == 0:
			pass
		else:
			return -1
	return score
print(solve())


input()
(a, i, c) = (input().split(), 0, 0)
a.sort()
while i < len(a):
	j = a.count(a[i])
	if a[i] != '0':
		if j == 2:
			c += 1
		elif j > 2:
			c = -1
			break
	i += j
print(c)


n = int(input())
idi = list(map(int, input().split()))
idi.sort()
ans = n > 1 and idi[0] == idi[1] and (idi[0] != 0)
for i in range(2, n):
	if idi[i] == 0:
		continue
	ans += idi[i] == idi[i - 1]
	if idi[i] == idi[i - 2]:
		ans = -1
		break
print(int(ans))


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
cnt = 0
for i in l:
	if l.count(i) == 2 and i > 0:
		cnt += 1
	elif l.count(i) >= 3 and i > 0:
		print(-1)
		exit()
print(int(cnt / 2))


t = int(input())
arr = list(map(int, input().split()))

def count(arr, elem):
	c = 0
	for i in arr:
		if i == elem:
			c += 1
	return c
c = 0
for i in arr:
	if i != 0:
		if count(arr, i) > 2:
			print(-1)
			exit(0)
		elif count(arr, i) == 2:
			c += 1
print(c // 2)


def cycleSort(array):
	writes = 0
	for cycleStart in range(0, len(array) - 1):
		item = array[cycleStart]
		pos = cycleStart
		for i in range(cycleStart + 1, len(array)):
			if array[i] < item:
				pos += 1
		if pos == cycleStart:
			continue
		while item == array[pos]:
			pos += 1
		(array[pos], item) = (item, array[pos])
		writes += 1
		while pos != cycleStart:
			pos = cycleStart
			for i in range(cycleStart + 1, len(array)):
				if array[i] < item:
					pos += 1
			while item == array[pos]:
				pos += 1
			(array[pos], item) = (item, array[pos])
			writes += 1
	return writes
n = int(input())
x = list(map(int, input().split()))
answer = 0
cycleSort(x)
for i in range(len(x) - 1):
	if i + 2 >= n:
		if x[i] == x[i + 1] and x[i] != 0:
			answer = answer + 1
			i = i + 1
	elif x[i] == x[i + 1] and x[i] != 0 and (x[i] != x[i + 2]):
		answer = answer + 1
		i = i + 1
	elif x[i] == x[i + 1] and x[i] != 0 and (x[i] != 0):
		answer = -1
		break
print(answer)


n = int(input())
lst = [int(i) for i in input().split()][:n]
lst.sort()
lst.append(lst[n - 1] + 1)
i = 0
chatting = 0
flag = 1
while True:
	if i > n - 2:
		break
	if lst[i] == 0:
		i += 1
		continue
	elif lst[i] == lst[i + 1] and lst[i] != lst[i + 2]:
		chatting += 1
		i += 2
	elif lst[i] == lst[i + 1] and lst[i] == lst[i + 2]:
		flag = 0
		print('-1')
		break
	else:
		i += 1
if flag:
	print(chatting)


n = int(input())
us = {}
for i in input().split():
	try:
		us[i] += 1
	except:
		us[i] = 1
counter = 0
for id in us:
	if us[id] == 2 and id != '0':
		counter += 1
	elif us[id] > 2 and id != '0':
		counter = -1
		break
print(counter)


import sys
my_file = sys.stdin
my_file.readline()
nums = [int(i) for i in my_file.readline().split(' ')]
speaking = 0
for i in nums:
	if i > 0:
		if nums.count(i) == 2:
			speaking += 1
		elif nums.count(i) > 2:
			speaking = -1
			break
if speaking > 0:
	print(int(speaking / 2))
else:
	print(speaking)


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
for i in range(l.count(0)):
	l.remove(0)
c = Counter(l)
a = c.values()
w = 0
for i in a:
	if i == 2:
		w += 1
	elif i > 2:
		print(-1)
		break
else:
	print(w)


n = int(input())
y = input().split()
x = [int(f) for f in y]
z = x[:]
zeros = []
while z.count(0) > 0:
	z.remove(0)
	zeros.append(0)
count = 0
count1 = 0
q = list(set(z))
for i in range(0, len(q)):
	key = q[i]
	if z.count(key) == 2:
		count += 1
	if z.count(key) == 1:
		count = count
	if z.count(key) > 2:
		count1 = count1 - 1
		break
if count1 == 0:
	print(count)
else:
	print(-1)


n = int(input())
s = list(map(int, input().split()))
x = set(s)
r = 0
for i in x:
	if i != 0:
		p = s.count(i)
		if p == 2:
			r += 1
		elif p > 2:
			print(-1)
			exit()
print(r)


import collections
n = int(input())
temp = list(map(int, input().split()))
l = [i for i in temp if i != 0]
x = collections.Counter(l)
y = x.values()
ans = 0
for i in y:
	if i == 2:
		ans = ans + 1
	elif i > 2:
		ans = -1
		break
print(ans)


I = input
I()
a = {}
for x in map(int, I().split()):
	if x:
		a[x] = a.get(x, 0) + 1
a = list(a.values())
b = max(a + [0])
print([-1, list(a).count(2)][b < 3])


n = int(input())
a = list(map(int, input().split()))
k = 0
count = 0
for i in range(len(a)):
	k += count
	count = 0
	if a[i] != 0:
		for j in range(i + 1, len(a)):
			if a[j] != 0:
				if a[i] == a[j]:
					count += 1
	if count > 1:
		print(-1)
		break
	if i == len(a) - 1:
		print(k)


n = int(input())
l = sorted([int(x) for x in input().split()])
l = [l.count(x) for x in {*l} - {0}]
if max(l + [0]) > 2:
	print(-1)
else:
	print(l.count(2))


from collections import Counter

def program():
	c = Counter(l)
	amt = list()
	if 0 in c:
		del c[0]
	for i in c.values():
		if i <= 2:
			amt.append(i)
		else:
			return -1
	return amt.count(2)
length = int(input())
l = list(map(int, input().strip().split()))
print(program())


n = int(input())
l = list(map(int, input().split()))
l.sort()
list1 = []
sum1 = 1
if n > 1:
	for i in range(n - 1):
		if l[i] == l[i + 1] and l[i] != 0:
			sum1 += 1
			if i == n - 2:
				list1.append(sum1)
		else:
			list1.append(sum1)
			sum1 = 1
	if max(list1) == 1:
		print(0)
	elif max(list1) > 2:
		print(-1)
	elif max(list1) == 2:
		count = 0
		for i in list1:
			if i == 2:
				count += 1
		print(count)
else:
	print(0)


secs = int(input())
calls = input().split(' ')
total = 0
calls.sort()
false = 0
for x in range(len(calls) - 2):
	if calls[x] == calls[x + 1] and calls[x] != '0':
		if calls[x + 1] == calls[x + 2] and calls[x + 1] != '0':
			print(-1)
			false = 1
			break
		else:
			total += 1
if false != 1:
	if len(calls) >= 2:
		if calls[len(calls) - 2] == calls[len(calls) - 1] and calls[len(calls) - 1] != '0':
			total += 1
	print(total)


n = int(input())
a = list(map(int, input().split()))
c = 0
b = list(set(a))
for i in b:
	d = a.count(i)
	if i == 0:
		pass
	elif d == 2:
		c += 1
	elif d >= 3:
		print('-1')
		exit()
print(c)


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
l = list(filter(lambda x: x > 0, l))
c = list(Counter(l).values())
if any([i > 2 for i in c]):
	print(-1)
else:
	print(c.count(2))


(n, s) = (int(input()), 0)
t = list(map(int, input().split()))
p = set(t)
p.discard(0)
for i in p:
	k = t.count(i)
	if k == 2:
		s += 1
	elif k > 2:
		s = -1
		break
print(s)


n = int(input())
d = {}
l = list(map(int, input().split()))
for i in l:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True))
ans = 0
for i in d:
	if d[i] > 2 and i != 0:
		ans = -1
		break
	elif d[i] == 2 and i != 0:
		ans += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
l = [x for x in l if x != 0]
total = 0
while len(l):
	i = l[0]
	no = l.count(i)
	if no > 2:
		print('-1')
		exit(0)
	elif no == 2 and i != 0:
		total += 1
	l = [x for x in l if x != i]
print(total)


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
count = Counter(arr)
ans = 0
for (key, val) in count.items():
	if val > 2 and key != 0:
		print(-1)
		exit()
	if val == 2 and key != 0:
		ans += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
d = {}
s = 0
for i in range(n):
	if l[i] != 0:
		if l[i] not in d:
			d[l[i]] = 1
		else:
			d[l[i]] += 1
			if d[l[i]] > 2:
				s = 1
				print('-1')
				break
if s == 0:
	c = 0
	for i in d:
		if d[i] == 2:
			c += 1
	print(c)


n = int(input())
l = list(input().split())
c = 0
for i in range(n):
	if l[i] == '0':
		continue
	if l.count(l[i]) > 2:
		print('-1')
		exit()
	elif l.count(l[i]) == 2:
		c += 1
print(c // 2)


from collections import defaultdict
corporates = int(input())
secretaries = [int(x) for x in input().split()]
counter = defaultdict(int)
pairs = 0
for secretary in secretaries:
	if secretary != 0:
		counter[secretary] += 1
for items in counter:
	if counter[items] > 2:
		pairs = -1
		break
	elif counter[items] == 2:
		pairs += 1
print(pairs)


ar = {}
ar1 = []
n = int(input())
inp = input().split(' ')
for i in range(n):
	m = int(inp[i])
	if m not in ar1:
		ar1.append(m)
		ar[m] = 1
	else:
		ar[m] += 1
sum = 0
for i in ar1:
	if i is not 0:
		if ar[i] > 2:
			sum = -1
			break
		elif ar[i] is 2:
			sum += 1
print(sum)


n = int(input())
li = list(map(int, input().rstrip().split()))
cnt = 0
b = set(li) - {0}
for i in b:
	p = li.count(i)
	if p > 2:
		print(-1)
		exit()
	elif p == 2:
		cnt += 1
print(cnt)


import sys
trash = int(input()) - 1
ID = list(map(int, input().split()))
otv = int()
ID.sort()
i = 0
while i < trash:
	if ID.count(ID[i]) == 2 and ID[i] != 0:
		otv += 1
		ID.remove(ID[i])
		ID.remove(ID[i])
		trash -= 2
		continue
	elif ID.count(ID[i]) > 2 and ID[i] != 0:
		print('-1')
		sys.exit()
	i += 1
print(otv)


input()
data = sorted(filter(lambda v: v != 0, map(int, input().split())))
if any((v1 == v2 for (v1, v2) in zip(data, data[2:]))):
	print(-1)
else:
	print(sum((v1 == v2 for (v1, v2) in zip(data, data[1:]))))


number = int(input())
calls = list(map(int, input().split()))
setOfCalls = set(calls)
count = 0
for id in setOfCalls:
	if id == 0:
		continue
	elif calls.count(id) > 2:
		count = -1
		break
	elif calls.count(id) == 2:
		count += 1
print(count)


import sys
n = int(input())
L = list(map(int, input().split()))
M = []
while L != []:
	d = L[0]
	m = 0
	for j in range(len(L)):
		if L[j] == d:
			m += 1
	M.append([d, m])
	L = list(filter(lambda a: a != d, L))
m = 0
for e in M:
	if e[0] != 0:
		if e[1] == 2:
			m += 1
		if e[1] > 2:
			print(-1)
			sys.exit()
print(m)


def solve(z, n):
	z = [int(z) for z in z.split()]
	c = 0
	r = 0
	x = []
	for i in range(n):
		if z[i] != 0:
			x.append(z[i])
	for i in x:
		c = 0
		for j in x:
			if i == j:
				c = c + 1
		if c > 2:
			return -1
		if c == 2:
			r = r + 1
	return int(r / 2)
n = int(input())
r1 = input()
print(solve(r1, n))


n = int(input())
l = list(map(int, input().split()))
s = set(l) - {0}
ans = 0
for i in s:
	if l.count(i) == 2:
		ans = ans + 1
	if l.count(i) > 2:
		ans = -1
		break
print(ans)


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
from sys import *
from types import new_class
n = int(input())
l = [int(x) for x in input().split()]
ans = 0
for x in set(l):
	if x != 0 and l.count(x) > 2:
		print(-1)
		exit(0)
	elif x != 0:
		ans += int(l.count(x) == 2)
print(ans)


n = int(input())
l = list(map(int, input().split()))
out = 0
l.sort()
i = 0
while i < n:
	q = i
	if l[i] != 0 and l.count(l[i]) >= 2:
		out = out + 1 if l.count(l[i]) == 2 else -1
		i = i + 2 if l.count(l[i]) == 2 else i
	if out == -1:
		break
	i = i + 1 if i == q else i
print(out)