Codeforces Round 506 (Div. 3)


A. Many Equal Substrings
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
aba
Output
ababababa
Input
3 2
cat
Output
catcat
----------------------------------------------------------------------------------------------------
B. Creating the Contest
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
1 2 5 6 7 10 21 23 24 49
Output
4
Input
5
2 10 50 110 250
Output
1
Input
6
4 7 12 100 150 199
Output
3
----------------------------------------------------------------------------------------------------
C. Maximal Intersection
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 3
2 6
0 4
3 3
Output
1
Input
5
2 6
1 3
0 4
1 20
0 4
Output
2
Input
3
4 5
1 2
9 20
Output
0
Input
2
3 10
1 5
Output
7
----------------------------------------------------------------------------------------------------
D. Concatenated Multiples
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
----------------------------------------------------------------------------------------------------
E. Tree with Small Distances
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
4 4
Output
12
Input
3 9
Output
14
Input
9 3
Output
14
Input
3 6
Output
12
Input
506 2708
Output
3218
----------------------------------------------------------------------------------------------------
