atcoder#AGC026E. [AGC026E] Synchronized Subsequence

[AGC026E] Synchronized Subsequence

Score : 16001600 points

Problem Statement

You are given a string SS of length 2N2N, containing NN occurrences of a and NN occurrences of b.

You will choose some of the characters in SS. Here, for each i=1,2,...,Ni = 1,2,...,N, it is not allowed to choose exactly one of the following two: the ii-th occurrence of a and the ii-th occurrence of b. (That is, you can only choose both or neither.) Then, you will concatenate the chosen characters (without changing the order).

Find the lexicographically largest string that can be obtained in this way.

Constraints

  • 1N30001 \leq N \leq 3000
  • SS is a string of length 2N2N containing NN occurrences of a and NN occurrences of b.

Input

Input is given from Standard Input in the following format:

NN

SS

Output

Print the lexicographically largest string that satisfies the condition.

3
aababb
abab

A subsequence of TT obtained from taking the first, third, fourth and sixth characters in SS, satisfies the condition.

3
bbabaa
bbabaa

You can choose all the characters.

6
bbbaabbabaaa
bbbabaaa
9
abbbaababaababbaba
bbaababababa