#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
int nxt[4][N];
void getnext(int m, char str[], int t) {
  int j = 0;
  for (int i = 2; i <= m; ++i) {
    while (j != 0 && str[j + 1] != str[i]) {
      j = nxt[t][j];
    }
    if (str[j + 1] == str[i]) j++;
    nxt[t][i] = j;
  }
  return;
}
int kmp(int n, int m, char s1[], char s2[], int t) {
  int j = 0, cnt = 0;
  for (int i = 1; i <= n; ++i) {
    while (j != 0 && s2[j + 1] != s1[i]) j = nxt[t][j];
    if (s2[j + 1] == s1[i]) j++;
    if (j == m) {
      return -1;
      j = nxt[t][j];
    }
  }
  return j;
}
int main() {
  char s[4][N];
  int K[4][4], len[4];
  for (int i = 1; i < 4; ++i) {
    scanf("%s", s[i] + 1);
    len[i] = strlen(s[i] + 1);
  }
  for (int i = 1; i < 4; ++i) {
    getnext(len[i], s[i], i);
    for (int j = 1; j < 4; ++j) {
      if (i == j) continue;
      K[j][i] = kmp(len[j], len[i], s[j], s[i], i);
    }
  }
  int ans = INF;
  for (int i = 1; i < 4; ++i) {
    for (int j = 1; j < 4; ++j) {
      for (int k = 1; k < 4; ++k) {
        if (i == j || i == k || j == k) continue;
        int sum = len[i] + len[j] + len[k] - K[i][j] - K[j][k];
        if (K[i][j] >= 0 && K[j][k] >= 0)
          ans = min(ans, sum);
        else {
          if (K[i][j] < 0 && K[i][k] < 0)
            ans = min(ans, len[i]);
          else if (K[i][j] < 0)
            ans = min(ans, sum + K[i][j] + K[j][k] - len[j] - K[i][k]);
          if (K[j][k] < 0) ans = min(ans, sum + K[j][k] - len[k]);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
