#include <bits/stdc++.h>
using namespace std;
char s[3][2005];
int len[3];
int cnt[3][3];
void solve(int x, int y) {
  for (int i = len[y] - 1; i >= 0; --i) {
    int j = len[x] - 1, k = i;
    while ((j >= 0 && k >= 0) &&
           (s[y][k] == s[x][j] || s[y][k] == '?' || s[x][j] == '?')) {
      --j, --k;
    }
    if (j < 0) {
      cnt[x][y] = len[x];
      return;
    } else if (k < 0) {
      cnt[x][y] = i + 1;
      return;
    }
  }
}
int main() {
  cin >> s[0] >> s[1] >> s[2];
  for (int i = 0; i < 3; ++i) len[i] = strlen(s[i]);
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      if (i != j) solve(i, j);
  int sum = len[0] + len[1] + len[2];
  int ans = sum;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      if (i != j && 3 - i - j >= 0) {
        ans = min(ans, min(sum - cnt[j][i] - cnt[i][3 - i - j],
                           sum - cnt[3 - i - j][i] - cnt[i][j]));
      }
  cout << ans << endl;
}
