#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 20;
long long P = 237;
long long MO = 1000000009;
char ss[3][MAX];
int len[3];
long long head[3][MAX], tail[3][MAX];
void iniHeadTailHa(char s[], long long headha[], long long tailha[]) {
  int l = strlen(s);
  long long base = 1;
  for (int i = (0); i <= (l - 1); ++i) {
    if (i == 0)
      headha[i] = s[i];
    else {
      headha[i] = (headha[i - 1] + s[i] * base) % MO;
    }
    base = base * P % MO;
  }
  for (int i = (l - 1); i >= (0); --i) {
    if (i == l - 1)
      tailha[i] = s[i];
    else {
      tailha[i] = (tailha[i + 1] * P % MO + s[i]) % MO;
    }
  }
}
bool contain(string &s1, string &s2) {
  if (s1.size() > s2.size()) return 0;
  bool ok = 0;
  long long ha = 0, base = 1, ha2 = 0, base2 = 1;
  for (int i = (0); i <= (s1.size() - 1); ++i) {
    ha = (ha + base * s1[i]) % MO;
    base = base * P % MO;
  }
  for (int i = (s2.size() - s1.size()); i <= (s2.size() - 1); ++i) {
    ha2 = (ha2 + base2 * s2[i]) % MO;
    base2 = base2 * P % MO;
  }
  base2 = 1;
  for (int i = (0); i <= ((int)s1.size() - 2); ++i) base2 = base2 * P % MO;
  for (int i = (s2.size() - s1.size()); i >= (0); --i) {
    if (ha == (ha2 + MO) % MO) {
      ok = 1;
      break;
    }
    if (i != 0) {
      int y = i + s1.size() - 1;
      ha2 = (ha2 - s2[y] * base2) % MO;
      ha2 = (ha2 * P + s2[i - 1]) % MO;
    }
  }
  if (!ok) return false;
  return true;
}
string s[3];
string hh[3];
int hnt;
int a, b;
int suo[4][4];
int track[4], ans;
int suo2[4][4];
void sol(int pos) {
  if (pos == hnt) {
    int tlen = 0;
    for (int i = 0; i < hnt; i++) tlen += len[i];
    for (int i = 1; i < hnt; i++) {
      tlen -= suo[track[i - 1]][track[i]];
    }
    if (tlen < ans) ans = tlen;
  } else {
    for (int j = pos; j < hnt; j++) {
      swap(track[j], track[pos]);
      sol(pos + 1);
      swap(track[j], track[pos]);
    }
  }
}
bool bb[3];
bool debug;
int main() {
  for (int i = 0; i < 3; i++) cin >> s[i];
  debug = 0;
  for (int i = 0; i < 3; i++) {
    bool ok = 1;
    for (int j = 0; j < 3; j++) {
      if (i != j) {
        if (contain(s[i], s[j])) {
          ok = 0;
          break;
        }
      }
    }
    bb[i] = ok;
  }
  for (int i = 0; i < 3; i++)
    if (bb[i]) hh[hnt++] = s[i];
  if (hnt == 0)
    printf("%d\n", s[0].size());
  else if (hnt == 1)
    printf("%d\n", hh[0].size());
  else {
    for (int i = 0; i < hnt; i++) {
      for (int j = 0; j < hh[i].size(); j++) ss[i][j] = hh[i][j];
      ss[i][hh[i].size()] = 0;
      len[i] = hh[i].size();
    }
    for (int i = 0; i < hnt; i++) iniHeadTailHa(ss[i], head[i], tail[i]);
    for (int i = 0; i < hnt; i++) {
      for (int j = 0; j < hnt; j++) {
        if (i != j) {
          int mlen = min(len[i], len[j]);
          int mx = 0;
          for (int pos = 0; pos < mlen; pos++) {
            if (tail[i][len[i] - 1 - pos] == head[j][pos]) {
              mx = max(mx, pos + 1);
            }
          }
          suo[i][j] = mx;
        }
      }
    }
    if (debug) {
      for (int i = 0; i < hnt; i++) {
        printf("len = %d\n", len[i]);
        for (int j = 0; j < hnt; j++) {
          if (i != j) {
          }
        }
      }
    }
    ans = INT_MAX;
    for (int i = 0; i < 3; i++) track[i] = i;
    sol(0);
    printf("%d\n", ans);
  }
  return 0;
}
