There is a large pile of socks that must be paired by color. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.

Example 

$n=7$ 

$ar=[1,2,1,2,1,3,2]$   

There is one pair of color $\mbox{I}$ and one of color $2$.  There are three odd socks left, one of each color.  The number of pairs is $2$.  

Function Description  

Complete the sockMerchant function in the editor below.     

sockMerchant has the following parameter(s):  

int n: the number of socks in the pile   
int ar[n]: the colors of each sock   

Returns   

int: the number of pairs   

Input Format

The first line contains an integer $n$, the number of socks represented in $\boldsymbol{ar}$. 

The second line contains $n$ space-separated integers, $ar[i]$, the colors of the socks in the pile.

Constraints

$1\leq n\leq100$
$1\leq ar[i]\leq100$ where $0\leq i<n$

Sample Input
STDIN                       Function
-----                       --------
9                           n = 9
10 20 20 10 10 30 50 10 20  ar = [10, 20, 20, 10, 10, 30, 50, 10, 20]

Sample Output
3

Explanation

There are three pairs of socks.

Difficulty: EASY

Solutions:
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
ans = 0
for x in c:
	ans += c[x] // 2
print(ans)


n = int(input())
temp = input().split(' ')
graph = {}
for item in temp:
	graph[item] = 0
for item in temp:
	graph[item] += 1
count = 0
for item in graph:
	count += int(graph[item] / 2)
print(count)


import sys
from collections import Counter
n = int(sys.stdin.readline())
socks = Counter(sys.stdin.readline().split(' '))
total = 0
for sock in socks:
	total += socks[sock] // 2
print(total)


n = int(input())
socks = list(map(int, input().split()))
my_hash = {}
for each in socks:
	if each in my_hash:
		my_hash[each] += 1
	else:
		my_hash[each] = 1
count = 0
for each in my_hash:
	count += my_hash[each] // 2
print(count)


n = int(input())
C = list(map(int, input().split()))
X = set(C)
s = 0
for x in X:
	s += C.count(x) // 2
print(s)


n = int(input())
l = [int(x) for x in input().split()]
q = [0 for x in range(101)]
for i in l:
	q[i] += 1
ans = 0
for i in q:
	if i > 1:
		ans += int(i / 2)
print(ans)


n = eval(input())
l = [int(x) for x in input().split()]
s = set(l)
p = 0
for i in s:
	p += len([x for x in l if x == i]) // 2
print(p)


n = int(input())
a = [int(x) for x in input().split()]
s = set()
count = 0
for color in a:
	if color in s:
		s.remove(color)
		count += 1
	else:
		s.add(color)
print(count)


n = int(input())
c = list(map(int, input().split()))
socks = {}
for x in c:
	if x in socks:
		socks[x] = socks[x] + 1
	else:
		socks[x] = 1
total = 0
for (k, v) in socks.items():
	total += v // 2
print(total)


n = int(input())
c = list((int(i) for i in input().split()))
cou = 0
for i in set(c):
	if c.count(i) >= 2:
		cou += c.count(i) // 2
print(cou)


n = int(input())
socks = [int(v) for v in input().split(' ')]
socks_set = set(socks)
sell = 0
for s in socks_set:
	sell += int(socks.count(s) / 2)
print(sell)


arr = [0] * 102
num = int(input())
colors = [int(x) for x in input().split()]
for i in colors:
	arr[i] += 1
ans = 0
for i in arr:
	ans += int(i / 2)
print(ans)


n = int(input())
l = [int(x) for x in input().split()]
t = 0
for i in set(l):
	if l.count(i) % 2 == 0:
		t += int(l.count(i) / 2)
	else:
		t += int((l.count(i) - 1) / 2)
print(t)


from collections import Counter
n = int(input())
socks = list(map(int, input().split()))
socks = Counter(socks)
total = 0
for elem in socks:
	total += socks[elem] // 2
print(total)


n = int(input())
l = list(map(int, input().split()))
l1 = dict()
cnt = 0
for i in l:
	if i not in l1.keys():
		l1[i] = 1
	else:
		l1[i] += 1
