#include <bits/stdc++.h>
using namespace std;
string l[3];
string subproblem(string a, string b) {
  string proto = b + "#" + a;
  vector<int> prefix(proto.length());
  for (int i = 1; i < proto.length(); i++) {
    int j = prefix[i - 1];
    while (j > 0 and proto[i] != proto[j]) {
      j = prefix[j - 1];
    }
    if (proto[i] == proto[j]) {
      j++;
    }
    prefix[i] = j;
    if (j == b.length()) {
      return a;
    }
  }
  int found = prefix[proto.length() - 1];
  return (a + b.substr(found, b.length()));
}
int solve(string a, string b, string c) {
  return subproblem(subproblem(a, b), c).length();
}
int main() {
  for (int i = 0; i < 3; i++) {
    cin >> l[i];
  }
  vector<int> pos = {0, 1, 2};
  int best = 5e5 + 5;
  do {
    best = min(best, solve(l[pos[0]], l[pos[1]], l[pos[2]]));
  } while (next_permutation(pos.begin(), pos.end()));
  cout << best << '\n';
}
