Encoded Strings II
题号:NC230858
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Tommy has just invented an interesting string encoding algorithm, which is described below.
  • For every string S, we may define a character-mapping function F_S, which maps every character occurring in S to a lowercase letter, as below

where is the -th lowercase Latin letter, and G(c, S) is the number of different characters after the last occurrence of c in S.
  • To encode a string S by Tommy's algorithm, replace every character c in S by F_S(c) simultaneously.
For example, the encoded string of "abc" is "cba", and the encoded string of "cac" is "aba".

You are given a string of length n and then encode all the  nonempty subsequences. Your task is to find the encoded string that has the greatest lexicographical order among all the encoded strings.

输入描述:

The first line contains an integer n .

The second line contains a string of length n, which consists of only the first 20 lowercase letters, 'a' to 't'.

输出描述:

Output the encoded string that has the greatest lexicographical order among all the encoded strings.
示例1

输入

复制
4
aacc

输出

复制
bbaa
示例2

输入

复制
4
acac

输出

复制
bba