#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)

using namespace std;

string s[3];
bool conf[3][3][10005];

bool check(string &s, string &t, llint p)
{
	llint q = 0;
	for(int i = p; i < s.size(); i++){
		if(q >= t.size()) break;
		if(s[i] != '?' && t[q] != '?' && s[i] != t[q]) return true;
		q++;
	}
	return false;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	rep(i, 0, 3) cin >> s[i];
	llint p[] = {0, 1, 2};
	
	rep(i, 0, 3){
		rep(j, 0, 3){
			if(i == j) continue;
			rep(k, 0, s[i].size()){
				conf[i][j][k] = check(s[i], s[j], k);
			}
		}
	}
	
	llint ans = inf;
	do{
		for(int i = 0; i <= 2005; i++){
			if(conf[p[0]][p[1]][i]) continue;
			for(int j = 0; j <= 4005; j++){
				if(conf[p[1]][p[2]][j]) continue;
				if(conf[p[0]][p[2]][i+j]) continue;
				llint len = s[p[0]].size();
				len = max(len, (llint)s[p[1]].size() + i);
				len = max(len, (llint)s[p[2]].size() + i + j);
				ans = min(ans, len);
			}
		}
	}while(next_permutation(p, p+3));
	cout << ans << endl;
	
	return 0;
}
### Prompt

Your challenge is to write 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 <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)

using namespace std;

string s[3];
bool conf[3][3][10005];

bool check(string &s, string &t, llint p)
{
	llint q = 0;
	for(int i = p; i < s.size(); i++){
		if(q >= t.size()) break;
		if(s[i] != '?' && t[q] != '?' && s[i] != t[q]) return true;
		q++;
	}
	return false;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	rep(i, 0, 3) cin >> s[i];
	llint p[] = {0, 1, 2};
	
	rep(i, 0, 3){
		rep(j, 0, 3){
			if(i == j) continue;
			rep(k, 0, s[i].size()){
				conf[i][j][k] = check(s[i], s[j], k);
			}
		}
	}
	
	llint ans = inf;
	do{
		for(int i = 0; i <= 2005; i++){
			if(conf[p[0]][p[1]][i]) continue;
			for(int j = 0; j <= 4005; j++){
				if(conf[p[1]][p[2]][j]) continue;
				if(conf[p[0]][p[2]][i+j]) continue;
				llint len = s[p[0]].size();
				len = max(len, (llint)s[p[1]].size() + i);
				len = max(len, (llint)s[p[2]].size() + i + j);
				ans = min(ans, len);
			}
		}
	}while(next_permutation(p, p+3));
	cout << ans << endl;
	
	return 0;
}
```