#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int solve(string a, string b, string c) {
    int res = 1e8;
    vector<bool> ab(2000 + 1, true);
    vector<bool> bc(2000 + 1, true);
    vector<bool> ac(4000 + 1, true);

    auto match = [](char c1, char c2) { return (c1 == '?' || c2 == '?' || c1 == c2); };

    for (int i = 0; i < a.size(); i++)
        for (int j = i; j < a.size() && j - i < b.size(); j++)
            ab[i] = ab[i] && match(a[j], b[j - i]);
    for (int i = 0; i < b.size(); i++)
        for (int j = i; j < b.size() && j - i < c.size(); j++)
            bc[i] = bc[i] && match(b[j], c[j - i]);
    for (int i = 0; i < a.size() + b.size(); i++)
        for (int j = i; j < a.size() && j - i < c.size(); j++)
            ac[i] = ac[i] && match(a[j], c[j - i]);

    for (int i = 0; i <= 2000; i++)
        for (int j = 0; j <= 2000; j++)
            if (ab[i] && bc[j] && ac[i + j])
                res = min<int>(res, max({a.size(), i + b.size(), i + j + c.size()}));
    return res;
}

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 1e8;
    ans = min(solve(a, b, c), ans);
    ans = min(solve(a, c, b), ans);
    ans = min(solve(b, a, c), ans);
    ans = min(solve(b, c, a), ans);
    ans = min(solve(c, a, b), ans);
    ans = min(solve(c, b, a), ans);
    cout << ans << endl;
    return 0;
}
### Prompt

Develop a solution in cpp 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>
using namespace std;
typedef long long ll;
#define INF 1e18

int solve(string a, string b, string c) {
    int res = 1e8;
    vector<bool> ab(2000 + 1, true);
    vector<bool> bc(2000 + 1, true);
    vector<bool> ac(4000 + 1, true);

    auto match = [](char c1, char c2) { return (c1 == '?' || c2 == '?' || c1 == c2); };

    for (int i = 0; i < a.size(); i++)
        for (int j = i; j < a.size() && j - i < b.size(); j++)
            ab[i] = ab[i] && match(a[j], b[j - i]);
    for (int i = 0; i < b.size(); i++)
        for (int j = i; j < b.size() && j - i < c.size(); j++)
            bc[i] = bc[i] && match(b[j], c[j - i]);
    for (int i = 0; i < a.size() + b.size(); i++)
        for (int j = i; j < a.size() && j - i < c.size(); j++)
            ac[i] = ac[i] && match(a[j], c[j - i]);

    for (int i = 0; i <= 2000; i++)
        for (int j = 0; j <= 2000; j++)
            if (ab[i] && bc[j] && ac[i + j])
                res = min<int>(res, max({a.size(), i + b.size(), i + j + c.size()}));
    return res;
}

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 1e8;
    ans = min(solve(a, b, c), ans);
    ans = min(solve(a, c, b), ans);
    ans = min(solve(b, a, c), ans);
    ans = min(solve(b, c, a), ans);
    ans = min(solve(c, a, b), ans);
    ans = min(solve(c, b, a), ans);
    cout << ans << endl;
    return 0;
}
```