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;
    auto n = iota(3).map!(i => s[i].length.to!int).array;

    // s[x] の左から k 番目に s[y] が重なることは出来るか
    bool check(int x, int y, int k) {
        if (k >= n[x]) {
            return true;
        }
        foreach (i ; 0 .. n[y]) {
            if (k + i >= n[x]) break;
            if (s[x][k + i] == '?' || s[y][i] == '?') continue;
            if (s[x][k + i] !=  s[y][i]) {
                return false;
            }
        }

        return true;
    }

    auto ok = new bool[][][](3, 3, 2001);
    foreach (i ; 0 .. 3) {
        foreach (j ; 0 .. 3) {
            if (i == j) continue;
            foreach (k ; 0 .. 2001) {
                ok[i][j][k] = check(i, j, k);
            }
        }
    }

    int ans = inf;

    foreach (lb ; -4000 .. 4001) {
        foreach (lc ; -4000 .. 4001) {
            bool valid = true;

            if (abs(lb) >= 2000) {
            }
            else if (lb < 0) {
                valid &= ok[1][0][-lb];
            }
            else {
                valid &= ok[0][1][lb];
            }

            if (abs(lc) >= 2000) {
            }
            else if (lc < 0) {
                valid &= ok[2][0][-lc];
            }
            else {
                valid &= ok[0][2][lc];
            }

            if (abs(lb - lc) >= 2000) {
            }
            else if (lb < lc) {
                valid &= ok[1][2][lc - lb];
            }
            else {
                valid &= ok[2][1][lb - lc];
            }

            if (valid) {
                int l = min(lb, lc, 0);
                int r = max(lb + n[1], lc + n[2], n[0]);
                chmin(ans, r - l);
            }
        }
    }

    writeln(ans);
}



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);
}
