#include <bits/stdc++.h>
using namespace std;
const int maxa = 500000;
const int cha = 26;
int vis[maxa];
int a[10];
struct Tire {
  int next[maxa][cha], fail[maxa], end[maxa];
  int root, L;
  int newnode() {
    for (int i = 0; i < cha; i++) {
      next[L][i] = -1;
    }
    end[L++] = 0;
    return L - 1;
  }
  void init() {
    L = 0;
    root = newnode();
  }
  int insert(char buf[], int jj) {
    int len = strlen(buf);
    int now = root;
    for (int i = 0; i < len; i++) {
      if (next[now][buf[i] - 'a'] == -1) next[now][buf[i] - 'a'] = newnode();
      now = next[now][buf[i] - 'a'];
    }
    end[now] |= jj;
    return now;
  }
  void build() {
    queue<int> Q;
    fail[root] = root;
    for (int i = 0; i < cha; i++) {
      if (next[root][i] == -1)
        next[root][i] = root;
      else {
        fail[next[root][i]] = root;
        Q.push(next[root][i]);
      }
    }
    while (!Q.empty()) {
      int now = Q.front();
      Q.pop();
      end[now] |= end[fail[now]];
      for (int i = 0; i < cha; i++) {
        if (next[now][i] == -1)
          next[now][i] = next[fail[now]][i];
        else {
          end[next[now][i]] |= end[now];
          fail[next[now][i]] = next[fail[now]][i];
          Q.push(next[now][i]);
        }
      }
    }
  }
  int solve(int ii, int jj) {
    queue<int> Q;
    Q.push(a[ii]);
    vis[a[ii]] = 1;
    while (!Q.empty()) {
      int now = Q.front();
      if (end[now] & (1 << jj)) return vis[now] - 1;
      if (now == a[jj]) {
        break;
      }
      Q.pop();
      for (int i = 0; i < cha; i++) {
        if (vis[next[now][i]]) continue;
        Q.push(next[now][i]);
        vis[next[now][i]] = vis[now] + 1;
      }
    }
    return vis[a[jj]] - 1;
  }
};
char buf[1000005];
Tire ac;
int edge[5][5];
int l[10];
int main() {
  scanf("%s", buf);
  l[0] = strlen(buf);
  ac.init();
  a[0] = ac.insert(buf, 1);
  scanf("%s", buf);
  l[1] = strlen(buf);
  a[1] = ac.insert(buf, 2);
  scanf("%s", buf);
  l[2] = strlen(buf);
  a[2] = ac.insert(buf, 4);
  ac.build();
  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 3; k++) {
      if (k == i) continue;
      memset(vis, 0, sizeof(vis));
      int ss = ac.solve(i, k);
      edge[i][k] = ss;
    }
  }
  int ans = 100000000;
  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 3; k++) {
      if (k == i) continue;
      for (int j = 0; j < 3; j++) {
        if (j == i || j == k) continue;
        ans = min(ans, edge[i][k] + min(edge[i][j], edge[k][j]) + l[i]);
      }
    }
  }
  printf("%d\n", ans);
}
