struct pam{ int S[maxn]; int len[maxn], fail[maxn], last, n; int ch[maxn][30], cnt[maxn], tot, id[maxn]; void init() { tot = 0; newnode(0);newnode(-1);last = 0; last = 0;n = 0;S[n] = -1;fail[0] = 1; } int newnode(int x) { len[tot] = x; cnt[tot] = fail[tot] = 0; for(int i = 0; i < 26; i++) ch[tot]...