#include <bits/stdc++.h>
using namespace std;
char str[200020];
char s[3][100010];
int p[200020];
int kmp(char *s1, char *s2) {
  int len1 = strlen(s1);
  int len2 = strlen(s2);
  p[0] = 0, p[1] = 0;
  int j;
  for (int i = 1; i < len2; i++) {
    j = p[i];
    while (j && s2[i] != s2[j]) j = p[j];
    p[i + 1] = s2[i] == s2[j] ? j + 1 : 0;
  }
  j = 0;
  for (int i = 0; i < len1; i++) {
    while (j && s1[i] != s2[j]) j = p[j];
    if (s1[i] == s2[j]) j++;
    if (j == len2) return 0;
  }
  return len2 - j;
}
int compair(char *s1, char *s2, char *s3) {
  int len = kmp(s1, s2);
  str[0] = '\0';
  strcat(str, s1);
  strcat(str, s2 + strlen(s2) - len);
  len = kmp(str, s3);
  return strlen(str) + len;
}
int main() {
  while (scanf("%s%s%s", s[0], s[1], s[2]) != EOF) {
    int minn;
    int l;
    minn = compair(s[0], s[1], s[2]);
    l = compair(s[0], s[2], s[1]);
    if (l < minn) minn = l;
    l = compair(s[1], s[2], s[0]);
    if (l < minn) minn = l;
    l = compair(s[1], s[0], s[2]);
    if (l < minn) minn = l;
    l = compair(s[2], s[0], s[1]);
    if (l < minn) minn = l;
    l = compair(s[2], s[1], s[0]);
    if (l < minn) minn = l;
    cout << minn << endl;
  }
}
