Codeforces Round 169 (Div. 2)


A. Lunch Rush
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 5
3 3
4 5
Output
4
Input
4 6
5 8
3 6
2 3
2 2
Output
3
Input
1 5
1 7
Output
-1
----------------------------------------------------------------------------------------------------
B. Little Girl and Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
aba
Output
First
Input
abca
Output
Second
----------------------------------------------------------------------------------------------------
C. Little Girl and Maximum Sum
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
5 3 2
1 2
2 3
1 3
Output
25
Input
5 3
5 2 4 1 3
1 5
2 3
2 3
Output
33
----------------------------------------------------------------------------------------------------
D. Little Girl and Maximum XOR
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 2
Output
3
Input
8 16
Output
31
Input
1 1
Output
0
----------------------------------------------------------------------------------------------------
E. Little Girl and Problem on Trees
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 6
1 2
1 3
0 3 1 2
0 2 3 1
0 1 5 2
1 1
1 2
1 3
Output
9
9
6
Input
6 11
1 2
2 5
5 4
1 6
1 3
0 3 1 3
0 3 4 5
0 2 1 4
0 1 5 5
0 4 6 2
1 1
1 2
1 3
1 4
1 5
1 6
Output
11
17
11
16
17
11
----------------------------------------------------------------------------------------------------
