#include <bits/stdc++.h>
char s1[300011], s2[300011], s3[300011], s[300011], ss[300011], t[300011],
    u[300011], v[300011], sss[300011];
int x[300011];
void kmp() {
  int T = strlen(t);
  memset(x, 0, sizeof(x));
  int i, j;
  for (i = 1, j = 0; i < T;)
    t[i] == t[j] ? i++, j++, x[i] = j : j ? j = x[j] : i++;
}
void g(char *t1, char *t2) {
  int len1 = strlen(t1), len2 = strlen(t2);
  for (int i = 0; i < len1; i++) t[i] = t1[len1 - 1 - i];
  for (int i = 0; i < len2; i++) t[len1 + i] = t2[len2 - 1 - i];
  t[len1 + len2] = NULL;
  kmp();
  for (int i = 2 * len1; i < len1 + len2; i++)
    if (x[i] >= len1) {
      strcpy(s, t2);
      return;
    }
  int len = x[len1 + len2];
  len = ((len) < (len1) ? (len) : (len1));
  len = ((len) < (len2) ? (len) : (len2));
  strcpy(s, t1);
  for (int i = len; i < len2; i++) s[len1 + i - len] = t2[i];
  s[len1 + len2 - len] = NULL;
}
int f(char *t1, char *t2, char *t3) {
  int ans = 3000000;
  g(t1, t2);
  strcpy(ss, s);
  g(ss, t3);
  ans = ((ans) < (strlen(s)) ? (ans) : (strlen(s)));
  g(t3, ss);
  ans = ((ans) < (strlen(s)) ? (ans) : (strlen(s)));
  return ans;
}
int main() {
  scanf("%s %s %s", s1, s2, s3);
  int ans = 3000000;
  ans = ((ans) < (f(s1, s2, s3)) ? (ans) : (f(s1, s2, s3)));
  ans = ((ans) < (f(s1, s3, s2)) ? (ans) : (f(s1, s3, s2)));
  ans = ((ans) < (f(s2, s3, s1)) ? (ans) : (f(s2, s3, s1)));
  ans = ((ans) < (f(s2, s1, s3)) ? (ans) : (f(s2, s1, s3)));
  ans = ((ans) < (f(s3, s1, s2)) ? (ans) : (f(s3, s1, s2)));
  ans = ((ans) < (f(s3, s2, s1)) ? (ans) : (f(s3, s2, s1)));
  printf("%d\n", ans);
}
