#include <bits/stdc++.h>
using namespace std;
vector<int> alz(string a) {
  int n = a.size();
  vector<int> res(n);
  int left = 0, right = 0;
  for (int k = 1; k < n; k++) {
    if (right < k) {
      right = left = k;
      while (right < n && a[right] == a[right - left]) right++;
      res[k] = right - left;
      right--;
    } else {
      int k1 = k - left;
      if (res[k1] < right - k + 1)
        res[k] = res[k1];
      else {
        left = k;
        while (right < n && a[right] == a[right - left]) right++;
        res[k] = right - left;
        right--;
      }
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string ar[3];
  cin >> ar[0] >> ar[1] >> ar[2];
  int ta = ar[0].size() + ar[1].size() + ar[2].size();
  int res = ta;
  int a = ar[0].size(), b = ar[1].size(), c = ar[2].size();
  string neo;
  int per[] = {0, 1, 2};
  vector<int> z;
  do {
    z = alz(ar[per[1]] + "$" + ar[per[0]]);
    int mi = 0;
    int ta = ar[per[1]].size() + 1 + ar[per[0]].size();
    bool ins = false;
    for (int i = ar[per[1]].size() + 1; i < ta; i++) {
      if (z[i] == ar[per[1]].size()) {
        ins = true;
        break;
      }
      if (z[i] + i == ta) {
        mi = z[i];
        break;
      }
    }
    if (ins)
      neo = ar[per[0]];
    else
      neo = ar[per[0]].substr(0, ar[per[0]].size() - mi) + ar[per[1]];
    ins = false;
    z = alz(ar[per[2]] + "$" + neo);
    ta = ar[per[2]].size() + 1 + neo.size();
    mi = 0;
    for (int i = ar[per[2]].size() + 1; i < ta; i++) {
      if (z[i] == ar[per[2]].size()) {
        ins = true;
        break;
      }
      if (z[i] + i == ta) {
        mi = z[i];
        break;
      }
    }
    if (ins) {
      res = min(res, (int)neo.size());
    } else
      res = min(res, (int)neo.size() + (int)ar[per[2]].size() - mi);
  } while (next_permutation(per, per + 3));
  cout << res << '\n';
  return 0;
}
