#include "bits/stdc++.h"
using namespace std;

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //


#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()         

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 1e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr12[N], arr23[N], arr13[N];
int mid = 60000;


void solve()
{
      string s1, s2, s3;
      cin >> s1 >> s2 >> s3;
      int n1 = s1.length();
      int n2 = s2.length();
      int n3 = s3.length();
      lop(i,0,n2)
            lop(j,0,n1) if( s2[i] != s1[j] and s2[i] != '?' and s1[j] != '?' ) arr12[mid+i-j] = 1;
      lop(i,0,n2)
            lop(j,0,n3)
                  if( s2[i] != s3[j] and s2[i] != '?' and s3[j] != '?' ) arr23[mid+i-j] = 1;  
      lop(i,0,n1)
            lop(j,0,n3)
                  if( s1[i] != s3[j] and s1[i] != '?' and s3[j] != '?' ) arr13[mid+i-j] = 1;

      n = max({n1, n2, n3});
      int ans = 3*n;
      for(int id1= mid-2*n-2; id1 < mid + 3*n +2; id1++) 
      {     
            for(int id3= mid-2*n-2; id3< mid+ 3*n +2; id3++){
                  if( arr12[id1] or arr23[id3] ) continue;
                  int d = id3 - id1;
                  if( arr13[mid+d] ) continue;

                  int l = min(id1, min(id3,mid));
                  int r = max(id1+n1, max(id3+n3,mid+n2));
                  if(ans > r - l)
                  {
                        ans = r - l;
                  }
            }     
      }
      cout << ans << endl;
      
}

int32_t main()
{
      ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);
      //INP(); 
      int test = 1;
      // cin >> test;

     cout << setprecision(9) << fixed;
     clock_t z = clock();
      while(test--)solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






Measured memory_bytes: 4352