#include <bits/stdc++.h>
using namespace std;

int main() {
  vector<string> s(3);
  for (int i = 0; i < 3; ++i) cin >> s[i];
  int n = s[0].size() + s[1].size() + s[2].size();
  vector<vector<vector<bool>>> goods(3, vector<vector<bool>>(3, vector<bool>(n + 1)));
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (i == j) continue;
      for (int k = 0; k < s[i].size(); ++k) {
        bool ok = true;
        for (int p = 0; p < s[j].size() && k + p < s[i].size(); ++p) {
          char a = s[i][k + p];
          char b = s[j][p];
          if (a != '?' && b != '?' && a != b) ok = false;
        }
        goods[i][j][k] = ok;
      }
    }
  }
  vector<int> ord(3);
  iota(ord.begin(), ord.end(), 0);

  int res = n;

  do {
    string a = s[ord[0]];
    string b = s[ord[1]];
    string c = s[ord[2]];
    for (int i = 0; i <= n; ++i) {
      for (int j = i; j <= n; ++j) {
        bool ok = true;
        int kv = max(a.size(), max(i + b.size(), j + c.size()));
        if (i < a.size()) {
          ok &= goods[ord[0]][ord[1]][i];
        }
        if (j < a.size()) {
          ok &= goods[ord[0]][ord[2]][j];
        }
        if (j - i < b.size()) {
          ok &= goods[ord[1]][ord[2]][j - i];
        }
        if (ok) res = min(res, kv);
      }
    }
  } while (next_permutation(ord.begin(), ord.end()));

  cout << res << "\n";
  return 0;
}

### Prompt

In Cpp, your task is to solve 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;

int main() {
  vector<string> s(3);
  for (int i = 0; i < 3; ++i) cin >> s[i];
  int n = s[0].size() + s[1].size() + s[2].size();
  vector<vector<vector<bool>>> goods(3, vector<vector<bool>>(3, vector<bool>(n + 1)));
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (i == j) continue;
      for (int k = 0; k < s[i].size(); ++k) {
        bool ok = true;
        for (int p = 0; p < s[j].size() && k + p < s[i].size(); ++p) {
          char a = s[i][k + p];
          char b = s[j][p];
          if (a != '?' && b != '?' && a != b) ok = false;
        }
        goods[i][j][k] = ok;
      }
    }
  }
  vector<int> ord(3);
  iota(ord.begin(), ord.end(), 0);

  int res = n;

  do {
    string a = s[ord[0]];
    string b = s[ord[1]];
    string c = s[ord[2]];
    for (int i = 0; i <= n; ++i) {
      for (int j = i; j <= n; ++j) {
        bool ok = true;
        int kv = max(a.size(), max(i + b.size(), j + c.size()));
        if (i < a.size()) {
          ok &= goods[ord[0]][ord[1]][i];
        }
        if (j < a.size()) {
          ok &= goods[ord[0]][ord[2]][j];
        }
        if (j - i < b.size()) {
          ok &= goods[ord[1]][ord[2]][j - i];
        }
        if (ok) res = min(res, kv);
      }
    }
  } while (next_permutation(ord.begin(), ord.end()));

  cout << res << "\n";
  return 0;
}

```