#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n,s) for (int i=a;s>0?i<n:i>n;i+=s)
#define rep(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int inf = 1e9+10, mod = 1e9+7; const long long llinf = 1e18;
// head
bool AB[200000],BC[200000],CA[200000];

bool not_macth(char a,char b){
  if (a == '?' or b == '?' or a == b){
    return false;
  }
  else return true;
}

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int A = a.size();
  int B = b.size();
  int C = c.size();
  int ans = inf;
  rep(i,200000){
    AB[i] = true;
    BC[i] = true;
    CA[i] = true;
  }
  rep(i,A) rep(j,B){
    if (not_macth(a[i],b[j])) AB[i-j+100000] = false;
  }
  rep(i,B) rep(j,C){
    if (not_macth(b[i],c[j])) BC[i-j+100000] = false;
  }
  rep(i,C) rep(j,A){
    if (not_macth(c[i],a[j])) CA[i-j+100000] = false;
  }
  rep(i,-4000,4001) rep(j,-4000,4001){
    if (AB[i+100000] and BC[j-i+100000] and CA[-j+100000]) ans = min(ans,max({A,i+B,j+C})-min({0,i,j}));
  }
  cout << ans << endl;
}