for j in l1.values():
	cnt += j // 2
print(cnt)


n = int(input())
cs = list(map(int, input().split()))
free_colors = set()
total = 0
for c in cs:
	if c in free_colors:
		total += 1
		free_colors.remove(c)
	else:
		free_colors.add(c)
print(total)


from collections import Counter
input()
col = [int(i) for i in input().split()]
colCount = Counter(col)
answer = 0
for num in colCount.values():
	answer += num // 2
print(answer)


import sys
n = int(sys.stdin.readline())
c = [int(x) for x in sys.stdin.readline().split()]
result = 0
d = {}
for s in c:
	if d.get(s, 0) == 0:
		d[s] = 1
	else:
		d[s] = 0
		result += 1
print(result)


n = int(input())
arr = [int(i) for i in input().strip().split(' ')]
dic_colors = {}
for sock_color in arr:
	if sock_color in dic_colors.keys():
		dic_colors[sock_color] += 1
	else:
		dic_colors[sock_color] = 1
count_pairs = 0
for (color, num) in dic_colors.items():
	count_pairs += num // 2
print(count_pairs)


from collections import defaultdict
n = input()
c = sorted(input().strip().split())
socks = defaultdict(int)
for color in c:
	socks[color] += 1
pairs = 0
for color in socks:
	pairs += socks[color] // 2
print(pairs)


from collections import defaultdict
d = defaultdict(int)
n = int(input())
arr = [int(i) for i in input().split(' ')]
for i in arr:
	d[i] += 1
counter = 0
for (key, value) in d.items():
	counter += value // 2
print(counter)


n = int(input())
c = [int(i) for i in input().split(' ')]
tot = 0
while len(c) > 1:
	v = c.pop(0)
	tmp = 1
	tmp2 = 0
	while tmp2 < len(c):
		if c[tmp2] == v:
			c.pop(tmp2)
			tmp = tmp + 1
		else:
			tmp2 = tmp2 + 1
	tot = tot + tmp // 2
print(tot)


