rt,AC自动机写挂了
#include <bits/stdc++.h>
#define N 1000010
using namespace std;
int n;
bool vis[N];
string s[210], str;
int ans[210], same[N], ed[N];
int tot = 0, fail[N], trie[N][26], cnt[N];
void add(string s, int x) {
int p = 0, len = s.size();
for(int i = 0; i < len; ++i) {
int num = s[i] - 'a';
if(!trie[p][num]) trie[p][num] = ++tot;
p = trie[p][num];
++cnt[p];
}
if(ed[p])
same[x] = ed[p];
else
ed[p] = x;
}
void getfail() {
queue<int> q;
for(int i = 0; i < 26; ++i) {
if(trie[0][i]) {
fail[trie[0][i]] = 0;
q.push(trie[0][i]);
}
}
while(!q.empty()) {
int now = q.front();
q.pop();
for(int i = 0; i < 26; ++i) {
if(trie[now][i]) {
fail[trie[now][i]] = trie[fail[now]][i];
q.push(trie[now][i]);
} else
trie[now][i] = trie[fail[now]][i];
}
}
}
void query(string str) {
int now = 0, len = str.size();
for(int i = 0; i < len; ++i) {
now = trie[now][str[i] - 'a'];
for(int j = now; j; j = fail[j])
if(ed[j] && !vis[now]) ans[ed[j]] += cnt[now];
vis[now] = true;
}
}
int main() {
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> s[i];
add(s[i], i);
}
getfail();
for(int i = 1; i <= n; ++i)
if(!same[i]) query(s[i]);
for(int i = 1; i <= n; ++i) {
if(!same[i])
printf("%d\n", ans[i]);
else
printf("%d\n", ans[same[i]]);
}
return 0;
}