Codeforces Round 407 (Div. 1)


A. Functions again
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
----------------------------------------------------------------------------------------------------
B. Weird journey
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
1 4
1 5
Output
6
Input
5 3
1 2
2 3
4 5
Output
0
Input
2 2
1 1
1 2
Output
1
----------------------------------------------------------------------------------------------------
C. The Great Mixing
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
400 4
100 300 450 500
Output
2
Input
50 2
100 25
Output
3
----------------------------------------------------------------------------------------------------
D. Finding lines
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
1
3
2
Output
0 1 2
0 -2 -2
0 5 6
0 -2 2
1 1 2
2
0 -3
----------------------------------------------------------------------------------------------------
E. New task
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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