Codeforces Round 664 (Div. 1)


A. Boboniu Chats with Du
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 2 11
8 10 15 23 5
Output
48
Input
20 2 16
20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7
Output
195
----------------------------------------------------------------------------------------------------
B. Boboniu Walks on Graph
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 6 3
4 2 1
1 2 2
2 4 3
4 1 4
4 3 5
3 1 6
Output
2
Input
5 5 1
1 4 1
5 1 2
2 5 3
4 3 4
3 2 5
Output
1
Input
6 13 4
3 5 1
2 5 2
6 3 3
1 4 4
2 6 5
5 3 6
4 1 7
4 3 8
5 2 9
4 2 10
2 1 11
6 1 12
4 6 13
Output
1
----------------------------------------------------------------------------------------------------
C. Boboniu and String
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
B
N
BN
Output
1
BN
Input
10
N
BBBBBB
BNNNBBNBB
NNNNBNBNNBNNNBBN
NBNBN
NNNNNN
BNBNBNBBBBNNNNBBBBNNBBNBNBBNBBBBBBBB
NNNNBN
NBBBBBBBB
NNNNNN
Output
12
BBBBBBBBBBBBNNNNNNNNNNNN
Input
8
NNN
NNN
BBNNBBBN
NNNBNN
B
NNN
NNNNBNN
NNNNNNNNNNNNNNNBNNNNNNNBNB
Output
12
BBBBNNNNNNNNNNNN
Input
3
BNNNBNNNNBNBBNNNBBNNNNBBBBNNBBBBBBNBBBBBNBBBNNBBBNBNBBBN
BBBNBBBBNNNNNBBNBBBNNNBB
BBBBBBBBBBBBBBNBBBBBNBBBBBNBBBBNB
Output
12
BBBBBBBBBBBBBBBBBBBBBBBBBBNNNNNNNNNNNN
----------------------------------------------------------------------------------------------------
D. Boboniu and Jianghu
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
40 10 30 50 20
2 3 2 3 1
1 2
1 3
2 4
2 5
Output
160
Input
5
1000000 1 1 1 1
1000000 1 1 1 1
1 2
1 3
1 4
1 5
Output
4000004
Input
10
510916 760492 684704 32545 484888 933975 116895 77095 127679 989957
402815 705067 705067 705067 623759 103335 749243 138306 138306 844737
1 2
3 2
4 3
1 5
6 4
6 7
8 7
8 9
9 10
Output
6390572
----------------------------------------------------------------------------------------------------
E. Boboniu and Banknote Collection
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9
1 2 3 3 2 1 4 4 1
Output
0 0 0 1 1 1 1 2 2
Input
9
1 2 2 2 2 1 1 2 2
Output
0 0 1 2 3 3 4 4 5
Input
15
1 2 3 4 5 5 4 3 2 2 3 4 4 3 6
Output
0 0 0 0 0 1 1 1 1 2 2 2 3 3 0
Input
50
1 2 4 6 6 4 2 1 3 5 5 3 1 2 4 4 2 1 3 3 1 2 2 1 1 1 2 4 6 6 4 2 1 3 5 5 3 1 2 4 4 2 1 3 3 1 2 2 1 1
Output
0 0 0 0 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 4 4 4 5 5 6 7 3 3 3 4 4 4 4 3 3 4 4 4 4 4 5 5 5 5 6 6 6 7 7 8
----------------------------------------------------------------------------------------------------
