#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
bool f(string a, string b) {
  if (a.length() < b.length()) return false;
  a += ' ';
  long long c = 0, bs = b.length();
  for (long long i = 0; i < a.length() + 1; ++i) {
    if (a[i] == b[c]) {
      while (a[i] == b[c]) {
        ++c;
        ++i;
      }
      if (c == bs)
        return true;
      else
        c = 0;
    }
  }
  return false;
}
vector<long long> kmp(string s) {
  long long n = s.length();
  vector<long long> pi(n);
  for (long long i = 1; i <= n - 1; ++i) {
    long long j = pi[i - 1];
    while (j > 0 && s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) ++j;
    pi[i] = j;
  }
  return pi;
}
long long gogogo(string a, string b, string c) {
  string ab, ac, ba, bc, ca, cb, aa, bb, cc;
  long long AB, AC, BA, BC, CA, CB, l, A, B, C;
  aa = a, bb = b, cc = c;
  A = a.length(), B = b.length(), C = c.length();
  l = A + B + C;
  reverse(aa.begin(), aa.end());
  reverse(bb.begin(), bb.end());
  reverse(cc.begin(), cc.end());
  ab = aa + bb, ac = aa + cc, ba = bb + aa, bc = bb + cc, ca = cc + aa,
  cb = cc + bb;
  AB = min(kmp(ab).back(), B);
  AC = min(kmp(ac).back(), C);
  BA = min(kmp(ba).back(), A);
  BC = min(kmp(bc).back(), C);
  CA = min(kmp(ca).back(), A);
  CB = min(kmp(cb).back(), B);
  if (!f(a, b)) a = a.substr(0, a.length() - AB) + b;
  long long tmp = min(C, kmp(c + a).back());
  if (!f(a, c)) a = a.substr(0, a.length() - tmp) + c;
  return a.length();
}
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  vector<long long> sol;
  sol.push_back(gogogo(a, b, c));
  sol.push_back(gogogo(a, c, b));
  sol.push_back(gogogo(b, a, c));
  sol.push_back(gogogo(b, c, a));
  sol.push_back(gogogo(c, a, b));
  sol.push_back(gogogo(c, b, a));
  cout << *min_element(sol.begin(), sol.end());
}
