Codeforces Round #402 (Div. 2) A. Pupils Redistribution

来源:互联网 发布:larrycms 源码下载 编辑:程序博客网 时间:2024/05/17 05:07

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

In high school 0xFF there are two groups of pupils: the groupA and the group B. Each group consists of exactlyn students. An academic performance of each student is known — integer value between1 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 to1, the same number of students whose academic performance is2 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 classA 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 a1, a2, ..., an (1 ≤ ai ≤ 5), whereai is academic performance of thei-th student of the group A.

The third line contains sequence of integer numbers b1, b2, ..., bn (1 ≤ bi ≤ 5), wherebi is academic performance of thei-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

45 4 4 45 5 4 5

Output

1

Input

61 1 1 1 1 15 5 5 5 5 5

Output

3

Input

153

Output

-1

Input

93 2 5 5 2 3 3 3 24 1 4 1 1 2 4 4 1

Output

4


#include<stdio.h>#include<iostream>#include<algorithm>#include<map>#include<string.h>using namespace std;typedef long long ll;const int maxn=25000000+10;int a[110],b[110];int p1[10],p2[10];int abs(int f){    if(f<0)        return -f;    return f;}int main(){    int n,i,j;    while(~scanf("%d",&n))    {        memset(p1,0,sizeof(p1));        memset(p2,0,sizeof(p2));        int flag=0,sum=0;        for(i=0; i<n; i++)        {            scanf("%d",&a[i]);            p1[a[i]]++;        }        for(i=0; i<n; i++)        {            scanf("%d",&b[i]);            p2[b[i]]++;        }        for(i=1; i<=5; i++)        {            int m=p1[i]+p2[i];            if(m%2==1)            {                flag=1; break;            }        }        if(flag)        {            printf("-1\n"); continue;        }        for(i=1; i<=5; i++)        {            int m=(p1[i]+p2[i])/2;            sum+=abs(m-p1[i]);        }        printf("%d\n",sum>>1);    }    return 0;}



0 0
原创粉丝点击