Codeforces Round 243 (Div. 1)


A. Sereja and Swaps
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 2
10 -1 2 2 2 2 2 2 -1 10
Output
32
Input
5 10
-1 -1 -1 -1 -1
Output
-1
----------------------------------------------------------------------------------------------------
B. Sereja and Table
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5 2
1 1 1 1 1
1 1 1 1 1
1 1 0 1 1
1 1 1 1 1
1 1 1 1 1
Output
1
Input
3 4 1
1 0 0 0
0 1 1 1
1 1 1 0
Output
-1
Input
3 4 1
1 0 0 1
0 1 1 0
1 0 0 1
Output
0
----------------------------------------------------------------------------------------------------
C. Sereja and Two Sequences
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 5 100000 1000
1 2 3 4 5
3 2 4 5 1
Output
3
Input
3 4 3006 1000
1 2 3
1 2 4 3
Output
2
----------------------------------------------------------------------------------------------------
D. Sereja and Squares
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1
Input
9
0 0
1 1
2 2
0 1
1 0
0 2
2 0
1 2
2 1
Output
5
----------------------------------------------------------------------------------------------------
E. Sereja and Sets
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
Output
23
Input
3 2
Output
32
Input
2 0
Output
1
Input
2 2
Output
2
----------------------------------------------------------------------------------------------------
