Codeforces Round 601 (Div. 1)


A. Feeding Chicken
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
----------------------------------------------------------------------------------------------------
B1. Send Boxes to Alice (Easy Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 0 1
Output
2
Input
1
1
Output
-1
----------------------------------------------------------------------------------------------------
B2. Send Boxes to Alice (Hard Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4 8 5
Output
9
Input
5
3 10 2 1 5
Output
2
Input
4
0 5 15 10
Output
0
Input
1
1
Output
-1
----------------------------------------------------------------------------------------------------
C. Point Ordering
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
15
-1
1
Output
1 1 4 6
2 1 5 6
2 2 1 4
0 1 3 4 2 6 5
----------------------------------------------------------------------------------------------------
D. Tree Queries
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 12
1 2
1 3
2 4
2 5
1 1 1
2 1
2 2
2 3
2 4
2 5
1 2 2
2 1
2 2
2 3
2 4
2 5
Output
1
199648871
399297742
199648871
199648871
598946614
199648873
2
2
2
----------------------------------------------------------------------------------------------------
E. Send Tree to Charlie
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
3 4
2 4
4 1
0 4 0 0
Output
2
Input
5
1 2
2 4
3 4
5 4
0 0 0 0 0
Output
12
Input
3
1 2
1 3
1 0 0
Output
0
----------------------------------------------------------------------------------------------------
