#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
string a[3], s;
int z[300010], ans = 1e9;
void calcZ() {
  int lb = 0, ub = 0;
  for (int i = 1; i <= s.size() - 1; i++) {
    if (s[i] != s[0]) continue;
    if (i > ub) {
      int p = i;
      while (p < s.size() && s[p] == s[p - i]) p++;
      lb = i;
      ub = p - 1;
      z[i] = p - i;
    } else {
      int j = i - lb;
      if (j + z[j] - 1 < ub - lb)
        z[i] = z[j];
      else {
        int p = ub + 1;
        while (p < s.size() && s[p] == s[p - i]) p++;
        z[i] = p - i;
        lb = i;
        ub = p - 1;
      }
    }
  }
}
int main() {
  for (int i = 0; i < 3; i++) cin >> a[i];
  sort(a, a + 3);
  do {
    s = a[1] + a[0];
    memset(z, 0, sizeof(z));
    calcZ();
    int pos = a[0].size();
    for (int i = 0; i < a[0].size(); i++) {
      if (z[i + a[1].size()] >= min(a[1].size(), a[0].size() - i)) {
        pos = i;
        break;
      }
    }
    int sz = max(a[0].size(), pos + a[1].size());
    int stane = sz;
    s = a[0];
    if (pos + a[1].size() > a[0].size())
      s += a[1].substr(a[1].size() - (a[1].size() - (a[0].size() - pos)),
                       a[1].size() - (a[0].size() - pos));
    s = a[2] + s;
    memset(z, 0, sizeof(z));
    calcZ();
    pos = sz;
    for (int i = a[2].size(), j = 0; i < s.size(); i++, j++) {
      if (z[i] >= min(a[2].size(), s.size() - i)) {
        pos = j;
        break;
      }
    }
    sz = max(sz, (int)(pos + a[2].size()));
    ans = min(ans, sz);
  } while (next_permutation(a, a + 3));
  cout << ans << endl;
  return 0;
}
