Codeforces Round 896 (Div. 1)


A. Fill in the Matrix
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 3
1 16
6 6
2 1
Output
3
1 0 2
0 2 1
1 0 2
0 2 1
2
14 7 15 4 10 0 8 6 1 2 3 5 9 11 12 13 
6
3 0 1 4 2 5 
5 2 1 0 4 3 
1 3 2 4 5 0 
4 1 3 2 5 0 
4 2 5 3 0 1 
2 4 0 5 1 3
0
0
0
----------------------------------------------------------------------------------------------------
B1. Candy Party (Easy Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
3
2 4 3
5
1 2 3 4 5
6
1 4 7 1 5 4
2
20092043 20092043
12
9 9 8 2 4 4 3 5 1 1 1 1
6
2 12 7 16 11 12
Output
Yes
Yes
No
Yes
No
No
----------------------------------------------------------------------------------------------------
B2. Candy Party (Hard Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
3
2 4 3
5
1 2 3 4 5
6
1 4 7 1 5 4
2
20092043 20092043
12
9 9 8 2 4 4 3 5 1 1 1 1
6
2 12 7 16 11 12
Output
Yes
Yes
No
Yes
No
Yes
----------------------------------------------------------------------------------------------------
C. Travel Plan
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
3 1
2 2
10 9
43 20
154 147
Output
6
19
583217643
68816635
714002110
----------------------------------------------------------------------------------------------------
D. Flower-like Pseudotree
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
3
2 2 2
4
1 2 3 4
7
4 3 3 1 1 1 1
6
1 1 2 2 3 3
10
1 1 5 2 1 1 1 1 1 6
9
1 1 3 1 1 4 1 1 5
Output
Yes
1 2
2 3
3 1
No
Yes
1 2
2 3
3 1
1 4
1 5
2 6
3 7
Yes
5 6
6 5
1 3
2 4
3 5
4 6
No
Yes
3 6
6 9
9 3
1 3
2 6
4 6
5 9
7 9
8 9
----------------------------------------------------------------------------------------------------
E. Min-Sum-Max
time limit per test: 5 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
8
3
-1 5 4
2
2023 2043
6
1 4 7 -1 5 -4
5
-4 0 3 -18 10
1
998244853
10
-4 2 5 -10 4 8 2 9 -15 7
7
-7 3 8 -9 -2 2 4
4
-5 5 -2 -5
Output
2
1
3
2
1
6
5
3
----------------------------------------------------------------------------------------------------
F. LIS?
time limit per test: 5 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 3 4 5
Output
6
Input
6
-1 -5 -4 -1 -4 -7
Output
0
Input
11
0 1000000 1 -50000 2 998353 3 -100007 4 200943 0
Output
1936973
----------------------------------------------------------------------------------------------------
