import sys input = sys.stdin.readline def read_values(): return tuple(map(int, input().split())) def read_list(): return list(map(int, input().split())) class PalindromicTree: def __init__(self): self.st=[] self.length=[-1,0] self.parent=[0,0] self.count=[0,0] self.link=[dict() for _ in range(2)] self.lastNodeIdx=0 def add(self,v): self.st.append(v) prevNodeIdx=self.lastNodeIdx nextNodeIdx=self.lastNodeIdx while True: head = self.length[nextNodeIdx] + 2 if head <= len(self.st) and self.st[-head]==self.st[-1]: break nextNodeIdx=self.parent[nextNodeIdx] nextLen=self.length[nextNodeIdx]+2 if v in self.link[nextNodeIdx].keys(): self.lastNodeIdx=self.link[nextNodeIdx][v] self.count[self.lastNodeIdx]+=1 return self.lastNodeIdx=len(self.length) self.length.append(nextLen) if self.length[-1]==1: self.parent.append(1) else: prevNodeIdx=self.parent[nextNodeIdx] while True: head = self.length[prevNodeIdx] + 2 if head <= len(self.st) and self.st[-head]==self.st[-1]: break prevNodeIdx=self.parent[prevNodeIdx] self.parent.append(self.link[prevNodeIdx][v]) self.count.append(1) self.link[nextNodeIdx][v]=self.lastNodeIdx self.link.append(dict()) def main(): s=input() pt = PalindromicTree() for i in range(len(s)): pt.add(s[i]) nodeCount = len(pt.length) count=pt.count[:] for i in range(nodeCount-1,1,-1): count[pt.parent[i]]+=count[i] score=[-1]*nodeCount score[0]=0 score[1]=0 for i in range(nodeCount): if score[i]!=-1: continue stk=[i] while score[stk[-1]]==-1: stk.append(pt.parent[stk[-1]]) tmp=score[stk[-1]] stk.pop() for v in stk[::-1]: tmp+=pt.length[v]*count[v] score[v]=tmp print(max(score)) if __name__ == "__main__": main()