#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int INF=1e9+5;
const int N=2e3+5;
const int mod=998244353;

void max_self(int& a,int b){
	if(a<b) a=b;
}

void min_self(int& a,int b){
	if(b<a) a=b;
}

string s[3];
bool ok[3][3][N];

bool ask(int i,int j,int k){
	if(k>=(int)s[i].size()) return 1;
	return ok[i][j][k];
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	for(int i=0;i<3;++i) cin>>s[i];
	sort(s,s+3);
	int ans=INF;
	do{
		for(int i=0;i<3;++i){
			for(int j=0;j<3;++j){
				for(int k=0;k<(int)s[i].size();++k){
					if(i>=j) continue;
					bool check=1;
					for(int ni=k;ni<(int)s[i].size();++ni){
						int nj=ni-k;
						if(nj>=(int)s[j].size()) break;
						if(s[i][ni]=='?'||s[j][nj]=='?') continue;
						if(s[i][ni]!=s[j][nj]) check=0;
					}
					ok[i][j][k]=check;
				}
			}
		}
		for(int i=0;i<N;++i){
			for(int j=0;j<N;++j){
				if(!ask(0,1,i)) continue;
				if(!ask(1,2,j)) continue;
				if(!ask(0,2,i+j)) continue;
				int cur=0;
				max_self(cur,(int)s[0].size());
				max_self(cur,i+(int)s[1].size());
				max_self(cur,i+j+(int)s[2].size());
				min_self(ans,cur);
			}
		}
	}
	while(next_permutation(s,s+3));
	cout<<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>
using namespace std;
typedef long long ll;
#define endl '\n'
const int INF=1e9+5;
const int N=2e3+5;
const int mod=998244353;

void max_self(int& a,int b){
	if(a<b) a=b;
}

void min_self(int& a,int b){
	if(b<a) a=b;
}

string s[3];
bool ok[3][3][N];

bool ask(int i,int j,int k){
	if(k>=(int)s[i].size()) return 1;
	return ok[i][j][k];
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	for(int i=0;i<3;++i) cin>>s[i];
	sort(s,s+3);
	int ans=INF;
	do{
		for(int i=0;i<3;++i){
			for(int j=0;j<3;++j){
				for(int k=0;k<(int)s[i].size();++k){
					if(i>=j) continue;
					bool check=1;
					for(int ni=k;ni<(int)s[i].size();++ni){
						int nj=ni-k;
						if(nj>=(int)s[j].size()) break;
						if(s[i][ni]=='?'||s[j][nj]=='?') continue;
						if(s[i][ni]!=s[j][nj]) check=0;
					}
					ok[i][j][k]=check;
				}
			}
		}
		for(int i=0;i<N;++i){
			for(int j=0;j<N;++j){
				if(!ask(0,1,i)) continue;
				if(!ask(1,2,j)) continue;
				if(!ask(0,2,i+j)) continue;
				int cur=0;
				max_self(cur,(int)s[0].size());
				max_self(cur,i+(int)s[1].size());
				max_self(cur,i+j+(int)s[2].size());
				min_self(ans,cur);
			}
		}
	}
	while(next_permutation(s,s+3));
	cout<<ans;
	return 0;
}

```