Codeforces Round 447 (Div. 2)


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

Examples
Input
QAQAQYSYIOIWIN
Output
4
Input
QAQQQZZYNOIWIN
Output
3
----------------------------------------------------------------------------------------------------
B. Ralph And His Magic Field
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1 -1
Output
1
Input
1 3 1
Output
1
Input
3 3 -1
Output
16
----------------------------------------------------------------------------------------------------
C. Marco and GCD Sequence
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 4 6 12
Output
3
4 6 12
Input
2
2 3
Output
-1
----------------------------------------------------------------------------------------------------
D. Ralph And His Tour in Binary Country
time limit per test: 2.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 2
5
1 8
2 4
Output
11
4
Input
6 4
2
1
1
3
2
2 4
1 3
3 2
1 7
Output
11
6
3
28
----------------------------------------------------------------------------------------------------
E. Ralph and Mushrooms
time limit per test: 2.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 2
1 2 4
2 1 4
1
Output
16
Input
3 3
1 2 4
2 3 3
1 3 8
1
Output
8
----------------------------------------------------------------------------------------------------
