Codeforces Round 155 (Div. 2)


A. Cards with Numbers
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
3
20 30 10 30 20 10
Output
4 2
1 5
6 3
Input
1
1 2
Output
-1
----------------------------------------------------------------------------------------------------
B. Jury Size
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
2
5 23 1 2
3 13 2 3
Output
2
Input
3
12 9 2 1
12 8 1 3
12 8 2 2
Output
3
Input
1
1 10 1 13
Output
1
----------------------------------------------------------------------------------------------------
C. Anagram
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
ABA
CBA
Output
1
ABC
Input
CDBABC
ADCABD
Output
2
ADBADC
----------------------------------------------------------------------------------------------------
D. Rats
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
4 4 1
XXXX
XR.X
X.RX
XXXX
Output
2 2 2 3
Input
9 14 5
XXXXXXXXXXXXXX
X....R...R...X
X..R.........X
X....RXR..R..X
X..R...X.....X
XR.R...X.....X
X....XXR.....X
X....R..R.R..X
XXXXXXXXXXXXXX
Output
2 3 6 9
Input
7 7 1
XXXXXXX
X.R.R.X
X.....X
X..X..X
X..R..X
X....RX
XXXXXXX
Output
-1
----------------------------------------------------------------------------------------------------
E. Dormitory
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
4 1
3 2 5 4
3
1 3 2
1 4 1
3 4 2
Output
7
1 2
1 2
3 2 1 3
2 2 3
----------------------------------------------------------------------------------------------------
