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() {
    string a, b, c;
    scan(a);
    scan(b);
    scan(c);

    auto A = a.length.to!int;
    auto B = b.length.to!int;
    auto C = c.length.to!int;

    auto ab = new bool[](20000);
    auto ac = new bool[](20000);
    auto bc = new bool[](20000);
    ab[] = ac[] = bc[] = true;

    bool match(char c1, char c2) {
        return c1 == '?' || c2 == '?' || c1 == c2;
    }

    foreach (i ; 0 .. A) {
        foreach (j ; 0 .. B) {
            if (!match(a[i], b[j])) {
                ab[i - j + 10000] = false;
            }
        }
    }

    foreach (i ; 0 .. A) {
        foreach (j ; 0 .. C) {
            if (!match(a[i], c[j])) {
                ac[i - j + 10000] = false;
            }
        }
    }

    foreach (i ; 0 .. B) {
        foreach (j ; 0 .. C) {
            if (!match(b[i], c[j])) {
                bc[i - j + 10000] = false;
            }
        }
    }

    int ans = inf;

    foreach (lb ; -4000 .. 4001) {
        foreach (lc ; -4000 .. 4001) {
            bool valid = ab[lb + 10000] && ac[lc + 10000] && bc[lc - lb + 10000];
            if (valid) {
                int l = min(lb, lc, 0);
                int r = max(lb + B, lc + C, A);
                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);
}
