#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define all(x) (x).begin(), (x).end()

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


bool is_equal(const string& a, const string& b) {
    for (int i = 0; i < (int)a.size(); ++i) {
        if (a[i] != '?' && b[i] != '?' && a[i] != b[i]) {
            return false;
        }
    }
    return true;
}

string get(const string& a, const string& b) {
    int m = min(a.size(), b.size());

    for (size_t i = m; i >= 1; --i) {
        if (is_equal(a.substr(a.size() - i), b.substr(0, i))) {
            string ret = a + b.substr(i);
            for (int j = 0; j < m; ++j) {
                if (b[j] != '?') {
                    ret[a.size() - i + j] = b[j];
                }
            }
            return ret;
        }
    }
    return a + b;
}

set<size_t> getv(const string& a, const string& b) {
    set<size_t> ret;
    ret.insert(a.size());

    for (size_t i = 0; i < a.size(); ++i) {
        int m = min(a.size() - i, b.size());
        if (is_equal(a.substr(i, m), b.substr(0, m))) {
            ret.insert(i);
        }
    }
    return ret;
}

string in(const string& a, const string& b) {
    if (a.size() >= b.size()) {
        int m = b.size();
        for (size_t i = 0; i < a.size() - b.size() + 1; ++i) {
            if (is_equal(a.substr(i, m), b)) {
                string ret = a;
                for (int j = 0; j < m; ++j) {
                    if (b[j] != '?') {
                        ret[i + j] = b[j];
                    }
                }
                return ret;
            }
        }
    }
    return a + b;
}

int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif
    vector<string> s(3);
    while (cin >> s[0]) {
        size_t ans = 0;
        for (int i = 1; i < 3; ++i) {
            cin >> s[i];
        }
        for (int i = 0; i < 3; ++i) {
            ans += s[i].size();
        }
        set<size_t> f[3][3];
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (i != j) {
                    f[i][j] = getv(s[i], s[j]);
                }
            }
        }

        vector<int> p = {0, 1, 2};
        do {
            int a = p[0];
            int b = p[1];
            int c = p[2];
            for (auto& dx : f[a][b]) {
                for (auto& dy : f[b][c]) {
                    size_t res = max(max(s[a].size(), s[b].size() + dx), s[c].size() + dx + dy);
                    if (res >= ans) {
                        break;
                    }
                    if (dx + dy > s[a].size() || f[a][c].count(dx + dy)) {
                        chmin(ans, res);
                    }
                }
                for (auto& dy : f[a][c]) {
                    size_t res = max(max(s[a].size(), s[b].size() + dx), s[c].size() + dy);
                    if (res >= ans || dy > dx) {
                        break;
                    }
                    if (dx - dy > s[c].size() || f[c][b].count(dx - dy)) {
                        chmin(ans, res);
                    }
                }
            }
        } while (next_permutation(all(p)));
        cout << ans << endl;
    }

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 512