// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/14/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  string a,b,c; cin>>a>>b>>c;

  auto eq = [](char a, char b) {
    return a == '?' or b == '?' or a == b;
  };

  vector<bool> ab(8001, true), bc(8001, true), ac(8001, true);
  for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) {
    ab[i-j+4000] = ab[i-j+4000] and eq(a[i], b[j]);
  }
  for (int i = 0; i < a.size(); i++) for (int j = 0; j < c.size(); j++) {
      ac[i-j+4000] = ac[i-j+4000] and eq(a[i], c[j]);
    }
  for (int i = 0; i < b.size(); i++) for (int j = 0; j < c.size(); j++) {
      bc[i-j+4000] = bc[i-j+4000] and eq(b[i], c[j]);
    }

  int A=a.size(),B=b.size(),C=c.size();
  int ans = a.size()+b.size()+c.size();
  for (int i = -B-C; i <= A+C; i++) for (int j = max(-B-C, -B-C+i); j <= min(A+B, A+B+i); j++) {
    if (not (ab[i+4000] and ac[j+4000] and bc[j-i+4000]))
      continue;
    int l = min(min(i,j), 0);
    int r = max(max(A, i+B), j+C);
    ans = min(ans, int(r-l));
  }

  cout << ans << endl;

  return 0;
}

### 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
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/14/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  string a,b,c; cin>>a>>b>>c;

  auto eq = [](char a, char b) {
    return a == '?' or b == '?' or a == b;
  };

  vector<bool> ab(8001, true), bc(8001, true), ac(8001, true);
  for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) {
    ab[i-j+4000] = ab[i-j+4000] and eq(a[i], b[j]);
  }
  for (int i = 0; i < a.size(); i++) for (int j = 0; j < c.size(); j++) {
      ac[i-j+4000] = ac[i-j+4000] and eq(a[i], c[j]);
    }
  for (int i = 0; i < b.size(); i++) for (int j = 0; j < c.size(); j++) {
      bc[i-j+4000] = bc[i-j+4000] and eq(b[i], c[j]);
    }

  int A=a.size(),B=b.size(),C=c.size();
  int ans = a.size()+b.size()+c.size();
  for (int i = -B-C; i <= A+C; i++) for (int j = max(-B-C, -B-C+i); j <= min(A+B, A+B+i); j++) {
    if (not (ab[i+4000] and ac[j+4000] and bc[j-i+4000]))
      continue;
    int l = min(min(i,j), 0);
    int r = max(max(A, i+B), j+C);
    ans = min(ans, int(r-l));
  }

  cout << ans << endl;

  return 0;
}

```