#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=a;i<b;++i)

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    const int L = 50000;
    const int M = 25000;
    const int N = 2000;

    auto match = [&](char x, char y) { return x == '?' or y == '?' or x == y; };
    
    auto preproc = [&](string S, string T) {
        vector<bool> v(L, true);
        int n = S.size(), m = T.size();
        for_(i,0,n) for_(j,0,m) if (!match(S[i], T[j])) v[i-j+M] = false;
        return v;
    };

    vector<bool> ab = preproc(a, b);
    vector<bool> bc = preproc(b, c);
    vector<bool> ac = preproc(a, c);

    int ans = 1L << 30, A = a.size(), B = b.size(), C = c.size();
    for_(i,-2*N,2*N+1) for_(j,-2*N,2*N+1) {
        if (ab[i+M] and ac[j+M] and bc[j-i+M]) {
            int L = min(0, min(i, j));
            int R = max(A, max(B+i, C+j));
            ans = min(ans, R - L);
        }
    }
    cout << ans << endl;
}
### Prompt

Please create a solution in Cpp 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
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=a;i<b;++i)

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    const int L = 50000;
    const int M = 25000;
    const int N = 2000;

    auto match = [&](char x, char y) { return x == '?' or y == '?' or x == y; };
    
    auto preproc = [&](string S, string T) {
        vector<bool> v(L, true);
        int n = S.size(), m = T.size();
        for_(i,0,n) for_(j,0,m) if (!match(S[i], T[j])) v[i-j+M] = false;
        return v;
    };

    vector<bool> ab = preproc(a, b);
    vector<bool> bc = preproc(b, c);
    vector<bool> ac = preproc(a, c);

    int ans = 1L << 30, A = a.size(), B = b.size(), C = c.size();
    for_(i,-2*N,2*N+1) for_(j,-2*N,2*N+1) {
        if (ab[i+M] and ac[j+M] and bc[j-i+M]) {
            int L = min(0, min(i, j));
            int R = max(A, max(B+i, C+j));
            ans = min(ans, R - L);
        }
    }
    cout << ans << endl;
}
```