#include <bits/stdc++.h>
using namespace std;
bool same(char a, char b) { return a == b || a == '?' || b == '?'; }
string s[3];
int match_cache[3][3][2000 + 2000 + 10];
bool match(int i1, int start, int i2) {
  ;
  if (match_cache[i1][i2][start] != 0) {
    return match_cache[i1][i2][start] == 1 ? true : false;
  }
  string a = s[i1];
  string b = s[i2];
  bool ans = true;
  for (int i = start; i <= a.size() - 1; i++) {
    if (i - start + 1 >= b.size()) {
      break;
    }
    if (!same(a[i], b[i - start])) {
      ans = false;
      break;
    }
  }
  match_cache[i1][i2][start] = ans ? 1 : -1;
  return ans;
}
int solve(int i1, int i2, int i3) {
  string a = s[i1];
  string b = s[i2];
  string c = s[i3];
  int alen = a.size();
  int blen = b.size();
  int clen = c.size();
  int ans = alen + blen + clen;
  for (int i = 0; i <= alen + max(blen, clen); i++) {
    if (!match(i1, i, i2)) {
      continue;
    }
    for (int j = i; j <= alen + max(blen, clen); j++) {
      if (!match(i1, j, i3) || !match(i2, j - i, i3)) {
        continue;
      }
      int b_end = i + blen - 1;
      int c_end = j + clen - 1;
      int len = max(alen, max(b_end + 1, c_end + 1));
      ans = min(ans, len);
    }
  }
  return ans;
}
string rand_s(int n) {
  string a = "";
  for (int i = 0; i <= n - 1; i++) {
    bool q_mark = rand() < RAND_MAX / 10;
    if (q_mark) {
      a.push_back('?');
    } else {
      char c = rand() % 26 + 'a';
      a.push_back(c);
    }
  }
  return a;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> s[0] >> s[1] >> s[2];
  int ans = s[0].size() + s[1].size() + s[2].size();
  for (int i = 0; i <= 2; i++) {
    for (int j = 0; j <= 2; j++) {
      if (i != j) {
        for (int k = 0; k <= 2; k++) {
          if (i != k && j != k) {
            ans = min(ans, solve(i, j, k));
          }
        }
      }
    }
  }
  cout << ans << '\n';
}
