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

const int offset=4000;
bool unmatch01[8001];
bool unmatch12[8001];
bool unmatch02[8001];

inline bool match(char x, char y) { return x == y || x == '?' || y =='?'; }

signed main() {
  string S[3];
  cin >> S[0] >> S[1] >> S[2];

  for(int i=0; i<S[0].size(); i++) for(int j=0; j<S[1].size(); j++)
    if(!match(S[0][i], S[1][j])) unmatch01[i-j+offset] = true;

  for(int i=0; i<S[1].size(); i++) for(int j=0; j<S[2].size(); j++)
    if(!match(S[1][i], S[2][j])) unmatch12[i-j+offset] = true;

  for(int i=0; i<S[0].size(); i++) for(int j=0; j<S[2].size(); j++)
    if(!match(S[0][i], S[2][j])) unmatch02[i-j+offset] = true;

  int ans = 1<<30;
  for(int s1=-4000; s1<=4000; s1++) for(int s2=-4000; s2<=4000; s2++)
      if (!unmatch01[s1 + offset] && !unmatch12[s2-s1+offset] && !unmatch02[s2+offset])
        ans = min(ans, 1 + max((int)S[0].size()-1, max(s1+(int)S[1].size()-1, s2+(int)S[2].size()-1)) - min(0, min(s1, s2)));
  cout << ans << endl;
}

### Prompt

Develop a solution in Cpp to the problem described below:

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;

const int offset=4000;
bool unmatch01[8001];
bool unmatch12[8001];
bool unmatch02[8001];

inline bool match(char x, char y) { return x == y || x == '?' || y =='?'; }

signed main() {
  string S[3];
  cin >> S[0] >> S[1] >> S[2];

  for(int i=0; i<S[0].size(); i++) for(int j=0; j<S[1].size(); j++)
    if(!match(S[0][i], S[1][j])) unmatch01[i-j+offset] = true;

  for(int i=0; i<S[1].size(); i++) for(int j=0; j<S[2].size(); j++)
    if(!match(S[1][i], S[2][j])) unmatch12[i-j+offset] = true;

  for(int i=0; i<S[0].size(); i++) for(int j=0; j<S[2].size(); j++)
    if(!match(S[0][i], S[2][j])) unmatch02[i-j+offset] = true;

  int ans = 1<<30;
  for(int s1=-4000; s1<=4000; s1++) for(int s2=-4000; s2<=4000; s2++)
      if (!unmatch01[s1 + offset] && !unmatch12[s2-s1+offset] && !unmatch02[s2+offset])
        ans = min(ans, 1 + max((int)S[0].size()-1, max(s1+(int)S[1].size()-1, s2+(int)S[2].size()-1)) - min(0, min(s1, s2)));
  cout << ans << endl;
}

```