#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
ll solve(string s,string t){
    if(s.size()>t.size())swap(s,t);
    ll n=s.size(),m=t.size();
    vi see;
    rep(i,n)if(s[i]!='?')see.pb(i);
    rep(i,m-s.size()+1){
        bool ok=true;
        for(auto x:see){
            if(s[x]!=t[x+i]&&t[x+i]!='?'){
                ok=false;
                break;
            }
        }
        if(ok)return m;
    }
    REP(i,1,s.size()){
        bool ok=true;
        for(auto x:see){
            if(x<i)continue;
            if(s[x]!=t[x-i]&&t[x-i]!='?'){
                ok=false;
                break;
            }
        }
        if(ok)return m+i;
        ok=true;
        for(auto x:see){
            if(x>=n-i)break;
            if(s[x]!=t[m-n+x+i]&&t[m-n+x+i]!='?'){
                //if(i==2)cout<<s[x]<<t[m-n+x+i]<<endl;
                ok=false;
                break;
            }
        }
        if(ok)return m+i;
    }
    return m+n;
}
int main(){
    string s,t,u;cin>>s>>t>>u;
    if(s.size()>t.size())swap(s,t);
    if(t.size()>u.size())swap(t,u);
    if(s.size()>t.size())swap(s,t);
    ll a=s.size(),b=t.size(),c=u.size();
    ll ans=a+b+c;
    for(int i=-b;i<=a;i++){
        string m;
        bool ok=true;
        //out(s);out(t);
        rep(j,i)m.pb(s[j]);
        rep(j,b){
            if(i+j<0||a<=i+j)m.pb(t[j]);
            else if(t[j]==s[i+j]||t[j]=='?')m.pb(s[i+j]);
            else if(s[i+j]=='?')m.pb(t[j]);
            else ok=false;
            if(!ok)break;
        }
        REP(j,i+b,a)m.pb(s[j]);
        //out(m);out(u);
        if(ok){
            if(ans>max(m.size(),u.size()))chmin(ans,solve(m,u));
            //cout<<m<<' '<<u<<' '<<solve(m,u)<<endl;
        }
        if(ans==max({a,b,c})){
            out(ans);
            return 0;
        }
    }
    for(int i=-c;i<=a;i++){
        string m;
        bool ok=true;
        //out(s);out(u);
        rep(j,i)m.pb(s[j]);
        rep(j,c){
            if(i+j<0||a<=i+j)m.pb(u[j]);
            else if(u[j]==s[i+j]||u[j]=='?')m.pb(s[i+j]);
            else if(s[i+j]=='?')m.pb(u[j]);
            else ok=false;
            if(!ok)break;
        }
        REP(j,i+c,a)m.pb(s[j]);
        //o//ut(m);out(u);
        if(ok){
            if(ans>max(m.size(),t.size()))chmin(ans,solve(m,t));
            //cout<<m<<' '<<t<<solve(m,t)<<endl;
        }
    }
    out(ans);
}

Measured memory_bytes: 256