#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

vector<int> Z_algorithm(string &W) {
	int i = 1, j = 0;
	vector<int> Z(W.size());
	Z[0] = W.size();
	while (i < W.size()) {
		while (i + j < W.size() && (W[i+j] == W[j] || W[i+j] == '?' || W[j] == '?')) ++j;
		Z[i] = j; 
		if (j == 0) { ++i; continue; }
		int k = 1;
		while (Z[k] + k < j) Z[i + k] = Z[k], ++k;
		i += k, j -= k;
	}
	return (Z);
}


void Main() {
	vector<string> abc(3);
	cin >> abc;
	vint dat = {0, 1, 2};
	int ans = abc[0].size() + abc[1].size() + abc[2].size();
	do {
		string a = abc[dat[0]], b = abc[dat[1]], c = abc[dat[2]];

		vint cab, cbc, cac;
		for (int i = 0; i <= a.size(); i++) {
			bool flag = true;
			int j;
			for (j = 0; j < b.size() && i+j < a.size(); j++) {
				flag &= (b[j] == a[i+j] || a[i+j] == '?' || b[j] == '?');
			}
			if (flag) cab.push_back(i);
		}

		for (int i = 0; i <= b.size(); i++) {
			bool flag = true;
			int j;
			for (j = 0; j < c.size() && i+j < b.size(); j++) {
				flag &= (c[j] == b[i+j] || b[i+j] == '?' || c[j] == '?');
			}
			//cout << endl;
			if (flag) cbc.push_back(i);
		}
		for (int i = 0; i <= a.size() + b.size(); i++) {
			bool flag = true;
			int j;
			for (j = 0; j < c.size() && i+j < a.size(); j++) {
				flag &= (c[j] == a[i+j] || a[i+j] == '?' || c[j] == '?');
			}
			//cout << endl;
			if (flag) cac.push_back(i);
		}
		//cout << el;	

		sort(begin(cab), end(cab));
		sort(begin(cbc), end(cbc));
		sort(begin(cac), end(cac));

		for (int i = 0; i < cab.size(); i++) {
			for (int j = 0; j < cac.size(); j++) {
				if (cab[i] > cac[j]) continue;
				if (cac[j] - cab[i] >= b.size() || binary_search(begin(cbc), end(cbc), cac[j] - cab[i])) { 
					chmin(ans, max({a.size(), cab[i] + b.size(), cac[j] + c.size()}));
				}
			}
		}

		//cout << a << " " << b << " " << c << " " << ans << endl;
	} while (next_permutation(begin(dat), end(dat)));
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 384