（然而这题实际上暴力跑的最快）

#include <bits/stdc++.h>

#define NS (100005)
#define MOD (1000000007)
#define LS(a) ((a) << 1)
#define RS(a) ((a) << 1 | 1)

using namespace std;

inline int pls(int a, int b)
{
return a + b < MOD ? a + b : a + b - MOD;
}

inline int mul(int a, int b) { return 1ll * a * b % MOD; }

template<typename _Tp> inline void IN(_Tp &dig)
{
char c; bool flag = 0; dig = 0;
while (c = getchar(), !isdigit(c)) if (c == '-') flag = 1;
while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
if (flag) dig = -dig;
}

int n, lst[NS], D[NS << 1], V[NS << 3], S[NS << 3], tag[NS << 3];

char s[NS];

void build(int l, int r, int a)
{
if (l == r) { V[a] = D[l]; return; }
int mid = (l + r) >> 1;
build(l, mid, LS(a)), build(mid + 1, r, RS(a));
V[a] = pls(V[LS(a)], V[RS(a)]);
}

void pup(int a) { S[a] = pls(S[LS(a)], S[RS(a)]); }

void pdown(int a)
{
if (!tag[a]) return;
int l = LS(a), r = RS(a);
S[l] = pls(S[l], mul(tag[a], V[l]));
S[r] = pls(S[r], mul(tag[a], V[r]));
tag[l] = pls(tag[l], tag[a]);
tag[r] = pls(tag[r], tag[a]);
tag[a] = 0;
}

int _query(int l, int r, int L, int R, int a)
{
if (l <= L && R <= r) return S[a];
pdown(a);
int Mid = (L + R) >> 1, res = 0;
if (l <= Mid) res = _query(l, r, L, Mid, LS(a));
if (r > Mid) res = pls(res, _query(l, r, Mid + 1, R, RS(a)));
return res;
}

void _add(int l, int r, int L, int R, int a)
{
if (l <= L && R <= r) { S[a] = pls(S[a], V[a]), tag[a]++; return; }
pdown(a);
int Mid = (L + R) >> 1;
if (l <= Mid) _add(l, r, L, Mid, LS(a));
if (r > Mid) _add(l, r, Mid + 1, R, RS(a));
pup(a);
}

struct SAM
{
struct N
{
int nxt[26], l, f;
int & operator [] (const char c) { return nxt[c - 'a']; }
} e[NS << 1];
int lst, sz;
SAM() { lst = sz = 1; }
void insert(char c)
{
int a = ++sz, p = lst;
e[a].l = e[p].l + 1, lst = a;
while (p && !e[p][c]) e[p][c] = a, p = e[p].f;
if (!p) { e[a].f = 1; return; }
int q = e[p][c];
if (e[q].l == e[p].l + 1) { e[a].f = q; return; }
int nq = ++sz;
e[nq] = e[q], e[nq].l = e[p].l + 1, e[a].f = e[q].f = nq;
while (e[p][c] == q) e[p][c] = nq, p = e[p].f;
}
vector<int> g[NS << 1];
int top[NS << 1], id[NS << 1], dfn;
void tree() { for (int i = 1; i <= sz; i += 1) g[e[i].f].push_back(i); }
void dfs(int a)
{
if (!top[a]) top[a] = a;
id[a] = ++dfn, D[dfn] = e[a].l - e[e[a].f].l;
if (g[a].empty()) return;
int nxt = g[a][rand() % g[a].size()];
top[nxt] = top[a], dfs(nxt);
for (int i = 0; i < g[a].size(); i += 1)
if (g[a][i] != nxt) dfs(g[a][i]);
}
int query(int a)
{
int res = 0;
while (a)
{
res = pls(res, _query(id[top[a]], id[a], 1, sz, 1));
a = e[top[a]].f;
}
return res;
}
{
while (a)
{
a = e[top[a]].f;
}
}
} sam;

int main(int argc, char const* argv[])
{
srand(19260817), IN(n), scanf("%s", s + 1);
for (int i = 1; i <= n; i += 1) sam.insert(s[i]), lst[i] = sam.lst;
sam.tree(), sam.dfs(1), build(1, sam.sz, 1);
for (int i = 1, ans = 0, dt = 0; i <= n; i += 1)
{
dt = pls(dt, sam.query(lst[i])), ans = pls(ans, dt);