#include <bits/stdc++.h>
using namespace std;
string s[3];
int p[] = {0, 1, 2}, ans = 1e9, pf[300003], k;
int cpf(int b, string t) {
  int tlen = t.length();
  pf[1] = 0;
  for (int i = 2; i <= tlen; i++) {
    k = pf[i - 1];
    while ((k > 0) && (t[i - 1] != t[k])) k = pf[k];
    pf[i] = (t[i - 1] == t[k]) ? k + 1 : 0;
    if ((i >= 2 * b) && (pf[i] >= b)) return -1;
  }
  return pf[tlen];
}
string j(string a, string b) {
  int bl = b.length();
  int k = min(a.length(), b.length());
  k = min(k, cpf(bl, b + a));
  if (k < 0) k = bl;
  return a + b.substr(k);
}
int main() {
  cin >> s[0] >> s[1] >> s[2];
  do {
    int now = j(j(s[p[0]], s[p[1]]), s[p[2]]).length();
    ans = min(now, ans);
  } while (next_permutation(p, p + 3));
  cout << ans << endl;
}
