#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


constexpr int R = 50000;

void func(const string &a, const string &b, int offset, bool *ok) {
	for (int ib = 0; ib < (int)b.size(); ib++) {
		int ia = offset + ib;
		ok[offset + R] &=
			ia < 0 || ia >= a.size() || a[ia] == '?' || b[ib] == '?' || a[ia] == b[ib];
	}
}

bool ab[2*R], ac[2*R], bc[2*R];

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	for (int i = 0; i < 2*R; i++) {
		ab[i] = ac[i] = bc[i] = true;
	}
	for (int i = -R; i < R; i++) func(a, b, i, ab);
	for (int i = -R; i < R; i++) func(a, c, i, ac);
	for (int i = -R; i < R; i++) func(b, c, i, bc);
	int ans = 1e9;
	for (int i = -4000; i <= 4000; i++) {
		for (int j = -4000; j <= 4000; j++) {
			if (ab[i + R] && ac[j + R] && bc[j - i + R]) {
				int l = min({ 0, i, j });
				int r = max({ (int)a.size(), i + (int)b.size(), j + (int)c.size() });
				ans = min(ans, r - l);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

### Prompt

Develop a solution in CPP to the problem described below:

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 <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


constexpr int R = 50000;

void func(const string &a, const string &b, int offset, bool *ok) {
	for (int ib = 0; ib < (int)b.size(); ib++) {
		int ia = offset + ib;
		ok[offset + R] &=
			ia < 0 || ia >= a.size() || a[ia] == '?' || b[ib] == '?' || a[ia] == b[ib];
	}
}

bool ab[2*R], ac[2*R], bc[2*R];

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	for (int i = 0; i < 2*R; i++) {
		ab[i] = ac[i] = bc[i] = true;
	}
	for (int i = -R; i < R; i++) func(a, b, i, ab);
	for (int i = -R; i < R; i++) func(a, c, i, ac);
	for (int i = -R; i < R; i++) func(b, c, i, bc);
	int ans = 1e9;
	for (int i = -4000; i <= 4000; i++) {
		for (int j = -4000; j <= 4000; j++) {
			if (ab[i + R] && ac[j + R] && bc[j - i + R]) {
				int l = min({ 0, i, j });
				int r = max({ (int)a.size(), i + (int)b.size(), j + (int)c.size() });
				ans = min(ans, r - l);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

```