#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<string> v(3);
bool okmr[3][3][7000]={};

void fill(string x, string y, bool f[]){
	for(int i=0; i<x.size(); ++i){
		f[i]=1;
		for(int j=0; j<y.size() && i+j<x.size(); ++j){
			f[i]=f[i]&&(x[i+j]==y[j] || x[i+j]=='?' || y[j]=='?');
		}
	}
}

int solve(int x, int y, int z){
	int res=7000;
	for(int i=0; i<=v[x].size(); ++i){
		if(i==v[x].size() || okmr[x][y][i]){
			for(int j=0; j<=v[y].size() || i+j<=v[x].size(); ++j){
				if(j>=v[y].size() || okmr[y][z][j]){
					if(i+j>=v[x].size() || okmr[x][z][i+j]){
						res=min(res, int(max({v[x].size(), i+v[y].size(), i+j+v[z].size()})));
						break;
					}
				}
			}
		}
	}
	return res;
}

int main() {
	for(int i=0; i<3; ++i) cin >> v[i];
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			if(i!=j){
				fill(v[i], v[j], okmr[i][j]);
			}
		}
	}
	int ans=7000;
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			if(i!=j){
				ans=min(ans, solve(i, j, 3-i-j));
			}
		}
	}
	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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<string> v(3);
bool okmr[3][3][7000]={};

void fill(string x, string y, bool f[]){
	for(int i=0; i<x.size(); ++i){
		f[i]=1;
		for(int j=0; j<y.size() && i+j<x.size(); ++j){
			f[i]=f[i]&&(x[i+j]==y[j] || x[i+j]=='?' || y[j]=='?');
		}
	}
}

int solve(int x, int y, int z){
	int res=7000;
	for(int i=0; i<=v[x].size(); ++i){
		if(i==v[x].size() || okmr[x][y][i]){
			for(int j=0; j<=v[y].size() || i+j<=v[x].size(); ++j){
				if(j>=v[y].size() || okmr[y][z][j]){
					if(i+j>=v[x].size() || okmr[x][z][i+j]){
						res=min(res, int(max({v[x].size(), i+v[y].size(), i+j+v[z].size()})));
						break;
					}
				}
			}
		}
	}
	return res;
}

int main() {
	for(int i=0; i<3; ++i) cin >> v[i];
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			if(i!=j){
				fill(v[i], v[j], okmr[i][j]);
			}
		}
	}
	int ans=7000;
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			if(i!=j){
				ans=min(ans, solve(i, j, 3-i-j));
			}
		}
	}
	cout << ans << endl;
	return 0;
}
```