#include <bits/stdc++.h>
using namespace std;
string a, b, c;
bool ab[100000], ac[100000], bc[100000];
bool match(char c1, char c2) { return (c1 == '?' || c2 == '?' || c1 == c2); }
int search(string a, string b, int i, int j) {
  if (a.size() < i || b.size() < j) {
    return 0;
  } else if (a.size() < i) {
    return 0;
  } else if (b.size() < j) {
    return search(a, b, ++i, 0);
  }
  if (a[i] == b[j]) {
    cout << "HER2" << endl;
    return search(a, b, ++i, ++j);
  } else if (a[i] != b[j]) {
    cout << "HERE" << endl;
    return search(a, b, i, ++j);
  }
  return 0;
}
int main() {
  int i, j;
  cin >> a;
  cin >> b;
  cin >> c;
  int A = a.length();
  int B = b.length();
  int C = c.length();
  int M = (A + B + C);
  for ((i) = 0; (i) < (int)(A); (i)++) {
    for ((j) = 0; (j) < (int)(B); (j)++) {
      if (!match(a[i], b[j])) {
        ab[i - j + 50000] = true;
      }
    }
  }
  for ((i) = 0; (i) < (int)(A); (i)++) {
    for ((j) = 0; (j) < (int)(C); (j)++) {
      if (!match(a[i], c[j])) {
        ac[i - j + 50000] = true;
      }
    }
  }
  for ((i) = 0; (i) < (int)(B); (i)++) {
    for ((j) = 0; (j) < (int)(C); (j)++) {
      if (!match(b[i], c[j])) {
        bc[i - j + 50000] = true;
      }
    }
  }
  int ans = M;
  for (i = -M; i <= M; i++) {
    for (j = -M; j <= M; j++) {
      if (!ab[i + 50000] && !ac[j + 50000] && !bc[j - i + 50000]) {
        int L = min(0, min(i, j));
        int R = max(A, max(B + i, C + j));
        ans = min(ans, R - L);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
