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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (int i = 1; i <= N; i++)
const int intinf = numeric_limits<int>::max();

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define MOD 1000000007
#define M 2000

bool is_matched(char x, char y)
{
    return x == y or x == '?' or y == '?';
}

void solveE()
{
    string a, b, c;
    cin >> a >> b >> c;

    int A = a.length();
    int B = b.length();
    int C = c.length();

    vector<bool> ab(M * 8, true);
    vector<bool> ac(M * 8, true);
    vector<bool> bc(M * 8, true);
    rep(i, A) rep(j, B) if (!is_matched(a[i], b[j])) ab[i - j + M * 4] = false;
    rep(i, A) rep(j, C) if (!is_matched(a[i], c[j])) ac[i - j + M * 4] = false;
    rep(i, B) rep(j, C) if (!is_matched(b[i], c[j])) bc[i - j + M * 4] = false;

    int ans = A + B + C;
    for (int i = -M * 2; i <= M * 2; i++)
        for (int j = -M * 2; j <= M * 2; j++)
            if (ab[i + M * 4] and ac[j + M * 4] and bc[j - i + M * 4])
            {
                int L = min(0, min(i, j));
                int R = max(A, max(i + B, j + C));
                ans = min(ans, R - L);
            }
    cout << ans << endl;
}

int main()
{
    solveE();
    return 0;
}

### Prompt

Generate 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
#include <bits/stdc++.h>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (int i = 1; i <= N; i++)
const int intinf = numeric_limits<int>::max();

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define MOD 1000000007
#define M 2000

bool is_matched(char x, char y)
{
    return x == y or x == '?' or y == '?';
}

void solveE()
{
    string a, b, c;
    cin >> a >> b >> c;

    int A = a.length();
    int B = b.length();
    int C = c.length();

    vector<bool> ab(M * 8, true);
    vector<bool> ac(M * 8, true);
    vector<bool> bc(M * 8, true);
    rep(i, A) rep(j, B) if (!is_matched(a[i], b[j])) ab[i - j + M * 4] = false;
    rep(i, A) rep(j, C) if (!is_matched(a[i], c[j])) ac[i - j + M * 4] = false;
    rep(i, B) rep(j, C) if (!is_matched(b[i], c[j])) bc[i - j + M * 4] = false;

    int ans = A + B + C;
    for (int i = -M * 2; i <= M * 2; i++)
        for (int j = -M * 2; j <= M * 2; j++)
            if (ab[i + M * 4] and ac[j + M * 4] and bc[j - i + M * 4])
            {
                int L = min(0, min(i, j));
                int R = max(A, max(i + B, j + C));
                ans = min(ans, R - L);
            }
    cout << ans << endl;
}

int main()
{
    solveE();
    return 0;
}

```