#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
void solve() {
int n;
cin >> n;
string s;
cin >> s;
if (n % 2 == 0) {
cout << "NOT POSSIBLE";
return;
}
set<int> ans;
set<ar<int,2>> bugs;
for (int i = 0; i < n / 2;i++) {
if (s[i] != s[i + n / 2 + 1]) bugs.insert({i, i + n / 2 + 1});
}
auto bl = bugs;
auto br = bugs;
for (int r = n / 2; r < n - 1;r++) {
int l = r - n / 2;
if (s[l] != s[r + 1]) bl.erase({l,r + 1});
if (s[l] != s[r]) bl.insert({l,r});
if (bl.empty()) ans.insert(r + 1);
}
for (int l = n /2 - 1; l >= 0; l--) {
int r = l + n / 2 + 1;
if (s[l] != s[r]) br.erase({l,r});
if (s[l + 1] != s[r]) br.insert({l + 1, r});
if (br.empty()) ans.insert(l);
}
if (ans.size() > 1) cout << "NOT UNIQUE";
else if (ans.empty()) cout << "NOT POSSIBLE";
else {
int cnt = 0,ok = 0;
for (int i = 0; cnt < n / 2;i++) {
if (ok == 0 && ans.count(i)) {
ok = 1;
continue;
}
cout << s[i];
cnt++;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
cout << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |