This page is still under construction.

Parts of this page are still being built. What you see may change.

The Third Smallest Number

Interview

Time limit1sMemory limit128 MB

Summary
Given n distinct natural numbers, list all two-element ordered concatenations by value and report the third smallest.
Level

Medium6 of 10

Topics
String, Sorting, Greedy, Brute force
Solved
No attempts yet

Problem

You are given nn distinct natural numbers a1,a2,…,ana_1, a_2, \dots, a_n. By choosing two of them in order — that is, picking two distinct indices i≠ji \ne j, placing aia_i in front and aja_j behind — and concatenating them, you can form a new number.

For example, concatenating 33 and 44 gives 3434 or 4343. Likewise, for a1=1a_1 = 1 and a4=11a_4 = 11, the results aiaja_i a_j and ajaia_j a_i are counted as different results (because the concatenation order differs), even when their values coincide (both equal 111111 here).

List every number that can be formed this way in nondecreasing order, counting each equal value as many times as it occurs. Write a program that prints the third smallest number in this list.

Input

The first line contains the count of numbers nn (3≤n≤1083 \le n \le 108). Each of the next nn lines contains one aia_i (1≤ai≤100001 \le a_i \le 10000). The nn given numbers are all distinct.

Output

Print the third smallest number on a single line.

Examples2

  1. Example 1

    Input
    3
    2
    7
    5
    
    Expected output
    52
    
  2. Example 2

    Input
    4
    17
    888
    1
    71
    
    Expected output
    171