#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, base = 727, mod = 1e9 + 7;
long long hsh[N << 2][2], pw[N];
long long get(long long x, long long y) {
  x *= base;
  x %= mod;
  x += y;
  x %= mod;
  return (x + mod) % mod;
}
long long get(int l, int r, int type) {
  int len = r - l + 1;
  long long a = hsh[r + 1][type];
  long long b = (hsh[l][type] * pw[len]) % mod;
  a -= b;
  a %= mod;
  return (a + mod) % mod;
}
string solve(string s, string t) {
  int n = s.size(), m = t.size();
  memset(hsh, 0, sizeof hsh);
  hsh[0][0] = 0;
  long long now = 0;
  for (int i = 0; i < n; i++) {
    now = get(now, s[i] - 'a' + 1);
    hsh[i + 1][0] = now;
  }
  hsh[0][1] = 0;
  now = 0;
  for (int i = 0; i < m; i++) {
    now = get(now, t[i] - 'a' + 1);
    hsh[i + 1][1] = now;
  }
  for (int len = m; len >= 0; len--) {
    if (n - len >= 0 && get(n - len, n - 1, 0) == get(0, len - 1, 1)) {
      string ret = s;
      for (int i = len; i < m; i++) ret.push_back(t[i]);
      return ret;
    }
  }
  string ret;
  ret += s;
  ret += t;
  return ret;
}
string s[3];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (int i = 0; i < 3; i++) cin >> s[i];
  pw[0] = 1;
  for (int i = 1; i < N; i++) pw[i] = (pw[i - 1] * base) % mod;
  int c[] = {0, 1, 2};
  int ans = N * 4;
  do {
    string res = solve(s[c[0]], s[c[1]]);
    string f = solve(s[c[2]], res);
    string k = solve(res, s[c[2]]);
    int sz = min((int)f.size(), (int)k.size());
    ans = min(ans, sz);
  } while (next_permutation(c, c + 3));
  cout << ans << "\n";
}
