In Berland each high school student is characterized by academic performance — integer value between 1 and 5.

In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 5.

The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.

To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class A and one student of class B. After that, they both change their groups.

Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.


-----Input-----

The first line of the input contains integer number n (1 ≤ n ≤ 100) — number of students in both groups.

The second line contains sequence of integer numbers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 5), where a_{i} is academic performance of the i-th student of the group A.

The third line contains sequence of integer numbers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 5), where b_{i} is academic performance of the i-th student of the group B.


-----Output-----

Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.


-----Examples-----
Input
4
5 4 4 4
5 5 4 5

Output
1

Input
6
1 1 1 1 1 1
5 5 5 5 5 5

Output
3

Input
1
5
3

Output
-1

Input
9
3 2 5 5 2 3 3 3 2
4 1 4 1 1 2 4 4 1

Output
4

Difficulty: interview

Starter code:

Solutions:
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0] * 5
b = [0] * 5
for j in range(n):
    a[A[j]-1] += 1
    b[B[j]-1] +=1
per = 0
for j in range(5):
    if (a[j] + b[j]) % 2 == 1:
        per = 1
        break
if per == 1:
    print(-1)
else:
    ans = 0
    for j in range(5):
        if a[j] > b[j]:
            ans += (a[j] - b[j])//2
    print(ans)

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=0
for i in range(1,6):
    x=a.count(i)
    y=b.count(i)
    if not (x+y)%2:s+=abs(x-y)//2
    else:print(-1);return()
