#include <bits/stdc++.h>
using namespace std;
string ecat(const string& a, const string& b) {
  string c = a + '&' + b;
  int* p = new int[c.size()];
  p[0] = -1;
  for (int q = 1; q < (int)c.size(); q++) {
    int t = p[q - 1];
    while (t >= 0 && c[t + 1] != c[q]) t = p[t];
    if (c[t + 1] == c[q]) t++;
    p[q] = t;
  }
  for (int i = a.size() + 1; i < (int)c.size(); i++) {
    if (p[i] == (int)a.size() - 1) {
      delete[] p;
      return b;
    }
  }
  int len = p[c.size() - 1] + 1;
  delete[] p;
  return b.substr(0, b.size() - len) + a;
}
int main() {
  string s[3];
  for (int i = 0; i < 3; i++) cin >> s[i];
  int t[3] = {0, 1, 2};
  int ans = s[0].size() + s[1].size() + s[2].size();
  do {
    ans = min(ans, (int)ecat(ecat(s[t[0]], s[t[1]]), s[t[2]]).size());
  } while (next_permutation(t, t + 3));
  cout << ans << endl;
  return 0;
}
