#include<bits/stdc++.h>
using namespace std;
int S[3],ord[3],res;
char s[3][4010];
bool mat[3][3][4010];
int main(){
	memset(mat,true,sizeof(mat));
	for(int i=0;i<3;i++)scanf("%s",s[i]),S[i]=strlen(s[i]),res+=S[i];
	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];k++){
			for(int l=0;l<S[j]&&k+l<S[i];l++)if(s[i][k+l]!='?'&&s[j][l]!='?'&&s[i][k+l]!=s[j][l]){mat[i][j][k]=false;break;}
			if(mat[i][j][k])res=min(res,(S[0]+S[1]+S[2])-min(S[j],S[i]-k));
//			printf("%d ",mat[i][j][k]);
		}
//		puts("");
	}
	for(int i=0;i<3;i++)ord[i]=i;
	do{
		for(int j=0;j<S[ord[0]];j++)for(int k=j;k<max(S[ord[0]],j+S[ord[1]]);k++){
			if(!mat[ord[0]][ord[1]][j])continue;
			if(!mat[ord[0]][ord[2]][k])continue;
			if(!mat[ord[1]][ord[2]][k-j])continue;
			res=min(res,max(S[ord[0]],max(j+S[ord[1]],k+S[ord[2]])));
		}
	}while(next_permutation(ord,ord+3));
	printf("%d\n",res);
	return 0;
}

### Prompt

Your task is to create a CPP solution 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;
int S[3],ord[3],res;
char s[3][4010];
bool mat[3][3][4010];
int main(){
	memset(mat,true,sizeof(mat));
	for(int i=0;i<3;i++)scanf("%s",s[i]),S[i]=strlen(s[i]),res+=S[i];
	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];k++){
			for(int l=0;l<S[j]&&k+l<S[i];l++)if(s[i][k+l]!='?'&&s[j][l]!='?'&&s[i][k+l]!=s[j][l]){mat[i][j][k]=false;break;}
			if(mat[i][j][k])res=min(res,(S[0]+S[1]+S[2])-min(S[j],S[i]-k));
//			printf("%d ",mat[i][j][k]);
		}
//		puts("");
	}
	for(int i=0;i<3;i++)ord[i]=i;
	do{
		for(int j=0;j<S[ord[0]];j++)for(int k=j;k<max(S[ord[0]],j+S[ord[1]]);k++){
			if(!mat[ord[0]][ord[1]][j])continue;
			if(!mat[ord[0]][ord[2]][k])continue;
			if(!mat[ord[1]][ord[2]][k-j])continue;
			res=min(res,max(S[ord[0]],max(j+S[ord[1]],k+S[ord[2]])));
		}
	}while(next_permutation(ord,ord+3));
	printf("%d\n",res);
	return 0;
}

```