#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  unsigned long long c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
}
string rs, rss, rsss, s[3];
int z[100010];
void fail(string s) {
  memset(z, 0, (int)sizeof z);
  for (int i = 1, j = 0; i < s.size(); i++) {
    while (j > 0 && s[i] != s[j]) j = z[j - 1];
    if (s[i] == s[j])
      z[i] = ++j;
    else
      z[i] = j;
  }
}
bool KMPfind(string &s, string &p) {
  for (int i = 0, j = 0; i < s.size(); i++) {
    while (j > 0 && p[j] != s[i]) j = z[j - 1];
    if (p[j] == s[i]) j++;
    if (j == p.size()) return 1;
  }
  return 0;
}
string KMPapp(string s, string p) {
  int j = 0;
  for (int i = 0; i < s.size(); i++) {
    while (j > 0 && p[j] != s[i]) j = z[j - 1];
    if (p[j] == s[i]) j++;
  }
  s += p.substr(j, -1);
  return s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  while (cin >> s[0] >> s[1] >> s[2]) {
    int arr[3] = {0, 1, 2};
    vector<string> v;
    do {
      string get = s[arr[0]];
      fail(s[arr[1]]);
      if (!KMPfind(s[arr[0]], s[arr[1]])) get = KMPapp(s[arr[0]], s[arr[1]]);
      fail(s[arr[2]]);
      if (!KMPfind(get, s[arr[2]])) get = KMPapp(get, s[arr[2]]);
      v.push_back(get);
    } while (next_permutation(arr, arr + 3));
    int minn = 1000000000;
    for (int i = 0; i < v.size(); i++) minn = min((int)v[i].size(), minn);
    cout << minn << "\n";
  }
  return 0;
}
