Central-European Olympiad in Informatics, CEOI 2020, Day 2 (IOI, Unofficial Mirror Contest, Unrated)


A. The Potion of Great Power
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 5 11 4
2 42 1000 54 68 234
0 1
2 0
3 4
3 5
3 5
1 3
5 3
0 5
3 0
1 3
3 5
0 3 4
3 0 8
0 5 5
3 0 11
Output
26
0
1000000000
14
----------------------------------------------------------------------------------------------------
B. Spring cleaning
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 3
1 2
2 4
4 5
5 6
5 7
3 4
1 4
2 2 4
1 1
Output
-1
10
8
----------------------------------------------------------------------------------------------------
C. Chess Rush
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 8 5
P 1 2
R 4 8
Q 2 3
B 3 6
K 5 5
Output
0 0
2 2
2 5
2 2
7 393
----------------------------------------------------------------------------------------------------
