#include <bits/stdc++.h>
using namespace std;
string h(const string& a, const string& b, unsigned p) {
	for (unsigned i = 0; i < b.length() && p+i < a.length(); ++ i) {
		if (!(a[p+i] == '?' || b[i] == '?' || a[p+i] == b[i])) return "";
	}
	string r = a;
	for (unsigned i = 0; i < b.length() && p+i < a.length(); ++ i) {
		if (b[i] != '?' && a[p+i] == '?') r[p+i] = b[i];
	}
	for (unsigned i = 0; i < b.length(); ++ i) {
		if (p+i >= a.length()) r += b[i];
	}
	return r;
}
int h2(const string& a, const string& b, unsigned p) {
	for (unsigned i = 0; i < b.length() && p+i < a.length(); ++ i) {
		if (!(a[p+i] == '?' || b[i] == '?' || a[p+i] == b[i])) return 0;
	}
	int r = a.length();
	for (unsigned i = 0; i < b.length(); ++ i) if (p+i >= a.length()) ++ r;
	return r;
}
int g(const string& a, const string& b) {
	for (unsigned i = 0; i <= a.length(); ++ i) {
		int x = h2(a, b, i);
		if (x) return x;
	}
	throw 1;
}
int f(const string& a, const string& b, const string& c) {
	int r = 1<<30;
	for (unsigned i = 0; i <= a.length(); ++ i) {
		string x = h(a, b, i);
		if (x.length()) {
			if ((int)x.length() >= r) break;
			r = min(r, g(x, c));
		}
	}
	return r;
}
int main() {
	string A, B, C;
	cin >> A >> B >> C;
	int r = f(A,B,C);
	r = min(r, f(A,C,B));
	r = min(r, f(B,A,C));
	r = min(r, f(B,C,A));
	r = min(r, f(C,A,B));
	r = min(r, f(C,B,A));
	cout << r << endl;
}

### 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 <bits/stdc++.h>
using namespace std;
string h(const string& a, const string& b, unsigned p) {
	for (unsigned i = 0; i < b.length() && p+i < a.length(); ++ i) {
		if (!(a[p+i] == '?' || b[i] == '?' || a[p+i] == b[i])) return "";
	}
	string r = a;
	for (unsigned i = 0; i < b.length() && p+i < a.length(); ++ i) {
		if (b[i] != '?' && a[p+i] == '?') r[p+i] = b[i];
	}
	for (unsigned i = 0; i < b.length(); ++ i) {
		if (p+i >= a.length()) r += b[i];
	}
	return r;
}
int h2(const string& a, const string& b, unsigned p) {
	for (unsigned i = 0; i < b.length() && p+i < a.length(); ++ i) {
		if (!(a[p+i] == '?' || b[i] == '?' || a[p+i] == b[i])) return 0;
	}
	int r = a.length();
	for (unsigned i = 0; i < b.length(); ++ i) if (p+i >= a.length()) ++ r;
	return r;
}
int g(const string& a, const string& b) {
	for (unsigned i = 0; i <= a.length(); ++ i) {
		int x = h2(a, b, i);
		if (x) return x;
	}
	throw 1;
}
int f(const string& a, const string& b, const string& c) {
	int r = 1<<30;
	for (unsigned i = 0; i <= a.length(); ++ i) {
		string x = h(a, b, i);
		if (x.length()) {
			if ((int)x.length() >= r) break;
			r = min(r, g(x, c));
		}
	}
	return r;
}
int main() {
	string A, B, C;
	cin >> A >> B >> C;
	int r = f(A,B,C);
	r = min(r, f(A,C,B));
	r = min(r, f(B,A,C));
	r = min(r, f(B,C,A));
	r = min(r, f(C,A,B));
	r = min(r, f(C,B,A));
	cout << r << endl;
}

```