cho.sh
Notes
Loading...

Inequality Signs

Time limit

1s

Memory limit

256 MB

Problem

You are given a sequence of k inequality signs, each either < or >. Place k+1 distinct one-digit numbers around these signs so that every inequality is true.

The available digits are 0 through 9, and no digit may be used more than once.

After removing the inequality signs, read the chosen digits from left to right as one string. At least one valid arrangement always exists. Find the largest and smallest strings among all valid arrangements.

Input

The first line contains an integer k, the number of inequality signs.

The second line contains k inequality signs separated by spaces.

2 <= k <= 9

Output

Print the largest valid k+1 digit string on the first line, and the smallest valid string on the second line.

If the first character is 0, print it as part of the string.