#include <iostream>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

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

    auto f = [&](string x, string y)
    {
        set<int> S;
        for (int d=-(int)y.size()+1; d<=(int)x.size()-1; d++)
        {
            bool ok = true;
            for (int i=max(0, d); i<(int)min(x.size(), y.size()+d); i++)
                if (x[i]!='?' && y[i-d]!='?' && x[i]!=y[i-d])
                    ok = false;
            if (ok)
                S.insert(d);
        }
        return S;
    };

    set<int> ab = f(a, b);
    set<int> ac = f(a, c);
    set<int> bc = f(b, c);
    int an = (int)a.size();
    int bn = (int)b.size();
    int cn = (int)c.size();

    int ans = an+bn+cn;
    for (int d1=-bn-cn; d1<=an+cn; d1++)
        if (d1<=-bn || an<=d1 || ab.count(d1)>0)
            for (int d2=-bn-cn; d2<=an+bn; d2++)
                if ((d2<=-cn || an<=d2 || ac.count(d2)>0) &&
                    (d2-d1<=-cn || bn<=d2-d1 || bc.count(d2-d1)>0))
                    ans = min(ans, max({an, d1+bn, d2+cn})-min({0, d1, d2}));
    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
#include <iostream>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

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

    auto f = [&](string x, string y)
    {
        set<int> S;
        for (int d=-(int)y.size()+1; d<=(int)x.size()-1; d++)
        {
            bool ok = true;
            for (int i=max(0, d); i<(int)min(x.size(), y.size()+d); i++)
                if (x[i]!='?' && y[i-d]!='?' && x[i]!=y[i-d])
                    ok = false;
            if (ok)
                S.insert(d);
        }
        return S;
    };

    set<int> ab = f(a, b);
    set<int> ac = f(a, c);
    set<int> bc = f(b, c);
    int an = (int)a.size();
    int bn = (int)b.size();
    int cn = (int)c.size();

    int ans = an+bn+cn;
    for (int d1=-bn-cn; d1<=an+cn; d1++)
        if (d1<=-bn || an<=d1 || ab.count(d1)>0)
            for (int d2=-bn-cn; d2<=an+bn; d2++)
                if ((d2<=-cn || an<=d2 || ac.count(d2)>0) &&
                    (d2-d1<=-cn || bn<=d2-d1 || bc.count(d2-d1)>0))
                    ans = min(ans, max({an, d1+bn, d2+cn})-min({0, d1, d2}));
    cout<<ans<<endl;
}

```