#include <bits/stdc++.h>
using namespace std;
bool srch(string a, string x) {
  string c = a + " " + x;
  int n = c.size();
  int b[n + 1];
  b[0] = -1;
  int i = 0, j = -1;
  while (i < n) {
    while (j >= 0 && c[i] != c[j]) j = b[j];
    j++, i++;
    b[i] = j;
    if (b[i] == a.size()) return 1;
  }
  return 0;
}
int solve(string a, string x) {
  string c = a + " " + x;
  int n = c.size();
  int b[n + 1];
  b[0] = -1;
  int i = 0, j = -1;
  while (i < n) {
    while (j >= 0 && c[i] != c[j]) j = b[j];
    j++, i++;
    b[i] = j;
  }
  return c.size() - 1 - b[n];
}
int sol2(string a, string b) {
  if (srch(a, b)) return b.size();
  if (srch(b, a)) return a.size();
  return min(solve(b, a), solve(a, b));
}
int main(int argc, char* argv[]) {
  string a[3];
  cin >> a[0] >> a[1] >> a[2];
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 3; j++) {
      if (srch(a[i], a[j])) {
        cout << sol2(a[j], a[3 - i - j]);
        return 0;
      } else if (srch(a[j], a[i])) {
        cout << sol2(a[i], a[3 - i - j]);
        return 0;
      }
    }
  }
  sort(a, a + 3);
  int mn = 1e9;
  do {
    mn = min(mn, solve(a[1], a[0]) + solve(a[2], a[1]) - (int)a[1].size());
  } while (next_permutation(a, a + 3));
  cout << mn;
}
