#include <bits/stdc++.h>
using namespace std;
string a, b, c;
string ans;
string tmp;
int Z[int(3e5 + 100)];
int Zfunction(string a, string b) {
  string tmp = a + "*" + b;
  memset(Z, 0, sizeof(Z));
  int l = 0, r = 0;
  for (int i = 1; i < tmp.length(); i++) {
    if (i <= r) Z[i] = min(Z[i - l], r - i + 1);
    while (tmp[Z[i]] == tmp[i + Z[i]] && i + Z[i] < tmp.length()) Z[i]++;
    if (r <= i + Z[i] - 1) {
      l = i;
      r = i + Z[i] - 1;
    }
  }
  for (int i = 1; i < tmp.length(); i++)
    if (Z[i] == tmp.length() - i || Z[i] == a.length()) return Z[i];
  return 0;
}
int Work(string a, string b, string c) {
  int calc = Zfunction(b, a);
  tmp = a;
  for (int i = calc; i < b.length(); i++) tmp += b[i];
  calc = Zfunction(c, tmp);
  ans = tmp;
  for (int i = calc; i < c.length(); i++) ans += c[i];
  return ans.length();
}
int main() {
  cin >> a >> b >> c;
  int ans = Work(a, b, c);
  ans = min(ans, Work(a, c, b));
  ans = min(ans, Work(b, a, c));
  ans = min(ans, Work(b, c, a));
  ans = min(ans, Work(c, a, b));
  ans = min(ans, Work(c, b, a));
  cout << ans;
}
