#include<iostream> #include<cstring> #include<vector> #include<algorithm> #define maxn 100010 #define ll long long usingnamespacestd;
int n;
int cnt[4][maxn];
char s[maxn];
vector<int> A[4];
int ch[256], p[4], hc[4]; voidwork(){ cin >> s + 1; n = strlen(s + 1); for (int i = 0; i < 4; ++i) { A[i].clear(); for (int j = 1; j <= n; ++j) cnt[i][j] = 0; } for (int i = 1; i <= n; ++i) cnt[ch[s[i]]][i] = 1, A[ch[s[i]]].push_back(i); for (int i = 0; i < 4; ++i) for (int j = 1; j <= n; ++j) cnt[i][j] += cnt[i][j - 1]; for (int i = 0; i < 4; ++i) p[i] = i; ll ans = 0; int Ans[4] = { 0, 1, 2, 3 }; do { ll sum = 0; for (int i = 0; i < 4; ++i) for (auto u : A[p[i]]) for (int j = i + 1; j < 4; ++j) sum += cnt[p[j]][u]; if (sum > ans) { for (int i = 0; i < 4; ++i) Ans[i] = p[i]; ans = sum; } } while (next_permutation(p, p + 4)); for (int i = 0; i < 4; ++i) for (int j = 1; j <= A[Ans[i]].size(); ++j) cout << (char) hc[Ans[i]]; cout << "\n"; }