#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1E9 + 7, INF = 2E18 + 5;
const double PI = 2 * acos(0.0);
const long double EPS = 1.0E-14;
long long arrPow[100005], arrHash1[100005], arrHash2[100005], mat[5][5];
long long p1 = 31, mod1 = 1001110699, maxPow = 100000;
void init() {
  arrPow[0] = 1;
  for (int i = 1; i <= maxPow; i++) {
    arrPow[i] = (arrPow[i - 1] * p1) % mod1;
  }
  return;
}
void makeHash(string s1, string s2) {
  arrHash1[0] = arrHash2[0] = 0;
  for (int i = 0; i < s1.size(); i++) {
    arrHash1[i + 1] = (arrHash1[i] + ((s1[i] - 'a' + 1) * arrPow[i])) % mod1;
  }
  for (int i = 0; i < s2.size(); i++) {
    arrHash2[i + 1] = (arrHash2[i] + ((s2[i] - 'a' + 1) * arrPow[i])) % mod1;
  }
  return;
}
long long getHash1(long long L, long long R) {
  long long ans = (arrHash1[R] - arrHash1[L - 1] + mod1) % mod1;
  ans *= arrPow[maxPow - (R - 1)];
  ans %= mod1;
  return ans;
}
long long getHash2(long long L, long long R) {
  long long ans = (arrHash2[R] - arrHash2[L - 1] + mod1) % mod1;
  ans *= arrPow[maxPow - (R - 1)];
  ans %= mod1;
  return ans;
}
long long preFixsufFix(string s1, string s2) {
  makeHash(s1, s2);
  long long sz1 = s1.size(), sz2 = s2.size(), len;
  for (int i = 1; i <= sz1; i++) {
    len = sz1 - i + 1;
    if (len <= sz2) {
      if (getHash1(i, sz1) == getHash2(1, len)) return len;
    }
  }
  return 0;
}
bool contains(string s1, string s2) {
  makeHash(s1, s2);
  if (s2.size() > s1.size()) return false;
  long long sz = s2.size(), lim = s1.size() - sz + 1;
  for (int i = 1; i <= lim; i++) {
    if (getHash1(i, i + sz - 1) == getHash2(1, sz)) {
      return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  init();
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  long long ans = INF, sz12 = s1.size() + s2.size(),
            sz13 = s1.size() + s3.size(), sz23 = s2.size() + s3.size(),
            sz = s1.size() + s2.size() + s3.size(), AB, BC, AC, BA, CB, CA;
  AB = preFixsufFix(s1, s2), BA = preFixsufFix(s2, s1);
  BC = preFixsufFix(s2, s3), CB = preFixsufFix(s3, s2);
  AC = preFixsufFix(s1, s3), CA = preFixsufFix(s3, s1);
  mat[1][2] = contains(s1, s2), mat[2][1] = contains(s2, s1);
  mat[1][3] = contains(s1, s3), mat[3][1] = contains(s3, s1);
  mat[2][3] = contains(s2, s3), mat[3][2] = contains(s3, s2);
  if (mat[1][2]) {
    if (mat[1][3]) ans = min(ans, (long long)s1.size());
    if (mat[3][1]) ans = min(ans, (long long)s3.size());
    ans = min(ans, sz13 - AC);
    ans = min(ans, sz13 - CA);
  }
  if (mat[2][1]) {
    if (mat[2][3]) ans = min(ans, (long long)s2.size());
    if (mat[3][2]) ans = min(ans, (long long)s3.size());
    ans = min(ans, sz23 - BC);
    ans = min(ans, sz23 - CB);
  }
  if (mat[1][3]) {
    if (mat[1][2]) ans = min(ans, (long long)s1.size());
    if (mat[2][1]) ans = min(ans, (long long)s2.size());
    ans = min(ans, sz12 - AB);
    ans = min(ans, sz12 - BA);
  }
  if (mat[3][1]) {
    if (mat[3][2]) ans = min(ans, (long long)s3.size());
    if (mat[2][3]) ans = min(ans, (long long)s2.size());
    ans = min(ans, sz23 - BC);
    ans = min(ans, sz23 - CB);
  }
  if (mat[2][3]) {
    if (mat[2][1]) ans = min(ans, (long long)s2.size());
    if (mat[1][2]) ans = min(ans, (long long)s1.size());
    ans = min(ans, sz12 - AB);
    ans = min(ans, sz12 - BA);
  }
  if (mat[3][2]) {
    if (mat[3][1]) ans = min(ans, (long long)s3.size());
    if (mat[1][3]) ans = min(ans, (long long)s1.size());
    ans = min(ans, sz13 - AC);
    ans = min(ans, sz13 - CA);
  }
  ans = min(ans, sz - AB - BC);
  ans = min(ans, sz - AC - CB);
  ans = min(ans, sz - BA - AC);
  ans = min(ans, sz - BC - CA);
  ans = min(ans, sz - CA - AB);
  ans = min(ans, sz - CB - BA);
  cout << ans << "\n";
  return 0;
}
