Codeforces Round 317 [AimFund Thanks-Round] (Div. 1)


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

Examples
Input
1 1 1 2
Output
4
Input
1 2 3 1
Output
2
Input
10 2 1 7
Output
0
----------------------------------------------------------------------------------------------------
B. Minimization
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 2 4
Output
1
Input
5 2
3 -5 3 -5 3
Output
0
Input
6 3
4 3 4 3 2 5
Output
3
----------------------------------------------------------------------------------------------------
C. CNF 2
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
2 1 -2
2 2 -1
Output
YES
11
Input
4 3
1 1
1 2
3 -1 -2 3
1 -3
Output
NO
Input
5 6
2 1 2
3 1 -2 3
4 -3 5 4 6
2 -6 -4
1 5
Output
YES
100010
----------------------------------------------------------------------------------------------------
D. Campus
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 7
A 1
Q 1
U 1 2
A 1
Z 1
Q 1
Q 2
Output
1
0
2
Input
5 12
U 1 2
M 4 5
A 1
Q 1
A 3
A 4
Q 3
Q 4
Z 4
Q 4
A 5
Q 5
Output
2
1
1
0
1
----------------------------------------------------------------------------------------------------
E. Geometric Progressions
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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