#include <bits/stdc++.h>
using namespace std;
int findd(string s1, string s2) {
  long long h1 = 0, h2 = 0, x = 1;
  int i, n = (int)s1.size(), m = (int)s2.size();
  if (n < m) return -1;
  for (i = 0; i < m; i++) h2 = h2 * 33 + s2[i] - 'a' + 1;
  for (i = 0; i < n; i++) {
    if (i < m) {
      h1 = h1 * 33 + s1[i] - 'a' + 1;
      x = x * 33;
      if (i == m - 1)
        if (h1 == h2) return 1;
    } else {
      h1 = h1 * 33 - (s1[i - m] - 'a' + 1) * x + s1[i] - 'a' + 1;
      if (h1 == h2) return 1;
    }
  }
  return -1;
}
string join(string s1, string s2) {
  string st;
  long long x, h1, h2;
  int j, maxj = 0;
  if (findd(s1, s2) != -1)
    st = s1;
  else {
    h1 = h2 = 0;
    x = 1;
    for (j = 0; j < min(s1.size(), s2.size());) {
      h1 = h1 * 33 + s2[j] - 'a' + 1;
      h2 = h2 + (s1[s1.size() - 1 - j] - 'a' + 1) * x;
      x = x * 33;
      if (h1 == h2) {
        j++;
        maxj = max(j, maxj);
      } else {
        j++;
      }
    }
    if (maxj == 0)
      st = s1 + s2;
    else {
      st = s1;
      for (j = maxj; j < s2.size(); j++) st += s2[j];
    }
  }
  return st;
}
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int m;
  string S[3], s1, s2, s3;
  cin >> S[0] >> S[1] >> S[2];
  m = (int)S[0].size() + (int)S[1].size() + (int)S[2].size();
  vector<int> V = {0, 1, 2};
  do {
    s1 = S[V[0]];
    s2 = S[V[1]];
    s3 = S[V[2]];
    s1 = join(s1, s2);
    s1 = join(s1, s3);
    m = min(m, (int)s1.size());
  } while (next_permutation(V.begin(), V.end()));
  cout << m;
  return 0;
}
