Problem A. Simple prefix compression
Statement
Many databases store the data in the character fields (and especially indices) using
prefix compression. This technique compresses a sequence of strings
A_{1}, ..., A_{N} by
the following method: if there are strings
A_{i} =
a_{i,1}a_{i,2}...a_{i,p}
and
A_{i + 1} =
a_{i+1,1}a_{i+1,2}...a_{i+1,q}
such that for some j ≤ min(p, q)
a_{i,1} = a_{i+1,1},
a_{i,2} = a_{i+1,2}, ...
a_{i,j} = a_{i+1,j},
then the second string is stored as
[j]a_{i+1,j+1}a_{i+1,j+2}...
a_{i+1,q}, where [j] is a single character with code j.
If j = 0, that is, strings do not have any common prefix, then the second
string is prefixed with zero byte, and so the total length actually increases.
Input file format
First line of input file contains integer number
N, with following
N lines containing strings
A_{1} ...
A_{N}
Output file format
Output file must contain a single integer — minimal total length of
compressed strings.
Constraints
1 ≤
N ≤ 10000,
1 ≤ length(
A_{i}) ≤ 255.
Sample tests
No. 
Input file (input.txt ) 
Output file (output.txt ) 
1 
3
abc
atest
atext

11

2 
2
test
notest

11

Problem B. Second Best
Statement
Given the sequence of integers A_{1}, A_{2}, …, A_{N},
find a number A_{s} such that there exists exactly one
A_{m} > A_{s}, and for all k ≠ m A_{k} ≤ A_{s}.
Input file format
Input contains
N followed by
A_{1} A_{2}… A_{N}.
Output file format
Output should contain a single integer —
A_{s}, or
−1 if no such number exists.
Constraints
1 ≤ N ≤ 1000000, 0 ≤ A_{i} ≤ 10^{9},
Sample tests
No. 
Input file (input.txt ) 
Output file (output.txt ) 
1 
3
1 2 3

2

2 
4
3 3 2 3

1
