Educational Codeforces Round 36 (Rated for Div. 2)


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

Examples
Input
3 6
2 3 5
Output
2
Input
6 7
1 2 3 4 5 6
Output
7
----------------------------------------------------------------------------------------------------
B. Browser
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 3 2 4
Output
5
Input
6 3 1 3
Output
1
Input
5 2 1 5
Output
0
----------------------------------------------------------------------------------------------------
C. Permute Digits
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
----------------------------------------------------------------------------------------------------
D. Almost Acyclic Graph
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
1 2
2 3
3 2
3 1
Output
YES
Input
5 6
1 2
2 3
3 2
3 1
2 1
4 5
Output
NO
----------------------------------------------------------------------------------------------------
E. Physical Education Lessons
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
6
1 2 1
3 4 1
2 3 2
1 3 2
2 4 1
1 4 2
Output
2
0
2
3
1
4
----------------------------------------------------------------------------------------------------
F. Imbalance Value of a Tree
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 2 3 1
1 2
1 3
1 4
Output
6
----------------------------------------------------------------------------------------------------
G. Coprime Arrays
time limit per test: 3.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
Output
82
Input
2000000 8
Output
339310063
----------------------------------------------------------------------------------------------------
