#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  string A, B, C, D, E, F;
  ll ans = 10000;
  ll as = a.size();
  ll bs = b.size();
  ll cs = c.size();
  ll match = 0;
  A += a;
  for (int i = as - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < bs; j++) {
      if (k >= as) break;
      if (a[k] == b[j] || a[k] == '?' || b[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == as) match = max(match, tmp);
      if (k < as && j == bs - 1) match = bs;
    }
  }
  for (int i = match; i < bs; i++) {
    A += b[i];
  }
  match = 0;
  ll As = A.size();
  for (int i = As - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < cs; j++) {
      if (k >= As) break;
      if (A[k] == c[j] || A[k] == '?' || c[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == As) match = max(match, tmp);
      if (k < As && j == cs - 1) match = cs;
    }
  }
  for (int i = match; i < cs; i++) {
    A += c[i];
  }
  As = A.size();
  ans = min(ans, As);
  match = 0;
  B += a;
  for (int i = as - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < cs; j++) {
      if (k >= as) break;
      if (a[k] == c[j] || a[k] == '?' || c[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == as) match = max(match, tmp);
      if (k < as && j == cs - 1) match = cs;
    }
  }
  for (int i = match; i < cs; i++) {
    B += c[i];
  }
  match = 0;
  As = B.size();
  for (int i = As - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < bs; j++) {
      if (k >= As) break;
      if (B[k] == b[j] || B[k] == '?' || b[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == As) match = max(match, tmp);
      if (k < As && j == bs - 1) match = bs;
    }
  }
  for (int i = match; i < bs; i++) {
    B += b[i];
  }
  As = B.size();
  ans = min(ans, As);
  match = 0;
  C += b;
  for (int i = bs - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < as; j++) {
      if (k >= bs) break;
      if (b[k] == a[j] || b[k] == '?' || a[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == bs) match = max(match, tmp);
      if (k < As && j == as - 1) match = as;
    }
  }
  for (int i = match; i < as; i++) {
    C += a[i];
  }
  match = 0;
  As = C.size();
  for (int i = As - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < cs; j++) {
      if (k >= As) break;
      if (C[k] == b[j] || C[k] == '?' || c[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == As) match = max(match, tmp);
      if (k < As && j == cs - 1) match = cs;
    }
  }
  for (int i = match; i < cs; i++) {
    C += c[i];
  }
  As = C.size();
  ans = min(ans, As);
  match = 0;
  D += b;
  for (int i = bs - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < cs; j++) {
      if (k >= bs) break;
      if (b[k] == c[j] || b[k] == '?' || c[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == bs) match = max(match, tmp);
      if (k < bs && j == cs - 1) match = cs;
    }
  }
  for (int i = match; i < cs; i++) {
    D += c[i];
  }
  match = 0;
  As = D.size();
  for (int i = As - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < as; j++) {
      if (k >= As) break;
      if (C[k] == a[j] || C[k] == '?' || a[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == As) match = max(match, tmp);
      if (k < As && j == as - 1) match = as;
    }
  }
  for (int i = match; i < as; i++) {
    D += a[i];
  }
  As = D.size();
  ans = min(ans, As);
  match = 0;
  E += c;
  for (int i = cs - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < as; j++) {
      if (k >= cs) break;
      if (c[k] == a[j] || c[k] == '?' || a[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == cs) match = max(match, tmp);
      if (k < cs && j == as - 1) match = as;
    }
  }
  for (int i = match; i < as; i++) {
    E += a[i];
  }
  match = 0;
  As = E.size();
  for (int i = As - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < bs; j++) {
      if (k >= As) break;
      if (C[k] == b[j] || C[k] == '?' || b[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == As) match = max(match, tmp);
      if (k < As && j == bs - 1) match = bs;
    }
  }
  for (int i = match; i < bs; i++) {
    E += b[i];
  }
  As = E.size();
  ans = min(ans, As);
  match = 0;
  F += c;
  for (int i = cs - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < bs; j++) {
      if (k >= cs) break;
      if (c[k] == b[j] || c[k] == '?' || b[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == cs) match = max(match, tmp);
      if (k < cs && j == bs - 1) match = bs;
    }
  }
  for (int i = match; i < bs; i++) {
    F += b[i];
  }
  match = 0;
  As = F.size();
  for (int i = As - 1; i >= 0; i--) {
    ll tmp = 0;
    ll k = i;
    for (int j = 0; j < as; j++) {
      if (k >= As) break;
      if (C[k] == a[j] || C[k] == '?' || a[j] == '?') {
        tmp++;
        k++;
      } else
        break;
      if (k == As) match = max(match, tmp);
      if (k < As && j == as - 1) match = as;
    }
  }
  for (int i = match; i < as; i++) {
    F += a[i];
  }
  As = F.size();
  ans = min(ans, As);
  cout << ans << endl;
}
