#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) begin(a),end(a)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct BigInt {
	static const int kBase = 1000000000;
	static const int kBaseDigits = 9;
	vector<int> d;
	int sign;
	BigInt() :sign(1) {}
	BigInt(long long v) {
		sign = 1;
		if (v < 0)
			sign = -1, v = -v;
		for (; v > 0; v = v / kBase)
			d.emplace_back(v % kBase);
	}
	BigInt(const string &s) { read(s); }

	bool operator<(const BigInt &v)const {
		if (sign != v.sign)
			return sign < v.sign;
		if (d.size() != v.d.size())
			return d.size() * sign < v.d.size() * v.sign;
		for (int i = d.size() - 1; i >= 0; i--)
			if (d[i] != v.d[i])
				return d[i] * sign < v.d[i] * sign;
		return false;
	}
	bool operator>(const BigInt &v)const { return v < *this; }
	bool operator<=(const BigInt &v)const { return !(v < *this); }
	bool operator>=(const BigInt &v)const { return !(*this < v); }
	bool operator==(const BigInt &v)const { return !(*this < v) && !(v < *this); }
	bool operator!=(const BigInt &v)const { return !(*this == v); }

	BigInt &operator+=(const BigInt &v) {
		if (sign == v.sign) {
			BigInt res = v;
			for (int i = 0, carry = 0; i < (int)max(d.size(), v.d.size()) || carry; ++i) {
				if (i == (int)res.d.size())
					res.d.emplace_back(0);
				res.d[i] += carry + (i < (int)d.size() ? d[i] : 0);
				carry = res.d[i] >= kBase;
				if (carry)
					res.d[i] -= kBase;
			}
			return *this = res;
		}
		else
			return *this -= (-v);
	}
	BigInt &operator-=(const BigInt &v) {
		if (sign == v.sign) {
			BigInt tmp = abs();
			if (abs() >= v.abs()) {
				BigInt res = *this;
				for (int i = 0, carry = 0; i < (int)v.d.size() || carry; ++i) {
					res.d[i] -= carry + (i < (int)v.d.size() ? v.d[i] : 0);
					carry = res.d[i] < 0;
					if (carry)
						res.d[i] += kBase;
				}
				res.trim();
				return *this = res;
			}
			else
				return *this = -(v - *this);
		}
		else
			return *this += -v;
	}
	BigInt &operator*=(const BigInt &v) {
		return *this = *this * v;
	}
	BigInt &operator/=(const BigInt &v) {
		return *this = *this / v;
	}
	BigInt operator-()const {
		BigInt res = *this;
		res.sign = -sign;
		return res;
	}

	BigInt operator+(const BigInt &v)const { return BigInt(*this) += v; }
	BigInt operator-(const BigInt &v)const { return BigInt(*this) -= v; }
	BigInt operator*(int v)const {
		BigInt res = *this;
		res *= v;
		return res;
	}
	BigInt operator*(const BigInt &v)const {
		vector<int> a6 = convert_base(this->d, kBaseDigits, 6);
		vector<int> b6 = convert_base(v.d, kBaseDigits, 6);
		vll a(a6.begin(), a6.end());
		vll b(b6.begin(), b6.end());
		while (a.size() < b.size())
			a.emplace_back(0);
		while (b.size() < a.size())
			b.emplace_back(0);
		while (a.size() & (a.size() - 1))
			a.emplace_back(0), b.emplace_back(0);
		vll c = karatsubaMultiply(a, b);
		BigInt res;
		res.sign = sign * v.sign;
		for (int i = 0, carry = 0; i < (int)c.size(); i++) {
			long long cur = c[i] + carry;
			res.d.emplace_back((int)(cur % 1000000));
			carry = (int)(cur / 1000000);
		}
		res.d = convert_base(res.d, 6, kBaseDigits);
		res.trim();
		return res;
	}

	BigInt operator/(const BigInt &v)const { return divmod(*this, v).first; }
	BigInt operator/(int v)const {
		BigInt res = *this;
		res /= v;
		return res;
	}
	BigInt operator%(const BigInt &v)const {
		return divmod(*this, v).second;
	}
	int operator%(int v)const {
		if (v < 0)
			v = -v;
		int m = 0;
		for (int i = d.size() - 1; i >= 0; --i)
			m = (d[i] + m * (long long)kBase) % v;
		return m * sign;
	}

	BigInt &operator*=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = 0, carry = 0; i < (int)d.size() || carry; ++i) {
			if (i == (int)d.size())
				d.emplace_back(0);
			long long cur = d[i] * (long long)v + carry;
			carry = (int)(cur / kBase);
			d[i] = (int)(cur % kBase);
		}
		trim();
		return *this;
	}
	BigInt &operator/=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = (int)d.size() - 1, rem = 0; i >= 0; --i) {
			long long cur = d[i] + rem * (long long)kBase;
			d[i] = (int)(cur / v);
			rem = (int)(cur % v);
		}
		trim();
		return *this;
	}
	static pair<BigInt, BigInt> divmod(const BigInt &a1, const BigInt &b1) {
		int norm = kBase / (b1.d.back() + 1);
		BigInt a = a1.abs() * norm;
		BigInt b = b1.abs() * norm;
		BigInt q, r;
		q.d.resize(a.d.size());

		for (int i = a.d.size() - 1; i >= 0; i--) {
			r *= kBase;
			r += a.d[i];
			int s1 = r.d.size() <= b.d.size() ? 0 : r.d[b.d.size()];
			int s2 = r.d.size() <= b.d.size() - 1 ? 0 : r.d[b.d.size() - 1];
			int d = ((long long)kBase * s1 + s2) / b.d.back();
			r -= b * d;
			while (r < 0)
				r += b, --d;
			q.d[i] = d;
		}

		q.sign = a1.sign * b1.sign;
		r.sign = a1.sign;
		q.trim();
		r.trim();
		return make_pair(q, r / norm);
	}
	void trim() {
		while (!d.empty() && !d.back())
			d.pop_back();
		if (d.empty())
			sign = 1;
	}
	bool isZero()const {
		return d.empty() || (d.size() == 1 && !d[0]);
	}

	BigInt abs()const {
		BigInt res = *this;
		res.sign *= res.sign;
		return res;
	}

	long long longValue()const {
		long long res = 0;
		for (int i = d.size() - 1; i >= 0; i--)
			res = res * kBase + d[i];
		return res * sign;
	}

	void read(const string &s) {
		sign = 1;
		d.clear();
		int pos = 0;
		while (pos < (int)s.size() && (s[pos] == '-' || s[pos] == '+')) {
			if (s[pos] == '-')
				sign = -sign;
			++pos;
		}
		for (int i = s.size() - 1; i >= pos; i -= kBaseDigits) {
			int x = 0;
			for (int j = max(pos, i - kBaseDigits + 1); j <= i; j++)
				x = x * 10 + s[j] - '0';
			d.emplace_back(x);
		}
		trim();
	}

	friend istream& operator >> (istream &stream, BigInt &v) {
		string s;
		stream >> s;
		v.read(s);
		return stream;
	}

	friend ostream& operator << (ostream &stream, const BigInt &v) {
		if (v.sign == -1)
			stream << '-';
		stream << (v.d.empty() ? 0 : v.d.back());
		for (int i = (int)v.d.size() - 2; i >= 0; --i)
			stream << setw(kBaseDigits) << setfill('0') << v.d[i];
		return stream;
	}

	static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
		vector<long long> p(max(old_digits, new_digits) + 1);
		p[0] = 1;
		for (int i = 1; i < (int)p.size(); i++)
			p[i] = p[i - 1] * 10;
		vector<int> res;
		long long cur = 0;
		int cur_digits = 0;
		for (int i = 0; i < (int)a.size(); i++) {
			cur += a[i] * p[cur_digits];
			cur_digits += old_digits;
			while (cur_digits >= new_digits) {
				res.emplace_back(int(cur % p[new_digits]));
				cur /= p[new_digits];
				cur_digits -= new_digits;
			}
		}
		res.emplace_back((int)cur);
		while (!res.empty() && !res.back())
			res.pop_back();
		return res;
	}

	using vll = vector<long long>;
	static vll karatsubaMultiply(const vll &a, const vll &b) {
		int n = a.size();
		vll res(n + n);
		if (n <= 32) {
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					res[i + j] += a[i] * b[j];
			return res;
		}

		int k = n >> 1;
		vll a1(a.begin(), a.begin() + k);
		vll a2(a.begin() + k, a.end());
		vll b1(b.begin(), b.begin() + k);
		vll b2(b.begin() + k, b.end());

		vll a1b1 = karatsubaMultiply(a1, b1);
		vll a2b2 = karatsubaMultiply(a2, b2);

		for (int i = 0; i < k; i++)
			a2[i] += a1[i];
		for (int i = 0; i < k; i++)
			b2[i] += b1[i];

		vll r = karatsubaMultiply(a2, b2);
		for (int i = 0; i < (int)a1b1.size(); i++)
			r[i] -= a1b1[i];
		for (int i = 0; i < (int)a2b2.size(); i++)
			r[i] -= a2b2[i];

		for (int i = 0; i < (int)r.size(); i++)
			res[i + k] += r[i];
		for (int i = 0; i < (int)a1b1.size(); i++)
			res[i] += a1b1[i];
		for (int i = 0; i < (int)a2b2.size(); i++)
			res[i + n] += a2b2[i];
		return res;
	}

};

