#include <bits/stdc++.h>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

constexpr int MOD = 1000000007;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

template <class T>
string to_string(T s);
template <class S, class T>
string to_string(pair<S, T> p);
string to_string(string s) { return s; }
string to_string(const char s[]) { return to_string(string(s)); }

template <class T>
string to_string(T v) {
  if (v.empty()) return "{}";
  string ret = "{";
  for (auto x : v) ret += to_string(x) + ",";
  ret.back() = '}';
  return ret;
}
template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

void debug() { cerr << endl; }
template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

struct IO {
#ifdef _WIN32
  inline char getchar_unlocked() { return getchar(); }
  inline void putchar_unlocked(char c) { putchar(c); }
#endif
  string separator = " ";
  template <class T>
  inline void read(T& x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c != '-' && (c < '0' || '9' < c));
    bool minus = 0;
    if (c == '-') {
      minus = 1;
      c = getchar_unlocked();
    }
    x = 0;
    while ('0' <= c && c <= '9') {
      x *= 10;
      x += c - '0';
      c = getchar_unlocked();
    }
    if (minus) x = -x;
  }
  inline void read(string& x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c == ' ' || c == '\n');
    x.clear();
    do {
      x += c;
      c = getchar_unlocked();
    } while (c != ' ' && c != '\n' && c != EOF);
  }
  template <class T>
  inline void read(vector<T>& v) {
    for (auto& x : v) read(x);
  }
  template <class Head, class... Tail>
  inline void read(Head& head, Tail&... tail) {
    read(head);
    read(tail...);
  }
  template <class T>
  inline void write(T x) {
    char buf[32];
    int p = 0;
    if (x < 0) {
      x = -x;
      putchar_unlocked('-');
    }
    if (x == 0) putchar_unlocked('0');
    while (x > 0) {
      buf[p++] = (x % 10) + '0';
      x /= 10;
    }
    while (p) {
      putchar_unlocked(buf[--p]);
    }
  }
  inline void write(string x) {
    for (char c : x) putchar_unlocked(c);
  }
  inline void write(const char s[]) {
    for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]);
  }
  template <class T>
  inline void write(vector<T> v) {
    for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) {
      write(*itr);
      write(separator);
    }
    write(v.back());
  }
  template <class Head, class... Tail>
  inline void write(Head head, Tail... tail) {
    write(head);
    write(separator);
    write(tail...);
  }
  template <class Head, class... Tail>
  inline void writeln(Head head, Tail... tail) {
    write(head, tail...);
    write("\n");
  }
  void set_separator(string s) { separator = s; }
} io;

int solve(string a, string b, string c) {
  vector<int> ok_ab(a.size() + 1);
  REP(i, a.size() + 1) {
    bool f = 1;
    for (int j = 0; i + j < a.size() && j < b.size(); ++j) {
      if (a[i + j] != '?' && b[j] != '?' && a[i + j] != b[j]) {
        f = 0;
        break;
      }
    }
    ok_ab[i] = f;
  }
  vector<int> ok_bc(b.size() + 1);
  REP(i, b.size() + 1) {
    bool f = 1;
    for (int j = 0; i + j < b.size() && j < c.size(); ++j) {
      if (b[i + j] != '?' && c[j] != '?' && b[i + j] != c[j]) {
        f = 0;
        break;
      }
    }
    ok_bc[i] = f;
  }
  vector<int> ok_ac(a.size() + 1);
  REP(i, a.size() + 1) {
    bool f = 1;
    for (int j = 0; i + j < a.size() && j < c.size(); ++j) {
      if (a[i + j] != '?' && c[j] != '?' && a[i + j] != c[j]) {
        f = 0;
        break;
      }
    }
    ok_ac[i] = f;
  }
  // debug(ok_ab, ok_bc, ok_ac);
  int ans = INF;
  REP(i, a.size() + 1) {
    if (!ok_ab[i]) continue;
    REP(j, max((int)a.size() - i + 1, (int)b.size() + 1)) {
      if (j < b.size() && !ok_bc[j]) continue;
      if (i + j < a.size() && !ok_ac[i + j]) continue;
      ans = min(ans, (int)(a.size() + b.size() + c.size() -
                           min((int)b.size(), ((int)a.size() - i)) -
                           min((int)c.size(),
                               max((int)a.size() - i - j, (int)b.size() - j))));
      // debug(i, j, ans, (int)a.size() - i - j);
    }
  }
  // debug(ans);
  return ans;
}

int main() {
  string a, b, c;
  io.read(a, b, c);
  int ans = INF;
  ans = min(ans, solve(a, b, c));
  ans = min(ans, solve(a, c, b));
  ans = min(ans, solve(b, a, c));
  ans = min(ans, solve(b, c, a));
  ans = min(ans, solve(c, a, b));
  ans = min(ans, solve(c, b, a));
  io.writeln(ans);
  return 0;
}

Measured memory_bytes: 384