P6140
30pts
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
char s[N];
int main()
{
string ans = "";
int n;
cin >> n;
for(int i = 0;i < n;i ++ ) {
cin >> s[i];
}
int i = 0, j = n - 1;
while(i < j)
{
if(s[i] < s[j]) {
ans += s[i];
i ++ ;
}
else if(s[i] > s[j]){
ans += s[j];
j -- ;
}
else {
// cout << i << ' ' << j << endl;
int lx = 0;
for(lx = 1; ; lx ++ )
{
if(s[i + lx] != s[j - lx]) break;
}
// cout << s[j - lx] << endl;
if(s[i + lx] < s[j - lx])
{
for(int k = 0;k <= lx;k ++ ) {
ans += s[i + k];
}
i += (lx + 1);
}
if(s[i + lx] > s[j - lx])
{
for(int k = 0;k <= lx;k ++ ) {
ans += s[j - k];
}
j -= (lx + 1);
}
}
}
ans += s[i];
// cout << ans.size() << endl;
for(int i = 0;i < n;i ++ ) {
cout << ans[i];
if((i + 1) % 80 == 0) {
puts("");
}
}
return 0;
}