Problem A. 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

Problem B. Customer support
Statement
Customer support department in an "Incomprehension Amateurs, Ltd" software company
has call center for answering users' questions.
Support prices are as follows:
1.  Answer to a question  10 USD 
2.  Correct answer to a question  20 USD 
3.  Correct answer to a question with explanation  40 USD 
4. 
Correct answer to a question which was already correctly answered before 
+10 USD for each previous correct answer 
So, for example, if user asks the same question three times,
first receives incorrect answer, then correct one, and the third time correct answer with explanation,
it will cost him 10 + 20 + (40 + 1 * 10) = 80 USD.
Customers are billed monthly according to call log.
Company engineers review the log and for each question determine:
 unique number, so the equivalent questions have same numbers,
 whether the answer was correct,
 whether the answer was short or included detailed enough explanation.
Given that data, your program must calculate the payment amount.
Input file format
Input file contains number of calls
N followed by
N triples
q_{i} a_{i} x_{i}, where
q_{i} is integer question number,
a_{i} = 1 if the answer was correct,
0 otherwise,
x_{i} = 1 if explanation was given,
0 otherwise.
Output file format
Output file must contain a single number — payment amount.
Constraints
1 ≤ N ≤ 10000, 1 ≤ q_{i} ≤ 10^{6}.
Sample tests
No. 
Input file (input.txt ) 
Output file (output.txt ) 
1 
1
9834 0 1

10

2 
3
33 1 0
33 0 0
33 1 1

80
