Codeforces Round 775 (Div. 1, based on Moscow Open Olympiad in Informatics)


A. Weird Sum
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
1 2 3
3 2 1
Output
7
Input
3 4
1 1 2 2
2 1 1 2
2 2 1 1
Output
76
Input
4 4
1 1 2 3
2 1 1 2
3 1 2 1
1 1 2 1
Output
129
----------------------------------------------------------------------------------------------------
B. Integral Array
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
3 5
1 2 5
4 10
1 3 3 7
1 2
2
1 1
1
Output
Yes
No
No
Yes
Input
1
1 1000000
1000000
Output
No
----------------------------------------------------------------------------------------------------
C. Tyler and Strings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
1 2 2
2 1 2 1
Output
2
Input
4 4
1 2 3 4
4 3 2 1
Output
23
Input
4 3
1 1 1 2
1 1 2
Output
1
----------------------------------------------------------------------------------------------------
D. Serious Business
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 3
1 0 2 -1
-3 1 9 2
3 2 4 1
1 2 5
2 3 4
1 4 14
Output
13
Input
5 4
-20 -10 -11 -10 1
1 3 3 6 3
14 -20 3 6 2
1 5 13
1 2 2
3 5 3
2 3 1
Output
-4
----------------------------------------------------------------------------------------------------
E. Air Reform
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
4 3
1 2 1
2 3 2
4 3 3
5 5
1 2 1
1 3 1
2 4 1
4 5 2
5 1 3
6 6
1 2 3
2 3 1
3 6 5
3 4 2
4 5 4
2 4 2
Output
3 3 3 
1 1 1 2 2 
4 4 5 3 4 4 
----------------------------------------------------------------------------------------------------
F. Two Avenues
time limit per test: 8 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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