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 k = new int[][](3, 3);
    foreach (i ; 0 .. 3) {
        foreach (j ; 0 .. 3) {
            if (i == j) continue;
            k[i][j] = f(i, j, s);
        }
    }

    auto p = iota(3).array;

    int d = 0;

    do {
        int t = k[p[0]][p[1]] + k[p[1]][p[2]];
        chmax(d, t);
    } while(nextPermutation(p));

    int ans;
    foreach (i ; 0 .. 3) {
        ans += s[i].length.to!int;
    }
    ans -= d;
    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;

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



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