Educational Codeforces Round 165 (Rated for Div. 2)


A. Two Friends
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5
3 1 2 5 4
4
2 3 4 1
2
2 1
Output
2
3
2
----------------------------------------------------------------------------------------------------
B. Shifts and Sorting
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
10
0000
11000
101011
01101001
Output
2
0
9
5
11
----------------------------------------------------------------------------------------------------
C. Minimizing the Sum
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 1
3 1 2
1 3
5
4 2
2 2 1 3
6 3
4 1 2 2 4 3
Output
4
5
5
10
----------------------------------------------------------------------------------------------------
D. Shop Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 0
2 1
1 2
4 1
1 2 1 4
3 3 2 3
4 2
2 1 1 1
4 2 3 2
6 2
1 3 4 9 1 3
7 6 8 10 6 8
Output
1
1
0
7
----------------------------------------------------------------------------------------------------
E. Unique Array
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
2 1 2
4
4 4 4 4
5
3 1 2 1 2
5
1 3 2 1 2
Output
0
2
1
0
----------------------------------------------------------------------------------------------------
F. Card Pairing
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 2 1 2
Output
0
Input
8 2
2 1 2 2 1 2 1 2
Output
1
Input
4 4
1 2 1 2
Output
2
Input
6 4
3 2 3 1 2 1
Output
3
Input
6 4
3 2 3 3 2 1
Output
2
Input
18 6
5 6 1 1 6 5 4 1 5 1 1 6 2 6 2 2 6 3
Output
6
Input
8 4
1 2 3 4 4 3 1 2
Output
2
Input
8 4
1 2 3 4 4 3 3 2
Output
3
----------------------------------------------------------------------------------------------------
