#include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << ", " << p.second << ')'; } template::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pi; const int mxN = 1e5+1, oo = 1e9; const int SIG = 26; const char firstC = 'a'; struct smallmap { int to[SIG] = {}; int& operator[](char c) { return to[c-firstC]; } }; struct eertree { struct node { smallmap to; // can store extra stuff! int len,link,occ; ll best=0; }; vector nd = {{},{}}; string s = "$"; int at=1,n=1; eertree() { nd[0].len=-1; } bool good(int at, char c) { return s[n-1-nd[at].len]==c; } void addNode(int p, char c) { int nw = nd.size(); nd.push_back({}); nd[nw].len=nd[p].len+2; auto& lnk = nd[nw].link = nd[p].link; while(lnk and !good(lnk,c)) lnk = nd[lnk].link; lnk = nd[lnk].to[c]; lnk+=!lnk; nd[p].to[c]=nw; } void add(char c) { s.push_back(c); while(true) { if(good(at,c)) { if(!nd[at].to[c]) addNode(at,c); at = nd[at].to[c]; break; } else at = nd[at].link; // if rollbacking is needed, don't traverse suffix links in a dumb way. } n++; nd[at].occ++; } ll findbest() { ll best=0; for(int i=nd.size()-1;i>1;--i) { nd[nd[i].link].occ+=nd[i].occ; best = max(best,nd[i].len*ll(nd[i].occ)); } for(int i=1;i> s; eertree et; for(auto c : s) et.add(c); cout << et.findbest() << '\n'; }