Codeforces Round 462 (Div. 2)


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

Examples
Input
2 2
20 18
2 14
Output
252
Input
5 3
-1 0 1 2 3
-1 0 1
Output
2
----------------------------------------------------------------------------------------------------
B. A Prosperous Lot
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
Output
462
Input
6
Output
8080
----------------------------------------------------------------------------------------------------
C. A Twisty Movement
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2 1 2
Output
4
Input
10
1 1 2 2 2 1 1 2 2 1
Output
9
----------------------------------------------------------------------------------------------------
D. A Determined Cleanup
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
46 2
Output
7
0 1 0 0 1 1 1
Input
2018 214
Output
3
92 205 1
----------------------------------------------------------------------------------------------------
E. A Colourful Prospect
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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