// Marcin Knapik
#include<bits/stdc++.h>
// #pragma GCC optimize("O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< int , null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;

#define boost                   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define REP(i, a, b)            for (int i = (a); i <= (b); i++)
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define TRAV(i, n)              for(auto&i:n)
#define beg(x)                  (*(x.begin()))
#define re(x)                   int x; cin >>x;   
#define f                       first
#define s                       second

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1000000000000000000;
const ll N = 1e6+7;
const ll T = 1<<20;

ll n, m, q;
string s[3];
bool dp[3][3][10002];
int ans = INF;

bool good(int id1, int id2, int shift){
	if(shift >= sz(s[id1]))
		return true;
	return dp[id1][id2][shift];
}

void check(vi kol){
	for(int i = 0; i <= sz(s[kol[0]]); i++)
		for(int j = 0; j <= max(sz(s[kol[1]]), sz(s[kol[0]])); j++)
			if(good(kol[0], kol[1], i) and good(kol[1], kol[2], j) and good(kol[0], kol[2], i + j)){
				int dl = max({sz(s[kol[0]]), sz(s[kol[1]]) + i, sz(s[kol[2]]) + i + j});
				ans = min(dl, ans);
			}
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	FOR(i, 3)
		cin >> s[i];

	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			for(int k = 0; k <= sz(s[i]); k++){
				bool ok = 1;
				for(int l = 0; k + l < sz(s[i]) and l < sz(s[j]); l++)
					if(s[j][l] != '?' and s[i][k + l] != '?' and s[i][k + l] != s[j][l]){
						ok = 0;
						break;
					}
				dp[i][j][k] = ok;
			}

	vi perm = {0, 1, 2};
	do{ 
		check(perm);
	}while(next_permutation(all(perm)));

	if(ans == INF){
		while(1);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 384