Encoded Strings I
题号:NC230856
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制: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 n nonempty prefixes. 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

说明

In the first sample case, the four nonempty prefixes "a", "aa", "aac" and "aacc" will be encoded to "a", "aa", "bba" and "bbaa" respectively, where "bbaa" has the greatest lexicographical order.

In the second sample case, the three nonempty prefixes "a", "ac" and "aca" will be encoded to "a", "ba" and "aba" respectively, where "ba" has the greatest lexicographical order.
示例2

输入

复制
3
aca

输出

复制
ba