Codeforces Round 285 (Div. 1)


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

Examples
Input
3
2 3
1 0
1 0
Output
2
1 0
2 0
Input
2
1 1
1 0
Output
1
0 1
----------------------------------------------------------------------------------------------------
B. Misha and Permutations Summation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
0 1
0 1
Output
0 1
Input
2
0 1
1 0
Output
1 0
Input
3
1 2 0
2 1 0
Output
1 0 2
----------------------------------------------------------------------------------------------------
C. Misha and Palindrome Degree
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 2 2
Output
6
Input
6
3 6 5 3 3 5
Output
0
Input
5
5 5 2 5 2
Output
4
----------------------------------------------------------------------------------------------------
D. Misha and XOR
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
7
6
5
4
3
2
1
Output
0
0
0
3 0 1 2
2 1 2
2 0 2
2 0 1
Input
2
5
5
Output
0
1 0
----------------------------------------------------------------------------------------------------
E. Misha and LCP on Tree
time limit per test: 8 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
bbbabb
2 1
3 2
4 3
5 2
6 5
6
2 5 3 1
1 5 2 3
5 6 5 6
6 3 4 1
6 2 3 4
2 2 4 5
Output
2
2
2
0
1
0
----------------------------------------------------------------------------------------------------
