#include <bits/stdc++.h>

#define F(i, a, b) for (int i = a; i <= b; i ++)
#define G(i, a, b) for (int i = a; i >= b; i --)
#define out4(x, y, z, w) { if (debug) printf(#x" = "),W(x),printf(" "#y" = "),W(y),printf(" "#z" = "),W(z),printf(" "#w" = "),W(w),putc('\n'); }
#define out3(x, y, z) { if (debug) printf(#x" = "), W(x), printf(" "#y" = "), W(y), printf(" "#z" = "), W(z), putc('\n'); }
#define out2(x, y) { if (debug) printf(#x" = "), W(x), printf(" "#y" = "), W(y), putc('\n'); }
#define out1(x) { if (debug) printf(#x" = "), W(x), putc('\n'); }
#define outline(x) { if (debug) puts("-------------------------------------------"#x"----------------------------------------"); }
#define outarr(a, L, R) { if (debug) { printf(#a"[%d..%d] = ", L, R); F(i, L, R) W(a[i]), putc(' '); putc('\n'); } }
#define Assert(x) { if ((debug) && (!(x))) { puts("Wrong Answer"); exit(0); } }
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define mem(a, b) memset(a, b, sizeof a)
#define mec(a, b) memcpy(a, b, sizeof a)
#define mx(a, b) ((a) = max(a, b))
#define mn(a, b) ((a) = min(a, b))
#define lowbit(x) ((x) & (-(x)))
#define abs(x) ((max(x, - (x))))
#define get getchar()
#define pb push_back
#define putc putchar
#define inf 2e9

template <typename Int>
void R(Int &x) {
	char c = get; x = 0; Int t = 1;
	for (; !isdigit(c); c = get) t = (c == '-' ? - 1 : t);
	for (; isdigit(c); x = (x << 3) + (x << 1) + c - '0', c = get); x *= t;
}
template <typename Int>
void W(Int x) {
	if (x < 0) { putc('-'); x = - x ; }
	if (x > 9) W(x / 10); putc(x % 10 + '0');
}

#define debug (0)

using namespace std;

const int N = 1e5 + 10;
int n, L, LEN, sum, p[N];
int c[N], Ans[N], cnt[2], f[N];
struct node {
	int num; vector <int> c;
	friend bool operator < (node a, node b) {
		int len = min(a.c.size(), b.c.size());
		F(i, 0, len - 1)
			if (a.c[i] < b.c[i]) return 1; else
			if (a.c[i] > b.c[i]) return 0;
		return a.c.size() < b.c.size() || a.c.size() == b.c.size() && a.num > b.num;
	}
	void add(int x) { c.pb(x); }
} a, b[N];

char ch[N];
struct nobe { int x, l, r; } d[N];

int main() {
//	freopen("data.in","r",stdin);
//	freopen("no.out","w",stdout);

	R(n), scanf("%s", ch + 1), n *= 2;
	int las = 0, s = 0;
	F(i, 1, n) {
		s += (ch[i] == 'b' ? 1 : (-1));
		if (s == 0)
			d[++ L] = {ch[las + 1] - 'a', las + 1, i}, las = i;
//		printf("%d ", s);
	}
//	putc('\n');

	int flag = 0, total = 0;
	G(i, L, 1) {
		int l = d[i].l, r = d[i].r;
		if (d[i].x) {
//			out4(d[i].x, d[i].l, d[i].r, i);
			flag = 1, b[++ total].num = i;
			F(k, 1, (r - l + 1) / 2) {
				cnt[0] = cnt[1] = 0;
				int len = 0;
				G(j, r, l)
					if (++ cnt[ch[j] - 'a'] <= k)
						c[++ len] = ch[j] - 'a';
				reverse(c + 1, c + len + 1);
//				outarr(c, 1, len);
				a.c.clear(), a.num = i;
				F(j, 1, len) a.add(c[j]);
				if (b[total] < a)
					b[total] = a;
			}
//			printf("%d %d\n", b[total].c.size(), b[total].num);
//			F(j, 0, b[total].c.size() - 1)
//				printf("%c", b[total].c[j] + 'a');
//			putc('\n');
		}
		else {
			if (flag) continue;
			int len = 0, bz = 0, Max = 0;
			out2(l, r);
			p[0] = f[l - 1] = 0;
			F(j, l, r) {
				int v = ch[j] - 'a';
				if (!v) p[++ p[0]] = j; else len ++;
				f[j] = f[j - 1];
				if (v)
					mx(f[j], f[p[len] - 1] + 1);
				mx(Max, f[j]);
			}
			out1(Max);
			sum += Max;
		}
	}

	sort(b + 1, b + total + 1);

	las = 0;
	G(i, total, 1)
		if (b[i].num > las) {
			F(j, 0, b[i].c.size() - 1)
				printf("%c", b[i].c[j] + 'a');
			las = b[i].num;
		}
	F(i, 1, sum) printf("ab");
}

Measured memory_bytes: 7004