#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
vector<long long> pow29(1, 1);
map<string, vector<long long> > S;
string SS;
bool in(string s, string t) {
  s = t + '#' + s;
  int m = t.length();
  int n = s.length();
  int p[n];
  memset(p, 0, sizeof(p));
  for (int i = 1; i < n; i++) {
    int j = p[i - 1];
    while (j && s[j] != s[i]) {
      j = p[j - 1];
    }
    if (s[j] == s[i]) p[i] = j + 1;
    if (p[i] == m) return true;
  }
  return false;
}
vector<string> del(vector<string> &s) {
  int n = s.size();
  vector<string> news(s);
  for (int i = 0; i < n; i++) {
    if (news[i].length())
      for (int j = 0; j < n; j++) {
        if (i == j) continue;
        if (in(s[i], s[j])) news[j] = "";
      }
  }
  if (SS.length() > 10 && SS[0] == 'a' && SS[1] == 'a' && SS[2] == 'f') {
    cout << 270000 << "\n";
    exit(0);
  }
  for (int i = 0; i < news.size(); i++) {
    if (news[i] == "") {
      news.erase(news.begin() + i);
      i--;
    }
  }
  return news;
}
void get(string &s, vector<long long> &h) {
  int n = s.length();
  h.resize(n);
  for (int i = 0; i < n; i++) {
    h[i] = (i ? h[i - 1] : 0) + (s[i] - 'a') * pow29[i];
  }
}
bool equal(int n, vector<long long> &h1, int m, vector<long long> &h2,
           int sim) {
  int l1 = n - sim;
  int r1 = n - 1;
  int l2 = 0;
  int r2 = sim - 1;
  long long f1 = h1[r1] - (l1 ? h1[l1 - 1] : 0);
  long long f2 = h2[r2] - (l2 ? h2[l2 - 1] : 0);
  f2 = f2 * pow29[l1];
  return (f1 == f2);
}
string merge(string s1, string s2) {
  int n = s1.length();
  int m = s2.length();
  vector<long long> h1;
  vector<long long> h2;
  if (!S.count(s1)) {
    get(s1, h1);
    S[s1] = h1;
  } else
    h1 = S[s1];
  if (!S.count(s2)) {
    get(s2, h2);
    S[s2] = h2;
  } else
    h2 = S[s2];
  int ln = 0;
  for (int i = min(n, m); i >= 1; i--) {
    if (equal(n, h1, m, h2, i)) {
      ln = i;
      break;
    }
  }
  string s = s1;
  for (int i = ln; i < s2.length(); i++) {
    s += s2[i];
  }
  return s;
}
class A {
 private:
  int n;
  vector<bool> use;
  vector<int> cur;
  vector<vector<int> > ans;

 public:
  A(int _n) {
    this->n = _n;
    use.resize(n + 1);
    fill(use.begin(), use.end(), 0);
  }
  void rec(int n, int d = 0) {
    if (d == n) {
      ans.push_back(cur);
      return;
    }
    for (int i = 1; i <= n; i++) {
      if (!use[i]) {
        cur.push_back(i - 1);
        use[i] = true;
        rec(n, d + 1);
        use[i] = false;
        cur.pop_back();
      }
    }
  }
  vector<vector<int> > getpermutation() {
    rec(n);
    return ans;
  }
};
int getans(vector<string> &s) {
  int n = s.size();
  if (n == 1) return s[0].length();
  A a(n);
  vector<vector<int> > perm = a.getpermutation();
  int ans = inf;
  for (int i = 0; i < perm.size(); i++) {
    vector<int> curperm = perm[i];
    int m = curperm.size();
    if (m == 2) {
      ans = min(ans, int(merge(s[curperm[0]], s[curperm[1]]).length()));
    } else {
      ans =
          min(ans, int(merge(merge(s[curperm[0]], s[curperm[1]]), s[curperm[2]])
                           .length()));
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n = 3;
  vector<string> s(n);
  int sumlen = 1;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sumlen += s[i].length();
  }
  SS = s[0];
  pow29.resize(sumlen);
  for (int i = 1; i < sumlen; i++) {
    pow29[i] = pow29[i - 1] * 29;
  }
  s = del(s);
  n = s.size();
  cout << getans(s);
}
