#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << H;
  debug_out(T...);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<string> arr(3);
  for (int i = 0; i < 3; i++) cin >> arr[i];
  sort(arr.begin(), arr.end());
  int mn = 1e9;
  function<string(string, string)> merge = [&](string a, string b) {
    string w = b + '#' + a;
    const int ALL = (int)b.size();
    const int T = (int)w.size();
    vector<int> z(T);
    z[0] = 0;
    int lo = 0, hi = 0;
    for (int i = 1; i < T; i++) {
      z[i] = (i <= hi ? min(z[i - lo], hi - i + 1) : 0);
      while (i + z[i] < T && w[i + z[i]] == w[z[i]]) ++z[i];
      if (i + z[i] > hi) {
        hi = i + z[i] - 1;
        lo = i;
      }
    }
    int mx = 0;
    bool can_ignore = false;
    for (int i = T - 1; w[i] != '#'; i--) {
      if (i + z[i] >= T) mx = z[i];
      if (z[i] == ALL) can_ignore = true;
    }
    return a + (can_ignore ? "" : b.substr(mx));
  };
  do {
    string cur = arr[0];
    cur = merge(cur, arr[1]);
    cur = merge(cur, arr[2]);
    mn = min(mn, (int)cur.size());
  } while (next_permutation(arr.begin(), arr.end()));
  cout << mn << '\n';
  return 0;
}
