Codeforces Round #402 (Div. 2) A+B

来源:互联网 发布:3d软件下载. 编辑:程序博客网 时间:2024/05/21 21:39

A. Pupils Redistribution

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

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 a1, a2, …, an (1 ≤ ai ≤ 5), where ai is academic performance of the i-th student of the group A.

The third line contains sequence of integer numbers b1, b2, …, bn (1 ≤ bi ≤ 5), where bi 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
题意:给出两个组学生成绩(1-5)。问至少交换多少次使得两个组的成绩完全相同(不是和!)。
题解:判断出现次数奇偶性即可。
代码:

#include<bits/stdc++.h>using namespace std;int m,n,x[6],y[6];int main(){    cin>>n;    for(int i=1;i<=n;i++)    {        cin>>m;        x[m]++;    }    for(int i=1;i<=n;i++)    {        cin>>m;        y[m]++;    }    for(int i=1;i<=5;i++)    {        if((x[i]+y[i])%2==1)            return 0*printf("-1\n");    }    int ans=0;    for(int i=1;i<=5;i++)    {        ans+=abs(x[i]-y[i])/2;    }    cout<<ans/2<<endl;}

B. Weird Rounding

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k.

In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000.

Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit).

It is guaranteed that the answer exists.

Input

The only line of the input contains two integer numbers n and k (0 ≤ n ≤ 2 000 000 000, 1 ≤ k ≤ 9).

It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros.

Output

Print w — the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0).

Examples

Input
30020 3

Output
1

Input
100 9

Output
2

Input
10203049 2

Output
3

Note

In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number
题意:给出一个数,问删去它多少位可以使它被10^kz整除。题目保证有有解。
题解:从后往前判断0个数,>=k跳出即可。没跳出说明只能留下一个0。
代码:

#include<bits/stdc++.h>using namespace std;string s;int k;int main(){    cin>>s>>k;    int ans,sum;    ans=sum=0;    for(int i=s.length()-1;i>=0;i--)    {        if(s[i]=='0')        {            ans++;            if(ans>=k) return 0*printf("%d\n",sum);        }        else            sum++;    }    return 0*printf("%d\n",s.length()-1);}
0 0
原创粉丝点击