Codeforces Round 590 (Div. 3)


A. Equalize Prices Again
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5
1 2 3 4 5
3
1 2 2
4
1 1 1 1
Output
3
2
1
----------------------------------------------------------------------------------------------------
B1. Social Network (easy version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 2
1 2 3 2 1 3 2
Output
2
2 1 
Input
10 4
2 3 3 1 1 2 1 2 3 3
Output
3
1 3 2 
----------------------------------------------------------------------------------------------------
B2. Social Network (hard version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 2
1 2 3 2 1 3 2
Output
2
2 1 
Input
10 4
2 3 3 1 1 2 1 2 3 3
Output
3
1 3 2 
----------------------------------------------------------------------------------------------------
C. Pipes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
7
2323216
1615124
1
3
4
2
13
24
2
12
34
3
536
345
2
46
54
Output
YES
YES
YES
NO
YES
NO
----------------------------------------------------------------------------------------------------
D. Distinct Characters Queries
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
abacaba
5
2 1 4
1 4 b
1 5 b
2 4 6
2 1 7
Output
3
1
2
Input
dfcbbcfeeedbaea
15
1 6 e
1 4 b
2 6 14
1 7 b
1 12 c
2 6 8
2 1 6
1 7 c
1 2 f
1 10 a
2 7 9
1 10 a
1 14 b
1 1 f
2 1 11
Output
5
2
5
2
6
----------------------------------------------------------------------------------------------------
E. Special Permutations
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1 2 3 4
Output
3 4 6 5 
Input
5 5
2 1 5 3 5
Output
9 8 12 6 8 
Input
2 10
1 2 1 1 2 2 2 2 2 2
Output
3 3 
----------------------------------------------------------------------------------------------------
F. Yet Another Substring Reverse
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
abacaba
Output
3
Input
abcdecdf
Output
6
Input
aabbcc
Output
3
Input
abcdeefc
Output
6
----------------------------------------------------------------------------------------------------
