#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/















bool ok_ab[6010]; // [a]
bool ok_bc[6010]; // [b]
bool ok_ac[6010]; // [a]
int solve(string A, string B, string C) {
	/*cout << A << " " << B << " " << C << endl;
	return 0;*/

	int na = A.size();
	int nb = B.size();
	int nc = C.size();

	rep(i, 0, 6010) ok_ab[i] = true;
	rep(a, 0, na) {
		for (int i = 0; a + i < na && i < nb; i++) {
			if (A[a + i] == '?') continue;
			if (B[i] == '?') continue;
			if (A[a + i] != B[i]) ok_ab[a] = false;
		}
	}

	rep(i, 0, 6010) ok_bc[i] = true;
	rep(b, 0, nb) {
		for (int i = 0; b + i < nb && i < nc; i++) {
			if (B[b + i] == '?') continue;
			if (C[i] == '?') continue;
			if (B[b + i] != C[i]) ok_bc[b] = false;
		}
	}

	rep(i, 0, 6010) ok_ac[i] = true;
	rep(a, 0, na) {
		for (int i = 0; a + i < na && i < nc; i++) {
			if (A[a + i] == '?') continue;
			if (C[i] == '?') continue;
			if (A[a + i] != C[i]) ok_ac[a] = false;
		}
	}

	int ans = inf;
	rep(a, 0, na + 1) rep(b, 0, nb + 1) if(ok_ab[a] && ok_bc[b] && ok_ac[a + b]) {
		chmin(ans, max({ na, a + nb, a + b + nc }));
	}
	rep(a, 0, na + 1) rep(b, nb, 4040) if (ok_ab[a] && ok_bc[b] && ok_ac[a + b]) {
		chmin(ans, max({ na, a + nb, a + b + nc }));
	}
	return ans;

	/*
	rep(a, 0, na) if (okb[a]) {
		string AB = A;
		int i = 0;
		for (; a + i < na && i < nb; i++) {
			if (A[a + i] == '?') AB += B[i];
			else AB += A[a + i];
		}
		while (a + i < na) AB += A[a + i], i++;
		while (i < nb) AB += B[i], i++;

		int nab = AB.size();
		bool ok = true;
		rep(ab, 0, nab) {
			for (int i = 0; a + i < na && i < nb; i++) {
				if (A[a + i] == '?') continue;
				if (B[i] == '?') continue;
		}
	}*/

	/*rep(a, 0, na + 1) rep(b, 0, nb + 1) dp1[a][b] = inf;
	dp1[0][0] = 0;

	rep(a, 0, na + 1) rep(b, 0, nb + 1) if(dp1[a][b] != inf) {
		if (a == 0) {
			if (b != 0) continue;

			chmin(dp1[a + 1][b], dp1[a][b] + 1);
		}

		if(a == )
	}

	rep(a, 0, na + 1) rep(b, 0, nb + 1) dp2[a][b] = inf;
	dp2[0][0] = 0;*/

}
//---------------------------------------------------------------------------------------------------
void _main() {
	string A, B, C;
	cin >> A >> B >> C;
	
	int ans = inf;

	chmin(ans, solve(A, B, C));
	chmin(ans, solve(A, C, B));
	chmin(ans, solve(B, A, C));
	chmin(ans, solve(B, C, A));
	chmin(ans, solve(C, A, B));
	chmin(ans, solve(C, B, A));
	
	cout << ans << endl;
}







Measured memory_bytes: 256