#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
const long long N = 3e5 + 444, MOD = 1e9 + 7, base = 31;
long long Pow[N], Hash[3][N], ans = INT_MAX;
long long GetHash(int i, int j, int x) {
  return (Hash[x][j] - Hash[x][i - 1] * Pow[j - i + 1] + MOD * MOD) % MOD;
}
void cal(string a, string b, string c) {
  int x[3] = {(int)a.size(), (int)b.size(), (int)c.size()};
  string s[3] = {'$' + a, '$' + b, '$' + c};
  for (int i = 0; i < 3; ++i) {
    Hash[i][0] = 0;
    for (int j = 1; j <= x[i]; ++j) {
      Hash[i][j] = Hash[i][j - 1] * base + s[i][j] - 'a' + 1;
      Hash[i][j] %= MOD;
    }
  }
  for (int j = 1; j < 3; ++j) {
    x[0] = s[0].size() - 1;
    int pos = x[0] + 1;
    for (int i = 1; i <= x[0]; ++i) {
      int tmp = min(x[0] - i + 1, x[j]);
      long long cur = GetHash(1, tmp, j);
      if (GetHash(i, i + tmp - 1, 0) == cur) {
        pos = i;
        break;
      }
    }
    pos = x[0] - pos + 1;
    for (int i = pos + 1; i <= x[j]; ++i) {
      Hash[0][s[0].size()] =
          Hash[0][s[0].size() - 1] * base + s[j][i] - 'a' + 1;
      Hash[0][s[0].size()] %= MOD;
      s[0] += s[j][i];
    }
  }
  amin(ans, s[0].size() - 1);
}
int Solve() {
  Pow[0] = 1;
  for (int i = 1; i < N; ++i) {
    Pow[i] = Pow[i - 1] * base % MOD;
  }
  string a, b, c;
  cin >> a >> b >> c;
  cal(a, b, c);
  cal(a, c, b);
  cal(b, a, c);
  cal(b, c, a);
  cal(c, a, b);
  cal(c, b, a);
  cout << ans << '\n';
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    Solve();
  }
  return 0;
}
