#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

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

  auto match = [](char c1, char c2) -> bool {
    return c1 == '?' || c2 == '?' || c1 == c2;
  };

  const int M = 2000;
  const int OFFSET = 4 * M;
  vector<bool> matchAB(2 * OFFSET + 1, true), matchAC(2 * OFFSET + 1, true),
      matchBC(2 * OFFSET + 1, true);

  for (int i = 0; i < (int)(A); ++i) for (int j = 0; j < (int)(B); ++j) if (!match(a[i], b[j])) matchAB[OFFSET - j + i] = false;
  for (int i = 0; i < (int)(A); ++i) for (int j = 0; j < (int)(C); ++j) if (!match(a[i], c[j])) matchAC[OFFSET - j + i] = false;
  for (int i = 0; i < (int)(B); ++i) for (int j = 0; j < (int)(C); ++j) if (!match(b[i], c[j])) matchBC[OFFSET - j + i] = false;

  int ans = 3 * M;
  for (int ab = -B - C; ab <= A + C; ++ab) {
    for (int ac = -C - B; ac <= A + B; ++ac) {
      if (!matchAB[OFFSET + ab] || !matchAC[OFFSET + ac] ||
          !matchBC[OFFSET + ac - ab])
        continue;
      int r = max({A, ab + B, ac + C});
      int l = min({0, ab, ac});
      chmin(ans, 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
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

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

  auto match = [](char c1, char c2) -> bool {
    return c1 == '?' || c2 == '?' || c1 == c2;
  };

  const int M = 2000;
  const int OFFSET = 4 * M;
  vector<bool> matchAB(2 * OFFSET + 1, true), matchAC(2 * OFFSET + 1, true),
      matchBC(2 * OFFSET + 1, true);

  for (int i = 0; i < (int)(A); ++i) for (int j = 0; j < (int)(B); ++j) if (!match(a[i], b[j])) matchAB[OFFSET - j + i] = false;
  for (int i = 0; i < (int)(A); ++i) for (int j = 0; j < (int)(C); ++j) if (!match(a[i], c[j])) matchAC[OFFSET - j + i] = false;
  for (int i = 0; i < (int)(B); ++i) for (int j = 0; j < (int)(C); ++j) if (!match(b[i], c[j])) matchBC[OFFSET - j + i] = false;

  int ans = 3 * M;
  for (int ab = -B - C; ab <= A + C; ++ab) {
    for (int ac = -C - B; ac <= A + B; ++ac) {
      if (!matchAB[OFFSET + ab] || !matchAC[OFFSET + ac] ||
          !matchBC[OFFSET + ac - ab])
        continue;
      int r = max({A, ab + B, ac + C});
      int l = min({0, ab, ac});
      chmin(ans, r - l);
    }
  }
  cout << ans << endl;

  return 0;
}

```