# Description

``````    讀入單詞
計算最長公共子串的長度
輸出結果
``````

1<=n<=5

# Code

``````#include <stdio.h>
#include <string.h>
#include <algorithm>
#define rep(i,st,ed) for (int i=st;i<=ed;  i)
#define fill(x,t) memset(x,t,sizeof(x))
#define copy(x,t) memcpy(x,t,sizeof(x))

const int N=200005;

int rec[N][26],fa[N],len[N];
int tmp[N],f[N];
int last,cnt;
bool vis[N];
char str[6][N];

void extend(char ch) {
int p,q,np,nq;
p=last; last=np=  cnt;
while (p&&!rec[p][ch]) {
rec[p][ch]=np;
p=fa[p];
}
if (!p) fa[np]=1;
else {
q=rec[p][ch];
if (len[p] 1==len[q]) fa[np]=q;
else {
int nq=  cnt; len[nq]=len[p] 1;
copy(rec[nq],rec[q]);
fa[nq]=fa[q];
fa[q]=fa[np]=nq;
while (p&&rec[p][ch]==q) {
rec[p][ch]=nq;
p=fa[p];
}
}
}
}

void solve(char *str) {
fill(tmp,0);
int now=1,l=0;
rep(i,0,strlen(str)-1) {
while (now&&!rec[now][str[i]-'a']) {
now=fa[now];
l=len[now];
vis[now]=1;
tmp[now]=std:: max(tmp[now],l);
}
if (!now) {
now=1;
l=0;
}
now=rec[now][str[i]-'a'];
l  ;
vis[now]=1;
tmp[now]=std:: max(tmp[now],l);
}
rep(i,1,cnt) f[i]=std:: min(f[i],tmp[i]);
}

int main(void) {
int n; scanf("%d",&n);
rep(i,1,n) scanf("%s",str[i]);
cnt=last=1;
rep(i,0,strlen(str[1])-1) extend(str[1][i]-'a');
fill(f,31);
rep(i,2,n) solve(str[i]);
int ans=0;
rep(i,1,cnt) ans=std:: max(ans,f[i]);
printf("%d\n", ans);
return 0;
}``````