#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string a,b,c;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        // freopen(output.c_str(), "w", stdout);
    #endif
    cin >> a >> b >> c;
}

// x+y
string lcm_str(string x, string y){
    string ret;
    string tmp;
    for (int i = 0; i < x.size(); i++)
    {
        bool isok=true;
        bool xout=false;
        tmp = "";
        for (int j = 0; j < y.size(); j++)
        {
            if(i+j>=x.size()){xout=true; continue;} 
            if(x[i+j]==y[j] || x[i+j]=='?' ||  y[j]=='?') {
                tmp += (x[i+j]==y[j]) ? x[i+j] : ((x[i+j]=='?') ? y[j]:x[i+j]);
                continue;
                }
            else isok=false;
        }
        if(isok) {
            if(xout) ret = x.substr(0,i)+tmp+y.substr(tmp.size());
            else ret = x.substr(0,i)+tmp+x.substr(i+tmp.size());
            return ret;
            }
    }

    for (int i = 0; i < y.size(); i++)
    {
        bool isok=true;
        bool yout=false;
        tmp = "";
        for (int j = 0; j < x.size(); j++)
        {
            if(i+j>=y.size()){yout=true; continue;} 
            if(y[i+j]==x[j] || y[i+j]=='?' ||  x[j]=='?') {
                tmp += (y[i+j]==x[j]) ? y[i+j] : ((y[i+j]=='?') ? x[j]:y[i+j]);
                continue;
                }
            else isok=false;
        }
        if(isok) {
            if(yout) ret = y.substr(0,i)+tmp+x.substr(tmp.size());
            else ret = y.substr(0,i)+tmp+y.substr(i+tmp.size());
            return ret;
            }
    }

    ret = x+y;
    return ret;
}

// greedyにやると?の位置によって答えが異なってくる。
int greedy(){
    string ab = lcm_str(a,b);
    string ac = lcm_str(a,c);
    string ba = lcm_str(b,a);
    string bc = lcm_str(b,c);
    string ca = lcm_str(c,a);
    string cb = lcm_str(c,b);
    string abc = lcm_str(ab,c);
    string acb = lcm_str(ac,b);
    string bac = lcm_str(ba,c);
    string bca = lcm_str(bc,a);
    string cab = lcm_str(ca,b);
    string cba = lcm_str(cb,a);
    int ans=0;
    // DBG(ab)
    DBG(abc)
    DBG(acb)
    DBG(bac)
    DBG(bca)
    DBG(cab)
    DBG(cba)
    ans=min({abc.size(),acb.size(),bac.size(),bca.size(),cab.size(),cba.size()});
    cout << ans << endl;
    return 0;
}

bool cmp(char x, char y){
    return (x==y||x=='?'||y=='?');
}

bool isOk(string a, string b, string c,int i, int j){
    bool ans=true;
    int ida,idb,idc;
    a+='?';
    b+='?';
    c+='?';
    int sza=a.size();
    int szb=b.size();
    int szc=c.size();
    
    // 互いに共通部分を持たないとき
    if(sza<=i && i+szb<=j) return true;
    if(sza<=j && j+szc<=i) return true;
    for (int k = min(i,j); k < max({sza,i+szb,j+szc}); k++)
    {
        ida=(k<sza)?k:sza-1;
        idb=((k-i)>=0&&(k-i)<szb)?(k-i):szb-1;
        idc=((k-j)>=0&&(k-j)<szc)?(k-j):szc-1;
        if(cmp(a[ida],b[idb]) && cmp(a[ida],c[idc]) && cmp(c[idc],b[idb])) continue;
        else return false;
    }
    return true;
}

int TLEsolve(){
    int ans=60000;
    int sza=a.size();
    int szb=b.size();
    int szc=c.size();
    int laxtid;
    int idM = sza+szb+szc-min({sza,szb,szc});
    for (int i = 0; i < idM; i++)
    {
        for (int j = 0; j < idM; j++)
        {
            if(isOk(a,b,c,i,j)) {
                laxtid = max({sza,i+szb,j+szc});
                ans=min(ans,laxtid);
                }
            if(isOk(b,c,a,i,j)) {
                laxtid = max({szb,i+szc,j+sza});
                ans=min(ans,laxtid);
                }
            if(isOk(c,a,b,i,j)) {
                laxtid = max({szc,i+sza,j+szb});
                ans=min(ans,laxtid);
                }
        }
        
    }
    cout << ans << endl;
    return 0;
}

#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)

int solve(){
    int M=2000;
    int ans=3*M;
    // map<int,bool> ab,bc,ac;
    const int L=50000;
    array<bool,2*L> ab,bc,ac;
    // bool ab[2*L],bc[2*L],ac[2*L];
    int A=a.length();
    int B=b.length();
    int C=c.length();
    rep(i,A) rep(j,B) if(!cmp(a[i],b[j])) ab[i-j+L]=true;
    rep(i,A) rep(j,C) if(!cmp(a[i],c[j])) ac[i-j+L]=true;
    rep(i,B) rep(j,C) if(!cmp(b[i],c[j])) bc[i-j+L]=true;
    for (int i = -2*M; i <= 2*M; i++) for (int j = -2*M; j <= 2*M; j++)
        if(!ab[i+L] && !ac[j+L] && !bc[j-i+L]){
            int L=min({0,i,j});
            int R=max({A,B+i,C+j});
            ans = min(ans,R-L);
        }
    cout << ans << endl;
    return 0;
}

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 636