#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e3; int n;
const int mid = 2*maxN;
char ss[maxN + 1];
string a, b, c;

bool ab[2*mid+1], ac[2*mid+1], bc[2*mid+1];
bool match(char ca, char cb)
{
  return ca == cb || ca == '?' || cb == '?';
}
void fillMatches(string &s, string &t, bool shifts[])
{
  memset(shifts, true, sizeof(bool)*(2*mid+1));
  for (int i = 0; i < s.size(); i++)
    for (int j = 0; j < t.size(); j++)
      shifts[mid + (i - j)] &= match(s[i], t[j]);
}

int main()
{
  while (scanf(" %s", ss) != EOF)
  {
    a = string(ss);
    scanf(" %s", ss); b = string(ss);
    scanf(" %s", ss); c = string(ss);
    DEBUG printf("%s - %s - %s\n", a.c_str(), b.c_str(), c.c_str());

    fillMatches(a, b, ab);
    fillMatches(a, c, ac);
    fillMatches(b, c, bc);

    int ans = 3*maxN;
    int aSize = a.size(), bSize = b.size(), cSize = c.size();
    for (int i = -mid; i <= mid; i++)
      for (int j = -mid; j <= mid; j++)
        if (ab[mid + i] && ac[mid + j] && bc[mid + (j - i)])
        {
          int left = max({-i, -j, 0});
          int right = max({(i + bSize) - aSize, (j + cSize) - aSize, 0});
          ans = min(ans, left + aSize + right);
        }
    printf("%d\n", ans);
  }
  return 0;
}
### 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>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e3; int n;
const int mid = 2*maxN;
char ss[maxN + 1];
string a, b, c;

bool ab[2*mid+1], ac[2*mid+1], bc[2*mid+1];
bool match(char ca, char cb)
{
  return ca == cb || ca == '?' || cb == '?';
}
void fillMatches(string &s, string &t, bool shifts[])
{
  memset(shifts, true, sizeof(bool)*(2*mid+1));
  for (int i = 0; i < s.size(); i++)
    for (int j = 0; j < t.size(); j++)
      shifts[mid + (i - j)] &= match(s[i], t[j]);
}

int main()
{
  while (scanf(" %s", ss) != EOF)
  {
    a = string(ss);
    scanf(" %s", ss); b = string(ss);
    scanf(" %s", ss); c = string(ss);
    DEBUG printf("%s - %s - %s\n", a.c_str(), b.c_str(), c.c_str());

    fillMatches(a, b, ab);
    fillMatches(a, c, ac);
    fillMatches(b, c, bc);

    int ans = 3*maxN;
    int aSize = a.size(), bSize = b.size(), cSize = c.size();
    for (int i = -mid; i <= mid; i++)
      for (int j = -mid; j <= mid; j++)
        if (ab[mid + i] && ac[mid + j] && bc[mid + (j - i)])
        {
          int left = max({-i, -j, 0});
          int right = max({(i + bSize) - aSize, (j + cSize) - aSize, 0});
          ans = min(ans, left + aSize + right);
        }
    printf("%d\n", ans);
  }
  return 0;
}
```