ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)


A. A Serial Killer
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler
Output
ross rachel
joey rachel
joey phoebe
joey monica
joey chandler
Input
icm codeforces
1
codeforces technex
Output
icm codeforces
icm technex
----------------------------------------------------------------------------------------------------
B. Sherlock and his girlfriend
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
Output
2
1 1 2 
Input
4
Output
2
2 1 1 2
----------------------------------------------------------------------------------------------------
C. Molly's Chemicals
time limit per test: 2.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
----------------------------------------------------------------------------------------------------
D. The Door Problem
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 0 1
2 1 3
2 1 2
2 2 3
Output
NO
Input
3 3
1 0 1
3 1 2 3
1 2
2 1 3
Output
YES
Input
3 3
1 0 1
3 1 2 3
2 1 2
1 3
Output
NO
----------------------------------------------------------------------------------------------------
E. The Holmes Children
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 1
Output
6
Input
10 2
Output
4
----------------------------------------------------------------------------------------------------
F. Sherlock's bet to Moriarty
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 1
1 3
Output
1 2
Input
6 3
1 3
1 4
1 5
Output
2 1 2 3
----------------------------------------------------------------------------------------------------
G. Sherlock and the Encrypted Data
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
1
1014 1014
Output
1
Input
2
1 1e
1 f
Output
1
0
Input
2
1 abc
d0e fe23
Output
412
28464
----------------------------------------------------------------------------------------------------
