#include <bits/stdc++.h>
using namespace std;
int diff(string a, string b, string c) {
  int sum = 0;
  int pos1 = 0, pos2 = 0;
  while (pos1 < a.size() && pos2 < b.size()) {
    if (a[pos1] == b[pos2] || a[pos1] == '?') {
      pos1++;
      pos2++;
      sum++;
    } else if (a[pos1] != b[pos2]) {
      pos2 = 0;
      sum = 0;
      if (a[pos1] == b[pos2]) {
        sum = 1;
      } else {
        sum = 0;
      }
      pos1++;
    }
  }
  int sum1 = 0;
  pos1 = 0, pos2 = 0;
  while (pos1 < b.size() && pos2 < c.size()) {
    if (b[pos1] == c[pos2] || b[pos1] == '?') {
      pos1++;
      pos2++;
      sum1++;
    } else if (b[pos1] != c[pos2]) {
      pos2 = 0;
      sum1 = 0;
      if (b[pos1] == c[pos2]) {
        sum1 = 1;
      } else {
        sum1 = 0;
      }
      pos1++;
    }
  }
  return (a.size() + b.size() + c.size() - sum - sum1);
}
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int one = diff(a, b, c);
  int two = diff(a, c, b);
  int three = diff(b, a, c);
  int four = diff(b, c, a);
  int five = diff(c, a, b);
  int six = diff(c, b, a);
  cout << min(one, min(two, min(three, min(four, min(five, six))))) << endl;
}
