Codeforces Round 263 (Div. 1)


A. Appleman and Toastman
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 1 5
Output
26
Input
1
10
Output
10
----------------------------------------------------------------------------------------------------
B. Appleman and Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
0 0
0 1 1
Output
2
Input
6
0 1 1 0 4
1 1 0 0 1 0
Output
1
Input
10
0 1 2 1 4 4 4 0 8
0 0 0 1 0 1 1 0 0 1
Output
27
----------------------------------------------------------------------------------------------------
C. Appleman and a Sheet of Paper
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 4
1 3
1 2
2 0 1
2 1 2
Output
4
3
Input
10 9
2 2 9
1 1
2 0 1
1 8
2 0 8
1 2
2 1 3
1 4
2 2 4
Output
7
2
10
4
5
----------------------------------------------------------------------------------------------------
D. Appleman and Complicated Task
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 1 x
2 2 o
Output
2
Input
4 3
2 4 x
3 4 x
3 2 x
Output
2
----------------------------------------------------------------------------------------------------
E. Appleman and a Game
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
ABCCAD
Output
5
Input
5
AAABACADBABBBCBDCACBCCCDDDBDCDD
Output
4
----------------------------------------------------------------------------------------------------
