#include <bits/stdc++.h>
using namespace std;
string match(string a, string b) {
  string ans = a;
  long long i;
  for (i = 0; i < a.size(); i++) {
    if (a[i] == b[0] || a[i] == '?' || b[0] == '?') {
      long long j = 1;
      while (j + i < a.size() && j < b.size() &&
             (a[j + i] == b[j] || a[j + i] == '?' || b[j] == '?'))
        j++;
      if (j + i == a.size() || j == b.size()) {
        string ss = a.substr(0, i);
        for (long long k = i; k < i + j; k++) {
          if (a[k] == '?')
            ss += b[k - i];
          else
            ss += a[k];
        }
        if (j + i == a.size())
          ss += b.substr(j);
        else
          ss += a.substr(i + j);
        ans = ss;
        break;
      }
    }
  }
  if (i == a.size()) ans += b;
  return ans;
}
int main() {
  string s1, s2, s3;
  string s;
  cin >> s1 >> s2 >> s3;
  long long minn = INT_MAX;
  s = match(s1, s2);
  s = match(s, s3);
  long long a = s.size();
  minn = min(minn, a);
  s = match(s1, s3);
  s = match(s, s2);
  a = s.size();
  minn = min(minn, a);
  s = match(s2, s1);
  s = match(s, s3);
  a = s.size();
  minn = min(minn, a);
  s = match(s2, s3);
  s = match(s, s1);
  a = s.size();
  minn = min(minn, a);
  s = match(s3, s1);
  s = match(s, s2);
  a = s.size();
  minn = min(minn, a);
  s = match(s3, s2);
  s = match(s, s1);
  a = s.size();
  minn = min(minn, a);
  cout << minn;
  return 0;
}
