#include<cstdio> #include<iostream> #include<cstdlib> #include<iomanip> #include<cmath> #include<cstring> #include<string> #include<algorithm> #include<time.h> #include<queue> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pr; const double pi=acos(-1); #define rep(i,a,n) for(int i=a;i<=n;i++) #define per(i,n,a) for(int i=n;i>=a;i--) #define Rep(i,u) for(int i=head[u];i;i=Next[i]) #define clr(a) memset(a,0,sizeof a) #define pb push_back #define mp make_pair #define fi first #define sc second ld eps=1e-9; ll pp=1000000007; ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;} ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;} ll read(){ ll ans=0; char last=' ',ch=getchar(); while(ch<'0' || ch>'9')last=ch,ch=getchar(); while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar(); if(last=='-')ans=-ans; return ans; } //head const int N=1e6+5; int n,t,cnt; int ch[N][26],nxt[N],bo[N],ans[N]; char buf[1000001]; string s[500]; inline void build(string s,int id) { int now=1,len=s.size(); rep(i,0,len-1) { int c=s[i]-'a'; if(!ch[now][c]) { ch[now][c]=++cnt; }//如果还没有这个节点,就新创建一个节点 now=ch[now][c];//当前节点转移过去 } bo[now]=id;//给以节点now为终止节点的打上标记 } inline void get_nxt()//预处理nxt { queue<int> q; rep(i,0,25) ch[0][i]=1; //初始化0节点的所有转移边都指向1 nxt[1]=0;//初始化1的前缀指针指向0 q.push(1);//先让1入队 while(!q.empty()) { int now=q.front();//取出队首元素 q.pop(); rep(i,0,25) { int u=ch[now][i]; if(!u) //如果节点now没有以i为转移边的节点 ch[now][i]=ch[nxt[now]][i]; //就继续向前寻找now的前缀指针指向的节点以i为转移边的节点 else //如果节点now有以i为转移边的节点 { q.push(u);//先入队 int v=nxt[now]; nxt[u]=ch[v][i]; //节点的前缀指针为u的前缀指针通过转移边i连接的儿子 } } } } inline void find(string s) { int now=1,len=s.size();//访问当前节点 rep(i,0,len-1) { now=ch[now][s[i]-'a'];//更新节点 for(int j=now;j;j=nxt[j])ans[bo[j]]++; } return ; } int main() { while(scanf("%d",&n)!=EOF&&n) { memset(ch,0,sizeof(ch)); memset(nxt,0,sizeof(nxt)); memset(bo,0,sizeof(bo)); memset(ans,0,sizeof(ans)); cnt=1; rep(i,0,25) { ch[0][i]=1,ch[1][i]=0; } rep(i,1,n) { scanf("%s",buf); s[i]=buf; build(s[i],i); } get_nxt(); string t; scanf("%s",buf); t=buf; find(t); int temp=0; rep(i,1,n) { if(ans[i]>temp) temp=ans[i]; } printf("%d ",temp); rep(i,1,n) { if(ans[i]==temp) { strcpy(buf,s[i].c_str()); printf("%s ",buf); } } } return 0; }