#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = (ll)1e19;

bool check(char c1, char c2) {
  if (c1 == '?' || c2 == '?' || c1 == c2) return true;
  return false;
}

void Main() {
  string a, b, c;
  cin >> a >> b >> c;
  int A, B, C;
  A = a.size();
  B = b.size();
  C = c.size();
  vector<bool> ab(20000, false), ac(20000, false), bc(20000, false);
  rep(i, A) rep(j, B) if (!check(a[i], b[j])) ab[i - j + 10000] = true;
  rep(i, A) rep(j, C) if (!check(a[i], c[j])) ac[i - j + 10000] = true;
  rep(i, B) rep(j, C) if (!check(b[i], c[j])) bc[i - j + 10000] = true;
  int ans = A+B+C;
  REP(i, -B-C, A+C) REP(j, -B-C, A+B) {
    if (!ab[i + 10000] && !ac[j + 10000] && !bc[j - i + 10000]) {
      int l = min(0, min(i, j));
      int r = max(A, max(i+B, j+C));
      ans = min(ans, r - l);
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

### Prompt

Please formulate 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"

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = (ll)1e19;

bool check(char c1, char c2) {
  if (c1 == '?' || c2 == '?' || c1 == c2) return true;
  return false;
}

void Main() {
  string a, b, c;
  cin >> a >> b >> c;
  int A, B, C;
  A = a.size();
  B = b.size();
  C = c.size();
  vector<bool> ab(20000, false), ac(20000, false), bc(20000, false);
  rep(i, A) rep(j, B) if (!check(a[i], b[j])) ab[i - j + 10000] = true;
  rep(i, A) rep(j, C) if (!check(a[i], c[j])) ac[i - j + 10000] = true;
  rep(i, B) rep(j, C) if (!check(b[i], c[j])) bc[i - j + 10000] = true;
  int ans = A+B+C;
  REP(i, -B-C, A+C) REP(j, -B-C, A+B) {
    if (!ab[i + 10000] && !ac[j + 10000] && !bc[j - i + 10000]) {
      int l = min(0, min(i, j));
      int r = max(A, max(i+B, j+C));
      ans = min(ans, r - l);
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

```