#include <bits/stdc++.h>
using namespace std;
void calc_failure_func(char *b, int m, int *f) {
  int t = 0;
  f[1] = 0;
  for (int s = 1; s <= m - 1; s++) {
    while (t > 0 && b[s + 1] != b[t + 1]) t = f[t];
    if (b[s + 1] == b[t + 1])
      f[s + 1] = ++t;
    else
      f[s + 1] = 0;
  }
}
int match(char *a, int n, char *b, int m, int *f) {
  int s = 0;
  for (int i = 1; i <= n; i++) {
    while (s > 0 && a[i] != b[s + 1]) s = f[s];
    if (a[i] == b[s + 1]) ++s;
    if (s == m) return -1;
  }
  return s;
}
int test_length(char *a, int na, char *b, int nb, int *fb, char *c, int nc,
                int *fc) {
  int sb = match(a, na, b, nb, fb);
  int result;
  if (sb == -1) {
    int sc = match(a, na, c, nc, fc);
    if (sc == -1)
      result = na;
    else
      result = na + nc - sc;
  } else {
    char a_tmp[1 + na + nb - sb];
    a_tmp[0] = '\0';
    memcpy(a_tmp + 1, a + 1, na * sizeof(char));
    memcpy(a_tmp + 1 + na, b + 1 + sb, (nb - sb) * sizeof(char));
    int sc = match(a_tmp, na + nb - sb, c, nc, fc);
    if (sc == -1)
      result = na + nb - sb;
    else
      result = na + nb + nc - sb - sc;
  }
  return result;
}
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int na = a.length();
  int nb = b.length();
  int nc = c.length();
  char a1[na + 1], b1[nb + 1], c1[nc + 1];
  a1[0] = b1[0] = c1[0] = '\0';
  memcpy(a1 + 1, a.c_str(), na * sizeof(char));
  memcpy(b1 + 1, b.c_str(), nb * sizeof(char));
  memcpy(c1 + 1, c.c_str(), nc * sizeof(char));
  int fa[na + 1], fb[nb + 1], fc[nc + 1];
  calc_failure_func(a1, na, fa);
  calc_failure_func(b1, nb, fb);
  calc_failure_func(c1, nc, fc);
  int minLen = na + nb + nc;
  int len = minLen;
  if ((len = test_length(a1, na, b1, nb, fb, c1, nc, fc)) < minLen) {
    minLen = len;
  }
  if ((len = test_length(a1, na, c1, nc, fc, b1, nb, fb)) < minLen) {
    minLen = len;
  }
  if ((len = test_length(b1, nb, a1, na, fa, c1, nc, fc)) < minLen) {
    minLen = len;
  }
  if ((len = test_length(b1, nb, c1, nc, fc, a1, na, fa)) < minLen) {
    minLen = len;
  }
  if ((len = test_length(c1, nc, a1, na, fa, b1, nb, fb)) < minLen) {
    minLen = len;
  }
  if ((len = test_length(c1, nc, b1, nb, fb, a1, na, fa)) < minLen) {
    minLen = len;
  }
  cout << minLen << endl;
  return 0;
}
