#include <bits/stdc++.h>
using namespace std;
string s[3];
bool b[3][3][2005][2005];
bool match(char c1, char c2) {
  if (c1 == '?' || c2 == '?') return true;
  return c1 == c2;
}
void solve() {
  for (int i = 0; i < 3; i++) cin >> s[i];
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (i == j) continue;
      int l1 = s[i].size();
      int l2 = s[j].size();
      for (int k = 0; k <= l1; k++) {
        b[i][j][k][0] = true;
        for (int l = 1; l + k <= l1 && l <= l2; l++) {
          if (!match(s[i][l1 - l - k], s[j][l2 - l])) break;
          b[i][j][k + l][l] = true;
        }
      }
      for (int k = 0; k <= l2; k++) {
        b[i][j][0][k] = true;
        for (int l = 1; l + k <= l2 && l <= l1; l++) {
          if (!match(s[i][l1 - l], s[j][l2 - l - k])) break;
          b[i][j][l][l + k] = true;
        }
      }
    }
  int ans = 0;
  for (int i = 0; i < 3; i++) ans += s[i].size();
  vector<int> v(3);
  for (int i = 0; i < 3; i++) v[i] = i;
  while (true) {
    int l1 = s[v[0]].size();
    int l2 = s[v[1]].size();
    int l3 = s[v[2]].size();
    for (int x = 0; x <= l2; x++) {
      for (int y = 0; y <= l1; y++) {
        int c = l2 - x;
        if (!b[v[1]][v[2]][c][l3]) continue;
        c = l1 - y;
        if (!b[v[0]][v[1]][c][l2]) continue;
        c = l1 - (x + y);
        if (c < 0) c = 0;
        if (!b[v[0]][v[2]][c][l3]) continue;
        int las = max({l1, l2 + y, l3 + x + y});
        if (las < ans) cout << x << ' ' << y << endl;
        ans = min(ans, las);
      }
    }
    if (!next_permutation((v).begin(), (v).end())) break;
  }
  cout << ans << endl;
}
signed main() {
  solve();
  return 0;
}
