Codeforces Round 507 (Div. 2, based on Olympiad of Metropolises)


A. Palindrome Dance
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 100 1
0 1 2 1 2
Output
101
Input
3 10 12
1 2 0
Output
-1
Input
3 12 1
0 1 0
Output
0
----------------------------------------------------------------------------------------------------
B. Shashlik Cooking
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7 2
Output
2
1 6 
Input
5 1
Output
2
1 4 
----------------------------------------------------------------------------------------------------
C. Timetable
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 10
4 6 8
2 2 3
Output
Yes
16 17 21 
Input
2 1
1 2
2 1
Output
No
----------------------------------------------------------------------------------------------------
D. Subway Pursuit
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
----------------------------------------------------------------------------------------------------
E. Network Safety
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 4 2
0 1 0 1
1 2
2 3
3 4
4 1
Output
50
Input
4 5 3
7 1 7 2
1 2
2 3
3 4
4 1
2 4
Output
96
----------------------------------------------------------------------------------------------------
