#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


namespace FFT{
  using dbl = double;

  struct num{
    dbl x,y;
    num(){x=y=0;}
    num(dbl x,dbl y):x(x),y(y){}
  };

  inline num operator+(num a,num b){
    return num(a.x+b.x,a.y+b.y);
  }
  inline num operator-(num a,num b){
    return num(a.x-b.x,a.y-b.y);
  }
  inline num operator*(num a,num b){
    return num(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);
  }
  inline num conj(num a){
    return num(a.x,-a.y);
  }

  int base=1;
  vector<num> rts={{0,0},{1,0}};
  vector<int> rev={0,1};

  const dbl PI=asinl(1)*2;

  void ensure_base(int nbase){
    if(nbase<=base) return;

    rev.resize(1<<nbase);
    for(int i=0;i<(1<<nbase);i++)
      rev[i]=(rev[i>>1]>>1)+((i&1)<<(nbase-1));

    rts.resize(1<<nbase);
    while(base<nbase){
      dbl angle=2*PI/(1<<(base+1));
      for(int i=1<<(base-1);i<(1<<base);i++){
        rts[i<<1]=rts[i];
        dbl angle_i=angle*(2*i+1-(1<<base));
        rts[(i<<1)+1]=num(cos(angle_i),sin(angle_i));
      }
      base++;
    }
  }

  void fft(vector<num> &as){
    int n=as.size();
    assert((n&(n-1))==0);

    int zeros=__builtin_ctz(n);
    ensure_base(zeros);
    int shift=base-zeros;
    for(int i=0;i<n;i++)
      if(i<(rev[i]>>shift))
        swap(as[i],as[rev[i]>>shift]);

    for(int k=1;k<n;k<<=1){
      for(int i=0;i<n;i+=2*k){
        for(int j=0;j<k;j++){
          num z=as[i+j+k]*rts[j+k];
          as[i+j+k]=as[i+j]-z;
          as[i+j]=as[i+j]+z;
        }
      }
    }
  }

  template<typename T>
  vector<long long> multiply(vector<T> &as,vector<T> &bs){
    int need=as.size()+bs.size()-1;
    int nbase=0;
    while((1<<nbase)<need) nbase++;
    ensure_base(nbase);

    int sz=1<<nbase;
    vector<num> fa(sz);
    for(int i=0;i<sz;i++){
      T x=(i<(int)as.size()?as[i]:0);
      T y=(i<(int)bs.size()?bs[i]:0);
      fa[i]=num(x,y);
    }
    fft(fa);

    num r(0,-0.25/sz);
    for(int i=0;i<=(sz>>1);i++){
      int j=(sz-i)&(sz-1);
      num z=(fa[j]*fa[j]-conj(fa[i]*fa[i]))*r;
      if(i!=j)
        fa[j]=(fa[i]*fa[i]-conj(fa[j]*fa[j]))*r;
      fa[i]=z;
    }
    fft(fa);

    vector<long long> res(need);
    for(int i=0;i<need;i++)
      res[i]=round(fa[i].x);

    return res;
  }

};

//INSERT ABOVE HERE

vector<int> calc(string s,string t){
  int n=s.size(),m=t.size();
  vector<int> res(n,0);
  for(int k=0;k<26;k++){
    vector<int> as(n),bs(m);
    for(int i=0;i<n;i++) as[i]=(s[i]=='a'+k||s[i]=='?');
    for(int j=0;j<m;j++) bs[j]=(t[m-(j+1)]=='a'+k||t[m-(j+1)]=='?');
    auto cs=FFT::multiply(as,bs);
    for(int i=0;i<n;i++) res[i]+=cs[m-1+i];
  }
  {
    vector<int> as(n),bs(m);
    for(int i=0;i<n;i++) as[i]=s[i]=='?';
    for(int j=0;j<m;j++) bs[j]=t[m-(j+1)]=='?';
    auto cs=FFT::multiply(as,bs);
    for(int i=0;i<n;i++) res[i]-=25*cs[m-1+i];
  }

  //for(int i=0;i<n;i++) cout<<res[i]<<" ";
  //cout<<endl;

  for(int i=0;i<n;i++)
    res[i]=res[i]==min(n-i,m);

  return res;
}
const int DEBUG = 0;

int solve(string a,string b,string c){
  vector<int> ab=calc(a,b);
  vector<int> ac=calc(a,c);
  vector<int> bc=calc(b,c);

  int res=a.size()+b.size()+c.size();
  for(int i=0;i<=(int)a.size();i++){
    for(int j=i;j<=(int)(a.size()+b.size());j++){
      if(DEBUG){
        cout<<"::::"<<i<<" "<<j<<endl;
        cout<<i-0<<" "<<ab[i-0]<<endl;
        cout<<j-0<<" "<<ac[j-0]<<endl;
        cout<<j-i<<" "<<bc[j-i]<<endl;
        cout<<endl;
      }
      if(i-0<(int)a.size() and !ab[i-0]) continue;
      if(j-0<(int)a.size() and !ac[j-0]) continue;
      if(j-i<(int)b.size() and !bc[j-i]) continue;
      chmin(res,(int)max({0+a.size(),i+b.size(),j+c.size()}));
    }
  }
  return res;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string a,b,c;
  cin>>a>>b>>c;

  int ans=a.size()+b.size()+c.size();
  chmin(ans,solve(a,b,c));
  chmin(ans,solve(a,c,b));
  chmin(ans,solve(b,a,c));
  chmin(ans,solve(b,c,a));
  chmin(ans,solve(c,a,b));
  chmin(ans,solve(c,b,a));

  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 640