// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;

#define fprintf(...) void(0)

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int can[2001][3][3];

int main() {
    vector<string> w(3);
    for(int i=0; i<3; i++) {
        cin >> w[i];
    }

    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            if(i == j) continue;
            for(size_t k=0; k<w[i].size(); k++) {
                int L = min<int>((int)w[i].size() - k, (int)w[j].size());
                can[k][i][j] = true;
                for(int x=0; x<L; x++) {
                    if(w[i][x+k] == '?' or w[j][x] == '?') continue;
                    can[k][i][j] &= (w[i][x+k] == w[j][x]);
                }

                if(can[k][i][j]) {
                    fprintf(stderr, "can[%d][%d][%d]\n", k, i, j);
                }
            }
        }
    }

    // 3 つとも重ねない
    int ans = w[0].size() + w[1].size() + w[2].size();

    // 2 つ (i, j) を重ねる
    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            if(i == j) continue;
            int cand = 0;

            // 関係ないやつ足す
            for(int k=0; k<3; k++) {
                if(i == k or j == k) continue;
                cand += w[k].size();
            }

            // かぶれる？
            int max_val = 0;
            for(size_t k=0; k<w[i].size(); k++) {
                int L = min<int>((int)w[i].size() - k, (int)w[j].size());
                if(can[k][i][j]) chmax(max_val, L);
            }

            cand += w[i].size() + w[j].size() - max_val;
            chmin(ans, cand);
        }
    }

    // 3 つとも重ねる、i が一番最初で j, k を適当なタイミングで
    for(int i=0; i<3; i++) {
        int j = -1, k = -1;
        for(int z=0; z<3; z++) {
            if(i == z) continue;
            if(j < 0) j = z;
            else if(k < 0) k = z;
        }

        for(int itr=0; itr<2; itr++) {
            // j を x 番目に、k を y 番目に配置しよう
            for(size_t x=0; x<w[i].size(); x++) {
                size_t lim = max(w[i].size(), x + w[j].size());
                for(size_t y=0; y<lim; y++) {
                    bool ok = true;
                    
                    // (i, j), (i, k)
                    ok &= can[x][i][j];
                    if(y < w[i].size()) ok &= can[y][i][k];
                    
                    fprintf(stderr, "stage 1: (%d, %d, %d) -> %zu, %zu\n", i, j, k, x, y);
                    if(!ok) continue;
                    
                    int l1 = x, r1 = x + w[j].size();
                    int l2 = y, r2 = y + w[k].size();
                    bool apart = false;
                    apart |= (r1 <= l2);
                    apart |= (r2 <= l1);
                    
                    if(!apart) {
                        if(l1 <= l2) {
                            int t = l2 - l1;
                            ok &= can[t][j][k];
                        }
                        if(l2 <= l1) {
                            int t = l1 - l2;
                            ok &= can[t][k][j];
                        }
                    }
                    
                    fprintf(stderr, "i = %d, j = %d, k = %d, x = %zu, y = %zu\n",
                            i, j, k, x, y);
                    
                    if(!ok) continue;
                    
                    fprintf(stderr, "i = %d, j = %d, k = %d, x = %zu, y = %zu\n",
                            i, j, k, x, y);
                    int v = max<int>({
                            (int)w[i].size(),
                                (int)x + (int)w[j].size(),
                                (int)y + (int)w[k].size()});
                    chmin(ans, v);
                }
            }
            swap(j, k);
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384