#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
using namespace std;
//#define int long long
#define ll long long
#define X first
#define Y second
#define lc (id<<1)
#define rc (lc|1)
#define mid ((l+r+1)>>1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define sep ' '
#define endl "\n"
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FileIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define all(x) x.begin(), x.end()
#define ret(x) {cout << x << endl; return;}
typedef pair<int, int> pii;
typedef pair<ll , ll > pll;
const int N = 2e6+13;
const int LOG = 23;
const int MOD = 1e9 + 7; //998244353; //1e9+9;
const int BASE = 691;
const int INF = 1e9; //1e18;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
ll md(ll x) {x%=MOD; return (x < 0 ? x+MOD : x);}
ll GCD(ll _a, ll _b) { return (!_b ? _a : GCD(_b, _a % _b)); }
ll POW(ll _a, ll _b) { return !_b ? 1 : ((_b & 1 ? _a : 1) * POW(_a * _a % MOD, _b / 2)) % MOD;}
int n, h1, h2, omit;
int p[N];
string s;
vector<int> ans;
void PREP() {
p[0] = 1;
for(int i = 1; i < N; i++) {
p[i] = md(p[i-1] * BASE);
}
}
void F() {
cin >> n >> s;
if(!(1&n)) ret("NOT POSSIBLE");
omit = n>>1;
for(int i = 0; i < (n>>1); i++) {
h1 = md(h1 + s[i] * p[i]);
}
for(int i = omit+1; i < n; i++) {
h2 = md(h2 + s[i] * p[i-omit-1]);
}
if(h1 == h2) ans.pb(omit);
while(omit > 0) {
h1 = md(h1 - s[omit-1] * p[omit-1]);
h1 = md(h1 + s[omit] * p[omit-1]);
omit --;
if(h1 == h2) ans.pb(omit);
}
omit = n>>1; h1 = h2 = 0;
for(int i = 0; i < (n>>1); i++) {
h1 = md(h1 + s[i] * p[i]);
}
for(int i = omit+1; i < n; i++) {
h2 = md(h2 + s[i] * p[i-omit-1]);
}
while(omit < n-1) {
h2 = md(h2 - s[omit+1] * p[omit-(n>>1)]);
h2 = md(h2 + s[omit] * p[omit-(n>>1)]);
omit ++;
if(h1 == h2) ans.pb(omit);
}
if(ans.empty()) ret("NOT POSSIBLE");
if(ans.size() > 1) ret("NOT UNIQUE");
string t = "";
for(int i = 0; i < n; i++) {
if(i != ans[0]) t.pb(s[i]);
}
while(t.size() > (n>>1)) t.pop_back();
ret(t);
}
int32_t main() {
migmig;
PREP();
int t=1;
//cin >> t;
while(t--)
F();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |