#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool match(char a, char b) {
  return a == '?' || b == '?' || a == b;
}

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

  int na = a.length(), nb = b.length(), nc = c.length();
  vector<bool> ab(na + nb, true), ac(na + nc, true), bc(nb + nc, true);
  for (int i = 0; i < na; i++)
    for (int j = 0; j < nb; j++)
      if (!match(a[i], b[j])) ab[i - j + nb] = false;
  for (int i = 0; i < na; i++)
    for (int j = 0; j < nc; j++)
      if (!match(a[i], c[j])) ac[i - j + nc] = false;
  for (int i = 0; i < nb; i++)
    for (int j = 0; j < nc; j++)
      if (!match(b[i], c[j])) bc[i - j + nc] = false;

  int ans = na + nb + nc;
  for (int i = -(nb + nc); i <= na + nc; i++)
    for (int j = -(nb + nc); j <= na + nb; j++) {
      int k = j - i;
      bool match_ab = (i < -nb || i > na || ab[i + nb]);
      bool match_ac = (j < -nc || j > na || ac[j + nc]);
      bool match_bc = (k < -nc || k > nb || bc[k + nc]);

      if (match_ab && match_ac && match_bc) {
        int l = min(0, min(i, j));
        int r = max(na, max(i + nb, j + nc));
        ans = min(ans, r - l);
      }
    }
  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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool match(char a, char b) {
  return a == '?' || b == '?' || a == b;
}

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

  int na = a.length(), nb = b.length(), nc = c.length();
  vector<bool> ab(na + nb, true), ac(na + nc, true), bc(nb + nc, true);
  for (int i = 0; i < na; i++)
    for (int j = 0; j < nb; j++)
      if (!match(a[i], b[j])) ab[i - j + nb] = false;
  for (int i = 0; i < na; i++)
    for (int j = 0; j < nc; j++)
      if (!match(a[i], c[j])) ac[i - j + nc] = false;
  for (int i = 0; i < nb; i++)
    for (int j = 0; j < nc; j++)
      if (!match(b[i], c[j])) bc[i - j + nc] = false;

  int ans = na + nb + nc;
  for (int i = -(nb + nc); i <= na + nc; i++)
    for (int j = -(nb + nc); j <= na + nb; j++) {
      int k = j - i;
      bool match_ab = (i < -nb || i > na || ab[i + nb]);
      bool match_ac = (j < -nc || j > na || ac[j + nc]);
      bool match_bc = (k < -nc || k > nb || bc[k + nc]);

      if (match_ab && match_ac && match_bc) {
        int l = min(0, min(i, j));
        int r = max(na, max(i + nb, j + nc));
        ans = min(ans, r - l);
      }
    }
  printf("%d\n", ans);

  return 0;
}
```