output_description: Print the lexicographically largest string that satisfies the condition.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      S
attempt: n = int(input())
  s = input()
  
  ab_index = {"a": 0, "b": 0}
  ab_dic = {}
  i = 0
  while i < (2 * n):
      ab_dic[i] = (s[i], ab_index[s[i]])
      ab_index[s[i]] += 1
      i += 1
  
  import copy
  
  
  class Info:
      def __init__(self, string, includeds, excludeds):
          self.string = string
          self.includeds = includeds
          self.excludeds = excludeds
  
      def include(self, s, i):
          dic = copy.copy(self.includeds)
          dic[(s, i)] = True
          return Info(self.string + s, dic, self.excludeds)
  
      def exclude(self, s, i):
          dic = copy.copy(self.excludeds)
          dic[(s, i)] = True
          return Info(self.string, self.includeds, dic)
  
      def __repr__(self):
          return "({0}, {1}, {2})".format(self.string, self.includeds, self.excludeds)
  
  
  dp: [[Info]] = [[None for _ in range(len(s) + 1)] for _ in range(len(s) + 1)]
  dp[0][0] = Info("", {}, {})
  
  
  for i in range(len(s)):
      ab, abi = ab_dic[i]
      for j in range(i + 1):
          inf = dp[i][j]
          if inf is None:
              continue
  
          if ab == "a":
              if inf.includeds.get(("b", abi)):
                  dp[i + 1][j + 1] = inf.include("a", abi)
              elif inf.excludeds.get(("b", abi)):
                  candidate = inf.exclude("a", abi)
                  if dp[i + 1][j] is None:
                      dp[i + 1][j] = candidate
                  else:
                      if dp[i + 1][j].string <= candidate.string:
                          dp[i + 1][j] = candidate
                      else:
                          pass
              else:
                  dp[i + 1][j + 1] = inf.include("a", abi)
  
                  candidate = inf.exclude("a", abi)
                  if dp[i + 1][j] is None:
                      dp[i + 1][j] = candidate
                  else:
                      if dp[i + 1][j].string <= candidate.string:
                          dp[i + 1][j] = candidate
                      else:
                          pass
          if ab == "b":
              if inf.includeds.get(("a", abi)):
                  dp[i + 1][j + 1] = inf.include("b", abi)
              elif inf.excludeds.get(("a", abi)):
                  candidate = inf.exclude("b", abi)
                  if dp[i + 1][j] is None:
                      dp[i + 1][j] = candidate
                  else:
                      if dp[i + 1][j].string < candidate.string:
                          dp[i + 1][j] = candidate
                      else:
                          pass
              else:
                  dp[i + 1][j + 1] = inf.include("b", abi)
  
                  candidate = inf.exclude("b", abi)
                  if dp[i + 1][j] is None:
                      dp[i + 1][j] = candidate
                  else:
                      if dp[i + 1][j].string < candidate.string:
                          dp[i + 1][j] = candidate
                      else:
                          pass
  
  print(sorted(map(lambda x: x.string, filter(lambda x: x is not None, dp[-1])))[-1])
  
problem_description: Statement
  
  You are given a string S of length 2N, containing N occurrences of `a` and N
  occurrences of `b`.
  
  You will choose some of the characters in S. Here, for each i = 1,2,...,N, it
  is not allowed to choose exactly one of the following two: the i-th occurrence
  of `a` and the i-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.
samples: [{"input": "3\n    aababb", "output": "abab\n    \n\nA subsequence of T obtained from taking the first, third, fourth and sixth\ncharacters in S, satisfies the condition.\n\n* * *"}, {"input": "3\n    bbabaa", "output": "bbabaa\n    \n\nYou can choose all the characters.\n\n* * *"}, {"input": "6\n    bbbaabbabaaa", "output": "bbbabaaa\n    \n\n* * *"}, {"input": "9\n    abbbaababaababbaba", "output": "bbaababababa"}]