#include <bits/stdc++.h>
using namespace std;
long long pre[200005];
long long mod = 1000000007;
long long base = 347;
int fun(string a, string b, string c) {
  int x = 0;
  long long h1 = 0;
  long long h2 = 0;
  int j = a.size() - 1;
  int lop = min(a.size(), b.size());
  for (int i = 0; i < lop; i++) {
    h1 += (pre[i] * b[i]) % mod;
    if (h1 >= mod) {
      h1 %= mod;
    }
    h2 = (h2 % mod * base % mod) % mod;
    h2 += a[j];
    if (h2 >= mod) h2 %= mod;
    if (h1 == h2) {
      x = i + 1;
    }
    j--;
  }
  if (a.size() > b.size()) {
    h1 = 0;
    h2 = 0;
    j = b.size() - 1;
    for (int i = 0; i < b.size(); i++) {
      h1 += (pre[j] * b[i]) % mod;
      if (h1 >= mod) h1 %= mod;
      h2 += (pre[j] * a[i]) % mod;
      if (h2 >= mod) h2 %= mod;
      j--;
    }
    if (h1 == h2) {
      x = b.size();
    } else {
      j = 0;
      int op = b.size() - 1;
      for (int i = b.size(); i < a.size(); i++) {
        h2 -= (pre[op] * a[j]) % mod;
        if (h2 < 0) h2 += mod;
        h2 = (h2 * base);
        if (h2 >= mod) h2 %= mod;
        h2 += a[i];
        if (h2 >= mod) h2 % mod;
        if (h2 == h1) {
          x = b.size();
          break;
        }
        j++;
      }
    }
  }
  string nw = a;
  for (int i = x; i < b.size(); i++) {
    nw += b[i];
  }
  h1 = 0;
  h2 = 0;
  x = 0;
  j = nw.size() - 1;
  lop = min(c.size(), nw.size());
  for (int i = 0; i < lop; i++) {
    h1 += (pre[i] * c[i]) % mod;
    if (h1 >= mod) {
      h1 %= mod;
    }
    h2 = (h2 % mod * base % mod) % mod;
    h2 += nw[j];
    if (h2 >= mod) h2 %= mod;
    if (h1 == h2) {
      x = i + 1;
    }
    j--;
  }
  if (nw.size() > c.size()) {
    h1 = 0;
    h2 = 0;
    j = c.size() - 1;
    for (int i = 0; i < c.size(); i++) {
      h1 += (pre[j] * c[i]) % mod;
      if (h1 >= mod) h1 %= mod;
      h2 += (pre[j] * nw[i]) % mod;
      if (h2 >= mod) h2 %= mod;
      j--;
    }
    if (h1 == h2) {
      x = c.size();
    } else {
      j = 0;
      int op = c.size() - 1;
      for (int i = c.size(); i < nw.size(); i++) {
        h2 -= (pre[op] * nw[j]) % mod;
        if (h2 < 0) h2 += mod;
        h2 = (h2 * base);
        if (h2 >= mod) h2 %= mod;
        h2 += nw[i];
        if (h2 >= mod) h2 % mod;
        if (h2 == h1) {
          x = c.size();
          break;
        }
        j++;
      }
    }
  }
  int ans = nw.size() + c.size() - x;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  pre[0] = 1;
  for (int i = 1; i <= 2e5; i++) {
    pre[i] = pre[i - 1] * base;
    if (pre[i] >= mod) pre[i] %= mod;
  }
  string a, b, c;
  while (cin >> a >> b >> c) {
    int mn = 5 * 1e5;
    mn = fun(a, b, c);
    mn = min(mn, fun(a, c, b));
    mn = min(mn, fun(b, a, c));
    mn = min(mn, fun(b, c, a));
    mn = min(mn, fun(c, a, b));
    mn = min(mn, fun(c, b, a));
    cout << mn << endl;
  }
  return 0;
}
