#include <bits/stdc++.h>
using namespace std;
string s[3], tmp;
int ans = INT_MAX;
inline bool check(const string &s, const string &b, const int &x) {
  for (register int len = s.length(), i = len - x, j = 0; i < len; ++i)
    if (s[i] != '?' && b[j] != '?' && s[i] != b[j])
      return 0;
    else
      ++j;
  return 1;
}
inline void connect(string &s, const string &b) {
  register int ls = s.length(), lb = b.length(), i, j;
  if (ls > lb)
    for (i = 0; i < ls - lb; ++i)
      if (check(s, b, lb)) {
        for (j = 0; j < lb; ++j)
          if (s[i + j] == '?') s[i + j] = b[j];
        return;
      }
  for (i = min(ls, lb); i >= 0; --i)
    if (check(s, b, i)) {
      for (j = 0; j < i; ++j)
        if (s[ls - i + j] == '?') s[ls - i + j] = b[j];
      s += b.substr(i, lb - i);
      break;
    }
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> s[0] >> s[1] >> s[2];
  sort(s, s + 3);
  do {
    tmp = s[0];
    connect(tmp, s[1]);
    connect(tmp, s[2]);
    if (tmp.length() < ans) ans = tmp.length();
  } while (next_permutation(s, s + 3));
  cout << ans << endl;
  return 0;
}
