#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
bool d[3][3][2005];
int main() {
  vector<string> s(3);
  for (int i = 0; i < (int)(3); i++) cin >> s[i];
  sort(s.begin(), s.end());
  int ans = 2005 * 3;
  do {
    for (int i = 0; i < (int)(3); i++)
      for (int j = 0; j < (int)(3); j++)
        for (int k = 0; k < (int)(s[i].size()); k++) {
          bool ok = true;
          for (int ni = k; ni < s[i].size(); ni++) {
            int nj = ni - k;
            if (nj >= s[j].size()) break;
            if (s[i][ni] == s[j][nj] || s[j][nj] == '?' || s[i][ni] == '?')
              continue;
            ok = false;
          }
          d[i][j][k] = ok;
        }
    auto f = [&](int i, int j, int k) {
      if (k >= s[i].size()) return true;
      return d[i][j][k];
    };
    for (int x = 0; x < (int)(2005); x++)
      for (int y = 0; y < (int)(2005); y++) {
        if (!f(0, 1, x)) continue;
        if (!f(1, 2, y)) continue;
        if (!f(0, 2, y)) continue;
        int now = 0;
        now = max<int>(now, s[0].size());
        now = max<int>(now, x + s[1].size());
        now = max<int>(now, x + y + s[2].size());
        ans = min(ans, now);
      }
  } while (next_permutation(s.begin(), s.end()));
  cout << ans << endl;
  return 0;
}
