#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int zero;
void match(string a, string b, vector<bool> &ab){
// ofstream ofs("a.txt");
// if(!ofs){
//     cout<<"file open error"<<endl;
//     cin.get();
//     return;
// }
    int A=a.size();
    int B=b.size();
    for(int i=-B+1; i<A; i++){
        int a_start=max(0,i);
        int a_end=min(A-1,i+B-1);
        int b_start=max(-i,0);
        for (int j = 0; j <= a_end-a_start; j++){
// ofs<<i<<" "<<j<<endl;
           char c=a[a_start+j];
           char d=b[b_start+j];
           if(c!='?'&&d!='?'&&c!=d){
               ab[zero+i]=false;
               break;
           } 
        }
    }
}
int main() {
    string a,b,c;
    cin>>a>>b>>c;
    int A=a.size();
    int B=b.size();
    int C=c.size();
// cout<<A<<" "<<B<<" "<<C<<endl;
    zero=2*(A+B+C);
    vector<bool> ab(2*zero,true);
    vector<bool> ac(2*zero,true);
    vector<bool> bc(2*zero,true);
    match(a,b,ab);
    match(a,c,ac);
    match(b,c,bc);
    int ans=10000;
    for(int i=-B-C;i<=A+C;i++){
        for (int j = -B-C; j <=A+B; j++){
            if(ab[zero+i]&&ac[zero+j]&&bc[zero+j-i])
                ans=min(ans,max(max(i+B,j+C),A)-min(min(i,j),0));
        }
    }
    cout << ans<<endl;
}
### Prompt

Your challenge is to write a cpp solution to the following problem:

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.

Examples

Input

a?c
der
cod


Output

7


Input

atcoder
atcoder
???????


Output

7

### Response

```cpp
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int zero;
void match(string a, string b, vector<bool> &ab){
// ofstream ofs("a.txt");
// if(!ofs){
//     cout<<"file open error"<<endl;
//     cin.get();
//     return;
// }
    int A=a.size();
    int B=b.size();
    for(int i=-B+1; i<A; i++){
        int a_start=max(0,i);
        int a_end=min(A-1,i+B-1);
        int b_start=max(-i,0);
        for (int j = 0; j <= a_end-a_start; j++){
// ofs<<i<<" "<<j<<endl;
           char c=a[a_start+j];
           char d=b[b_start+j];
           if(c!='?'&&d!='?'&&c!=d){
               ab[zero+i]=false;
               break;
           } 
        }
    }
}
int main() {
    string a,b,c;
    cin>>a>>b>>c;
    int A=a.size();
    int B=b.size();
    int C=c.size();
// cout<<A<<" "<<B<<" "<<C<<endl;
    zero=2*(A+B+C);
    vector<bool> ab(2*zero,true);
    vector<bool> ac(2*zero,true);
    vector<bool> bc(2*zero,true);
    match(a,b,ab);
    match(a,c,ac);
    match(b,c,bc);
    int ans=10000;
    for(int i=-B-C;i<=A+C;i++){
        for (int j = -B-C; j <=A+B; j++){
            if(ab[zero+i]&&ac[zero+j]&&bc[zero+j-i])
                ans=min(ans,max(max(i+B,j+C),A)-min(min(i,j),0));
        }
    }
    cout << ans<<endl;
}
```