Codeforces Round 789 (Div. 1)


A. Tokitsukaze and Strange Inequality
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
6
5 3 6 1 4 2
4
1 2 3 4
10
5 1 6 2 8 3 4 10 9 7
Output
3
0
28
----------------------------------------------------------------------------------------------------
B. Tokitsukaze and Meeting
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 2
1100
4 2
11001101
2 4
11001101
Output
2 3 4 3
2 3 4 3 5 4 6 5
2 3 3 3 4 4 4 5
----------------------------------------------------------------------------------------------------
C. Tokitsukaze and Two Colorful Tapes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
6
1 5 4 3 2 6
5 3 1 4 6 2
6
3 5 4 6 2 1
3 6 4 5 2 1
1
1
1
Output
18
10
0
----------------------------------------------------------------------------------------------------
D. Tokitsukaze and Permutations
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5 0
0 1 2 3 4
5 2
-1 1 2 0 0
5 2
0 1 1 0 0
Output
1
6
6
----------------------------------------------------------------------------------------------------
E. Tokitsukaze and Beautiful Subsegments
time limit per test: 4 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
8 3
1 3 5 2 4 7 6 8
1 3
1 1
1 8
Output
2
0
10
Input
10 10
6 1 3 2 5 8 4 10 7 9
1 8
1 10
1 2
1 4
2 4
5 8
4 10
4 7
8 10
5 9
Output
17
25
1
5
2
0
4
1
0
0
----------------------------------------------------------------------------------------------------
F. Tokitsukaze and Gems
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 2 2
1 1 1 2 2
Output
6428
Input
6 2 2
2 2 2 2 2 3
Output
338940
----------------------------------------------------------------------------------------------------
