#include <bits/stdc++.h>

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}



void check(const string &a, const string &b, map<int, bool> &mp) {
  for(int i=0;i<SZ(b);++i) {
    bool ok = true;
    for(int j=0;j<min(SZ(a), SZ(b)-i);++j) {
      if(a[j] != b[i+j] && a[j] != '?' && b[i+j] != '?') {
        ok = false;
        break;
      }
    }
    if(ok) mp[-i] = true;
  }
  for(int i=0;i<SZ(a);++i) {
    bool ok = true;
    for(int j=0;j<min(SZ(b), SZ(a)-i);++j) {
      if(b[j] != a[i+j] && b[j] != '?' && a[i+j] != '?') {
        ok = false;
        break;
      }
      
    }
    if(ok) mp[i] = true;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string a, b, c; cin >> a >> b >> c;
  map<int, bool> mpab, mpac, mpba, mpbc, mpca, mpcb;

  check(a, b, mpab);
  check(b, c, mpbc);
  check(c, a, mpca);
  mpab[SZ(a)] = true;
  mpab[-SZ(b)] = true;
  mpbc[SZ(b)] = true;
  mpbc[-SZ(c)] = true;
  mpca[SZ(c)] = true;
  mpca[-SZ(a)] = true;
  for(const auto &e: mpab) {
    //cout << "ab:" << e << endl;
    mpba[-e.first] = true;
  }
  for(const auto &e: mpbc) {
    //cout << "bc:" << e << endl;
    mpcb[-e.first] = true;
  }
  for(const auto &e: mpca) {
    //cout << "ca:" << e <<endl;
    mpac[-e.first] = true;
  }

  int mi = SZ(a) + SZ(b) + SZ(c);
  for(const auto &e1: mpab) {
    if(!e1.second) continue;
    for(const auto &e2: mpac) {
      if(!e2.second) continue;
      if(mpbc[e2.first - e1.first] || e2.first - e1.first >= SZ(b) || e1.first - e2.first >= SZ(c)) {
        int beg = min(0, min(e1.first, e2.first));
        int ed = max(SZ(a), max(e1.first + SZ(b), e2.first + SZ(c)));
        mi = min(mi, ed - beg);
      }
    }
  }
  for(const auto &e1: mpba) {
    if(!e1.second) continue;
    for(const auto &e2: mpbc) {
      if(!e2.second) continue;
      if(mpac[e2.first - e1.first] || e2.first - e1.first >= SZ(a) || e1.first - e2.first >= SZ(c)) {
        int beg = min(0, min(e1.first, e2.first));
        int ed = max(SZ(b), max(e1.first + SZ(a), e2.first + SZ(c)));
        mi = min(mi, ed - beg);
      }
    }
  }
  for(const auto &e1: mpca) {
    if(!e1.second) continue;
    for(const auto &e2: mpcb) {
      if(!e2.second) continue;
      if(mpab[e2.first - e1.first] || e2.first - e1.first >= SZ(a) || e1.first - e2.first >= SZ(b)) {
        //cout << e1.first << ":" << e2.first << endl;
        int beg = min(0, min(e1.first, e2.first));
        int ed = max(SZ(c), max(e1.first + SZ(a), e2.first + SZ(b)));
        mi = min(mi, ed - beg);
      }
    }
  }

  cout << mi << endl;

}


Measured memory_bytes: 1664