#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

bool match(char a, char b) {
    return (a==b || a=='?' || b=='?');
}

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    int na=a.size();
    int nb=b.size();
    int nc=c.size();
    vector<int> ab(20001),ac(20001),bc(20001);
    int mid=10000;
    rep(i,na) {
        rep(j,nb) {
            if (!match(a[i],b[j])) ab[i-j+mid]=1;
        }
        rep(j,nc) {
            if (!match(a[i],c[j])) ac[i-j+mid]=1;
        }
    }
    rep(i,nb) {
        rep(j,nc) {
            if (!match(b[i],c[j])) bc[i-j+mid]=1;
        }
    }
    int sum=na+nb+nc;
    int ans=sum;
    repr(i,-4000,4001) {
        repr(j,-4000,4001) {
            if (!ab[mid+i] && !ac[mid+j] && !bc[mid-i+j]) {
                int tans=max(na,max(i+nb,j+nc))-min(0,min(i,j));
                ans=min(ans,tans);
            }
        }
    }

    cout << ans << endl;
    
}
### Prompt

Please provide a CPP coded solution to the problem described below:

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
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

bool match(char a, char b) {
    return (a==b || a=='?' || b=='?');
}

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    int na=a.size();
    int nb=b.size();
    int nc=c.size();
    vector<int> ab(20001),ac(20001),bc(20001);
    int mid=10000;
    rep(i,na) {
        rep(j,nb) {
            if (!match(a[i],b[j])) ab[i-j+mid]=1;
        }
        rep(j,nc) {
            if (!match(a[i],c[j])) ac[i-j+mid]=1;
        }
    }
    rep(i,nb) {
        rep(j,nc) {
            if (!match(b[i],c[j])) bc[i-j+mid]=1;
        }
    }
    int sum=na+nb+nc;
    int ans=sum;
    repr(i,-4000,4001) {
        repr(j,-4000,4001) {
            if (!ab[mid+i] && !ac[mid+j] && !bc[mid-i+j]) {
                int tans=max(na,max(i+nb,j+nc))-min(0,min(i,j));
                ans=min(ans,tans);
            }
        }
    }

    cout << ans << endl;
    
}
```