#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
string lcp(string txt, string pat) {
  string S = pat + "$" + txt;
  vector<int> Arr(S.size(), 0);
  int j = 0;
  for (int i = 1; i < S.size(); i++) {
    while (j > 0 && S[j] != S[i]) j = Arr[j - 1];
    if (S[j] == S[i]) j++;
    Arr[i] = j;
  }
  int MX = 0;
  for (int i = 0; i < S.size(); i++) MX = max(MX, Arr[i]);
  if (MX == pat.size()) return txt;
  return txt + pat.substr(Arr[S.size() - 1]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  sort(s, s + 3);
  int Res = 1e9 + 7;
  do {
    string s1 = lcp(lcp(s[0], s[1]), s[2]);
    string s2 = lcp(s[0], lcp(s[1], s[2]));
    int a = s1.size(), b = s2.size();
    Res = min(Res, min(a, b));
  } while (next_permutation(s, s + 3));
  cout << Res << "\n";
  return 0;
}
