#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long n;
string s;
cin >> n >> s;
if((n - 1) % 2){
cout << "NOT POSSIBLE";
return 0;
}
long long k = (n - 1) / 2;
long long l = 0, r = k + 1;
while(l < k && s[l] == s[r]){
l++;
r++;
}
vector<long long> cands;
if(l == k){
cands.push_back(k);
} else {
cands.push_back(l);
cands.push_back(r);
}
long long cnt = 0;
string answer;
set<string> seen;
cands.push_back(n - 1);
for(long long i : cands) {
if(i < 0 || i >= n) continue;
string t = s.substr(0, i) + s.substr(i + 1);
if(t.substr(0, k) == t.substr(k)) {
string half = t.substr(0, k);
if(seen.count(half)) continue;
seen.insert(half);
cnt++;
if(cnt > 1) {
cout << "NOT UNIQUE";
return 0;
}
answer = half;
}
}
if(cnt == 0)
cout << "NOT POSSIBLE";
else
cout << answer;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |