import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void combine(char[] x, char[] y, ref char[] r) {
    foreach (i; 0..x.length) {
        r.length = max(x.length, i + y.length);
        foreach (j; 0..i) r[j] = x[j];
        size_t j, l;
        foreach (k; i..x.length) {
            if (j == y.length) break;
            if (x[k] != '?' && y[j] != '?' && x[k] != y[j]) goto ng;
            if (x[k] == '?' && y[j] == '?') {
                r[k] = '?';
            } else if (x[k] == '?') {
                r[k] = y[j];
            } else {
                r[k] = x[k];
            }
            ++j;
        }
        if (i+j < x.length) {
            foreach (k; i+j..x.length) r[k] = x[k];
        } else {
            auto k = x.length;
            while (j < y.length) r[k++] = y[j++];
        }
        return;
        ng:
    }
    r.length = 0;
    foreach (xx; x) r ~= xx;
    foreach (yy; y) r ~= yy;
    return;
}

int solve(char[] a, char[] b, char[] c)
{
    char[] r1, r2, r3;
    combine(a, b, r1);
    combine(c, r1, r2);
    combine(r1, c, r3);
    return min(r2.length.to!int, r3.length.to!int);
}

void main()
{
    auto a = readln.chomp.to!(char[]);
    auto b = readln.chomp.to!(char[]);
    auto c = readln.chomp.to!(char[]);

    writeln(min(
        solve(a, b, c),
        solve(a, c, b),
        solve(b, a, c),
        solve(b, c, a),
        solve(c, a, b),
        solve(c, b, a)
    ));
}