#include<bits/stdc++.h>

#define REP(i,N) for(int i=0;i<(int)(N);i++)

constexpr int MX=2005;

using namespace std;

int main(){
  vector<string> s(3);
  REP(i,3) cin >> s[i];
  sort(s.begin(), s.end());
  
  int ret = 3 *MX;
  do{
    bool bPosOK[3][3][MX];
    REP(i,3)REP(j,3)REP(k,s[i].size()){
      bool bOK = true;
      if(i >= j) continue;
      for(int l=k; l<s[i].size();l++){
        int ni = l;
        int nj = ni - k;
        if (nj >= s[j].size()) break;
        if (s[i][ni] == '?' || s[j][nj] == '?') continue;
        if (s[i][ni] == s[j][nj]) continue;
        bOK = false;
        break;
      }
      bPosOK[i][j][k] = bOK;
    }
    
    auto isOK = [&](int i, int j, int k){
      if (k >= s[i].size()) return true;
      return bPosOK[i][j][k]; 
    };
    
    REP(x,MX)REP(y,MX){
      if(!isOK(0, 1, x)) continue;
      if(!isOK(1, 2, y)) continue;
      if(!isOK(0, 2, x+y)) continue;
      
      int length = 0;
      length = max<int>(length, s[0].size());
      length = max<int>(length, x + s[1].size());
      length = max<int>(length, x + y + s[2].size());
      
      ret = min(ret, length);
    }
  }while(next_permutation(s.begin(), s.end()));
  
  cout << ret;
  return 0;
  
}
### Prompt

Please provide a Cpp coded solution 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>

#define REP(i,N) for(int i=0;i<(int)(N);i++)

constexpr int MX=2005;

using namespace std;

int main(){
  vector<string> s(3);
  REP(i,3) cin >> s[i];
  sort(s.begin(), s.end());
  
  int ret = 3 *MX;
  do{
    bool bPosOK[3][3][MX];
    REP(i,3)REP(j,3)REP(k,s[i].size()){
      bool bOK = true;
      if(i >= j) continue;
      for(int l=k; l<s[i].size();l++){
        int ni = l;
        int nj = ni - k;
        if (nj >= s[j].size()) break;
        if (s[i][ni] == '?' || s[j][nj] == '?') continue;
        if (s[i][ni] == s[j][nj]) continue;
        bOK = false;
        break;
      }
      bPosOK[i][j][k] = bOK;
    }
    
    auto isOK = [&](int i, int j, int k){
      if (k >= s[i].size()) return true;
      return bPosOK[i][j][k]; 
    };
    
    REP(x,MX)REP(y,MX){
      if(!isOK(0, 1, x)) continue;
      if(!isOK(1, 2, y)) continue;
      if(!isOK(0, 2, x+y)) continue;
      
      int length = 0;
      length = max<int>(length, s[0].size());
      length = max<int>(length, x + s[1].size());
      length = max<int>(length, x + y + s[2].size());
      
      ret = min(ret, length);
    }
  }while(next_permutation(s.begin(), s.end()));
  
  cout << ret;
  return 0;
  
}
```