BigInt gcd(const BigInt &x, const BigInt &y) { return y.isZero() ? x : gcd(y, x % y); }
BigInt lcm(const BigInt &x, const BigInt &y) { return x / gcd(x, y) * y; }


struct MinimumCostFlow {
	using Flow = int;
	using Cost = BigInt;
	const Cost kInfCost = BigInt(string(log10(pow(2500, 70)), '9'));
	struct Edge {
		int to, rev;
		Flow cap;
		Cost cost;
		Edge() {}
		Edge(int to, int rev, Flow cap, Cost cost) :to(to), rev(rev), cap(cap), cost(cost) {}
	};
	int n;
	vector<vector<Edge>> g;
	vector<Cost> dist;
	vector<int> prevv, preve;
	MinimumCostFlow(int n) :n(n), g(n), dist(n), prevv(n), preve(n) {}
	void addArc(int from, int to, Flow cap, Cost cost) {
		g[from].emplace_back(to, (int)g[to].size(), cap, cost);
		g[to].emplace_back(from, (int)g[from].size() - 1, 0, -cost);
	}
	// s??????t????????????f???????°??????¨???
	// ??????????????´?????? -1
	Cost minimumCostFlow(int s, int t, Flow f) {
		Cost total = 0;
		while (f > 0) {
			// Bellman-Ford
			fill(dist.begin(), dist.end(), kInfCost);
			dist[s] = 0;
			bool update = true;
			while (update) {
				update = false;
				for (int v = 0; v < n; v++) {
					if (dist[v] == kInfCost)continue;
					for (int i = 0; i < g[v].size(); i++) {
						Edge &e = g[v][i];
						if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
							dist[e.to] = dist[v] + e.cost;
							prevv[e.to] = v;
							preve[e.to] = i;
							update = true;
						}
					}
				}
			}
			// ????????\???????????????
			if (dist[t] == kInfCost)
				return -1;
			// ?????????????????£??????????????????
			Flow d = f;
			for (int v = t; v != s; v = prevv[v])
				d = min(d, g[prevv[v]][preve[v]].cap);
			f -= d;
			total += dist[t] * d;
			for (int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.rev].cap += d;
			}
		}
		return total;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	BigInt w[52];
	w[0] = -1;
	rep(i, 0, 51) {
		w[i + 1] = w[i] * 2500;
	}
	reverse(w, w + 52);

	int N; cin >> N;
	vector<vector<BigInt>> a(N, vector<BigInt>(N));
	vector<vector<char>> c(N, vector<char>(N));
	rep(i, 0, N) rep(j, 0, N) {
		cin >> c[i][j];
		if (c[i][j] <= 'Z')
			a[i][j] = w[c[i][j] - 'A'];
		else
			a[i][j] = w[26 + c[i][j] - 'a'];
	}

	dump(a);

	MinimumCostFlow mcf(N + N + 2);
	int s = mcf.n - 2, t = s + 1;

	rep(i, 0, N) {
		rep(j, 0, N) {
			mcf.addArc(i, N + j, 1, a[i][j]);
		}
	}
	rep(i, 0, N) {
		mcf.addArc(s, i, 1, 0);
		mcf.addArc(N + i, t, 1, 0);
	}



	auto cost = mcf.minimumCostFlow(s, t, N);
	dump(cost);

	vector<char> ans;
	rep(i, 0, N) {
		rep(j, 0, N) {
			if (mcf.g[i][j].cap == 0) {
				ans.emplace_back(c[i][j]);
			}
		}
	}
	sort(all(ans));
	rep(i, 0, ans.size())
		cout << ans[i];
	cout << endl;
	return 0;
}
### Prompt

