#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const double eps = 1e-9;
int ab[20005], bc[20005], ac[20005];
string a, b, c;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> a >> b >> c;
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < b.size(); j++) {
      if (a[i] != b[j] && a[i] != '?' && b[j] != '?') {
        ab[j - i + 10000] = 1;
      }
    }
  }
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < c.size(); j++) {
      if (a[i] != c[j] && a[i] != '?' && c[j] != '?') {
        ac[j - i + 10000] = 1;
      }
    }
  }
  for (int i = 0; i < b.size(); i++) {
    for (int j = 0; j < c.size(); j++) {
      if (b[i] != c[j] && b[i] != '?' && c[j] != '?') {
        bc[j - i + 10000] = 1;
      }
    }
  }
  int ans = 1e9;
  for (int i = -4000; i <= 4000; i++) {
    for (int j = -4000; j <= 4000; j++) {
      if (ab[-i + 10000] || ac[-j + 10000] || bc[i - j + 10000]) continue;
      int mx = max({(int)a.size(), i + (int)b.size(), j + (int)c.size()});
      int mi = min({0, i, j});
      ans = min(ans, mx - mi);
    }
  }
  cout << ans << '\n';
}
