VK Cup 2018 - Final


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

Examples
Input
bwwwbwwbw
Output
5
Input
bwwbwwb
Output
3
----------------------------------------------------------------------------------------------------
B. Colored Cubes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
1 1
2 2
Output
2
1 1 1 2
1 2 2 2
Input
2 2
1 1
2 2
1 2
2 1
Output
2
2 2 2 1
1 1 1 2
Input
2 2
2 1
2 2
2 2
2 1
Output
4
2 1 1 1
2 2 2 1
1 1 1 2
1 2 2 2
Input
4 3
2 2
2 3
3 3
3 2
2 2
2 3
Output
9
2 2 1 2
1 2 1 1
2 3 2 2
3 3 2 3
2 2 1 2
1 1 2 1
2 1 3 1
3 1 3 2
1 2 2 2
----------------------------------------------------------------------------------------------------
C. Down or Right
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
 
YES
 
NO
 
YES
 
YES
 
Output
 
? 1 1 4 4
 
? 1 2 4 3
 
? 4 1 4 4
 
? 1 4 4 4
 
! RDRRDD
----------------------------------------------------------------------------------------------------
D. Mobile Phone Network
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3 6
1 2
3 4
1 3
2 3 3
3 1 4
1 2 4
4 2 8
4 3 8
4 1 10
Output
14
Input
3 2 1
1 2
2 3
1 2 30
Output
-1
Input
4 3 3
1 2
1 3
1 4
4 1 1000000000
4 2 1000000000
4 3 1000000000
Output
3000000000
----------------------------------------------------------------------------------------------------
E. Disjoint Triangles
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1 1
2 2
4 6
4 5
7 2
5 3
Output
6
Input
7
0 -1000000000
-5 -5
5 -5
-5 0
5 0
-2 2
2 2
Output
21
----------------------------------------------------------------------------------------------------
F. Company Acquisitions
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
-1 -1 -1
Output
3
Input
2
2 -1
Output
0
Input
40
3 3 -1 -1 4 4 -1 -1 -1 -1 -1 10 10 10 10 10 10 4 20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 3 3 3 3 3 3 3
Output
755808950
----------------------------------------------------------------------------------------------------
G. Pisces
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2 1
1 3 1
1 4 1
5
1 1 2
1 1 3
2 2 1
3 1 4
3 1 2
Output
2
Input
5
1 2 1
1 3 1
1 4 1
1 5 1
4
1 1 2
2 1 3
3 1 4
4 1 5
Output
2
Input
5
2 5 1
5 1 1
2 4 1
5 3 3
6
5 2 4
2 1 1
2 1 3
2 2 4
4 7 5
4 1 2
Output
10
----------------------------------------------------------------------------------------------------
