#include <bits/stdc++.h>
using namespace std;
using namespace std;
string s[3];
int dp[3][3];
int match(int a, int b) {
  if (dp[a][b] != -1) return dp[a][b];
  int &ans = dp[a][b];
  ans = 0;
  map<long long int, int> m;
  long long int x = 1, val = 0;
  for (int i = 0; i < s[b].size(); ++i) {
    val = (val + s[b][i] * x) % 18014398241046527LL;
    m[val] = i + 1;
    x = (x * 107) % 18014398241046527LL;
  }
  val = 0, x = 1;
  for (int i = s[a].size() - 1; i >= 0; --i) {
    val = (107 * val + s[a][i]) % 18014398241046527LL;
    if (m[val] == s[a].size() - i) {
      ans = m[val];
    }
  }
  return ans;
}
int matchs(string sa, string sb) {
  int ans = 0;
  map<long long int, int> m;
  long long int x = 1, val = 0;
  for (int i = 0; i < sb.size(); ++i) {
    val = (val + sb[i] * x) % 18014398241046527LL;
    m[val] = i + 1;
    x = (x * 107) % 18014398241046527LL;
  }
  val = 0, x = 1;
  for (int i = sa.size() - 1; i >= 0; --i) {
    val = (107 * val + sa[i]) % 18014398241046527LL;
    if (m[val] == sa.size() - i) {
      ans = m[val];
    }
  }
  return ans;
}
int get(int a1, int a2, int a3) {
  int m12 = match(a1, a2);
  int m23 = match(a2, a3);
  if (m12 + m23 >= s[a2].size())
    return s[a1].size() + s[a3].size() - match(a1, a3);
  return s[a1].size() + s[a2].size() + s[a3].size() - m12 - m23;
}
void compute_prefix(const char *P, int *pie) {
  pie[1] = 0;
  int m = strlen(P), k = 0;
  for (int i = 1; i < m; ++i) {
    while (k > 0 && P[k] != P[i]) {
      k = pie[k];
    }
    if (P[i] == P[k]) {
      k++;
    }
    pie[i + 1] = k;
  }
  return;
}
bool KMP(const char *T, const char *P) {
  int pie[100005];
  compute_prefix(P, pie);
  int n = strlen(T), m = strlen(P);
  int q = 0;
  for (int i = 0; i < n; ++i) {
    while (q > 0 && P[q] != T[i]) q = pie[q];
    if (P[q] == T[i]) q++;
    if (q == m) {
      return true;
    }
  }
  return false;
}
int main() {
  memset(dp, -1, sizeof(dp));
  ;
  cin >> s[0] >> s[1] >> s[2];
  if (s[0].size() > s[1].size()) swap(s[0], s[1]);
  if (s[1].size() > s[2].size()) swap(s[1], s[2]);
  if (s[0].size() > s[1].size()) swap(s[0], s[1]);
  if (KMP(s[1].c_str(), s[0].c_str())) s[0] = "";
  if (KMP(s[2].c_str(), s[0].c_str())) s[0] = "";
  if (KMP(s[2].c_str(), s[1].c_str())) s[1] = "";
  int ans = 1 << 30;
  ans = min(ans, get(0, 1, 2));
  ans = min(ans, get(1, 0, 2));
  ans = min(ans, get(2, 1, 0));
  ans = min(ans, get(1, 2, 0));
  ans = min(ans, get(2, 0, 1));
  ans = min(ans, get(0, 2, 1));
  if (ans == 100001)
    cout << "100002";
  else
    cout << ans;
  return 0;
}
