1 #include<iostream>
2 #include<string>
3 #include<algorithm>
4 #include<cstdio>
5 #include<cstring>
6 #include<cstdlib>
7 #include<cmath>
8 #include<map>
9 using namespace std;
10 typedef long long s64;
11
12 const int ONE = 400005;
13 const int INF = 2147483640;
14
15 int n,x;
16 s64 Ans;
17
18 int get()
19 {
20 int res=1,Q=1;char c;
21 while( (c=getchar())<48 || c>57 )
22 if(c==‘-‘)Q=-1;
23 res=c-48;
24 while( (c=getchar())>=48 && c<=57 )
25 res=res*10+c-48;
26 return res*Q;
27 }
28
29 struct SAM
30 {
31 map <int, int> a[ONE];
32 int len[ONE], fa[ONE];
33 int last, cnt;
34 SAM() {last = cnt = 1;}
35 void Add(int c)
36 {
37 int x = last, New = last = ++cnt;
38 len[New] = len[x] + 1;
39 while(x && !a[x][c]) a[x][c] = New, x = fa[x];
40 if(!x) {fa[New] = 1; Ans += len[New] - len[fa[New]]; return;}
41
42 int q = a[x][c];
43 if(len[x] + 1 == len[q]) fa[New] = q;
44 else
45 {
46 int Nq = ++cnt; len[Nq] = len[x] + 1;
47 a[Nq] = a[q];
48 fa[Nq] = fa[q];
49 fa[New] = fa[q] = Nq;
50 while(a[x][c] == q) a[x][c] = Nq, x = fa[x];
51 }
52 Ans += len[New] - len[fa[New]];
53 }
54 }S;
55
56 int main()
57 {
58 n = get();
59 while(n--)
60 {
61 x = get();
62 S.Add(x);
63 printf("%lld\n", Ans);
64 }
65
66 }