#include <bits/stdc++.h>
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
void failure(int *ff, char *aa, int n) {
  int i, j;
  ff[0] = -1;
  for (i = 0, j = 1; j < n; i++, j++) {
    while (aa[i] != aa[j]) {
      if (i == 0) {
        i = -1;
        break;
      }
      i = ff[i - 1] + 1;
    }
    ff[j] = i;
  }
}
void failure_(int *ff, char *aa, int na, char *bb, int nb) {
  static char tt[100000 + 100000 + 1];
  int i, j;
  for (i = 0; i < na; i++) tt[i] = aa[i];
  for (j = 0; j < nb; j++) tt[na + j] = bb[j];
  failure(ff, tt, na + nb);
}
int contained(int *ff, int n, int m) {
  int j;
  for (j = n - 1; j < m; j++)
    if (ff[n + j] >= n - 1) return 1;
  return 0;
}
int main() {
  static char aa_[100000 + 1], bb_[100000 + 1], cc_[100000 + 1],
      *aa = aa_, *bb = bb_, *cc = cc_, *tmp;
  static int fab[100000 + 100000], fac[100000 + 100000], fbc[100000 + 100000],
      fba[100000 + 100000], fca[100000 + 100000], fcb[100000 + 100000];
  int na, nb, nc, t, ab, ac, bc, ans, iab, iac, ibc, iba, ica, icb;
  scanf("%s%s%s", aa, bb, cc);
  na = strlen(aa), nb = strlen(bb), nc = strlen(cc);
  if (na > nb) {
    t = na, na = nb, nb = t;
    tmp = aa, aa = bb, bb = tmp;
  }
  if (na > nc) {
    t = na, na = nc, nc = t;
    tmp = aa, aa = cc, cc = tmp;
  }
  if (nb > nc) {
    t = nb, nb = nc, nc = t;
    tmp = bb, bb = cc, cc = tmp;
  }
  failure_(fab, aa, na, bb, nb);
  failure_(fac, aa, na, cc, nc);
  failure_(fbc, bb, nb, cc, nc);
  failure_(fba, bb, nb, aa, na);
  failure_(fca, cc, nc, aa, na);
  failure_(fcb, cc, nc, bb, nb);
  iab = fba[nb + na - 1] + 1;
  iac = fca[nc + na - 1] + 1;
  ibc = fcb[nc + nb - 1] + 1;
  iba = fab[na + nb - 1] + 1;
  ica = fac[na + nc - 1] + 1;
  icb = fbc[nb + nc - 1] + 1;
  ab = contained(fab, na, nb);
  ac = contained(fac, na, nc);
  bc = contained(fbc, nb, nc);
  if (ab && bc)
    ans = nc;
  else if (ab || ac)
    ans = nb + nc - max(ibc, icb);
  else if (bc)
    ans = na + nc - max(iac, ica);
  else {
    int it = 0;
    it = max(it, iab + ibc);
    it = max(it, iac + icb);
    it = max(it, iba + iac);
    it = max(it, ibc + ica);
    it = max(it, ica + iab);
    it = max(it, icb + iba);
    ans = na + nb + nc - it;
  }
  printf("%d\n", ans);
  return 0;
}
