详见代码
WA ON #5
在输入 S 之后,n 的值不同
// #include<cassert>
// #include<cctype>
// #include<climits>
// #include<cmath>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstring>
// #include<ctime>
// #include<algorithm>
// using std::lower_bound;
// using std::max;
// using std::min;
// using std::next_permutation;
// using std::reverse;
// using std::sort;
// using std::swap;
// using std::unique;
// using std::upper_bound;
// #include<bitset>
// using std::bitset;
// #include<deque>
// using std::deque;
// #include<fstream>
// using std::ifstream;
// using std::ofstream;
// #include<iomanip>
// using std::fixed;
// using std::setprecision;
// #include<iostream>
// using std::cin;
// using std::cout;
// using std::ios;
// #include<list>
// using std::list;
// #include<map>
// using std::map;
// #include<memory>
// using std::make_unique;
// using std::move;
// using std::unique_ptr;
// #include<queue>
// using std::priority_queue;
// using std::queue;
// #include<stack>
// using std::stack;
// #include<set>
// using std::multiset;
// using std::set;
// #include<sstream>
// using std::stringstream;
// #include<string>
// using std::getline;
// using std::string;
// using std::to_string;
// #include<utility>
// using std::make_pair;
// using std::pair;
// #include<unordered_map>
// using std::unordered_map;
// #include<unordered_set>
// using std::unordered_set;
// #include<vector>
// using std::vector;
// #include<windows.h>
#define UP(i,a,b) for(i=a;i<=(b);++i)
#define DN(i,a,b) for(i=a;i>=(b);--i)
#define up(i,a,b) for(i=a;i<(b);++i)
#define dn(i,a,b) for(i=a;i>(b);--i)
#define pai make_pair
#define gtch() char(getchar())
#define ptch putchar
#define EXIT() system("pause");\
return 0
typedef unsigned char unc;
typedef unsigned short uns;
typedef unsigned uni;
typedef unsigned long unl;
typedef long long ll;
typedef unsigned long long ull;
bool ___f;
char ___c,___a[45],*___p;
typedef __int128 pll;
typedef unsigned __int128 upll;
void rd(pll &r){r=0;___f=false;for(___c=gtch();___c<'0'||___c>'9';___c=gtch()){___f=(___c=='-');}for(;___c>='0'&&___c<='9';___c=gtch()){r=(r<<3)+(r<<1)+(___c^'0');}if(___f){r=~(r-1);}}
void rd(upll &r){r=0;for(___c=gtch();___c<'0'||___c>'9';___c=gtch());for(;___c>='0'&&___c<='9';___c=gtch()){r=(r<<3)+(r<<1)+(___c^'0');}}
void wt(pll r){if(!r){ptch('0');return;}if(r<0){ptch('-');r=~(r-1);}___p=___a;while(r!=0){++___p;*___p=char(r%10)^'0';r/=10;}while(___p!=___a){ptch(*___p);--___p;}}
void wt(upll r){if(!r){ptch('0');return;}___p=___a;while(r!=0){++___p;*___p=char(r%10)^'0';r/=10;}while(___p!=___a){ptch(*___p);--___p;}}
void rd(bool &r){r=false;for(___c=gtch();___c<'0'||___c>'9';___c=gtch());for(;___c>='0'&&___c<='9';___c=gtch()){r|=bool(___c^'0');}}
void rd(char &c){for(c=gtch();c==' '||c=='\r'||c=='\n';c=gtch());}
void rd(short &r){r=0;___f=false;for(___c=gtch();___c<'0'||___c>'9';___c=gtch()){___f=(___c=='-');}for(;___c>='0'&&___c<='9';___c=gtch()){r=(r<<3)+(r<<1)+(short)(___c^'0');}if(___f){r=~(r-1);}}
void rd(int &r){r=0;___f=false;for(___c=gtch();___c<'0'||___c>'9';___c=gtch()){___f=(___c=='-');}for(;___c>='0'&&___c<='9';___c=gtch()){r=(r<<3)+(r<<1)+(___c^'0');}if(___f){r=~(r-1);}}
void rd(long &r){r=0;___f=false;for(___c=gtch();___c<'0'||___c>'9';___c=gtch()){___f=(___c=='-');}for(;___c>='0'&&___c<='9';___c=gtch()){r=(r<<3)+(r<<1)+(___c^'0');}if(___f){r=~(r-1);}}
void rd(ll &r){r=0;___f=false;for(___c=gtch();___c<'0'||___c>'9';___c=gtch()){___f=(___c=='-');}for(;___c>='0'&&___c<='9';___c=gtch()){r=(r<<3)+(r<<1)+(___c^'0');}if(___f){r=~(r-1);}}
void rd(unc &c){for(c=gtch();c==' '||c=='\r'||c=='\n';c=gtch());}
void rd(uns &r){r=0;for(___c=gtch();___c<'0'||___c>'9';___c=gtch());for(;___c>='0'&&___c<='9';___c=gtch()){r=(r<<3)+(r<<1)+(uns)(___c^'0');}}
void rd(uni &r){r=0;for(___c=gtch();___c<'0'||___c>'9';___c=gtch());for(;___c>='0'&&___c<='9';___c=gtch()){r=(r<<3)+(r<<1)+(___c^'0');}}
void rd(unl &r){r=0;for(___c=gtch();___c<'0'||___c>'9';___c=gtch());for(;___c>='0'&&___c<='9';___c=gtch()){r=(r<<3)+(r<<1)+(___c^'0');}}
void rd(ull &r){r=0;for(___c=gtch();___c<'0'||___c>'9';___c=gtch());for(;___c>='0'&&___c<='9';___c=gtch()){r=(r<<3)+(r<<1)+(___c^'0');}}
void rd(char *s){for(*s=gtch();*s==' '||*s=='\r'||*s=='\n';*s=gtch());for(;~*s&&*s!=' '&&*s!='\r'&&*s!='\n';++s,*s=gtch());*s=0;}
void rd(char *s,char n){for(*s=gtch();*s==' '||*s=='\r'||*s=='\n';*s=gtch());for(;~*s&&*s!=n;++s,*s=gtch());*s=0;}
void wt(bool a){ptch('0'+a);}
void wt(char c){ptch(c);}
void wt(short r){if(!r){ptch('0');return;}if(r<0){ptch('-');r=~(r-1);}___p=___a;while(r!=0){++___p;*___p=char(r%10)^'0';r/=10;}while(___p!=___a){ptch(*___p);--___p;}}
void wt(int r){if(!r){ptch('0');return;}if(r<0){ptch('-');r=~(r-1);}___p=___a;while(r!=0){++___p;*___p=char(r%10)^'0';r/=10;}while(___p!=___a){ptch(*___p);--___p;}}
void wt(long r){if(!r){ptch('0');return;}if(r<0){ptch('-');r=~(r-1);}___p=___a;while(r!=0){++___p;*___p=char(r%10)^'0';r/=10;}while(___p!=___a){ptch(*___p);--___p;}}
void wt(ll r){if(!r){ptch('0');return;}if(r<0){ptch('-');r=~(r-1);}___p=___a;while(r!=0){++___p;*___p=char(r%10)^'0';r/=10;}while(___p!=___a){ptch(*___p);--___p;}}
void wt(unc c){ptch(c);}
void wt(uns r){if(!r){ptch('0');return;}___p=___a;while(r!=0){++___p;*___p=char(r%10)^'0';r/=10;}while(___p!=___a){ptch(*___p);--___p;}}
void wt(uni r){if(!r){ptch('0');return;}___p=___a;while(r!=0){++___p;*___p=char(r%10)^'0';r/=10;}while(___p!=___a){ptch(*___p);--___p;}}
void wt(unl r){if(!r){ptch('0');return;}___p=___a;while(r!=0){++___p;*___p=char(r%10)^'0';r/=10;}while(___p!=___a){ptch(*___p);--___p;}}
void wt(ull r){if(!r){ptch('0');return;}___p=___a;while(r!=0){++___p;*___p=char(r%10)^'0';r/=10;}while(___p!=___a){ptch(*___p);--___p;}}
void wt(char *s){for(;*s;++s){ptch(*s);}}
void wt(const char *s){for(;*s;++s){ptch(*s);}}
#ifdef _GLIBCXX_STRING
void rd(std::string &s){s.clear();for(___c=gtch();___c==' '||___c=='\r'||___c=='\n';___c=gtch());for(;~___c&&___c!=' '&&___c!='\r'&&___c!='\n';___c=gtch()){s.push_back(___c);}}
void wt(std::string s){wt(s.data());}
#endif
template<typename T,typename ...T1>void rd(T &a,T1 &...b){rd(a);rd(b...);}
template<typename T,typename ...T1>void wt(T a,T1 ...b){wt(a);wt(b...);}
template<typename T>void RD(T* a,int n=1){while(n--){rd(*a);++a;}}
ll llabs_(ll a){return a<0?-a:a;}
/*
*/
const int N(2e5+5);
char s[N];
int n,ans[N],num[N];
struct ac_node{
int num,ans,du;
ac_node *son[26],*fail;
ac_node():fail(nullptr){
memset(son,0,sizeof son);
}
}t[N],*tot(t);
struct queue{
ac_node *a[N],**h,**t;
void push(ac_node* k){*t=k;++t;}
void pop(){++h;}
ac_node* front(){return *h;}
ull size(){return t-h;}
void clear(){h=t=a;}
}q;
void insert(char *s,int i){
int c;
ac_node *p(t);
while(*s){
c=*s-'a';++s;
if(!p->son[c]){
p->son[c]=++tot;
}
p=p->son[c];
}
if(!p->num){
p->num=i;
}
num[i]=p->num;
}
void init(){
int i;
ac_node *p(t);
q.clear();
p->fail=t;
up(i,0,26){
// printf("%p\n",p->son[i]);
if(p->son[i]){
p->son[i]->fail=t;
++p->son[i]->fail->du;
q.push(p->son[i]);
}else{
p->son[i]=t;
}
}
while(q.size()){
p=q.front();q.pop();
up(i,0,26){
if(p->son[i]){
p->son[i]->fail=p->fail->son[i];
++p->son[i]->fail->du;
q.push(p->son[i]);
}else{
p->son[i]=p->fail->son[i];
}
}
}
}
void query(char *s){
int c;
ac_node *p(t);
while(*s){
c=*s-'a';++s;
p=p->son[c];
++p->ans;
}
}
void topo(){
ac_node *u,*v;
q.clear();
UP(u,t,tot){
if(!u->du){
q.push(u);
}
}
while(q.size()){
u=q.front();q.pop();
ans[u->num]=u->ans;
v=u->fail;
v->ans+=u->ans;
if(!--v->du){
q.push(v);
}
}
}
int main(){
int i;
freopen("P5357_5.in","r",stdin);
scanf("%d",&n);
UP(i,1,n){
scanf("%s",s);
insert(s,i);
}
printf("n=%d\n",n);
// std::string S;
scanf("%s",s);//this
printf("n=%d\n",n);
return 0;
init();
query(s);
topo();
UP(i,1,n){
wt(ans[num[i]],'\n');
}
EXIT();
return 0;
}