from collections import Counter
input()
print(sum((i // 2 for i in Counter(input().split()).values())))


n = int(input())
s = [int(x) for x in input().split(' ')]
s_set = set(s)
c = 0
for i in s_set:
	c += s.count(i) // 2
print(c)


cnt = int(input())
colorcnt = dict()
for x in input().split():
	if x in colorcnt:
		colorcnt[x] += 1
	else:
		colorcnt[x] = 1
result = 0
for x in colorcnt:
	result += colorcnt[x] // 2
print(result)


import sys
import math
first = sys.stdin.readline()
second = sys.stdin.readline().split(' ')
unique = []
for i in second:
	if i not in unique:
		unique.append(i)
count = 0
for j in unique:
	toAdd = math.floor(second.count(j) / 2)
	if toAdd >= 1:
		count += toAdd
print(count)


l = [0] * 101
x = int(input())
c = 0
k1 = [int(a) for a in input().strip().split()]
for i in range(0, x):
	k = k1[i]
	l[k] += 1
	while l[k] % 2 == 0 and l[k] != 0:
		c += 1
		l[k] -= 2
print(c)


import sys
linenum = 0
for line in sys.stdin:
	if linenum is 1:
		arr = line.split(' ')
		arr.sort()
		count = 0
		previ = None
		for i in arr:
			if i == previ:
				count += 1
				previ = None
			else:
				previ = i
		print(count)
	linenum += 1


n = input()
_list = str(input()).split()
_dict = {}
for num in _list:
	_dict[num] = _dict.get(num, 0) + 1
result = 0
for i in _dict:
	result += _dict[i] // 2
print(result)


from collections import Counter
n = int(input())
c = map(int, input().split())
S = Counter(c)
num_pairs = 0
for (k, v) in S.items():
	num_pairs += v // 2
print(num_pairs)


n = int(input())
l = list(map(int, input().strip().split(' ')))
d = {}
pairs = 0
for e in l:
	if e not in d:
		d[e] = 1
	else:
		d[e] += 1
for e in d:
	pairs += d[e] // 2
print(pairs)


n = int(input())
socks = list(map(int, input().split()))
sd = {}
for i in range(n):
	if socks[i] in sd:
		sd[socks[i]] += 1
	else:
		sd[socks[i]] = 1
count = 0
for (key, val) in sd.items():
	count += int(val / 2)
print(count)


import math
n = int(input())
arr = list(map(int, input().split()))
lookup = {}
for i in arr:
	if i in lookup.keys():
		lookup[i] += 1
	else:
		lookup[i] = 1
ans = 0
for i in lookup.keys():
	ans += int(lookup[i] / 2)
print(ans)


num_socks = int(input())
sock_colors = [int(color) for color in input().strip().split(' ')]
num_socks = [0 for _ in range(100)]
for sock_color in sock_colors:
	num_socks[sock_color - 1] += 1
num_pairs = sum([num_sock // 2 for num_sock in num_socks])
print(num_pairs)


num = int(input())
lis1 = [int(a) for a in input().split()]
lis1.sort()
count = 0
j = 0
while num - 1 > 0:
	if lis1[j] == lis1[j + 1]:
		count += 1
		j += 1
		num -= 1
	j += 1
	num -= 1
print(count)


n = int(input())
d = {}
for x in input().split():
	x = int(x)
	if x not in d:
		d[x] = 1
	else:
		d[x] += 1
s = 0
for (k, v) in d.items():
	s += v // 2
print(s)


(n, socks) = (int(input()), input().split())
socks.sort()
count = 0
cur = 0
while cur < len(socks) - 1:
	if socks[cur] == socks[cur + 1]:
		del socks[cur]
		del socks[cur]
		count += 1
	else:
		cur += 1
print(count)


n = int(input())
arr = [int(x) for x in input().split()]
counters = {}
res = 0
for i in range(len(arr)):
	if arr[i] in counters:
		counters[arr[i]] += 1
		if counters[arr[i]] % 2 == 0:
			res += 1
	else:
		counters[arr[i]] = 1
print(res)


N = int(input().strip())
C_hash = {}
pairs_n = 0
for c in map(int, input().split()):
	if C_hash.get(c):
		if C_hash[c]:
			C_hash[c] = 0
			pairs_n += 1
		else:
			C_hash[c] += 1
	else:
		C_hash[c] = 1
print(pairs_n)


n = int(input())
sock = input()
sock = sock.split()
new = list(sock)
fcou = 0
for x in range(0, n):
	count1 = new.count(sock[x])
	for y in range(0, count1):
		new.remove(sock[x])
	count2 = int(count1 / 2)
	fcou = count2 + fcou
print(fcou)


num_socks = int(input())
unmatched = set()
pairs = 0
for color in input().split():
	if color in unmatched:
		unmatched.remove(color)
		pairs += 1
	else:
		unmatched.add(color)
print(pairs)


import sys
a = int(input())
b = list(map(int, input().split()))
c = 0
x = []
for i in b:
	d = 0
	if i not in x:
		x.append(i)
		for j in b:
			if i == j:
				d += 1
	c += d // 2
print(c)


num = int(input())
lst = list(map(int, input().split()))
count = 0
buf = list()
for i in range(0, len(lst)):
	if buf.count(lst[i]) == 0:
		count = count + lst.count(lst[i]) // 2
		buf.append(lst[i])
print(count)


n = int(input().strip())
c = list(map(int, input().strip().split(' ')))
m = [0 for i in range(0, n)]
for i in range(0, n - 1):
	if m[i] == 0:
		for j in range(i + 1, n):
			if m[j] == 0:
				if c[i] == c[j]:
					(m[i], m[j]) = (1, 1)
					break
print(sum(m) // 2)


n = int(input())
l = list(map(int, input().split()))
ls = set(l)
ls = list(ls)
c = 0
su = 0
for i in range(len(ls)):
	c = l.count(ls[i])
	su = c // 2 + su
print(su)


n = int(input())
colors = map(int, input().split())
freqs = [0] * 101
for c in colors:
	freqs[c] += 1
print(sum((f // 2 for f in freqs)))


from collections import defaultdict
n = int(input())
nums = map(int, input().split())
d = defaultdict(int)
for num in nums:
	d[num] += 1
count = 0
for (_, v) in d.items():
	count += v // 2
print(count)


n = int(input())
s = set()
li = list(input().split())
cnt = 0
for i in li:
	if i in s:
		cnt = cnt + 1
		s.remove(i)
	else:
		s.add(i)
print(cnt)


number = input()
socks = input().strip().split()
result = 0
pair = 0
for x in set(socks):
	result += socks.count(x) // 2
print(result)


input()
l = list(map(int, input().split()))
d = {}
for e in l:
	if e not in d:
		d[e] = 0
	d[e] += 1
ans = 0
for e in d:
	ans += d[e] // 2
print(ans)


num = int(input())
socks = [int(i) for i in input().strip().split(' ')]
unq = set(socks)
total = 0
for i in unq:
	total += int(socks.count(i) / 2)
print(total)


t = int(input())
l = [int(s) for s in input().split()]
a = [0] * 110
for i in l:
	a[i] += 1
ans = 0
for i in a:
	ans += i // 2
print(ans)


n = int(input())
a = [int(x) for x in input().split(' ')]
a.sort()
count = 0
for i in range(n - 1):
	if a[i] == a[i + 1]:
		a[i + 1] = 0
		count = count + 1
		i = i + 1
print(count)


n = int(input())
socks = list(map(int, input().split()))
pairs = set()
count = 0
for i in socks:
	if i in pairs:
		count += 1
		pairs.remove(i)
	else:
		pairs.add(i)
print(count)


n = int(input())
if not n:
	print(0)
else:
	(ar, d) = ([int(i) for i in input().split()][0:n], {})
	for i in ar:
		d[i] = ar.count(i) // 2
	print(sum(d.values()))


n = int(input())
c = []
c[0:n] = map(int, input().split())
count = 0
for i in range(n):
	if c[i] is -1:
		continue
	for j in range(i + 1, n):
		if c[i] is c[j]:
			c[j] = -1
			count = count + 1
			break
print(count)


ar = [0] * 101
for i in (input(), map(int, input().split()))[1]:
	ar[i] += 1
print(sum((x >> 1 for x in ar)))


import sys
input = sys.stdin.readlines()[1].strip()
a_list = input.split()
pairs = 0
while len(a_list) > 0:
	current = a_list.pop()
	where = [i for (i, x) in enumerate(a_list) if x == current]
	pairs += int((len(where) + 1) / 2)
	for i in where:
		a_list.pop(a_list.index(current))
print(pairs)


n = int(input())
count = 0
c = list(map(int, input().split()))
a = [0] * max(c)
for i in range(0, n):
	a[c[i] - 1] += 1
for i in range(0, len(a)):
	if a[i] > 1:
		k = int(a[i] / 2)
		count = count + k
print(count)


n = int(input())
a = list(map(int, input().split()))
a.sort()
cnt = 0
prev = -1
i = 0
while i < len(a) - 1:
	if a[i] == a[i + 1]:
		cnt += 1
		i += 2
	else:
		i += 1
print(cnt)


import collections
n = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a)
cnt = 0
for key in a.keys():
	cnt = cnt + int(a[key] / 2)
print(cnt)


n = int(input())
arr = input().split()
arr = [int(i) for i in arr]
array = []
count = 0
for i in arr:
	if arr.count(i) > 1 and i not in array:
		count += arr.count(i) // 2
		array.append(i)
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
socks = {}
total = 0
for i in range(n):
	try:
		if socks[c[i]]:
			total += 1
			socks.pop(c[i])
	except KeyError:
		socks[c[i]] = 1
print(total)


from collections import Counter
n = int(input().strip())
socks = [int(arr_temp) for arr_temp in input().strip().split(' ')]
sumar = [x // 2 for x in Counter(socks).values() if x > 1]
print(sum(sumar))


n = int(input().strip())
c = [int(i) for i in input().strip().split()]
c.sort()
count = 0
i = 0
while i < len(c) - 1:
	if c[i] == c[i + 1]:
		count += 1
		i = i + 2
	else:
		i = i + 1
print(count)


count = int(input())
socks = input().split(' ')
for i in socks:
	i = int(i)
n = 0
for i in range(len(socks)):
	for j in range(i + 1, len(socks)):
		if socks[i] != 0 and socks[j] != 0:
			if socks[i] == socks[j]:
				socks[i] = 0
				socks[j] = 0
				n += 1
print(n)


import sys
from collections import defaultdict
n = int(input().strip())
socks = defaultdict(int)
socklist = list(map(int, input().split()))
for c in socklist:
	socks[c] += 1
ret = 0
for key in socks:
	ret += socks[key] // 2
print(ret)


n = int(input())
d = {}
for c in list(map(int, input().split())):
	if not c in d:
		d[c] = 0
	d[c] += 1
print(sum(map(lambda x: x // 2, [v for (u, v) in d.items()])))


def get_pairs(n, colours):
	colours = colours.split(' ')
	counted = []
	pairs = 0
	for i in colours:
		try:
			counted.index(i)
		except ValueError:
			counted.append(i)
			total = len([x for x in colours if x == i])
			pairs += (total - total % 2) / 2
	return int(pairs)
n = int(input(''))
c = input('')
print(get_pairs(n, c))


total = input()
F = [int(x) for x in input().split()]
freq = {}
for x in F:
	if x in freq.keys():
		freq[x] += 1
	else:
		freq[x] = 1
pairs = 0
for y in freq.keys():
	pairs += freq[y] // 2
print(pairs)


n = int(input())
socks = [int(x) for x in input().split()]
records = {}
for sock in socks:
	if sock not in records.keys():
		records[sock] = 1
	else:
		records[sock] += 1
count = 0
for x in records.keys():
	count += records[x] >> 1
print(count)


n = int(input())
c = [int(i) for i in input().split()]
count = 0
temp = list(set(c))
for i in temp:
	if c.count(i) % 2 == 0:
		count += c.count(i) // 2
	elif c.count(i) % 2 - 1 == 0:
		count += (c.count(i) - 1) // 2
print(count)


n = int(input())
a = [0 for i in range(100)]
c = input().split()
s = 0
for i in range(n):
	a[int(c[i]) - 1] += 1
for i in range(100):
	s += a[i] // 2
print(s)


import sys
n = int(input().strip())
colors = input().strip().split()
color_dict = {}
total_pairs = 0
for ind in range(n):
	color_dict[colors[ind]] = color_dict.get(colors[ind], 0) + 1
for ind in color_dict:
	total_pairs += color_dict[ind] // 2
print(total_pairs)


import sys
n = int(input().strip())
c = input().split()
c = [int(i) for i in c]
cn = 0
a = []
for i in c:
	if i in a:
		a.remove(i)
		cn += 1
	else:
		a.append(i)
print(cn)


import sys
import math
n = int(input().strip())
c = [int(i) for i in input().strip().split(' ')]
d = {}
for i in c:
	d[i] = d.get(i, 0) + 1
s = 0
for i in d:
	s = s + math.floor(d[i] / 2)
print(s)


from collections import Counter
import sys
n = int(input().strip())
c = list(input().strip().split())
s = set(c)
inp = Counter(c)
ans = 0
for key in s:
	ans += inp[key] // 2
print(ans)


from collections import Counter
import sys
n = int(input().strip())
c = [int(i) for i in input().strip().split()]
dict = Counter(c)
total = sum([v // 2 for v in dict.values()])
print(total)


ar = 1000 * [0]
n = int(input().strip())
c = list(map(int, input().split()))
for i in range(n):
	ar[c[i]] += 1
ans = 0
for i in range(len(ar)):
	ans += ar[i] // 2
print(ans)


n = input()
x = list(map(int, input().split()))
s = set(x)
s = list(s)
c = []
for i in range(len(s)):
	c.append(x.count(s[i]))
sums = 0
for i in range(len(c)):
	sums = sums + int(c[i] / 2)
print(sums)


import sys
n = int(input().strip())
c = [int(x) for x in input().split()]
c.sort()
(pairs, count) = (0, 1)
for i in range(n - 1):
	if c[i] == c[i + 1]:
		count += 1
	else:
		pairs += count // 2
		count = 1
if count != 1:
	pairs += count // 2
print(pairs)


from collections import Counter
N = int(input())
print(sum((v // 2 for v in Counter(input().split()).values())))


n = int(input().strip())
c = list(map(int, input().strip().split(' ')))
stocks = 0
d = {}
for i in range(len(c)):
	if c[i] in d:
		d[c[i]] += 1
	else:
		d[c[i]] = 1
for value in d.values():
	stocks += value // 2
print(stocks)


import sys
n = int(input().strip())
socks = {}
paired = 0
a_t = [int(a_temp) for a_temp in input().strip().split(' ')]
for a0 in range(n):
	c = a_t[a0]
	if c in socks:
		paired += 1
		del socks[c]
	else:
		socks[c] = None
print(paired)


import sys
n = int(input().strip())
c = list(map(int, input().strip().split()))[:n]
q = 2
d = {}
r = 0
for c in c:
	if not c in d:
		d[c] = 0
	d[c] += 1
	if d[c] == q:
		r += 1
		d[c] = 0
print(r)


import sys
from collections import Counter
total = 0
n = int(input().strip())
counts = Counter(input().strip().split(' '))
for item in counts.keys():
	total += counts[item] // 2
print(total)


import sys
C = {}
n = int(input().strip())
cs = [int(x) for x in input().strip().split(' ')]
for c in cs:
	C[c] = C.setdefault(c, 0) + 1
result = sum(map(lambda v: v // 2, C.values()))
print(result)


n = int(input())
a = [int(i) for i in input().split()]
b = []
c = []
for i in a:
	if i not in b:
		b.append(i)
		c.append(a.count(i) // 2)
print(sum(c))


n = int(input())
lst = [int(item) for item in input().split()]
cov = {}
c = 0
for i in range(n):
	if lst[i] in cov:
		cov.pop(lst[i])
		c += 1
	else:
		cov[lst[i]] = 0
print(c)


n = int(input())
l = input().split(' ')
a = 0
d = {x: l.count(x) for x in l}
for i in d.values():
	if i == 1:
		continue
	elif i % 2 == 0:
		a = a + i // 2
	else:
		q = i - 1
		a = a + q // 2
print(a)


n = int(input())
c = [int(i) for i in input().split(' ')]
cs = list(set(c))
pair = 0
for color in cs:
	pair += c.count(color) // 2
print(pair)


import sys
n = int(input().strip())
line = input().strip()
c = [int(s) for s in line.split(' ')]
freq = {}
pairs = 0
for i in c:
	if freq.get(i, None) is None:
		freq[i] = 1
	else:
		pairs += 1
		freq[i] = None
print(pairs)


import sys
n = int(sys.stdin.readline())
raw = sys.stdin.readline()
tab = []
x = ''
for i in raw:
	if i == ' ':
		tab.append(int(x))
		x = ''
	else:
		x += i
tab.append(int(x))
tab.sort()
ans = 0
pref = -1
for i in tab:
	if pref == i:
		ans += 1
		pref = -1
	else:
		pref = i
print(ans)


import sys
n = int(input().strip())
socks = [int(x) for x in input().strip().split(' ')]
count = 0
for (idx, x) in enumerate(socks):
	for (idy, y) in enumerate(socks):
		if x == y and idx < idy and (x != -1) and (y != -1):
			socks[idx] = socks[idy] = -1
			count += 1
			break
print(count)


import sys
n = int(input().strip())
a = list(map(int, input().split()))
d = dict()
for i in range(len(a)):
	if a[i] in d.keys():
		d[a[i]] += 1
	else:
		d[a[i]] = 1
tot = 0
for key in d.keys():
	tot += d[key] // 2
print(tot)


import sys
n = int(input().strip())
c = map(int, input().strip().split(' '))
s = {}
for x in c:
	s[x] = s.get(x, 0) + 1
d = 0
for (k, v) in s.items():
	d += int(v / 2)
print(d)