#include <bits/stdc++.h>
#define bb(L,R) (preb[R]-preb[L-1])
#define pz system("pause")
using namespace std;
int N;
int preb[6010];
int oca[6010],ocb[6010],act,bct,last;
int anum[6010],bnum[6010];
char a[6010];
int gcnt;
int tog[6010];
string * go[6010];
string ans;
string f[6010];
struct pstr{
    string *s;
    int id;
}P[60010];
bool cmp(pstr a,pstr b) {
    if(*(a.s)!=*(b.s)) return *(a.s)>*(b.s);
    else return a.id<b.id;
}
string * do_b_max(int L,int R) {
    //printf("\tdo_b_max in [%d,%d]\n",L,R);
    string *ret=new string;
    for(int i=L;i<=R;++i) tog[i]=0;
    for(int i=L;i<=R;++i) {
        if(a[i]=='b') {
            *ret+=a[i];
            tog[oca[bnum[i]]]=true;
        } else if(tog[i]) {
            *ret+=a[i];
        }
    }
    //cout<<"\t"<<*ret<<endl;
    return ret;
}
void solve(int L,int R,bool flag) {//flag==true a first else b first
    //printf("\tsolve [%d,%d] flag=%d\n",L,R,(int)(flag));
	++gcnt;
	go[gcnt]=new string;
	string &ret=*go[gcnt];
	if(flag) {
        int now=L;
        while(now<=R) {
                            //printf("prenow=%d\n",now);
            if(a[now]!='a') {
                ++now;
                continue;
            }
            //printf("now=%d\n",now);
            ret+="ab";
            int t=anum[now];
            now=ocb[t]+1;
            //printf("nxtnow=%d\n",now);
        }
       // cout<<"\t"<<ret<<endl;
        return;
	} else {
        int maxb=0;
        for(int i=L;i<=R;++i) if(a[i]=='b'){
            if(bb(i,oca[bnum[i]])>maxb) {
                maxb=bb(i,oca[bnum[i]]);
            }
        }
        //printf("\tmaxb=%d\n",maxb);
        for(int i=L;i<=R;++i) if(a[i]=='b'&&bb(i,oca[bnum[i]])==maxb) {
            string *tmp=do_b_max(i,R);
            if(*tmp>*go[gcnt]) {
                delete go[gcnt];
                go[gcnt]=tmp;
            }
            else delete tmp;
        }
	}
	//printf("\tto_solve [%d,%d] flag=%d\n",L,R,(int)(flag));
    //cerr<<"\t"<<*go[gcnt]<<endl;
}
int main() {
	scanf("%d",&N);
	scanf("%s",a+1);
	for(int i=1;i<=2*N;++i) {
        preb[i]=preb[i-1]+(a[i]=='b');
		if(a[i]=='a') oca[++act]=i,anum[i]=act;
		else ocb[++bct]=i,bnum[i]=bct;
		if(act==bct) {
			int t=last+1;last=i;
			//if(oca[act]<ocb[bct]) puts("~");
			solve(t,last,oca[act]<ocb[bct]);
		}
	}
//    for(int i=1;i<=2*N;++i) printf("%d ",oca[i]);puts("");
//    for(int i=1;i<=2*N;++i) printf("%d ",ocb[i]);puts("");
//    for(int i=1;i<=2*N;++i) printf("%d ",anum[i]);puts("");
//    for(int i=1;i<=2*N;++i) printf("%d ",bnum[i]);puts("");

    for(int i=1;i<=gcnt;++i) {
        P[i].s=go[i];
        P[i].id=i;
        //cerr<<*P[i].s<<endl;
    }
//    sort(P+1,P+gcnt+1,cmp);
//        for(int i=1;i<=gcnt;++i) {
//        cout<<*P[i].s<<endl;
//    }
//    ans=*(P[1].s);
//    int up=P[1].id;
//    for(int i=2;i<=gcnt;++i) {
//        if(P[i].id>up) {
//            ans+=*(P[i].s);
//            up=P[i].id;
//        }
//    }
//cerr<<"Yessssssssss"<<endl;
    ans=f[1]=*P[1].s;
    for(int i=2;i<=gcnt;++i) {
        f[i]=*P[i].s;
        for(int j=1;j<i;++j) {
            string t=f[j]+(*P[i].s);
            if(f[i]<t) f[i]=t;
        }


        if(f[i]>ans) ans=f[i];
        //cerr<<i<<" "<<f[i]<<endl;
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 14464