#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; struct palindromic_tree { struct Node { int link; int len; int l,r; vectorto; Node(int Link,int Len,int L,int R) { link = Link; len = Len; l = L; r = R; to.resize(26,-1); } }; vectornodes; vectorlens; vectorcnt; palindromic_tree(string s) { nodes.push_back(Node(-1,-1,0,-1)); nodes.push_back(Node(0,0,0,0)); int pre = 0; for(int i = 0; i < s.size(); i++) { lens.push_back(pre); while(pre) { int j = i-1-nodes[pre].len; if(j >= 0 && s[j] == s[i]) { break; } pre = nodes[pre].link; } if(nodes[pre].to[s[i]-'a'] != -1) { pre = nodes[pre].to[s[i]-'a']; continue; } int nxt = nodes.size(); int l = i-1-nodes[pre].len; int r = i+1; nodes[pre].to[s[i]-'a'] = nxt; int link = -1; if(pre == 0) { link = 1; } else { while(true) { pre = nodes[pre].link; int j = i-1-nodes[pre].len; if(j >= 0 && s[j] == s[i]) { break; } } link = nodes[pre].to[s[i]-'a']; } nodes.push_back(Node(link,r-l,l,r)); pre = nxt; } lens.push_back(pre); cnt.resize(nodes.size()); for(int i = 0; i < s.size(); i++) { cnt[lens[i+1]]++; } for(int i = nodes.size()-1; i >= 2; i--) { cnt[nodes[i].link] += cnt[i]; } } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; palindromic_tree tr(s); vectordp(tr.nodes.size()); for(int i = 2; i < tr.nodes.size(); i++) { dp[i] = 1ll*tr.cnt[i]*tr.nodes[i].len; dp[i] += dp[tr.nodes[i].link]; } cout << *max_element(dp.begin(),dp.end()) << "\n"; }