# Task
 You have two sorted arrays `a` and `b`, merge them to form new array of unique items.

 If an item is present in both arrays, it should be part of the resulting array if and only if it appears in both arrays the same number of times.

# Example

  For `a = [1, 3, 40, 40, 50, 60, 60, 60]` and `b = [2, 40, 40, 50, 50, 65]`, the result should be `[1, 2, 3, 40, 60, 65]`.
```
Number 40 appears 2 times in both arrays, 
thus it is in the resulting array.
Number 50 appears once in array a and twice in array b, 
therefore it is not part of the resulting array.```

# Input/Output


 - `[input]` integer array `a`

 A sorted array.
 
 1 ≤ a.length ≤ 500000
 
 
 - `[input]` integer array `b`

 A sorted array.
 
 `1 ≤ b.length ≤ 500000`
 

- `[output]` an integer array

  The resulting sorted array.

Source: codewars | Difficulty: EASY

Starter code: def merge_arrays(a, b):
	

Solutions:
def merge_arrays(a, b):
	out = []
	for n in a + b:
		if n in a and n in b:
			if a.count(n) == b.count(n):
				out.append(n)
		else:
			out.append(n)
	return sorted(set(out))


from collections import Counter

def merge_arrays(a, b):
	(ca, cb) = (Counter(a), Counter(b))
	return [k for k in sorted(ca.keys() | cb.keys()) if (k in ca) + (k in cb) == 1 or ca[k] == cb[k]]


merge_arrays = lambda a, b: sorted([x for x in set(a + b) if a.count(x) == b.count(x) or a.count(x) * b.count(x) == 0])


def merge_arrays(a, b):
	return sorted((n for n in set(a + b) if (n in a) != (n in b) or a.count(n) == b.count(n)))


def merge_arrays(a, b):
	list = []
	for i in a + b:
		if (a.count(i) == b.count(i) or b.count(i) == 0 or a.count(i) == 0) and i not in list:
			list.append(i)
	return sorted(list)


def merge_arrays(a, b):
	result = []
	currA = 0
	currB = 0
	while currA < len(a) and currB < len(b):
		if a[currA] < b[currB]:
			if not result or result[-1] != a[currA]:
				result.append(a[currA])
			currA += 1
		elif b[currB] < a[currA]:
			if not result or result[-1] != b[currB]:
				result.append(b[currB])
			currB += 1
		else:
			val = a[currA]
			countA = 0
			while currA < len(a):
				if a[currA] == val:
					countA += 1
					currA += 1
				else:
					break
			countB = 0
			while currB < len(b):
				if b[currB] == val:
					countB += 1
					currB += 1
				else:
					break
			if countA == countB:
				result.append(val)
	while currA < len(a):
		if not result or result[-1] != a[currA]:
			result.append(a[currA])
		currA += 1
	while currB < len(b):
		if not result or result[-1] != b[currB]:
			result.append(b[currB])
		currB += 1
	return result


from collections import Counter

def merge_arrays(a, b):
	(C1, C2) = (Counter(a), Counter(b))
	return sorted(C1.keys() ^ C2.keys() | {k for k in C1.keys() & C2.keys() if C1[k] == C2[k]})


from collections import Counter

def merge_arrays(a, b):
	c = Counter(a)
	d = Counter(b)
	return sorted((x for x in set(a) | set(b) if c[x] == d[x] or not c[x] or (not d[x])))


from collections import Counter

def merge_arrays(a, b):
	li = set()
	(c1, c2) = (Counter(a), Counter(b))
	for i in set(a + b):
		if i in c1 and i in c2:
			if c1[i] == c2[i]:
				li.add(i)
		else:
			li.add(i)
	return sorted(li)


from collections import Counter

def merge_arrays(a, b):
	ca = Counter(a)
	cb = Counter(b)
	return [x for x in sorted(set(ca).union(cb)) if ca[x] == cb[x] or ca[x] * cb[x] == 0]