import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    auto s = iota(3).map!(i => readln.chomp).array;

    int ans = inf;

    foreach (x ; 0 .. 3) {
        foreach (y ; 0 .. 3) {
            if (x == y) continue;

            string[] koho;

            int n = s[x].length.to!int;
            int m = s[y].length.to!int;

            foreach (k ; 0 .. n + 1) {
                string str;
                bool ok = true;
                foreach (j ; 0 .. k) {
                    str ~= s[x][j];
                }
                foreach (j ; 0 .. m) {
                    if (k + j >= n) {
                        str ~= s[y][j];
                    }
                    else if (s[x][k + j] == '?') {
                        str ~= s[y][j];
                    }
                    else if (s[x][k + j] == s[y][j]) {
                        str ~= s[y][j];
                    }
                    else {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    koho ~= str;
                }
            }

            debug {
                writeln(koho);
            }

            foreach (kohoi ; koho) {
                foreach (i ; 0 .. 3) {
                    if (i == x || i == y) continue;

                    if (allIn(kohoi, s[i])) {
                        chmin(ans, kohoi.length.to!int);
                        continue;
                    }

                    int nn = kohoi.length.to!int;
                    int mm = s[i].length.to!int;
                    
                    foreach_reverse (k ; 1 .. min(nn, mm) + 1) {
                        bool ok = true;

                        foreach (j ; 0 .. k) {
                            if (kohoi[nn - k + j] == '?' || s[i][j] == '?') {
                                continue;
                            }
                            if (kohoi[nn - k + j] != s[i][j]) {
                                ok = false;
                                break;
                            }
                        }

                        if (ok) {
                            chmin(ans, nn + mm - k);
                        }
                    }
                }
            }
        }
    }
    writeln(ans);
}

// s[x]のsuffix と s[y]のprefix の最大一致を求めたい
int f(int x, int y, string[] s) {
    int n = s[x].length.to!int;
    int m = s[y].length.to!int;

    if (n >= m && allIn(s[x], s[y])) {
        return m;
    }

    int res;

    foreach (k ; 1 .. min(n, m) + 1) {
        bool ok = true;

        foreach (i ; 0 .. k) {
            if (s[x][n - k + i] == '?' || s[y][i] == '?') continue;
            if (s[x][n - k + i] != s[y][i]) {
                ok = false;
                break;
            }
        }

        if (ok) {
            chmax(res, k);
        }
    }

    return res;
}
    
// t が s に完全に含まれているか？
bool allIn(string s, string t) {
    if (s.length < t.length) {
        return false;
    }

    int n = s.length.to!int;
    int m = t.length.to!int;

    foreach (i ; 0 .. n - m + 1) {
        bool ok = true;
        foreach (j ; 0 .. m) {
            if (s[i + j] == '?' || t[j] == '?') continue;
            if (s[i + j] != t[j]) ok = false;
        }
        if (ok) {
            return true;
        }
    }

    return false;
}

unittest {
    assert(allIn("abcde", "bcd"));
    assert(!allIn("abcde", "bce"));
    assert(allIn("ab", "ab"));
    assert(allIn("mississipi", "i?sissip?"));
    assert(allIn("?????", "ab"));
}


void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}
