#include<bits/stdc++.h>
#define rgi register int
#define ll long long
const int maxn=6666;
std::string a,b,c; 
bool ab[maxn<<1],ac[maxn<<1],bc[maxn<<1];
int ans=maxn<<2;
inline bool cmp(char c1,char c2) {return c1==c2||c1=='?'||c2=='?';}
signed main()
{
	std::cin>>a>>b>>c; int lena=a.length(),lenb=b.length(),lenc=c.length();
	for(rgi i=0;i<lena;++i) for(rgi j=0;j<lenb;++j) if(!cmp(a[i],b[j])) ab[i-j+maxn]=1;
	for(rgi i=0;i<lena;++i) for(rgi j=0;j<lenc;++j) if(!cmp(a[i],c[j])) ac[i-j+maxn]=1;
	for(rgi i=0;i<lenb;++i) for(rgi j=0;j<lenc;++j) if(!cmp(b[i],c[j])) bc[i-j+maxn]=1;
	for(rgi i=-4001;i<=4001;++i) for(rgi j=-4001;j<=4001;++j)
		if(!ab[i+maxn]&&!ac[j+maxn]&&!bc[j-i+maxn])
			ans=std::min(ans,std::max(lena,std::max(i+lenb,j+lenc))-std::min(0,std::min(i,j)));
	std::cout<<ans;
	return 0;
}
// ----------------------------
// by imzzy
