#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

bool corr(char c, char d) {
	return c == d || c == '?' || d == '?';
}

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	int mn = a.size() + b.size() + c.size();
	vector<int> Gab, Gbc, Gca, Gba, Gcb, Gac;

	bool bll;
	for (int i = 0;i < b.size();i++) {
		bll = 1;
		for (int j = 0;;j++) {
			if (i + j >= b.size())break;
			if (j >= a.size())break;
			if (!corr(a[j], b[i + j])) {
				bll = 0;
				break;
			}
		}
		if (bll) {
			Gab.push_back(i);
			Gba.push_back(-i);
		}
	}
	for (int i = 0;i < a.size();i++) {
		bll = 1;
		for (int j = 0;;j++) {
			if (i + j >= a.size())break;
			if (j >= b.size())break;
			if (!corr(b[j], a[i + j])) {
				bll = 0;
				break;
			}
		}
		if (bll) {
			Gba.push_back(i);
			Gab.push_back(-i);
		}
	}

	//bc///////////
	for (int i = 0;i < c.size();i++) {
		bll = 1;
		for (int j = 0;;j++) {
			if (i + j >= c.size())break;
			if (j >= b.size())break;
			if (!corr(b[j], c[i + j])) {
				bll = 0;
				break;
			}
		}
		if (bll) {
			Gbc.push_back(i);
			Gcb.push_back(-i);
		}
	}
	for (int i = 0;i < b.size();i++) {
		bll = 1;
		for (int j = 0;;j++) {
			if (i + j >= b.size())break;
			if (j >= c.size())break;
			if (!corr(c[j], b[i + j])) {
				bll = 0;
				break;
			}
		}
		if (bll) {
			Gcb.push_back(i);
			Gbc.push_back(-i);
		}
	}
	//ac///////////
	for (int i = 0;i < c.size();i++) {
		bll = 1;
		for (int j = 0;;j++) {
			if (i + j >= c.size())break;
			if (j >= a.size())break;
			if (!corr(a[j], c[i + j])) {
				bll = 0;
				break;
			}
		}
		if (bll) {
			Gac.push_back(i);
			Gca.push_back(-i);
		}
	}
	for (int i = 0;i < a.size();i++) {
		bll = 1;
		for (int j = 0;;j++) {
			if (i + j >= a.size())break;
			if (j >= c.size())break;
			if (!corr(c[j], a[i + j])) {
				bll = 0;
				break;
			}
		}
		if (bll) {
			Gca.push_back(i);
			Gac.push_back(-i);
		}
	}

	sort(all(Gab));
	sort(all(Gbc));
	sort(all(Gca));
	sort(all(Gac));
	sort(all(Gba));
	sort(all(Gcb));

	int al, bl, cl, ar, br, cr, uv;
	for (int x : Gab) {
		for (int y : Gbc) {
			al = 0;
			bl = al - x;
			cl = bl - y;
			ar = al + (int)a.size();
			br = bl + (int)b.size();
			cr = cl + (int)c.size();
			uv = max({ ar, br, cr }) - min({ al, bl, cl });
			if (al < cl) {
				if (cl - al >= a.size()) {
					mn = min(mn, uv);
				}
			}
			else {
				if (al - cl >= c.size()) {
					mn = min(mn, uv);
				}
			}
			auto it = lower_bound(all(Gac), x + y);
			if (it != Gac.end() && *it == x + y) {
				mn = min(mn, uv);
			}

			mn = min(mn, max(ar, br) - min(al, bl) + (int)c.size());
		}
	}

	for (int x : Gbc) {
		for (int y : Gca) {
			bl = 0;
			cl = bl - x;
			al = cl - y;
			ar = al + (int)a.size();
			br = bl + (int)b.size();
			cr = cl + (int)c.size();
			uv = max({ ar, br, cr }) - min({ al, bl, cl });
			if (bl < al) {
				if (al - bl >= b.size()) {
					mn = min(mn, uv);
				}
			}
			else {
				if (bl - al >= a.size()) {
					mn = min(mn, uv);
				}
			}
			auto it = lower_bound(all(Gba), x + y);
			if (it != Gba.end() && *it == x + y) {
				mn = min(mn, uv);
			}
			mn = min(mn, max(br, cr) - min(bl, cl) + (int)a.size());
		}
	}

	for (int x : Gca) {
		for (int y : Gab) {
			cl = 0;
			al = cl - x;
			bl = al - y;
			ar = al + (int)a.size();
			br = bl + (int)b.size();
			cr = cl + (int)c.size();
			uv = max({ ar, br, cr }) - min({ al, bl, cl });
			if (cl < bl) {
				if (bl - cl >= c.size()) {
					mn = min(mn, uv);
				}
			}
			else {
				if (cl - bl >= b.size()) {
					mn = min(mn, uv);
				}
			}
			auto it = lower_bound(all(Gcb), x + y);
			if (it != Gcb.end() && *it == x + y) {
				mn = min(mn, uv);
			}
			mn = min(mn, max(ar, cr) - min(al, cl) + (int)b.size());
		}
	}
	cout << mn << endl;
}

Measured memory_bytes: 384