#include <bits/stdc++.h>
using namespace std;
string s[100500];
int a[100500];
int p[4 * 100500];
string join(string s1, string s2) {
  string s;
  s = s1 + '$' + s2;
  p[0] = -1;
  for (int i = 1; i < s.size(); i++) {
    int t = p[i - 1];
    while (t != -1 && s[t + 1] != s[i]) t = p[t];
    if (s[t + 1] == s[i]) t++;
    p[i] = t;
  }
  int res = -1;
  for (int i = s1.size(); i < s.size(); i++) res = max(res, p[i]);
  if (res == s1.size() - 1) {
    return s2;
  }
  return s2 + s1.substr(p[s.size() - 1] + 1, s1.size() - p[s.size() - 1] - 1);
}
int main() {
  for (int i = 0; i < 3; i++) {
    getline(cin, s[i]);
    a[i] = i;
  }
  int res = 1000000000;
  do {
    string cur = join(join(s[a[0]], s[a[1]]), s[a[2]]);
    res = min(res, (int)cur.length());
  } while (next_permutation(a, a + 3));
  printf("%d\n", res);
  return 0;
}
