#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long as = 0, fu = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fu = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    as = as * 10 + c - '0';
    c = getchar();
  }
  return as * fu;
}
const int N = 200005;
char s[4][N];
int nxt[4][N];
int l[4], a[4][4];
void init(char s[], int idx) {
  int tmp = 0;
  for (int i = 2; i <= l[idx]; i++) {
    while (tmp && s[tmp + 1] != s[i]) tmp = nxt[idx][tmp];
    if (s[tmp + 1] == s[i]) ++tmp;
    nxt[idx][i] = tmp;
  }
}
int KMP(char s[], char t[], int S, int T, int idx) {
  int tmp = 0;
  for (int i = 1; i <= S; i++) {
    while (tmp && t[tmp + 1] != s[i]) tmp = nxt[idx][tmp];
    if (t[tmp + 1] == s[i]) tmp++;
    if (tmp == T) return -1;
  }
  return tmp;
}
int main() {
  for (int i = 1; i <= 3; i++) {
    cin >> (s[i] + 1);
    l[i] = strlen(s[i] + 1);
    init(s[i], i);
  }
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++)
      if (i ^ j) a[i][j] = KMP(s[i], s[j], l[i], l[j], j);
  int ans = 1e8;
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++)
      for (int k = 1; k <= 3; k++) {
        if (i == j || j == k || i == k) continue;
        if (a[i][j] >= 0 && a[j][k] >= 0)
          ans = min(ans, l[i] + l[j] + l[k] - a[i][j] - a[j][k]);
        else if (a[i][j] < 0 && a[i][k] < 0)
          ans = min(ans, l[i]);
        else if (a[i][j] < 0)
          ans = min(ans, l[i] + l[k] - a[i][k]);
        else if (a[j][k] < 0)
          ans = min(ans, l[i] + l[j] - a[i][j]);
      }
  cout << ans << endl;
  return 0;
}
