Problem A. Second Best

Input file:input.txt   Time limit:2 sec
Output file:output.txt   Memory limit:256 Mb

Statement

Given the sequence of integers A1, A2, …, AN, find a number As such that there exists exactly one Am > As, and for all k ≠ m Ak ≤ As.

Input file format

Input contains N followed by A1 A2… AN.

Output file format

Output should contain a single integer — As, or  − 1 if no such number exists.

Constraints

1 ≤ N ≤ 1000000, 0 ≤ Ai ≤ 109,

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. Avengers and Shawarma

Input file:Standard input   Time limit:1 sec
Output file:Standard output   Memory limit:256 Mb

Statement

Avengers defeated alien invaders and decided to eat some shawarma.

Hulk ordered N shawarmas. M shawarmen immediately started to cook his order. Each shawarman can cook his first shawarma in T minutes. Each next shawarma requires S minutes more to cook than the previous one.

HULK SMASHes!!! awaiting his shawarmas.

You should help Avengers to find out the time when all shawarmas ordered by Hulk will be ready and green giant will calm down. Of course, Jarvis could solve this task, but Iron Man's suit is broken and only air conditioner is working right now.

Input format

First line contains two integers N and M — number of shawarmas ordered by Hulk, and number of shawarmen who are going to complete his order.

Second line contains two integers T and S — time needed to cook the first shawarma and the difference of cooking time between two shawarmas in the row.

Output format

Print one integer — time needed to complete Hulk's order.

Constraints

1 ≤ N, M, T ≤ 100

0 ≤ S ≤ 100

Sample tests

No. Standard input Standard output
1
5 2
10 5
45
2
13 4
4 1
22
3
10 1
5 0
50

0.279s 0.017s 15