#include <bits/stdc++.h>
using namespace std;
const long double epsilon = 1e-9;
string s[3];
int fails[3][1 << 17];
void calcFails(const string& str, int f[]) {
  int n = str.size();
  f[1] = 0;
  int idx;
  for (int i = 2; i <= n; i++) {
    idx = i - 1;
    while (idx > 0 && str[f[idx]] != str[i - 1]) {
      idx = f[idx];
    }
    if (idx > 0 && str[f[idx]] == str[i - 1])
      f[i] = f[idx] + 1;
    else
      f[i] = 0;
  }
}
string deduceMinimal(int idx1, const string& str) {
  int idx = 0;
  int n = s[idx1].size();
  for (int i = 0; i < str.size(); i++) {
    while (idx > 0 && str[i] != s[idx1][idx]) {
      idx = fails[idx1][idx];
    }
    if (str[i] == s[idx1][idx]) idx++;
    if (idx == n) return str;
  }
  return str + s[idx1].substr(idx, s[idx1].size() - idx);
}
int main() {
  vector<int> v(3);
  for (int i = 0; i < 3; i++) {
    cin >> s[i];
    v[i] = i;
    calcFails(s[i], fails[i]);
  }
  int maxm = 10000000;
  do {
    string str = deduceMinimal(v[1], s[v[0]]);
    str = deduceMinimal(v[2], str);
    maxm = min(maxm, (int)str.size());
  } while (next_permutation(v.begin(), v.end()));
  cout << maxm << endl;
  return 0;
}
