1 #include <queue>
2 #include <cstdio>
3 #include <cstring>
4 #include <algorithm>
5 using namespace std;
6 #define maxn 100005
7 int last[maxn];
8 int f[maxn];
9 struct Trie{
10 int ch[maxn][33];
11 int val[maxn];
12 int sz;
13 Trie(){ sz = 1; memset(ch[0],0,sizeof ch[0]); }
14 void insert(char *p, int v){
15 int u=0,n = strlen(p);
16 for (int i = 0; i < n; i++){
17 int c = p[i] - 'a';
18 if (!ch[u][c]){
19 memset(ch[sz], 0, sizeof sz);
20 val[sz] = 0;
21 ch[u][c] = sz++;
22 }
23 u = ch[u][c];
24 }
25 val[u] = v;
26 }
27 void getfail(){
28 queue<int>q;
29 f[0] = 0;
30 for (int c = 0; c < 33; c++){
31 int u = ch[0][c];
32 if (u){ q.push(u); f[u] = last[u]= 0; }
33 }
34 while (!q.empty()){
35 int r = q.front(); q.pop();
36 for (int c = 0; c < 33; c++){
37 int u = ch[r][c];
38 if (!u)continue;
39 int v = f[r];
40 while (v&&!ch[v][c])v = f[v];
41 f[u] = ch[v][c];
42 last[u] = val[f[u]] ? f[u] : last[f[u]];
43 }
44 }
45 }
46 void print(int i, int j){
47 if (j)printf("%d: %d\n", i, val[j]);
48 print(i, last[j]);
49 }
50 int find(char *s){
51 int n = strlen(s);
52 int j = 0;
53 for (int i = 0; i < n; i++){
54 int c = s[i] - 'a';
55 while (j&&!ch[j][c])j = f[j];
56 j = ch[j][c];
57 if (val[j])print(i, j);
58 else if (last[j])print(i, last[j]);
59 }
60 }
61 };
62 int main(){
63 int t;
64 scanf("%d", &t);
65 return 0;
66 }