#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define x first
#define y second

#ifdef LOCAL
#include "debug.h"
#endif

const int N = int(2e3) + 10;

vector<bool> func(string a, string b) {
	vector<bool> ret(a.size() + 1, true);
	for (int i = 0; i < a.size(); i++) {
		for (int j = i, k = 0; j < a.size() && k < b.size(); j++, k++) {
			if (a[j] != '?' && b[k] != '?' && a[j] != b[k]) {
				ret[i] = false;
				break;
			}
		}
	}
	return ret;
}

int solve(string a, string b, string c) {
	vector<bool> ab = func(a, b);
	vector<bool> ac = func(a, c);
	vector<bool> bc = func(b, c);

	int ans = INT_MAX;
	for (int i = 0; i <= a.size(); i++) if (ab[i]) {
		for (int j = i; j <= max(a.size(), i + b.size()); j++) {
			if ((j >= ac.size() || ac[j])
					&& (j - i >= bc.size() || bc[j - i])) {
				ans = min(ans, (int)max(a.size(), max(i + b.size(), j + c.size())));
			}
		}
	}
	return ans;
}

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	string a, b, c;
	cin >> a >> b >> c;

	int ans = INT_MAX;
	ans = min(ans, solve(a, b, c));
	ans = min(ans, solve(a, c, b));
	ans = min(ans, solve(b, a, c));
	ans = min(ans, solve(b, c, a));
	ans = min(ans, solve(c, a, b));
	ans = min(ans, solve(c, b, a));
	cout << ans << endl;

	return 0;
}
### Prompt

In cpp, your task is to solve 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;

typedef long long ll;
typedef pair<int, int> pii;
#define x first
#define y second

#ifdef LOCAL
#include "debug.h"
#endif

const int N = int(2e3) + 10;

vector<bool> func(string a, string b) {
	vector<bool> ret(a.size() + 1, true);
	for (int i = 0; i < a.size(); i++) {
		for (int j = i, k = 0; j < a.size() && k < b.size(); j++, k++) {
			if (a[j] != '?' && b[k] != '?' && a[j] != b[k]) {
				ret[i] = false;
				break;
			}
		}
	}
	return ret;
}

int solve(string a, string b, string c) {
	vector<bool> ab = func(a, b);
	vector<bool> ac = func(a, c);
	vector<bool> bc = func(b, c);

	int ans = INT_MAX;
	for (int i = 0; i <= a.size(); i++) if (ab[i]) {
		for (int j = i; j <= max(a.size(), i + b.size()); j++) {
			if ((j >= ac.size() || ac[j])
					&& (j - i >= bc.size() || bc[j - i])) {
				ans = min(ans, (int)max(a.size(), max(i + b.size(), j + c.size())));
			}
		}
	}
	return ans;
}

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	string a, b, c;
	cin >> a >> b >> c;

	int ans = INT_MAX;
	ans = min(ans, solve(a, b, c));
	ans = min(ans, solve(a, c, b));
	ans = min(ans, solve(b, a, c));
	ans = min(ans, solve(b, c, a));
	ans = min(ans, solve(c, a, b));
	ans = min(ans, solve(c, b, a));
	cout << ans << endl;

	return 0;
}
```