#include<bits/stdc++.h>
using namespace std;
const int mxn=2005;
string s[3];bool used[9][mxn];
int len[3];
int ans=114514;
inline void go(int d,string a,string b){
	for(int i=0;i<a.size();++i)for(int j=0;i+j<a.size() and j<b.size();++j)if(a[i+j]!='?' and b[j]!='?' and a[i+j]!=b[j]){
		used[d][i]=1;
		break;
	}
}
inline bool check(int i,int j,int a,int b){
	b-=a;
	if(b<0){
		swap(i,j);
		b=-b;
	}
	return b>=len[i] or not used[i*3+j][b];
}
inline bool ok(int j,int k){return check(0,1,0,j) and check(0,2,0,k) and check(1,2,j,k);}
int main(){
	for(int i=0;i<3;++i)cin>>s[i],len[i]=s[i].size();
	for(int i=0;i<3;++i)for(int j=0;j<3;++j)if(i!=j)go(i*3+j,s[i],s[j]);
	for(int i=-len[2]-len[1];i<=len[0]+len[2];++i)
		for(int j=-len[2]-len[1];j<=len[0]+len[1];++j)
			if(ok(i,j))
				ans=min(ans,max(len[0],max(len[1]+i,len[2]+j))-min(0,min(i,j)));
	cout<<ans<<'\n';
}
### 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;
const int mxn=2005;
string s[3];bool used[9][mxn];
int len[3];
int ans=114514;
inline void go(int d,string a,string b){
	for(int i=0;i<a.size();++i)for(int j=0;i+j<a.size() and j<b.size();++j)if(a[i+j]!='?' and b[j]!='?' and a[i+j]!=b[j]){
		used[d][i]=1;
		break;
	}
}
inline bool check(int i,int j,int a,int b){
	b-=a;
	if(b<0){
		swap(i,j);
		b=-b;
	}
	return b>=len[i] or not used[i*3+j][b];
}
inline bool ok(int j,int k){return check(0,1,0,j) and check(0,2,0,k) and check(1,2,j,k);}
int main(){
	for(int i=0;i<3;++i)cin>>s[i],len[i]=s[i].size();
	for(int i=0;i<3;++i)for(int j=0;j<3;++j)if(i!=j)go(i*3+j,s[i],s[j]);
	for(int i=-len[2]-len[1];i<=len[0]+len[2];++i)
		for(int j=-len[2]-len[1];j<=len[0]+len[1];++j)
			if(ok(i,j))
				ans=min(ans,max(len[0],max(len[1]+i,len[2]+j))-min(0,min(i,j)));
	cout<<ans<<'\n';
}
```