#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int pre[N];
void compute(string pat) {
  for (int i = 1, k = 0; i < pat.size(); i++) {
    while (k > 0 && pat[i] != pat[k]) k = pre[k - 1];
    if (pat[k] == pat[i])
      pre[i] = ++k;
    else
      pre[i] = k;
  }
}
int kmp(string s, string pat) {
  compute(pat);
  int k = 0;
  for (int i = 0; i < s.size(); i++) {
    while (k > 0 && pat[k] != s[i]) k = pre[k - 1];
    if (s[i] == pat[k]) k++;
    if (k == pat.size()) return k;
  }
  return k;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s[3];
  for (int i = 0; i < 3; i++) cin >> s[i];
  int ans = 1e9;
  sort(s, s + 3);
  do {
    string st = s[0];
    for (int i = 1; i < 3; i++) {
      int len = kmp(st, s[i]);
      st += s[i].substr(len);
    }
    ans = min(ans, (int)st.size());
  } while (next_permutation(s, s + 3));
  cout << ans << endl;
}
