Codeforces Round 625 (Div. 2, based on Technocup 2020 Final Round)


A. Contest for Robots
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
----------------------------------------------------------------------------------------------------
B. Journey Planning
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
----------------------------------------------------------------------------------------------------
C. Remove Adjacent
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
bacabcab
Output
4
Input
4
bcda
Output
3
Input
6
abbbbb
Output
5
----------------------------------------------------------------------------------------------------
D. Navigation System
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 9
1 5
5 4
1 2
2 3
3 4
4 1
2 6
6 4
4 2
4
1 2 3 4
Output
1 2
Input
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
7
1 2 3 4 5 6 7
Output
0 0
Input
8 13
8 7
8 6
7 5
7 4
6 5
6 4
5 3
5 2
4 3
4 2
3 1
2 1
1 8
5
8 7 5 2 1
Output
0 3
----------------------------------------------------------------------------------------------------
E. World of Darkraft: Battle for Azathoth
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 3 3
2 3
4 7
2 4
3 2
5 11
1 2 4
2 1 6
3 4 6
Output
1
----------------------------------------------------------------------------------------------------
F. Reachable Strings
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
11011
3
1 3 3
1 4 2
1 2 3
Output
Yes
Yes
No
----------------------------------------------------------------------------------------------------
