This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct p_hash {
	const int mod = (int) 1e9 + 21;
	const int mod2 = (int) 1e9 + 33;
	const int b = 53;
	const int b2 = 47;
	int n;
	vector<long long> h, h2, pb, pb2;
	p_hash() {}
	p_hash(const string& s) {
		n = s.length();
		h.assign(n + 1, 0);
		h2.assign(n + 1, 0);
		pb.assign(n + 1, 1);
		pb2.assign(n + 1, 1);
		for (int i = 1; i <= n; i++) {
			pb[i] = pb[i - 1] * b % mod;
			pb2[i] = pb2[i - 1] * b2 % mod2;
		}
		for (int i = 0; i < n; i++) {
			h[i + 1] = (h[i] + (s[i] - 'a' + 1) * pb[i]) % mod;
			h2[i + 1] = (h2[i] + (s[i] - 'a' + 1) * pb2[i]) % mod2;
		}
	}
	pair<int, int> get(int l, int r) const {
		return {
			pb[n - l] * (h[r + 1] - h[l] + mod) % mod,
			pb2[n - l] * (h2[r + 1] - h2[l] + mod2) % mod2
		};
	}
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tt;
	cin >> tt;
	while (tt--) {
		string s;
		cin >> s;
		p_hash sh(s);
		int n = sh.n;
		int l = 0, r = n - 1, ans = 0;
		while (l <= r) {
			int ll = l, rr = r;
			while (1) {
				if (sh.get(l, ll) == sh.get(rr, r)) {
					break;
				}
				ll++;
				rr--;
			}
			if (rr <= ll) {
				ans++;
				break;
			}
			ans += 2;
			l = ll + 1;
			r = rr - 1;
		}
		cout << ans << '\n';
	}
	return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |