#include <bits/stdc++.h>
using namespace std;
const int max_n = 2e5 + 10;
const int inf = 0x7fffffff;
const int b0 = 233;
unsigned long long b[max_n], h1[max_n], h2[max_n];
string s1, s2, s3, res;
void init_b() {
  b[0] = 1;
  for (int i = 1; i < max_n; i++) {
    b[i] = b[i - 1] * b0;
  }
}
void init_Hash(string s, unsigned long long *h) {
  h[0] = (s[0] - 'a');
  for (int i = 1; i < s.size(); i++) {
    h[i] = h[i - 1] * b0 + (s[i] - 'a');
  }
}
unsigned long long lr_Hash(int l, int r, unsigned long long *h) {
  if (l == 0) return h[r];
  return h[r] - h[l - 1] * b[r - l + 1];
}
string connect(string s, string t) {
  init_Hash(s, h1);
  init_Hash(t, h2);
  const int sl = s.size(), tl = t.size();
  if (sl < tl) {
    unsigned long long tmp = lr_Hash(0, sl - 1, h1);
    for (int i = 0; i < tl - sl + 1; i++) {
      unsigned long long tmp2 = lr_Hash(i, i + sl - 1, h2);
      if (tmp == tmp2) return t;
    }
  } else if (sl > tl) {
    unsigned long long tmp = lr_Hash(0, tl - 1, h2);
    for (int i = 0; i < sl - tl + 1; i++) {
      unsigned long long tmp2 = lr_Hash(i, i + tl - 1, h1);
      if (tmp == tmp2) return s;
    }
  }
  int len = min(sl, tl);
  for (int i = len; i >= 1; i--) {
    unsigned long long tmps = lr_Hash(sl - i, sl - 1, h1);
    unsigned long long tmpt = lr_Hash(0, i - 1, h2);
    if (tmps == tmpt) {
      res.clear();
      int cnt = sl;
      res = s;
      for (int j = i; j < tl; j++) {
        res += t[j];
      }
      return res;
    }
  }
  return s + t;
}
int main() {
  init_b();
  cin >> s1 >> s2 >> s3;
  int ans = inf;
  ans = min(ans, (int)connect(s1, connect(s2, s3)).size());
  ans = min(ans, (int)connect(s1, connect(s3, s2)).size());
  ans = min(ans, (int)connect(s2, connect(s1, s3)).size());
  ans = min(ans, (int)connect(s2, connect(s3, s1)).size());
  ans = min(ans, (int)connect(s3, connect(s1, s2)).size());
  ans = min(ans, (int)connect(s3, connect(s2, s1)).size());
  printf("%d\n", ans);
  return 0;
}
