题目链接:https://codeforces.com/contest/25/problem/E
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
static const int MAXN=3e5+10;
char s[3][MAXN];
int ans,l[3],seq[3],nxt[MAXN];
void get_next(int k)
{
for(int i=2,j=0;i<=l[k];i++)
{
while(j && s[k][i]!=s[k][j+1]) j=nxt[j];
if(s[k][i]==s[k][j+1]) j++;
nxt[i]=j;
}
}
int kmp(int a,int b)
{
get_next(b);
int j=0;
for(int i=1;i<=l[a];i++)
{
while(j && s[a][i]!=s[b][j+1]) j=nxt[j];
if(s[a][i]==s[b][j+1]) j++;
if(j==l[b]) return j;
}
return j;
}
int calc(int a,int b,int c)
{
char tmp[MAXN]; int lt;
int t=kmp(a,b);
memcpy(tmp,s[a],sizeof(tmp)); lt=l[a];
int res=l[a]+l[b]-t;
for(int i=1;i<=l[b]-t;i++) s[a][l[a]+i]=s[b][t+i];
l[a]=res;
t=kmp(a,c);
memcpy(s[a],tmp,sizeof(s[a])); l[a]=lt;
res=res+l[c]-t;
return res;
}
int main()
{
for(int i=0;i<3;i++)
{
scanf("%s",s[i]+1);
l[i]=strlen(s[i]+1);
ans+=l[i];
seq[i]=i;
}
do{
ans=min(ans,calc(seq[0],seq[1],seq[2]));
}while(next_permutation(seq,seq+3));
printf("%d\n",ans);
return 0;
}