#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

template<typename T, T MOD1, T MOD2, T B1, T B2>
struct RollingHash {
	vector<T>hash[2], p[2];
	T MOD[2] = { MOD1,MOD2 };
	T B[2] = { B1,B2 };
	RollingHash(const string &s) {
		int N = s.size();
		for (int k = 0; k < 2; k++) {
			hash[k].assign(N + 1, 0);
			p[k].assign(N + 1, 1);
			for (int i = 0; i < N; i++) {
				hash[k][i + 1] = (hash[k][i] * B[k] + s[i]) % MOD[k];
				p[k][i + 1] = p[k][i] * B[k] % MOD[k];
			}
		}
	}

	//S[l,r)
	pair<T, T>find(int l, int r) {
		T res1 = hash[0][r] + MOD[0] - hash[0][l] * p[0][r - l] % MOD[0];
		res1 = (res1 >= MOD[0]) ? res1 - MOD[0] : res1;
		T res2 = hash[1][r] + MOD[1] - hash[1][l] * p[1][r - l] % MOD[1];
		res2 = (res2 >= MOD[1]) ? res2 - MOD[1] : res2;

		return make_pair(res1, res2);
	}
	T find1(int l, int r) {
		T res1 = hash[0][r] + MOD[0] - hash[0][l] * p[0][r - l] % MOD[0];
		return (res1 >= MOD[0]) ? res1 - MOD[0] : res1;
	}
	T find2(int l, int r) {
		T res2 = hash[1][r] + MOD[1] - hash[1][l] * p[1][r - l] % MOD[1];
		return (res2 >= MOD[1]) ? res2 - MOD[1] : res2;
	}
};
//using RH = RollingHash<ll, (ll)1e9 + 7, (ll)1e9 + 9, 1234567, 7654343>;
//RH rh(S);
using RH = RollingHash<ll, (ll)1e9 + 7, (ll)1e9 + 9, 1234567, 7654343>;

int siz[3];
int calc(string s, string t) {
	int n = s.size(), m = t.size();
	int M = min(n, m);
	FOR(i, n - M, n) {
		int k = n - i;
		bool ok = true;
		REP(j, k) {
			if (s[i + j] != t[j] && s[i + j] != '?'&&t[j] != '?') {
				ok = false; break;
			}
		}
		if (ok)return k;
	}
	return 0;
}
int A[3][3][6060];
void solve() {
	vector<string>v(3);
	int sum = 0;
	REP(i, 3) {
		cin >> v[i];
		siz[i] = v[i].size();
		sum += siz[i];
	}
	REP(i, 3)REP(j, 3)REP(k, 6060)A[i][j][k] = 1e9;
	REP(i, 3) {
		REP(j, 3) {
			if (i == j)continue;
			REP(k, siz[i]) {
				int res = 0;
				REP(l, min(siz[i] - k, siz[j])) {
					if (v[i][k + l] == v[j][l] || v[i][k + l] == '?' || v[j][l] == '?')res++;
					else break;
				}
				A[i][j][k] = res;
			}
		}
	}
	int id[3];
	REP(i, 3)id[i] = i;
	ll ans = sum;
	do {
		REP(b1, siz[id[0]]) {
			FOR(b2, b1, max(siz[id[0]], b1 + siz[id[1]])) {
				bool ok = true;
				if (A[id[0]][id[1]][b1] < min(siz[id[0]] - b1, siz[id[1]]))ok = false;
				if (A[id[1]][id[2]][b2 - b1] < min(siz[id[1]] - (b2 - b1), siz[id[2]]))ok = false;
				if (A[id[0]][id[2]][b2] < min(siz[id[0]] - b2, siz[id[2]]))ok = false;
				int res = max({ siz[id[0]],b1 + siz[id[1]],b2 + siz[id[2]] });
				if (ok)ans = min(ans, res);
			}
		}
	} while (next_permutation(id, id + 3));;
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 640