Codeforces Round 381 (Div. 2)


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

Examples
Input
1 1 3 4
Output
3
Input
6 2 1 1
Output
1
Input
4 4 4 4
Output
0
Input
999999999 1000000000 1000000000 1000000000
Output
1000000000
----------------------------------------------------------------------------------------------------
B. Alyona and flowers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
1 -2 1 3 -4
1 2
4 5
3 4
1 4
Output
7
Input
4 3
1 2 3 4
1 3
2 4
1 1
Output
16
Input
2 2
-1 -2
1 1
1 2
Output
0
----------------------------------------------------------------------------------------------------
C. Alyona and mex
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
----------------------------------------------------------------------------------------------------
D. Alyona and a tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 5 1 4 6
1 7
1 1
3 5
3 6
Output
1 0 1 0 0
Input
5
9 7 8 6 5
1 1
2 1
3 1
4 1
Output
4 3 2 1 0
----------------------------------------------------------------------------------------------------
E. Alyona and towers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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