Codeforces Beta Round 49 (Div. 2)


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

Examples
Input
next
2
nextpermutation
nextelement
Output
nextelement
Input
find
4
find
findfirstof
findit
fand
Output
find
Input
find
4
fondfind
fondfirstof
fondit
fand
Output
find
----------------------------------------------------------------------------------------------------
B. Blog Photo
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
Output
1 1
Input
2 2
Output
2 2
Input
5 5
Output
5 4
----------------------------------------------------------------------------------------------------
C. Little Frog
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
Output
1 2 
Input
3
Output
1 3 2 
----------------------------------------------------------------------------------------------------
D. Physical Education
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2 3 2
3 2 1 2
Output
4
2 3
1 2
3 4
2 3
Input
2
1 100500
1 100500
Output
0
----------------------------------------------------------------------------------------------------
E. Dead Ends
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 2
1 2
2 3
1 3
Output
3
Input
4 6 2
1 2
2 3
3 4
4 1
1 3
2 4
Output
12
Input
4 6 3
1 2
2 3
3 4
4 1
1 3
2 4
Output
4
----------------------------------------------------------------------------------------------------
