#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 11;
const double pi = acos(-1.0);
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const unsigned long long B = 100000007ULL;
char S[3][MAXN];
int len[3];
unsigned long long H[3][MAXN], B_[MAXN];
inline void init_hash() {
  for (int(i) = (0); (i) < (3); (i)++) {
    for (int(j) = (1); (j) < (len[i] + 1); (j)++) {
      H[i][j] = H[i][j - 1] * B + S[i][j];
    }
  }
  int n = max(max(len[0], len[1]), len[2]);
  B_[0] = 1;
  for (int(i) = (1); (i) < (n + 1); (i)++) B_[i] = B_[i - 1] * B;
}
inline unsigned long long hashs(unsigned long long *h, int l, int d) {
  return h[l + d - 1] - h[l - 1] * B_[d];
}
bool contain(int a, int b) {
  if (len[a] < len[b]) return 0;
  unsigned long long hb = H[b][len[b]];
  for (int i = 1; i + len[b] <= len[a]; i++)
    if (hashs(H[a], i, len[b]) == hb) return 1;
  return 0;
}
int overlap(int a, int b) {
  int ans = 0;
  for (int(i) = (1); (i) < (min(len[a], len[b]) + 1); (i)++)
    if (hashs(H[a], len[a] - i + 1, i) == hashs(H[b], 1, i)) ans = i;
  return ans;
}
int solve() {
  int ans = len[1] + len[2] + len[0];
  for (int(i) = (0); (i) < (2); (i)++)
    for (int(j) = (i + 1); (j) < (3); (j)++)
      if (contain(i, j) || contain(j, i)) {
        int x = len[i] > len[j] ? i : j;
        int y = 3 - i - j;
        if (contain(x, y) || contain(y, x)) return max(len[x], len[y]);
        return len[x] + len[y] - max(overlap(x, y), overlap(y, x));
      }
  int id[3] = {0, 1, 2};
  do
    ans = min(ans, len[0] + len[1] + len[2] - overlap(id[0], id[1]) -
                       overlap(id[1], id[2]));
  while (next_permutation(id, id + 3));
  return ans;
}
int main() {
  for (int(i) = (0); (i) < (3); (i)++) scanf("%s", S[i] + 1);
  for (int(i) = (0); (i) < (3); (i)++) len[i] = strlen(S[i] + 1);
  init_hash();
  printf("%d\n", solve());
  return 0;
}
