Problem:
Score : 500 points

Problem Statement

Snuke has a string s.
From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:

Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with ?s.

For example, if s is mississippi, we can choose the substring ssissip and replace its 1-st and 3-rd characters with ? to obtain ?s?ssip.

You are given the strings a, b, and c.
Find the minimum possible length of s.

Constraints

1 \leq |a|, |b|, |c| \leq 2000

a, b, and c consists of lowercase English letters and ?s.

Input

Input is given from Standard Input in the following format:

a
b
c

Output

Print the minimum possible length of s.

Sample Input 1

a?c
der
cod

Sample Output 1

7

For example, s could be atcoder.

Sample Input 2

atcoder
atcoder
???????

Sample Output 2

7

a, b, and c may not be distinct.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#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;
      n = s1.length();
      lop(i,0,n)
            lop(j,0,n)
            {
                  if( s2[i] != s1[j] and s2[i] != '?' and s1[j] != '?' ) arr12[mid+i-j] = 1;
                  if( s2[i] != s3[j] and s2[i] != '?' and s3[j] != '?' ) arr23[mid+i-j] = 1;
                  if( s1[i] != s3[j] and s1[i] != '?' and s3[j] != '?' ) arr13[mid+i-j] = 1;
            }

      int ans = 3*n;
      int val = 2*n+10;
      for(int id1=mid-n-val; id1 < mid + n + val; id1++) 
      {     
            for(int id3=mid-n-val; id3<mid+n+val; id3++){
                  if( arr12[id1] or arr23[id3] ) continue;
                  int d = id3 - id1;
                  if( arr13[mid+d] ) continue;

                  // bug(id1,id3,mid);
                  int l = min({id1,id3,mid});
                  int r = max({id1,id3,mid}) + n;
                  ans = min(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 //