#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
bool can[4][4][10010];
int main(){
	vector<string> s(3);
	cin>>s[0]>>s[1]>>s[2];
	int n=s[0].size()+s[1].size()+s[2].size();
	sort(s.begin(), s.end());
	int ans=n;
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			for(int k=0; k<n; ++k){
				can[i][j][k]=1;
			}
		}
	}
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			if(i==j){
				continue;
			}
			for(int k=0; k<s[i].size(); ++k){
				can[i][j][k]=1;
				for(int l=0; l+k<s[i].size()&&l<s[j].size(); ++l){
					if(s[i][l+k] != s[j][l] && s[i][l+k]!='?' && s[j][l]!='?'){
						can[i][j][k]=0;
						break;
					}
				}
			}
		}
	}
	map<string ,int> mp;
	mp[s[0]]=0;
	mp[s[1]]=1;
	mp[s[2]]=2;
	do{
		int tmp1=mp[s[0]], tmp2=mp[s[1]], tmp3=mp[s[2]];
		for(int i=0; i<s[0].size(); ++i){
			if(!can[tmp1][tmp2][i])
				continue;
			ans=min(ans, n-min((int)s[1].size(), ((int)s[0].size()-i)));
			for(int j=0; j<s[1].size()||j+i<s[0].size(); ++j){
				if(j<s[1].size())
				if(!can[tmp2][tmp3][j])
					continue;
				if(j+i<s[0].size()){
					if(!can[tmp1][tmp3][j+i]){
						continue;
					}
				}
				ans=min(ans, max(max((int)s[0].size(), (int)s[1].size()+i), (int)s[2].size()+i+j));
				break;
			}
		}
	}while(next_permutation(s.begin(), s.end()));
	printf("%d\n",ans);
	return 0;
}



### Prompt

Construct a CPP code solution to the problem outlined:

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 mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
bool can[4][4][10010];
int main(){
	vector<string> s(3);
	cin>>s[0]>>s[1]>>s[2];
	int n=s[0].size()+s[1].size()+s[2].size();
	sort(s.begin(), s.end());
	int ans=n;
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			for(int k=0; k<n; ++k){
				can[i][j][k]=1;
			}
		}
	}
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			if(i==j){
				continue;
			}
			for(int k=0; k<s[i].size(); ++k){
				can[i][j][k]=1;
				for(int l=0; l+k<s[i].size()&&l<s[j].size(); ++l){
					if(s[i][l+k] != s[j][l] && s[i][l+k]!='?' && s[j][l]!='?'){
						can[i][j][k]=0;
						break;
					}
				}
			}
		}
	}
	map<string ,int> mp;
	mp[s[0]]=0;
	mp[s[1]]=1;
	mp[s[2]]=2;
	do{
		int tmp1=mp[s[0]], tmp2=mp[s[1]], tmp3=mp[s[2]];
		for(int i=0; i<s[0].size(); ++i){
			if(!can[tmp1][tmp2][i])
				continue;
			ans=min(ans, n-min((int)s[1].size(), ((int)s[0].size()-i)));
			for(int j=0; j<s[1].size()||j+i<s[0].size(); ++j){
				if(j<s[1].size())
				if(!can[tmp2][tmp3][j])
					continue;
				if(j+i<s[0].size()){
					if(!can[tmp1][tmp3][j+i]){
						continue;
					}
				}
				ans=min(ans, max(max((int)s[0].size(), (int)s[1].size()+i), (int)s[2].size()+i+j));
				break;
			}
		}
	}while(next_permutation(s.begin(), s.end()));
	printf("%d\n",ans);
	return 0;
}



```