#ARC134B. [ARC134B] Reserve or Reverse

[ARC134B] Reserve or Reverse

Score : 400400 points

Problem Statement

Given is a string ss of length NN. Let sis_i denote the ii-th character of ss.

Snuke will transform ss by the following procedure.

  • Choose an even length (not necessarily contiguous) subsequence x=(x1,x2,,x2k)x=(x_1, x_2, \ldots, x_{2k}) of (1,2,,N)(1,2, \ldots, N) (kk may be 00).
  • Swap sx1s_{x_1} and sx2ks_{x_{2k}}.
  • Swap sx2s_{x_2} and sx2k1s_{x_{2k-1}}.
  • Swap sx3s_{x_3} and sx2k2s_{x_{2k-2}}.
  • \vdots
  • Swap sxks_{x_{k}} and sxk+1s_{x_{k+1}}.

Among the strings that ss can become after the procedure, find the lexicographically smallest one.

What is the lexicographical order?

Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. As a more formal definition, here is the algorithm to determine the lexicographical order between different strings SS and TT.

Below, let SiS_i denote the ii-th character of SS. Also, if SS is lexicographically smaller than TT, we will denote that fact as S<TS \lt T; if SS is lexicographically larger than TT, we will denote that fact as S>TS \gt T.

  1. Let LL be the smaller of the lengths of SS and TT. For each i=1,2,,Li=1,2,\dots,L, we check whether SiS_i and TiT_i are the same.
  2. If there is an ii such that SiTiS_i \neq T_i, let jj be the smallest such ii. Then, we compare SjS_j and TjT_j. If SjS_j comes earlier than TjT_j in alphabetical order, we determine that S<TS \lt T and quit; if SjS_j comes later than TjT_j, we determine that S>TS \gt T and quit.
  3. If there is no ii such that SiTiS_i \neq T_i, we compare the lengths of SS and TT. If SS is shorter than TT, we determine that S<TS \lt T and quit; if SS is longer than TT, we determine that S>TS \gt T and quit.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • ss is a string of length NN consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

NN

ss

Output

Print the lexicographically smallest possible string ss after the procedure by Snuke.

4
dcab
acdb
  • When x=(1,3)x=(1,3), the procedure just swaps s1s_{1} and s3s_{3}.
  • The ss after the procedure is acdb, the lexicographically smallest possible result.
2
ab
ab
  • When x=()x=(), the ss after the procedure is ab, the lexicographically smallest possible result.
  • Note that xx may have a length of 00.
16
cabaaabbbabcbaba
aaaaaaabbbbcbbbc
17
snwfpfwipeusiwkzo
effwpnwipsusiwkzo