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)

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     unsigned long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2
string match(string a, string b){
    int m = 0;
    f(i,1,min(a.size(), b.size()) + 1){
        bool match = true;
        f(j,0, i){
            if(a[a.size() - i +j] != '?' && b[j] != '?' && a[a.size() - i +j] != b[j]){
                match = false;
                break;
            }
        }
        if(match){
            m = max(m, i);
        }
    }
    if(m == 0) return "1";
    string merge;
    merge+=a.substr(0,a.size() - m);
    vector<char> middle;
    f(j,0,m){
        if(a[a.size() - m +j] == '?'){
            middle.push_back(b[j]);
        }else{
            middle.push_back(a[a.size() - m +j]);
        }
    }
    merge += string(range(middle));
    if(m<b.size()) merge+=b.substr(m,b.size() - m);
    return merge;
}
void ssolve(std::istream& in, std::ostream& out){
    vector<string> ss(3);
    int m =0;
    f(i,0,3){
        s(ss[i]);
        m+=ss[i].size();
    }
    int idxs[3] = {0,1,2};
    do{
        string a = ss[idxs[0]];
        string b = ss[idxs[1]];
        string c = ss[idxs[2]];
        string s1 = match(a,b);
        if(s1!="1"){
            string s2 = match(s1,c);
            if(s2!="1"){
                m = min(m,s2.size());
            }else{
                m = min(m,s1.size() + c.size());
            }
        }else{
            string s2 = match(b,c);
            if(s2!="1"){
                string s3 = match(a,s2);
                if(s3!="1"){
                    m = min(m,s3.size());
                }else{
                    m = min(m,s2.size() + a.size());
                }
            }
        }
        s1 = match(b,c);
        if(s1!="1"){
            string s2 = match(a,s1);
            if(s2!="1"){
                m = min(m,s2.size());
            }else{
                m = min(m,a.size() + s1.size());
            }
        }
    }while(next_permutation(idxs, idxs+3));
    out<<m<<endl;
}

class EThreeSubstrings {
public:
	void solve(std::istream& in, std::ostream& out) {
        ios_base::sync_with_stdio(false);
        in.tie(0);out.tie(0);
        int t;
        int READ = 0;
        if(READ) s(t);
        else t = 1;
        while(t--){
            ssolve(in, out);
        }
	}
};


integer main() {
	EThreeSubstrings solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}