#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T>
T sqr(T a) {
  return a * a;
}
template <typename T>
int sign(T a) {
  if (a == 0) return 0;
  return (a > 0 ? 1 : -1);
}
template <typename T1, typename T2>
T2 sum_mod(T1 x, T2 MOD) {
  if (x < 0) x += MOD;
  if (x >= MOD) x -= MOD;
  return x;
}
template <typename T1, typename T2>
T2 mul_mod(T1 x, T2 MOD) {
  if (x < 0) return (abs(x) % MOD == 0 ? 0 : MOD - abs(x) % MOD);
  return x % MOD;
}
template <typename T>
bool uax(T& a, const T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool uin(T& a, const T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2>& p) {
  out << p.first << ' ' << p.second;
  return out;
}
const int LOG = 18;
const int N = (int)1e5 + 7;
const int MAXN = (int)2e3 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 300;
const long long LINF = (int64_t)2e15;
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1;
string a[3];
vector<int> zfunc(const string& a, const string& b) {
  string s = a + '#' + b;
  int n = (int)s.size();
  vector<int> z(n);
  int l = 0, r = 0;
  for (int i = 1; i < n; i++) {
    if (i <= r) z[i] = min(z[i - l], r - i + 1);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;
    if (i + z[i] > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
string unite(const string& a, const string& b) {
  auto v = zfunc(b, a);
  string res = a;
  for (int i = (int)b.size() + 1; i <= (int)a.size() + (int)b.size(); i++) {
    if (v[i] >= (int)b.size()) return res;
    if (v[i] + i == (int)a.size() + (int)b.size() + 1) {
      res += b.substr(v[i], (int)b.size() - v[i]);
      return res;
    }
  }
  return a + b;
}
int get(const string& a, const string& b, const string& c) {
  string s = unite(a, b);
  s = unite(s, c);
  return (int)s.size();
}
int main() {
  double start = clock();
  cout << fixed << setprecision(20);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a[0] >> a[1] >> a[2];
  vector<int> perm = {0, 1, 2};
  int ans = INF;
  do {
    uin(ans, get(a[perm[0]], a[perm[1]], a[perm[2]]));
  } while (next_permutation(perm.begin(), perm.end()));
  cout << ans;
}
