779A.md (2223B)
1 Source: https://codeforces.com/problemset/problem/779/A 2 3 A. Pupils Redistribution 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 In Berland each high school student is characterized by academic performance — integer value between 1 and 5. 22 23 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. 24 25 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. 26 27 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. 28 29 Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance. 30 31 Input 32 33 The first line of the input contains integer number *n* (1 ≤ *n* ≤ 100) — number of students in both groups. 34 35 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*. 36 37 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*. 38 39 Output 40 41 Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. 42 43 Examples 44 45 Input 46 47 ``` 48 4 49 5 4 4 4 50 5 5 4 5 51 ``` 52 53 Output 54 55 ``` 56 1 57 ``` 58 59 Input 60 61 ``` 62 6 63 1 1 1 1 1 1 64 5 5 5 5 5 5 65 ``` 66 67 Output 68 69 ``` 70 3 71 ``` 72 73 Input 74 75 ``` 76 1 77 5 78 3 79 ``` 80 81 Output 82 83 ``` 84 -1 85 ``` 86 87 Input 88 89 ``` 90 9 91 3 2 5 5 2 3 3 3 2 92 4 1 4 1 1 2 4 4 1 93 ``` 94 95 Output 96 97 ``` 98 4 99 ```