#include <bits/stdc++.h>

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef pair <ll ,ll> pll;
typedef pair <int ,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define print(a) {for (auto iiiiiiiiii : a) cout << iiiiiiiiii << ' '; cout << '\n';}
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()

ll next() {ll x; cin >> x; return x;}

const ll inf = 1e18 , mod = 998244353;
const int intf = 2e9 , maxn = 3e5;
const double PI = 3.141592653589 , eps = 1e-9;

bool eq(char a , char b){
    return (a == '?' || b == '?' || a == b);
}

vector <bool> cnt(string a , string b){
    int n = a.size() , m = b.size();
    vector <bool> ans(n , false);
    for (int i = 0; i < n; i ++){
        bool brk = false;
        for (int j = 0; j < m && i + j < n; j ++){
            if (!eq(a[i + j] , b[j])){
                brk = true;
                break;
            }
        }
        if (!brk){
            ans[i] = true;
        }
    }
    return ans;
}

void solve(){
    string a[3];
    for (int i = 0; i < 3; i ++) cin >> a[i];

    vector < vector < vector <bool> > > d(3 , vector < vector <bool> > (3));
    for (int i = 0; i < 3; i ++){
        for (int j = 0; j < 3; j ++){
            if (i == j) continue;
            d[i][j] = cnt(a[i] , a[j]);
        }
    }
    int sz = a[0].size() + a[1].size() + a[2].size() , ans = sz;

    for (int i = 0; i < 3; i ++){
        int i1 = (i + 1) % 3 , i2 = (i + 2) % 3;
        //cout << i << ' ' << i1 << ' ' << i2 << '\n';
        for (int j = 0; j <= a[i].size(); j ++){
            for (int k = j; k <= max(a[i].size() , j + a[i1].size()); k ++){
                if ((j >= a[i].size() || d[i][i1][j]) && (k - j >= a[i1].size() || k < j || d[i1][i2][k - j]) && (k >= a[i].size() || d[i][i2][k])){
                    ans = min(ans , (int)max(a[i].size() , max(j + a[i1].size() , k + a[i2].size())));
                    //if ((int)max(a[i].size() , max(j + a[i1].size() , k + a[i2].size())) == 6) cout << i << ' ' << i1 << ' ' << i2 << '\n' << j << ' ' << k << '\n' << '\n';
                }
            }
        }
        swap(i1 , i2);
        //cout << i << ' ' << i1 << ' ' << i2 << '\n';
        for (int j = 0; j <= a[i].size(); j ++){
            for (int k = j; k <= max(a[i].size() , j + a[i1].size()); k ++){
                if ((j >= a[i].size() || d[i][i1][j]) && (k - j >= a[i1].size() || k < j || d[i1][i2][k - j]) && (k >= a[i].size() || d[i][i2][k])){
                    ans = min(ans , (int)max(a[i].size() , max(j + a[i1].size() , k + a[i2].size())));
                    //if ((int)max(a[i].size() , max(j + a[i1].size() , k + a[i2].size())) == 6) cout << i << ' ' << i1 << ' ' << i2 << '\n' << j << ' ' << k << '\n' << '\n';
                }
            }
        }
    }

    cout << ans;
}


int main()
{
    #ifdef HERE
        freopen("input.txt" , "r" , stdin);
    #else
        //freopen(".in" , "r" , stdin); freopen(".out" , "w" , stdout);
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(20);
    #endif

    for (int t = 1; t--;) solve();

    #ifdef HERE
        cout << setprecision(3) << fixed << "\n\nRuntime: " << (long double)(clock()) / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}
/*

*/


Measured memory_bytes: 256