print(s//2)



import sys
n = int(input())
g1 = list(map(int, input().split()))
g2 = list(map(int, input().split()))
ans = 0
for i in range(1, 6):
    n1 = g1.count(i)
    n2 = g2.count(i)
    if abs(n1 - n2) % 2 != 0:
        print(-1)
        return
    ans += abs(n1 -n2)//2
print(ans//2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0 for i in range(5)]
bb = [0 for i in range(5)]
cc = [0 for i in range(5)]
for i in range(n):
    aa[a[i] - 1] += 1
    cc[a[i] - 1] += 1
for i in range(n):
    bb[b[i] - 1] += 1
    cc[b[i] - 1] += 1
f = True
for i in range(5):
    if cc[i] % 2 != 0:
        f = False
        break
    else:
        cc[i] //= 2
if not f:
    print(-1)
else:
    o = 0
    for i in range(5):
        o += abs(cc[i] - aa[i])
    print(o // 2)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    count = [0] * 5
    balance = [0] * 5

    for e in a:
        count[e - 1] += 1
        balance[e - 1] += 1
    for e in b:
        count[e - 1] += 1
        balance[e - 1] -= 1

    for e in count:
        if e % 2 != 0:
            print(-1)
            return
    print(sum([abs(i) for i in balance]) // 4)


def __starting_point():
    main()
__starting_point()

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = [0] * 5
for elem in A:
    cnt[elem - 1] += 1
for elem in B:
    cnt[elem - 1] += 1
bad = 0
for elem in cnt:
    bad += elem % 2
if bad != 0:
    print(-1)
else:
    cntA = [0] * 5
    cntB = [0] * 5
    for elem in A:
        cntA[elem - 1] += 1
    for elem in B:
        cntB[elem - 1] += 1
    ans = 0
    for i in range(5):
        ans += abs(cntA[i] - cntB[i]) // 2
    print(ans // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ax = [0, 0, 0, 0, 0, 0]
bx = [0, 0, 0, 0, 0, 0]
for i in range(n):
    ax[a[i]] += 1
    bx[b[i]] += 1
ans = 0
for i in range(6):
    if (ax[i] + bx[i]) % 2 == 1:
        ans = -1
        break
    else:
        ans += abs((ax[i] - bx[i]) // 2)
print(ans // 2)

from sys import stdin
from collections import defaultdict

n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a_d = defaultdict(int)
b_d = defaultdict(int)
for i in range(n):
    a_d[a[i]] += 1
    b_d[b[i]] += 1
f = True
ans = 0
for i in range(6):
    if (a_d[i] + b_d[i]) % 2:
        f = False
        break
    ans += abs(a_d[i] - b_d[i])
if f:
    print(ans//4)
else:
    print(-1)

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = [0] * 6
b1 = [0] * 6
for i in a:
    a1[i] += 1
for i in b:
    b1[i] += 1
ans = 0
for i in range(1, 6):
    if (a1[i] + b1[i]) % 2 != 0:
        ans = -1
        break
    ans += (max(a1[i], b1[i]) - min(a1[i], b1[i])) // 2
if ans == -1:
    print(-1)
else:
    print(ans // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
q = [0] * 6

for i in a:
    q[i] += 1
for i in b:
    q[i] += 1

f = True
for i in q:
    if i % 2 != 0:
        f = False
if not f:
    print(-1)
else:
    for i in range(6):
        q[i] //= 2
    aa = [0] * 6
    bb = [0] * 6
    for i in a:
        aa[i] += 1
    for i in b:
        bb[i] += 1
    ans = 0
    for i in range(6):
        ans += abs(q[i] - aa[i])
    print(ans // 2)



from collections import Counter

bad = False

n = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

counts_a = Counter(A)
counts_b = Counter(B)
counts_total = Counter(A+B)

swaps = 0

for i in range(1,6):
    if counts_total[i] % 2 != 0:
        bad = True

    swaps += max(counts_a[i], counts_b[i]) - counts_total[i]//2

if bad:
    print(-1)
else:
    print(swaps//2)


#CF402
n=int(input())
a=list(sorted(map(int,input().split())))
b=list(sorted(map(int,input().split())))
s=[]
ei=0
for i in range(5):
    t=[a.count(i+1),b.count(i+1)]
    s.append(t[0]-t[1])
    if sum(t)%2==1:ei=1
if bool(ei):print(-1)
else:print(int(sum([x for x in s if x>0])/2))


n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if (a.count(1)+b.count(1))%2!=0 or (a.count(2)+b.count(2))%2!=0 or (a.count(3)+b.count(3))%2!=0 or (a.count(4)+b.count(4))%2!=0 or (a.count(5)+b.count(5))%2!=0:
    print(-1)
else:
    k=0
    k+=abs(a.count(1)-b.count(1))//2
    k+=abs(a.count(2)-b.count(2))//2
    k+=abs(a.count(3)-b.count(3))//2
    k+=abs(a.count(4)-b.count(4))//2
    k+=abs(a.count(5)-b.count(5))//2
    print(k//2)

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

c = [0,0,0,0,0]
d = [0,0,0,0,0]
for x in range(0,n):
	c[a[x]-1] = c[a[x]-1] + 1
	d[b[x]-1] = d[b[x]-1] + 1

def dingle():
	for x in range(0,5):
		if (c[x] + d[x])%2 != 0:
			return -1

	f = 0
	for x in range(0,5):
		f = f + abs((c[x]-d[x])//2)
	return(f//2)

print(dingle())


from sys import stdin, stdout

n = int(stdin.readline())

A = stdin.readline().rstrip().split()
A = [int(num) for num in A]

B = stdin.readline().rstrip().split()
B = [int(num) for num in B]

possible=True
totSwaps=0
for i in range(1,6):
    if (A.count(i)+B.count(i))%2==0:
        totSwaps+=int((A.count(i)+B.count(i))/2)-min([A.count(i),B.count(i)])
    else:
        possible=False
        break
        
if not possible:
    print(-1)
else:
    print(int(totSwaps/2))
    



n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = [0, 0, 0, 0, 0]
cb = [0, 0, 0, 0, 0]

for i in a:
    ca[i - 1] += 1

for i in b:
    cb[i - 1] += 1

c = 0
for i in range(5):
    if (ca[i] + cb[i]) % 2 == 0:
        c += (max(ca[i], cb[i]) - min(ca[i], cb[i])) // 2
    else:
        print(-1)
        return
print(c//2)


from collections import defaultdict

n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

q = defaultdict(int)
w = defaultdict(int)
e = defaultdict(int)

for a in aa:
    q[a] += 1
    e[a] += 1

for b in bb:
    w[b] += 1
    e[b] += 1

ans = 0
for i in range(1, 6):
    if e[i] % 2 != 0:
        ans = -1
        break
    ans += abs(q[i] - (e[i] // 2))

print(ans // 2)


from sys import stdin, stdout


n = int(stdin.readline())
first = list(map(int, stdin.readline().split()))
second = list(map(int, stdin.readline().split()))
cntf = [0, 0, 0, 0, 0]
cnts = [0, 0, 0, 0, 0]

for i in range(n):
    cntf[first[i] - 1] += 1
    cnts[second[i] - 1] += 1

label = 1
for i in range(5):
    if (cntf[i] + cnts[i]) % 2:
        label = 0


if not label:
    stdout.write('-1')
else:
    ans = 0
    for i in range(5):
        m = (cntf[i] + cnts[i]) // 2
        ans += max(cntf[i] - m, 0)
    
    stdout.write(str(ans))

import math, sys
def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a5 = 0
	a4 = 0
	a3 = 0
	a2 = 0
	a1 = 0
	b5 = 0
	b4 = 0
	b3 = 0
	b2 = 0
	b1 = 0
	ans = 0
	for i in a:
		if i==5:
			a5+=1
		if i==4:
			a4+=1
		if i==3:
			a3+=1
		if i==2:
			a2+=1
		if i==1:
			a1+=1
	for i in b:
		if i==5:
			b5+=1
		if i==4:
			b4+=1
		if i==3:
			b3+=1
		if i==2:
			b2+=1
		if i==1:
			b1+=1
	if (a5+b5)%2==0 and (a4+b4)%2==0 and (a3+b3)%2==0 and (a2+b2)%2==0 and (a1+b1)%2==0:
		ans += max(a5,b5) - (a5+b5)//2
		ans += max(a4,b4) - (a4+b4)//2
		ans += max(a3,b3) - (a3+b3)//2
		ans += max(a2,b2) - (a2+b2)//2
		ans += max(a1,b1) - (a1+b1)//2 
		print(ans//2)
		return
	
	print(-1)
def __starting_point():
	main()

__starting_point()

n = int(input())
A = list(map(int, input().split()))
a = [0] * 6
B = list(map(int, input().split()))
b = [0] * 6
for i in A:
    if i == 1:
        a[1] += 1
    if i == 2:
        a[2] += 1
    if i == 3:
        a[3] += 1    
    if i == 4:
        a[4] += 1
    if i == 5:
        a[5] += 1 
for i in B:
    if i == 1:
        b[1] += 1
    if i == 2:
        b[2] += 1
    if i == 3:
        b[3] += 1    
    if i == 4:
        b[4] += 1
    if i == 5:
        b[5] += 1

ans = 0
f = True
for i in range(1, 6):
    if (a[i] + b[i]) % 2 == 1:
        f = False
if f:
    for i in range(1, 6):
        ans += abs(a[i] - (a[i] + b[i]) // 2)
if f:
    print(ans // 2)
else:
    print(-1)

from collections import Counter


N = int(input())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))

a = Counter(A)
b = Counter(B)

cnt = 0
aa = 0
bb = 0
flag = False
for i in range(1,6):
    diff = a[i]-b[i]
    if diff % 2 == 1:
        flag = True
        break
    if diff > 0:
        aa += diff // 2
    else:
        bb += -diff // 2

if flag:
    print(-1)
else:
    if (aa == bb):
        print(aa)
    else:
        print(-1)



def f():
    n=int(input())
    a=[0]*5
    b=[0]*5

    X = [int(x) for x in input().split()]
    for x in X:
        a[x-1]+=1

    X = [int(x) for x in input().split()]
    for x in X:
        b[x-1]+=1

    for i in range(5):
        if (a[i]+b[i])%2==1:
            print('-1')
            return

    x=0
    for i in range(5):
        x += abs(a[i]-b[i])/2

    print(int(x/2))

f()


def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def check(li1, li2):
    result = 0
    for i in range(5):
        result += ((max(li1[i],li2[i])-min(li1[i],li2[i]))/2)
        if (li1[i]+li2[i])%2 != 0:
            print(-1)
            return
    print(int(result/2))
    return


li1 = [0, 0, 0, 0, 0]
li2 = [0, 0, 0, 0, 0]
n = II()

ll1 = LI()
ll2 = LI()
for i in range(n):
    li1[ll1[i]-1] += 1
    li2[ll2[i]-1] += 1
# print(li1, li2)

check(li1, li2)



n = int(input())

A = [0]*5
B = [0]*5

for a in map(int, input().split()):
    A[a - 1] += 1

for a in map(int, input().split()):
    B[a - 1] += 1


if any([(x + y) % 2 != 0 for x, y in zip(A, B)]):
    print(-1)
else:
    print(sum([abs(x - y) // 2 for x, y in zip(A, B)]) // 2)



from collections import Counter

n = int(input().strip())
ca = Counter([int(x) for x in input().strip().split(' ')])
cb = Counter([int(x) for x in input().strip().split(' ')])
cnt = 0

for i in range(1, 6):
    if (ca[i] + cb[i]) % 2 != 0:
        print(-1)
        return
    else:
        cnt += abs(ca[i] - (ca[i] + cb[i]) / 2)
print(int(cnt/2))