#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 10000;

int main()
{
vector<string> v(3);
cin >> v[0] >> v[1] >> v[2] ;
sort(v.begin(),v.end());
do{
vector<bool> a(v[0].size()+1000);
vector<bool> b(v[0].size()+1000);
vector<bool> c(v[1].size()+1000);
rep(i,v[0].size())rep(j,v[1].size())if(i+j<v[0].size()&&v[0][i+j]!='?'&&v[1][j]!='?'&&v[0][i+j]!=v[1][j]){a[i]=1;break;}
rep(i,v[0].size())rep(j,v[2].size())if(i+j<v[0].size()&&v[0][i+j]!='?'&&v[2][j]!='?'&&v[0][i+j]!=v[2][j]){b[i]=1;break;}
rep(i,v[1].size())rep(j,v[2].size())if(i+j<v[1].size()&&v[1][i+j]!='?'&&v[2][j]!='?'&&v[1][i+j]!=v[2][j]){c[i]=1;break;}
rep(i,v[0].size()+1000)rep(j,v[1].size()+1000){
  if(!a[i]&&((i+j>v[0].size())||(!b[i+j]))&&!c[j])ans=min(ans,max({(ll)v[0].size(),(ll)v[1].size()+i,(ll)v[2].size()+i+j}));
}
}while(next_permutation(v.begin(),v.end()));
cout << ans << endl;
return 0;
}

### Prompt

Please create a solution in cpp 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>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 10000;

int main()
{
vector<string> v(3);
cin >> v[0] >> v[1] >> v[2] ;
sort(v.begin(),v.end());
do{
vector<bool> a(v[0].size()+1000);
vector<bool> b(v[0].size()+1000);
vector<bool> c(v[1].size()+1000);
rep(i,v[0].size())rep(j,v[1].size())if(i+j<v[0].size()&&v[0][i+j]!='?'&&v[1][j]!='?'&&v[0][i+j]!=v[1][j]){a[i]=1;break;}
rep(i,v[0].size())rep(j,v[2].size())if(i+j<v[0].size()&&v[0][i+j]!='?'&&v[2][j]!='?'&&v[0][i+j]!=v[2][j]){b[i]=1;break;}
rep(i,v[1].size())rep(j,v[2].size())if(i+j<v[1].size()&&v[1][i+j]!='?'&&v[2][j]!='?'&&v[1][i+j]!=v[2][j]){c[i]=1;break;}
rep(i,v[0].size()+1000)rep(j,v[1].size()+1000){
  if(!a[i]&&((i+j>v[0].size())||(!b[i+j]))&&!c[j])ans=min(ans,max({(ll)v[0].size(),(ll)v[1].size()+i,(ll)v[2].size()+i+j}));
}
}while(next_permutation(v.begin(),v.end()));
cout << ans << endl;
return 0;
}

```