Codeforces Round 535 (Div. 3)


A. Two distinct points
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 1 2
2 6 3 4
2 4 1 3
1 2 1 3
1 4 5 8
Output
2 1
3 4
3 2
1 2
3 7
----------------------------------------------------------------------------------------------------
B. Divisors of Two Integers
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
----------------------------------------------------------------------------------------------------
C. Nice Garland
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
BRB
Output
1
GRB
Input
7
RGBGRBB
Output
3
RGBRGBR
----------------------------------------------------------------------------------------------------
D. Diverse Garland
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG
----------------------------------------------------------------------------------------------------
E1. Array and Segments (Easy version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
2 -2 3 1 2
1 3
4 5
2 5
1 3
Output
6
2
1 4 
Input
5 4
2 -2 3 1 4
3 5
3 4
2 4
2 5
Output
7
2
3 2 
Input
1 0
1000000
Output
0
0
----------------------------------------------------------------------------------------------------
E2. Array and Segments (Hard version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

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