#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
bool operator < (const string &s1,const string &s2){
	int sZ=min(s1.size(),s2.size());
	for (int i=0;i<sZ;++i)
		if (s1[i]<s2[i]) return 1;
		else if (s1[i]>s2[i]) return 0;
	return s1.size()<s2.size();
}
bool operator > (const string &s1,const string &s2){
	int sZ=min(s1.size(),s2.size());
	for (int i=0;i<sZ;++i)
		if (s1[i]>s2[i]) return 1;
		else if (s1[i]<s2[i]) return 0;
	return s1.size()>s2.size();
}
bool operator == (const string &s1,const string &s2){
	int sZ=s1.size();if (sZ!=s2.size()) return 0;
	for (int i=0;i<sZ;++i)
		if (s1[i]!=s2[i]) return 0;
	return 1;
}
int n;
string s;
struct segment{
	int l,r;bool type;
	segment(int L=0,int R=0,bool TYPE=0):l(L),r(R),type(TYPE){}
	segment operator = (const segment &sg){
		l=sg.l;r=sg.r;type=sg.type;return *this;
	}
};
segment seg[6005];int cntseg=0;
int rank_to_a[6005],rank_to_b[6005],a_to_rank[6005],b_to_rank[6005];
bool used_rank[6005];
pair<string,int> material_string[6005];
struct info{
	string s;int ptr,verdict;
	bitset<6005> must;
	info(int i=0):ptr(i),verdict(1){must.reset();must.set(rank_to_a[b_to_rank[i]]);s.clear();s.pb('b');}
};
vector<info> tmp;
inline string segProcess(segment sg){
	bool tp=sg.type;
	string ret;
	int l=sg.l,r=sg.r;
	if (tp==0){
		
		for (int i=l;i<=r;++i){
			while(i<=r&&s[i]=='b') ++i;
			if (i>r) break;
			ret.pb('a');ret.pb('b');
			i=rank_to_b[a_to_rank[i]];
		}
		return ret;
	}
	if (tp==1){
		int best_next=11;// 0:a  1:b  -1:end
		tmp.clear();
		for (int i=l;i<=r;++i){
			if (s[i]=='b') tmp.pb(info(i));
		}
		while(best_next!=-1){
			best_next=-1;
			for (int i=0;i<tmp.size();++i){
				info &temp=tmp[i];
				temp.ptr++;
				if (temp.ptr>r){
					temp.verdict=-1;continue;
				}
				while(temp.ptr<=r&&s[temp.ptr]=='a'&&temp.must[temp.ptr]==0) ++temp.ptr;
				if (temp.ptr>r){
					temp.verdict=-1;continue;
				}
				if (s[temp.ptr]=='a') temp.s+='a',temp.verdict=0,best_next=max(best_next,0);
				else temp.s+='b',temp.verdict=1,temp.must[rank_to_a[b_to_rank[temp.ptr]]]=1,best_next=1;
			}
			for (vector<info>::iterator it=tmp.begin();it!=tmp.end();){
				if (it->verdict < best_next) it=tmp.erase(it);
				else ++it;
			}
		}
		return tmp[0].s;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>s;s='*'+s;n*=2;
	int cnta=0,cntb=0;
	for (int i=1;i<=n;++i){
		if (s[i]=='a'){
			rank_to_a[++cnta]=i;
			a_to_rank[i]=cnta;
		}
		else{
			rank_to_b[++cntb]=i;
			b_to_rank[i]=cntb;
		}
	}
	int l=1,r;bool type;
	if (s[1]=='a') r=rank_to_b[1],type=0;
	else r=rank_to_a[1],type=1;
	used_rank[1]=1;
	for (int i=2;i<=n;++i){
		if (i>r){
			seg[++cntseg]=segment(l,r,type);
			l=i;
			if (s[i]=='a') r=rank_to_b[a_to_rank[i]],type=0;
			else r=rank_to_a[b_to_rank[i]],type=1;
			continue;
		}
		if (s[i]=='a'&&type==0){
			r=max(r,rank_to_b[a_to_rank[i]]);
		}
		if (s[i]=='b'&&type==1){
			r=max(r,rank_to_a[b_to_rank[i]]);
		}
	}
	seg[++cntseg]=segment(l,r,type);
	for (int i=1;i<=cntseg;++i) material_string[i]=mp(segProcess(seg[i]),-i);
	sort(material_string+1,material_string+cntseg+1);
	reverse(material_string+1,material_string+cntseg+1);
	int begin=0;
	for (int i=1;i<=cntseg;++i){
		if (material_string[i].F[0]=='a') break;
		else if (-material_string[i].S>begin){
			begin=-material_string[i].S;
			cout<<material_string[i].F;
		}
	}
	for (int i=1;i<=cntseg;++i){
		if (material_string[i].F[0]=='a'&&-material_string[i].S>begin) cout<<material_string[i].F;
	}
	cout<<endl;
}

Measured memory_bytes: 16244