#include <bits/stdc++.h>
using namespace std;
int pi[200015];
void PreKMP(char *P, int n) {
  int q, k = 0;
  pi[1] = 0;
  for (q = 2; q <= n; pi[q++] = k) {
    while (k && (P[k] != P[q - 1])) k = pi[k];
    if (P[k] == P[q - 1]) k++;
  }
}
int KMP(char *T, int n, char *P, int m) {
  int i, q = 0;
  PreKMP(P, m);
  for (i = 1; i <= n; i++) {
    while ((q > 0) && (P[q] != T[i - 1])) q = pi[q];
    if (P[q] == T[i - 1]) q++;
    if (q == m) return m;
  }
  return q;
}
char a[200015];
char b[200015];
char c[200015];
char cadab[200015];
char cadac[200015];
char cadba[200015];
char cadbc[200015];
char cadca[200015];
char cadcb[200015];
int main() {
  while (scanf("%s%s%s", a, b, c) != EOF) {
    int sa = strlen(a);
    int sb = strlen(b);
    int sc = strlen(c);
    PreKMP(a, sa);
    int ab = KMP(a, sa, b, sb);
    int ac = KMP(a, sa, c, sc);
    PreKMP(b, sb);
    int ba = KMP(b, sb, a, sa);
    int bc = KMP(b, sb, c, sc);
    PreKMP(c, sc);
    int ca = KMP(c, sc, a, sa);
    int cb = KMP(c, sc, b, sb);
    int minn = sa + sb + sc;
    minn = min(minn, sa + (sb - ab) + (sc - bc));
    minn = min(minn, sa + (sc - ac) + (sb - cb));
    minn = min(minn, sb + (sa - ba) + (sc - ac));
    minn = min(minn, sb + (sc - bc) + (sa - ca));
    minn = min(minn, sc + (sa - ca) + (sb - ab));
    minn = min(minn, sc + (sb - cb) + (sa - ba));
    int sab = 0;
    int sac = 0;
    int sba = 0;
    int sbc = 0;
    int sca = 0;
    int scb = 0;
    for (int i = 0; i < sa; i++) {
      cadab[sab++] = a[i];
      cadac[sac++] = a[i];
    }
    for (int i = 0; i < sb; i++) {
      cadba[sba++] = b[i];
      cadbc[sbc++] = b[i];
    }
    for (int i = 0; i < sc; i++) {
      cadca[sca++] = c[i];
      cadcb[scb++] = c[i];
    }
    for (int i = ab; i < sb; i++) {
      cadab[sab++] = b[i];
    }
    for (int i = ac; i < sc; i++) {
      cadac[sac++] = c[i];
    }
    for (int i = ba; i < sa; i++) {
      cadba[sba++] = a[i];
    }
    for (int i = bc; i < sc; i++) {
      cadbc[sbc++] = c[i];
    }
    for (int i = ca; i < sa; i++) {
      cadca[sca++] = a[i];
    }
    for (int i = ac; i < sc; i++) {
      cadcb[scb++] = b[i];
    }
    if (KMP(cadab, sab, c, sc) == sc) minn = min(minn, sab);
    if (KMP(cadac, sac, b, sb) == sb) minn = min(minn, sac);
    if (KMP(cadba, sba, c, sc) == sc) minn = min(minn, sba);
    if (KMP(cadbc, sbc, a, sa) == sa) minn = min(minn, sbc);
    if (KMP(cadca, sca, b, sb) == sb) minn = min(minn, sca);
    if (KMP(cadcb, scb, a, sa) == sa) minn = min(minn, scb);
    printf("%d\n", minn);
  }
}
