Codeforces Round 558 (Div. 2)


A. Eating Soup
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 4
Output
3
Input
6 2
Output
2
Input
3 0
Output
1
Input
2 2
Output
0
----------------------------------------------------------------------------------------------------
B1. Cat Party (Easy Edition)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
13
1 1 1 2 2 2 3 3 3 4 4 4 5
Output
13
Input
5
10 2 5 4 1
Output
5
Input
1
10
Output
1
Input
7
3 2 1 1 4 5 1
Output
6
Input
6
1 1 1 2 2 2
Output
5
----------------------------------------------------------------------------------------------------
B2. Cat Party (Hard Edition)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
13
1 1 1 2 2 2 3 3 3 4 4 4 5
Output
13
Input
5
10 100 20 200 1
Output
5
Input
1
100000
Output
1
Input
7
3 2 1 1 4 5 1
Output
6
Input
6
1 1 1 2 2 2
Output
5
----------------------------------------------------------------------------------------------------
C1. Power Transmission (Easy Edition)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
0 0
1 1
0 3
1 2
Output
14
Input
4
0 0
0 2
0 4
2 0
Output
6
Input
3
-1 -1
1 0
3 1
Output
0
----------------------------------------------------------------------------------------------------
C2. Power Transmission (Hard Edition)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
0 0
1 1
0 3
1 2
Output
14
Input
4
0 0
0 2
0 4
2 0
Output
6
Input
3
-1 -1
1 0
3 1
Output
0
----------------------------------------------------------------------------------------------------
D. Mysterious Code
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
*****
katie
shiro
Output
1
Input
caat
caat
a
Output
-1
Input
*a*
bba
b
Output
0
Input
***
cc
z
Output
2
----------------------------------------------------------------------------------------------------
E. Magical Permutation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2 3
Output
2
0 1 3 2 
Input
2
2 3
Output
2
0 2 1 3 
Input
4
1 2 3 4
Output
3
0 1 3 2 6 7 5 4 
Input
2
2 4
Output
0
0 
Input
1
20
Output
0
0 
Input
1
1
Output
1
0 1 
----------------------------------------------------------------------------------------------------
F. Indecisive Taxi Fee
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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