Codeforces Round 462 (Div. 1)


A. 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
----------------------------------------------------------------------------------------------------
B. 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
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. A Creative Cutout
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
Output
387
Input
233
Output
788243189
----------------------------------------------------------------------------------------------------
E. A Preponderant Reunion
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 1 3 1
Output
2
1
3
Input
5
2 2 1 3 1
Output
3
2
1
4
----------------------------------------------------------------------------------------------------
