#include <bits/stdc++.h>
using namespace std;
const int M = 2005;
string s[3];
int cm[3][3][2 * M] = {0};
int comp(string &a, string &b, int of) {
  for (int i = 0; i < b.size(); i++) {
    int ai = of + i;
    if (ai >= a.size()) continue;
    if (b[i] == '?' || a[ai] == '?') continue;
    if (a[ai] != b[i]) return 0;
  }
  return 1;
}
int main() {
  cin >> s[0] >> s[1] >> s[2];
  int o[3] = {0};
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 2 * M; k++) cm[i][j][k] = 1;
  for (int b1 = 0; b1 < 3; b1++)
    for (int b2 = 0; b2 < 3; b2++) {
      if (b1 == b2) continue;
      for (int of = 0; of < s[b1].size(); of++)
        cm[b1][b2][of] = comp(s[b1], s[b2], of);
    }
  int res = 1e9;
  for (int b1 = 0; b1 < 3; b1++) {
    memset(o, 0, sizeof(o));
    int b2 = (b1 + 1) % 3, b3 = (b1 + 2) % 3;
    for (o[b2] = 0; o[b2] < 2 * M; o[b2]++)
      for (o[b3] = 0; o[b3] < 2 * M; o[b3]++) {
        if (cm[b1][b2][o[b2]] && cm[b1][b3][o[b3]] &&
            (o[b3] >= o[b2] ? cm[b2][b3][o[b3] - o[b2]]
                            : cm[b3][b2][o[b2] - o[b3]])) {
          int tmp = max(o[b2] + (int)s[b2].size(), o[b3] + (int)s[b3].size());
          if (tmp < res) {
            res = tmp;
          }
        }
      }
  }
  cout << res << "\n";
  return 0;
}
