Under construction

Still being built. Things may change

Macaron Kama

Time limit1sMemory limit1024 MB

Summary
Pair each red shell with a blue shell from the same multiset so each macaron takes the larger size, and maximize the resulting digit string if it is a palindrome.
Level

Hard8 of 10

Topics
Dynamic programming, Greedy, String
Solved
No attempts yet

Problem

The land of fairies holds a macaron-making contest! A macaron is a dessert made by putting the filling of your choice between two baked shells. To prepare for the contest, Lulu first made the shells. Lulu made NN red shells and placed them on the floor. The size of the ii-th red shell is aia_{i}. Lulu also made NN blue shells, and the size of the ii-th blue shell is the same as the size of the ii-th red shell.

The contest has a special rule. The size of each macaron must be an integer from 1 to 9, and the contest must have exactly NN macarons in total. A participant's score is the number formed by writing the sizes of macarons 1 through NN in order. For example, when N=4N = 4 and (m1,m2,m3,m4)=(1,4,2,3)(m_{1}, m_{2}, m_{3}, m_{4}) = (1, 4, 2, 3), the score is 1423. The participant with the highest score wins the contest.

Lulu meant to place the ii-th blue shell on top of the ii-th red shell to finish the macarons, but decided to cheat to win. Lulu keeps the order of the red shells on the floor, but may place each blue shell on top of any red shell. After making all NN macarons, the larger shell of each pair is on top, so the fairies will think the larger shell's size is the size of that macaron.

Pixie, a fairy who was watching, allowed the trick on one condition: Lulu's score must be a palindrome. A palindrome reads the same forward and backward. For example, 12321 is a palindrome, but 3141 is not. Find the maximum score Lulu can get while meeting Pixie's request.

Input

The first line contains NN, the number of red shells Lulu made. (1≤N≤400)(1 \leq N \leq 400)

The second line contains a string of length NN giving the sizes of the red shells. The ii-th character is the size of the ii-th red shell, and is between 1 and 9.

Output

Print the maximum score Lulu can get on the first line.

Examples2

  1. Example 1

    Input
    5
    12345
    
    Expected output
    54345
    
  2. Example 2

    Input
    7
    1234321
    
    Expected output
    3234323