Wrong Answer.wrong answer Too short on line 1.
#include<bits/stdc++.h>
#define gc getchar
#define eb emplace_back
#define ef emplace_front
#define ep emplace
#ifndef DEBUG
#define debug
#endif
using namespace std;
template<typename T>void read(T &x){x = 0;int f = 1;char c = gc();while(!isdigit(c)){if(c == '-') f = -1;c = gc();}while(isdigit(c)) x = x * 10 + c - '0',c = gc();x *= f;}
const int N = 300000,L = 300000;
int n,rt,cnt,cs[L][30],se[L],tot[L],p[L],apt[N],ans;
vector<int>q,v[L];
string s[N],t;
inline void crt(int &x){
x = ++ cnt;
for(int i = 0;i < 26;i ++) cs[x][i] = 0;
se[x] = tot[x] = 0;
}
inline void insert(const string &s,const int x){
int u = rt;
for(auto c : s){
c -= 'a';
if(!cs[u][c]) crt(cs[u][c]);
u = cs[u][c];
}
v[u].eb(x);
}
inline void build(){
int l = 0;
for(int i = 0;i < 26;i ++) if(cs[rt][i]) q.eb(cs[rt][i]);
while(l < q.size()){
int u = q[l];
for(int i = 0;i < 26;i ++){
if(cs[u][i]) p[cs[u][i]] = cs[p[u]][i],q.eb(cs[u][i]);
else cs[u][i] = cs[p[u]][i];
}
l ++;
}
}
inline void go(const string &t){
int u = rt;
for(auto c : t) c -= 'a',u = cs[u][c],tot[u] ++;
}
inline void cal(){
for(int i = q.size() - 1;~i;i --){
int x = q[i];
for(auto j : v[x]) apt[j] += tot[x];
tot[p[x]] += tot[x];
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cnt = -1;
crt(rt);
cin >> n;
for(int i = 1;i <= n;i ++) cin >> s[i],insert(s[i],i);
build();
for(int i = 1;i <= n;i ++) go(s[i]);
cal();
for(int i = 1;i <= n;i ++) printf("%d\n",apt[i]);
return 0;
}