#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

string str[3];
int memo[3][3][20000];

bool ok(int a,int b,int diff) {
  if(memo[a][b][diff]!=0) return memo[a][b][diff]-1;
  if(str[a].size()<=diff) {
    memo[a][b][diff]=2;
    return memo[a][b][diff]-1;
  }
  for(ll i=0;i<min(str[a].size()-diff,str[b].size());i++) {
    if(str[a][i+diff]=='?'||str[b][i]=='?') continue;
    if(str[a][i+diff]!=str[b][i]) {
      memo[a][b][diff]=1;
      return memo[a][b][diff]-1;
    }
  }
  memo[a][b][diff]=2;
  return memo[a][b][diff]-1;
}

ll solve(int a,int b,int c) {
  int ans=1e6;
  for(int bs=0;bs<=str[a].size();bs++) {
    for(int cs=bs;cs<=max(bs+str[b].size(),str[a].size());cs++) {
      if(ok(a,b,bs)&&ok(a,c,cs)&&ok(b,c,cs-bs)) {
        int len=str[a].size();
        len=max(len,bs+(int)str[b].size());
        len=max(len,cs+(int)str[c].size());
        ans=min(ans,len);
      }
    }
  }
  return ans;
}

int main() {
  cin >> str[0] >> str[1] >> str[2];
  ll ans=solve(0,1,2);
  ans=min(ans,solve(0,2,1));
  ans=min(ans,solve(1,0,2));
  ans=min(ans,solve(1,2,0));
  ans=min(ans,solve(2,1,0));
  ans=min(ans,solve(2,0,1));
  cout << ans << endl;
}
### 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;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

string str[3];
int memo[3][3][20000];

bool ok(int a,int b,int diff) {
  if(memo[a][b][diff]!=0) return memo[a][b][diff]-1;
  if(str[a].size()<=diff) {
    memo[a][b][diff]=2;
    return memo[a][b][diff]-1;
  }
  for(ll i=0;i<min(str[a].size()-diff,str[b].size());i++) {
    if(str[a][i+diff]=='?'||str[b][i]=='?') continue;
    if(str[a][i+diff]!=str[b][i]) {
      memo[a][b][diff]=1;
      return memo[a][b][diff]-1;
    }
  }
  memo[a][b][diff]=2;
  return memo[a][b][diff]-1;
}

ll solve(int a,int b,int c) {
  int ans=1e6;
  for(int bs=0;bs<=str[a].size();bs++) {
    for(int cs=bs;cs<=max(bs+str[b].size(),str[a].size());cs++) {
      if(ok(a,b,bs)&&ok(a,c,cs)&&ok(b,c,cs-bs)) {
        int len=str[a].size();
        len=max(len,bs+(int)str[b].size());
        len=max(len,cs+(int)str[c].size());
        ans=min(ans,len);
      }
    }
  }
  return ans;
}

int main() {
  cin >> str[0] >> str[1] >> str[2];
  ll ans=solve(0,1,2);
  ans=min(ans,solve(0,2,1));
  ans=min(ans,solve(1,0,2));
  ans=min(ans,solve(1,2,0));
  ans=min(ans,solve(2,1,0));
  ans=min(ans,solve(2,0,1));
  cout << ans << endl;
}
```