#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

string s[3];

set<int> a_to_b;
set<int> a_to_c;
set<int> b_to_c;



const int MXX = 4002;
int b_to_c_tab[MXX * 2];
int main()
{
  REP(i, 3)cin >> s[i];

  // zakładam, że a stoi na pozycji 0
  // zakładam, że b stoi od -4k do 4k, tak samo c

  int a_poc = 0;
  int a_kon = (int)s[0].size()-1;



  FOR(b_poc, -MXX, MXX)
    {
    int b_kon = b_poc + s[1].size()-1;
    
    bool bad = 0;
    FOR(i, min(a_poc, b_poc), max(a_kon, b_kon))
      {
      if(a_poc <= i && i <= a_kon && b_poc <= i && i <= b_kon)
        {
        if(s[0][i-a_poc] == s[1][i-b_poc])continue;
        if(s[1][i-b_poc] == '?' || s[0][i-a_poc] == '?')continue;
        bad = 1;
        break;
        }
      }
    if(bad == 0)a_to_b.insert(b_poc);
    }
  

  FOR(c_poc, -MXX, MXX)
    {
    int c_kon = c_poc + s[2].size()-1;
    
    bool bad = 0;
    FOR(i, min(a_poc, c_poc), max(a_kon, c_kon))
      {
      if(a_poc <= i && i <= a_kon && c_poc <= i && i <= c_kon)
        {
        if(s[0][i-a_poc] == s[2][i-c_poc])continue;
        if(s[2][i-c_poc] == '?' || s[0][i-a_poc] == '?')continue;
        bad = 1;
        break;
        }
      }
    if(bad == 0)a_to_c.insert(c_poc);
    }

  a_poc = 0;
  a_kon = s[1].size()-1;
  FOR(c_poc, -MXX, MXX)
    {
    int c_kon = c_poc + s[2].size()-1;
    
    bool bad = 0;
    FOR(i, min(a_poc, c_poc), max(a_kon, c_kon))
      {
      if(a_poc <= i && i <= a_kon && c_poc <= i && i <= c_kon)
        {
        if(s[1][i-a_poc] == s[2][i-c_poc])continue;
        if(s[2][i-c_poc] == '?' || s[1][i-a_poc] == '?')continue;
        bad = 1;
        break;
        }
      }
    if(bad == 0)
      {
//      b_to_c.insert(c_poc);
      b_to_c_tab[c_poc + MXX] = 1;
      }
    }



  a_poc = 0;
  a_kon = s[0].size()-1;
  int res = 1e9;

  for(auto b_poc: a_to_b)
    for(auto c_poc: a_to_c)
        {
        int b_to_c_diff = c_poc - b_poc;
        if(b_to_c_diff < -MXX || b_to_c_diff > MXX)continue;
//        if(b_to_c.count(b_to_c_diff))
        if(b_to_c_tab[b_to_c_diff+MXX] == 1)
 
          {
          int b_kon = b_poc + s[1].size()-1;
          int c_kon = c_poc + s[2].size()-1;

          int mii = min(a_poc, min(b_poc, c_poc));
          int mxx = max(a_kon, max(b_kon, c_kon));
          mini(res, mxx - mii+1);

          if(mxx - mii + 1 == 3)debug(b_poc, c_poc, mii, mxx);
          }
        }
  cout << res << endl;
}


Measured memory_bytes: 1024