#include <bits/stdc++.h>
using namespace std;
const long long P[6][3] = {{1, 2, 3}, {1, 3, 2}, {2, 1, 3},
                           {2, 3, 1}, {3, 1, 2}, {3, 2, 1}};
const long long BASE = 571;
const long long INF = 0x7f7f7f7f;
long long len[4], p[1000005];
long long ans = INF;
long long hs[4][1000005];
char s[4][1000005];
bool cover(long long x, long long y) {
  if (len[y] > len[x]) return false;
  for (long long l = 1; l + len[y] - 1 <= len[x]; l++) {
    long long r = l + len[y] - 1;
    if (hs[x][r] - hs[x][l - 1] * p[len[y]] == hs[y][len[y]]) return true;
  }
  return false;
}
long long overlap(long long x, long long y) {
  for (long long l = min(len[x], len[y]); l >= 0; l--)
    if (hs[x][l] == hs[y][len[y]] - hs[y][len[y] - l] * p[l] ||
        hs[y][l] == hs[x][len[x]] - hs[x][len[x] - l] * p[l])
      return l;
}
signed main() {
  scanf("%s%s%s", s[1] + 1, s[2] + 1, s[3] + 1);
  for (long long i = 1; i <= 3; len[i] = strlen(s[i] + 1), i++)
    ;
  p[0] = 1;
  for (long long i = 1; i <= 1000002; p[i] = p[i - 1] * BASE, i++)
    ;
  for (long long i = 1; i <= 3; i++)
    for (long long j = 1; j <= len[i]; j++)
      hs[i][j] = hs[i][j - 1] * BASE + s[i][j];
  for (long long i = 0; i < 6; i++) {
    long long l1, l2;
    if (cover(P[i][0], P[i][1]))
      l1 = len[P[i][1]];
    else
      l1 = overlap(P[i][0], P[i][1]);
    if (cover(P[i][1], P[i][2]))
      l2 = len[P[i][2]];
    else
      l2 = overlap(P[i][1], P[i][2]);
    ans = min(ans, len[1] + len[2] + len[3] - l1 - l2);
  }
  cout << ans << endl;
  return 0;
}
