Codeforces Round 596 (Div. 1, based on Technocup 2020 Elimination Round 2)


A. p-binary
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
24 0
Output
2
Input
24 1
Output
3
Input
24 -1
Output
4
Input
4 -7
Output
2
Input
1 1
Output
-1
----------------------------------------------------------------------------------------------------
B. Power Products
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 3
1 3 9 8 24 1
Output
5
----------------------------------------------------------------------------------------------------
C. Rock Is Push
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
1 1
.
Output
1
Input
2 3
...
..R
Output
0
Input
4 4
...R
.RR.
.RR.
R...
Output
4
----------------------------------------------------------------------------------------------------
D. Tree Factory
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
0 0 1 1
Output
0 2 1 4 3
2
1 3
Input
4
0 1 2
Output
0 1 2 3
0
----------------------------------------------------------------------------------------------------
E. To Make 1
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 2
1 1
Output
YES
1 1
Input
4 3
7 8 13 23
Output
YES
23 13
8 7
5 4
Input
3 4
1 2 3
Output
NO
----------------------------------------------------------------------------------------------------
F. Cursor Distance
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
abcde
Output
20
Input
abacaba
Output
58
----------------------------------------------------------------------------------------------------
