#include <bits/stdc++.h>
using namespace std;
inline void Input_Output() {}
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const long long MOD = 1e18 + 9;
const long long INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;
const int M = 22;
const int pri = 997;
const int Magic = 2101;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n;
string s[5];
int p[5];
bool can(char a, char b) {
  if (a == '?') return 1;
  if (b == '?') return 1;
  return (a == b);
}
bool St[3][3][4020];
inline int calc() {
  memset(St, 1, sizeof St);
  for (int i = 0; i < 2; i++) {
    for (int j = i + 1; j < 3; ++j) {
      for (int st = 0; st <= (int)(s[p[i]].size()); ++st) {
        bool bad = 0;
        for (int k = 0;
             k < (int)(s[p[i]].size()) - st && k < (int)(s[p[j]].size()); ++k)
          if (!can(s[p[i]][st + k], s[p[j]][k])) {
            bad = 1;
            break;
          }
        St[i][j][st] = !bad;
      }
    }
  }
  int ans = inf;
  for (int s1 = 0; s1 <= (int)(s[p[0]].size()); ++s1)
    if (St[0][1][s1]) {
      for (int s2 = 0; s2 <= (int)(s[p[1]].size()); ++s2)
        if (St[1][2][s2] && St[0][2][s1 + s2]) {
          int cur = (int)(s[p[0]].size());
          cur = max(cur, s1 + (int)(s[p[1]].size()));
          cur = max(cur, s1 + s2 + (int)(s[p[2]].size()));
          ans = min(ans, cur);
        }
    }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int res = 0;
  for (int i = 0; i < 3; ++i) {
    cin >> s[i];
    p[i] = i;
    res += (int)(s[i].size());
  }
  do {
    int x = calc();
    res = min(res, x);
  } while (next_permutation(p, p + 3));
  cout << res << '\n';
  return 0;
}
