#include <bits/stdc++.h>
using namespace std;
#define int long long
int ans = INT_MAX;
void f(string a, string b, string c) {
	vector<string> v;
	for(int i=0; i<=a.size(); i++) {
		string acp = a;
		bool ok = 1;
		for(int j=0; j<b.size(); j++) {
			if(i+j >= acp.size()) {
				acp.push_back(b[j]);
			} else if(acp[i+j] == '?') {
				if(b[j] == '?') {
					continue;
				} else {
					acp[i+j] = b[j];
				}
			} else {
				if(b[j] == '?' || acp[i+j] == b[j])
					continue;
				else {
					ok = 0;
					break;
				}
			}
		}
		if(!ok || acp.size() >= ans)
			continue;
		for(int j=0; j<=acp.size(); j++) {
			int nxtans = max((int)acp.size(),j+(int)c.size());
			if(nxtans >= ans)
				continue;
			bool tok = 1;
			for(int k=0; k<c.size() && j+k<acp.size(); k++) {
				if(acp[j+k] == '?' || c[k] == '?' || acp[j+k] == c[k]) {
					continue;
				} else {
					tok = 0;
					break;
				}
			}
			if(tok) {
				ans = min(ans, nxtans);
				break;
			}
		}
	}
}
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	string a, b, c;
	cin >> a >> b >> c;
	f(a, b, c);
	f(a, c, b);
	f(b, a, c);
	f(b, c, a);
	f(c, a, b);
	f(c, b, a);
	cout << ans;
}