In Cpp, your task is to solve the following problem:

Example

Input

3
aab
czc
baa


Output

aac

### Response

```cpp
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) begin(a),end(a)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct BigInt {
	static const int kBase = 1000000000;
	static const int kBaseDigits = 9;
	vector<int> d;
	int sign;
	BigInt() :sign(1) {}
	BigInt(long long v) {
		sign = 1;
		if (v < 0)
			sign = -1, v = -v;
		for (; v > 0; v = v / kBase)
			d.emplace_back(v % kBase);
	}
	BigInt(const string &s) { read(s); }

	bool operator<(const BigInt &v)const {
		if (sign != v.sign)
			return sign < v.sign;
		if (d.size() != v.d.size())
			return d.size() * sign < v.d.size() * v.sign;
		for (int i = d.size() - 1; i >= 0; i--)
			if (d[i] != v.d[i])
				return d[i] * sign < v.d[i] * sign;
		return false;
	}
	bool operator>(const BigInt &v)const { return v < *this; }
	bool operator<=(const BigInt &v)const { return !(v < *this); }
	bool operator>=(const BigInt &v)const { return !(*this < v); }
	bool operator==(const BigInt &v)const { return !(*this < v) && !(v < *this); }
	bool operator!=(const BigInt &v)const { return !(*this == v); }

	BigInt &operator+=(const BigInt &v) {
		if (sign == v.sign) {
			BigInt res = v;
			for (int i = 0, carry = 0; i < (int)max(d.size(), v.d.size()) || carry; ++i) {
				if (i == (int)res.d.size())
					res.d.emplace_back(0);
				res.d[i] += carry + (i < (int)d.size() ? d[i] : 0);
				carry = res.d[i] >= kBase;
				if (carry)
					res.d[i] -= kBase;
			}
			return *this = res;
		}
		else
			return *this -= (-v);
	}
	BigInt &operator-=(const BigInt &v) {
		if (sign == v.sign) {
			BigInt tmp = abs();
			if (abs() >= v.abs()) {
				BigInt res = *this;
				for (int i = 0, carry = 0; i < (int)v.d.size() || carry; ++i) {
					res.d[i] -= carry + (i < (int)v.d.size() ? v.d[i] : 0);
					carry = res.d[i] < 0;
					if (carry)
						res.d[i] += kBase;
				}
				res.trim();
				return *this = res;
			}
			else
				return *this = -(v - *this);
		}
		else
			return *this += -v;
	}
	BigInt &operator*=(const BigInt &v) {
		return *this = *this * v;
	}
	BigInt &operator/=(const BigInt &v) {
		return *this = *this / v;
	}
	BigInt operator-()const {
		BigInt res = *this;
		res.sign = -sign;
		return res;
	}

	BigInt operator+(const BigInt &v)const { return BigInt(*this) += v; }
	BigInt operator-(const BigInt &v)const { return BigInt(*this) -= v; }
	BigInt operator*(int v)const {
		BigInt res = *this;
		res *= v;
		return res;
	}
	BigInt operator*(const BigInt &v)const {
		vector<int> a6 = convert_base(this->d, kBaseDigits, 6);
		vector<int> b6 = convert_base(v.d, kBaseDigits, 6);
		vll a(a6.begin(), a6.end());
		vll b(b6.begin(), b6.end());
		while (a.size() < b.size())
			a.emplace_back(0);
		while (b.size() < a.size())
			b.emplace_back(0);
		while (a.size() & (a.size() - 1))
			a.emplace_back(0), b.emplace_back(0);
		vll c = karatsubaMultiply(a, b);
		BigInt res;
		res.sign = sign * v.sign;
		for (int i = 0, carry = 0; i < (int)c.size(); i++) {
			long long cur = c[i] + carry;
			res.d.emplace_back((int)(cur % 1000000));
			carry = (int)(cur / 1000000);
		}
		res.d = convert_base(res.d, 6, kBaseDigits);
		res.trim();
		return res;
	}

	BigInt operator/(const BigInt &v)const { return divmod(*this, v).first; }
	BigInt operator/(int v)const {
		BigInt res = *this;
		res /= v;
		return res;
	}
	BigInt operator%(const BigInt &v)const {
		return divmod(*this, v).second;
	}
	int operator%(int v)const {
		if (v < 0)
			v = -v;
		int m = 0;
		for (int i = d.size() - 1; i >= 0; --i)
			m = (d[i] + m * (long long)kBase) % v;
		return m * sign;
	}

	BigInt &operator*=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = 0, carry = 0; i < (int)d.size() || carry; ++i) {
			if (i == (int)d.size())
				d.emplace_back(0);
			long long cur = d[i] * (long long)v + carry;
			carry = (int)(cur / kBase);
			d[i] = (int)(cur % kBase);
		}
		trim();
		return *this;
	}
	BigInt &operator/=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = (int)d.size() - 1, rem = 0; i >= 0; --i) {
			long long cur = d[i] + rem * (long long)kBase;
			d[i] = (int)(cur / v);
			rem = (int)(cur % v);
		}
		trim();
		return *this;
	}
	static pair<BigInt, BigInt> divmod(const BigInt &a1, const BigInt &b1) {
		int norm = kBase / (b1.d.back() + 1);
		BigInt a = a1.abs() * norm;
		BigInt b = b1.abs() * norm;
		BigInt q, r;
		q.d.resize(a.d.size());

		for (int i = a.d.size() - 1; i >= 0; i--) {
			r *= kBase;
			r += a.d[i];
			int s1 = r.d.size() <= b.d.size() ? 0 : r.d[b.d.size()];
			int s2 = r.d.size() <= b.d.size() - 1 ? 0 : r.d[b.d.size() - 1];
			int d = ((long long)kBase * s1 + s2) / b.d.back();
			r -= b * d;
			while (r < 0)
				r += b, --d;
			q.d[i] = d;
		}

		q.sign = a1.sign * b1.sign;
		r.sign = a1.sign;
		q.trim();
		r.trim();
		return make_pair(q, r / norm);
	}
	void trim() {
		while (!d.empty() && !d.back())
			d.pop_back();
		if (d.empty())
			sign = 1;
	}
	bool isZero()const {
		return d.empty() || (d.size() == 1 && !d[0]);
	}

	BigInt abs()const {
		BigInt res = *this;
		res.sign *= res.sign;
		return res;
	}

	long long longValue()const {
		long long res = 0;
		for (int i = d.size() - 1; i >= 0; i--)
			res = res * kBase + d[i];
		return res * sign;
	}

	void read(const string &s) {
		sign = 1;
		d.clear();
		int pos = 0;
		while (pos < (int)s.size() && (s[pos] == '-' || s[pos] == '+')) {
			if (s[pos] == '-')
				sign = -sign;
			++pos;
		}
		for (int i = s.size() - 1; i >= pos; i -= kBaseDigits) {
			int x = 0;
			for (int j = max(pos, i - kBaseDigits + 1); j <= i; j++)
				x = x * 10 + s[j] - '0';
			d.emplace_back(x);
		}
		trim();
	}

	friend istream& operator >> (istream &stream, BigInt &v) {
		string s;
		stream >> s;
		v.read(s);
		return stream;
	}

	friend ostream& operator << (ostream &stream, const BigInt &v) {
		if (v.sign == -1)
			stream << '-';
		stream << (v.d.empty() ? 0 : v.d.back());
		for (int i = (int)v.d.size() - 2; i >= 0; --i)
			stream << setw(kBaseDigits) << setfill('0') << v.d[i];
		return stream;
	}

	static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
		vector<long long> p(max(old_digits, new_digits) + 1);
		p[0] = 1;
		for (int i = 1; i < (int)p.size(); i++)
			p[i] = p[i - 1] * 10;
		vector<int> res;
		long long cur = 0;
		int cur_digits = 0;
		for (int i = 0; i < (int)a.size(); i++) {
			cur += a[i] * p[cur_digits];
			cur_digits += old_digits;
			while (cur_digits >= new_digits) {
				res.emplace_back(int(cur % p[new_digits]));
				cur /= p[new_digits];
				cur_digits -= new_digits;
			}
		}
		res.emplace_back((int)cur);
		while (!res.empty() && !res.back())
			res.pop_back();
		return res;
	}

	using vll = vector<long long>;
	static vll karatsubaMultiply(const vll &a, const vll &b) {
		int n = a.size();
		vll res(n + n);
		if (n <= 32) {
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					res[i + j] += a[i] * b[j];
			return res;
		}

		int k = n >> 1;
		vll a1(a.begin(), a.begin() + k);
		vll a2(a.begin() + k, a.end());
		vll b1(b.begin(), b.begin() + k);
		vll b2(b.begin() + k, b.end());

		vll a1b1 = karatsubaMultiply(a1, b1);
		vll a2b2 = karatsubaMultiply(a2, b2);

		for (int i = 0; i < k; i++)
			a2[i] += a1[i];
		for (int i = 0; i < k; i++)
			b2[i] += b1[i];

		vll r = karatsubaMultiply(a2, b2);
		for (int i = 0; i < (int)a1b1.size(); i++)
			r[i] -= a1b1[i];
		for (int i = 0; i < (int)a2b2.size(); i++)
			r[i] -= a2b2[i];

		for (int i = 0; i < (int)r.size(); i++)
			res[i + k] += r[i];
		for (int i = 0; i < (int)a1b1.size(); i++)
			res[i] += a1b1[i];
		for (int i = 0; i < (int)a2b2.size(); i++)
			res[i + n] += a2b2[i];
		return res;
	}

};

BigInt gcd(const BigInt &x, const BigInt &y) { return y.isZero() ? x : gcd(y, x % y); }
BigInt lcm(const BigInt &x, const BigInt &y) { return x / gcd(x, y) * y; }


struct MinimumCostFlow {
	using Flow = int;
	using Cost = BigInt;
	const Cost kInfCost = BigInt(string(log10(pow(2500, 70)), '9'));
	struct Edge {
		int to, rev;
		Flow cap;
		Cost cost;
		Edge() {}
		Edge(int to, int rev, Flow cap, Cost cost) :to(to), rev(rev), cap(cap), cost(cost) {}
	};
	int n;
	vector<vector<Edge>> g;
	vector<Cost> dist;
	vector<int> prevv, preve;
	MinimumCostFlow(int n) :n(n), g(n), dist(n), prevv(n), preve(n) {}
	void addArc(int from, int to, Flow cap, Cost cost) {
		g[from].emplace_back(to, (int)g[to].size(), cap, cost);
		g[to].emplace_back(from, (int)g[from].size() - 1, 0, -cost);
	}
	// s??????t????????????f???????°??????¨???
	// ??????????????´?????? -1
	Cost minimumCostFlow(int s, int t, Flow f) {
		Cost total = 0;
		while (f > 0) {
			// Bellman-Ford
			fill(dist.begin(), dist.end(), kInfCost);
			dist[s] = 0;
			bool update = true;
			while (update) {
				update = false;
				for (int v = 0; v < n; v++) {
					if (dist[v] == kInfCost)continue;
					for (int i = 0; i < g[v].size(); i++) {
						Edge &e = g[v][i];
						if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
							dist[e.to] = dist[v] + e.cost;
							prevv[e.to] = v;
							preve[e.to] = i;
							update = true;
						}
					}
				}
			}
			// ????????\???????????????
			if (dist[t] == kInfCost)
				return -1;
			// ?????????????????£??????????????????
			Flow d = f;
			for (int v = t; v != s; v = prevv[v])
				d = min(d, g[prevv[v]][preve[v]].cap);
			f -= d;
			total += dist[t] * d;
			for (int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.rev].cap += d;
			}
		}
		return total;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	BigInt w[52];
	w[0] = -1;
	rep(i, 0, 51) {
		w[i + 1] = w[i] * 2500;
	}
	reverse(w, w + 52);

	int N; cin >> N;
	vector<vector<BigInt>> a(N, vector<BigInt>(N));
	vector<vector<char>> c(N, vector<char>(N));
	rep(i, 0, N) rep(j, 0, N) {
		cin >> c[i][j];
		if (c[i][j] <= 'Z')
			a[i][j] = w[c[i][j] - 'A'];
		else
			a[i][j] = w[26 + c[i][j] - 'a'];
	}

	dump(a);

	MinimumCostFlow mcf(N + N + 2);
	int s = mcf.n - 2, t = s + 1;

	rep(i, 0, N) {
		rep(j, 0, N) {
			mcf.addArc(i, N + j, 1, a[i][j]);
		}
	}
	rep(i, 0, N) {
		mcf.addArc(s, i, 1, 0);
		mcf.addArc(N + i, t, 1, 0);
	}



	auto cost = mcf.minimumCostFlow(s, t, N);
	dump(cost);

	vector<char> ans;
	rep(i, 0, N) {
		rep(j, 0, N) {
			if (mcf.g[i][j].cap == 0) {
				ans.emplace_back(c[i][j]);
			}
		}
	}
	sort(all(ans));
	rep(i, 0, ans.size())
		cout << ans[i];
	cout << endl;
	return 0;
}
```