//我真的没有口吃，标题里的第一个后缀自动机是题目名称，第二个是解决问题用的算法

# 2. 题解

OvO 模板题做到要崩溃

#include <bits/stdc++.h>

#define NS (2000005)

using namespace std;

typedef long long LL;

struct GRAPH
{
int head[NS], nxt[NS], to[NS], sz;
GRAPH() {memset(head, -1, sizeof(head)), sz = 0;}
void push(int a, int b)
{
nxt[sz] = head[a], to[sz] = b, head[a] = sz++;
}
int operator [] (const int a) const {return to[a];}
} g;

struct SAM
{
struct N
{
int nxt[26], pre, mxl, sz;
int& operator [] (const int a) {return nxt[a];}
} e[NS];
int lst, sz;
SAM() {lst = sz = 1;}
void insert(int c)
{
int a = ++sz, b = lst; lst = a, e[a].mxl = e[b].mxl + 1, e[a].sz = 1;
while (b && !e[b][c]) e[b][c] = a, b = e[b].pre;
if (!b) {e[a].pre = 1; return;}
int q = e[b][c];
if (e[q].mxl == e[b].mxl + 1) e[a].pre = q;
else
{
int nq = ++sz; e[nq] = e[q], e[nq].mxl = e[b].mxl + 1, e[nq].sz = 0;
e[nq].pre = e[q].pre, e[q].pre = e[a].pre = nq;
while (e[b][c] == q) e[b][c] = nq, b = e[b].pre;
}
}
} sam;

char s[NS];

int n;

LL mx;

void Dfs(int a)
{
for (int i = g.head[a]; ~i; i = g.nxt[i])
Dfs(g[i]), sam.e[a].sz += sam.e[g[i]].sz;
if (sam.e[a].sz != 1) mx = max(mx, 1ll * sam.e[a].mxl * sam.e[a].sz);
}

int main(int argc, char const* argv[])
{
scanf("%s", s), n = strlen(s);
for (int i = 0; i < n; i += 1) sam.insert(s[i] - 'a');
for (int i = 2; i <= sam.sz; i += 1) g.push(sam.e[i].pre, i);
Dfs(1), printf("%lld\n", mx);
return 0;
}