import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = new string[](3);
    foreach (i; 0 .. 3)
        S[i] = sread();
    long M = S.map!"a.length"().reduce!(max);

    auto match = new bool[][][](3, 3, M * 3);
    foreach (x; 0 .. 3)
        foreach (y; 0 .. 3)
            loop_i: foreach (i; 0 .. M * 3)
            {
                if (S[x].length <= i)
                {
                    match[x][y][i] = true;
                    continue;
                }
                foreach (j; 0 .. M * 2)
                    if (j + i < S[x].length && j < S[y].length)
                        if (S[x][j + i] != S[y][j] && S[x][j + i] != '?' && S[y][j] != '?')
                        {
                            continue loop_i;
                        }
                match[x][y][i] = true;
            }
    // writeln(match[0][1]);
    auto p = [0, 1, 2];

    bool check(long i, long j)
    {
        auto A = p[0], B = p[1], C = p[2];
        if (!match[A][B][i])
            return false;
        if (!match[A][C][j])
            return false;
        if (!match[B][C][j - i])
            return false;
        return true;

    }

    long ans = long.max;
    do
    {
        foreach (i; 0 .. S[p[0]].length + 1)
            foreach (j; i .. max(S[p[0]].length, i + S[p[1]].length) + 1)
            {
                long len = max(S[p[0]].length, i + S[p[1]].length, j + S[p[2]].length);
                if (check(i, j) && len < ans)
                {
                    // writeln(i, " ", j, " ", len);
                    ans = len;
                }
                // writeln(i, " ", j, " ", i + S[2].length);
            }
    }
    while (nextPermutation(p));
    writeln(ans);
}
