Codeforces Global Round 4


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

Examples
Input
3
100 50 50
Output
2
1 2
Input
3
80 60 60
Output
0
Input
2
6 5
Output
1
1
Input
4
51 25 99 25
Output
3
1 2 4
----------------------------------------------------------------------------------------------------
B. WOW Factor
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
vvvovvv
Output
4
Input
vvovooovovvovoovoovvvvovovvvov
Output
100
----------------------------------------------------------------------------------------------------
C. Tiles
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
Output
16
Input
2 4
Output
64
----------------------------------------------------------------------------------------------------
D. Prime Graph
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
Output
5
1 2
1 3
2 3
2 4
3 4
Input
8
Output
13
1 2
1 3
2 3
1 4
2 4
1 5
2 5
1 6
2 6
1 7
1 8
5 8
7 8
----------------------------------------------------------------------------------------------------
E. Archaeology
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
cacbac
Output
aba
Input
abc
Output
a
Input
cbacacacbcbababacbcb
Output
cbaaacbcaaabc
----------------------------------------------------------------------------------------------------
F1. Short Colorful Strip
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2 3
Output
5
Input
7 7
4 5 1 6 2 3 7
Output
165
----------------------------------------------------------------------------------------------------
F2. Long Colorful Strip
time limit per test: 6 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2 3
Output
5
Input
2 3
1 2 1
Output
1
Input
2 3
2 1 2
Output
0
Input
7 7
4 5 1 6 2 3 7
Output
165
Input
8 17
1 3 2 2 7 8 2 5 5 4 4 4 1 1 6 1 1
Output
20
----------------------------------------------------------------------------------------------------
G. The Awesomest Vertex
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 6
1 1 2 2
10 -3 -7 -3 -10
10 3 9 3 6
2 1
2 2
1 2 6
2 1
1 2 5
2 1
Output
100
91
169
240
----------------------------------------------------------------------------------------------------
H. Stock Exchange
time limit per test: 6 seconds
memory limit per test: 16 megabytes
input: standard input
output: standard output

Examples
Input
1
3 10
1 16
Output
3 1
Input
2
3 0
2 1
1 10
1 11
Output
6 3
Input
1
42 42
47 47
Output
-1
Input
8
145 1729363
891 4194243
424 853731
869 1883440
843 556108
760 1538373
270 762781
986 2589382
610 99315884
591 95147193
687 99248788
65 95114537
481 99071279
293 98888998
83 99764577
769 96951171
Output
434847 11
Input
8
261 261639
92 123277
271 131614
320 154417
97 258799
246 17926
117 222490
110 39356
85 62864876
86 62781907
165 62761166
252 62828168
258 62794649
125 62817698
182 62651225
16 62856001
Output
1010327 11
----------------------------------------------------------------------------------------------------
