import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      auto S = new string[3];
      foreach (i; 0 .. 3) {
        S[i] = readToken();
      }
      auto L = new int[3];
      foreach (i; 0 .. 3) {
        L[i] = cast(int)(S[i].length);
      }
      
      auto oks = new bool[][][](3, 3);
      foreach (i; 0 .. 3) foreach (j; i + 1 .. 3) {
        // [-L[j], L[i]]
        oks[i][j] = new bool[L[j] + L[i] + 1];
        foreach (k; -L[j] .. L[i] + 1) {
          bool ok = true;
          foreach (x; 0 .. L[i]) {
            if (0 <= x - k && x - k < L[j]) {
              ok = ok && (S[i][x] == '?' || S[j][x - k] == '?' || S[i][x] == S[j][x - k]);
            }
          }
          oks[i][j][L[j] + k] = ok;
        }
      }
      
      int ans = L[0] + L[1] + L[2];
      foreach (k1; -L[2] - L[1] .. L[0] + L[2] + 1) {
        const l = min(0, k1);
        const r = max(L[0], k1 + L[1]);
        foreach (k2; l - L[2] .. r + 1) {
          bool ok = true;
          if (-L[1] <= k1 && k1 <= L[0]) {
            ok = ok && oks[0][1][L[1] + k1];
          }
          if (-L[2] <= k2 && k2 <= L[0]) {
            ok = ok && oks[0][2][L[2] + k2];
          }
          if (-L[2] <= k2 - k1 && k2 - k1 <= L[1]) {
            ok = ok && oks[1][2][L[2] + k2 - k1];
          }
          if (ok) {
            const ll = min(l, k2);
            const rr = max(r, k2 + L[2]);
            chmin(ans, rr - ll);
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
