#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

string s[3];
int lcp[3][3][4005][4005];

void build_lcp(int a, int b) {
	for (int i = s[a].size() - 1; ~i; -- i)
		for (int j = s[b].size() - 1; ~j; -- j)
			if (s[a][i] == s[b][j] || s[a][i] == '?' || s[b][j] == '?')
				lcp[a][b][i][j] = lcp[a][b][i + 1][j + 1] + 1;
}

int main() {
	ios :: sync_with_stdio(0);
	cin >> s[0] >> s[1] >> s[2];
	for (int i = 0; i < 3; ++ i) for (int j = 0; j < 3; ++ j) if (i != j) build_lcp(i, j);
	int id[3]; for (int i = 0; i < 3; ++ i) id[i] = i;
	int ans = 1e9;
	do {
		int a = id[0], b = id[1], c = id[2];
		int asiz = s[a].size();
		int bsiz = s[b].size();
		int csiz = s[c].size();
		int sa = 0;
		for (int sb = 0; sb <= asiz; ++ sb) {
			for (int sc = b; sc <= sb + bsiz || sc <= asiz; ++ sc) {
				if (sb - sa < asiz && lcp[a][b][sb - sa][0] < min(asiz - sb + sa, bsiz)) continue;
				if (sc - sb < bsiz && lcp[b][c][sc - sb][0] < min(bsiz - sc + sb, csiz)) continue;
				if (sc - sa < asiz && lcp[a][c][sc - sa][0] < min(asiz - sc + sa, csiz)) continue;
				ans = min(ans, max(sa + asiz, max(sb + bsiz, sc + csiz)));
			}
		}
	} while (next_permutation(id, id + 3)) ;
	cout << ans << endl;
	return 0;
}

### Prompt

Please provide a Cpp coded solution 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 <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

string s[3];
int lcp[3][3][4005][4005];

void build_lcp(int a, int b) {
	for (int i = s[a].size() - 1; ~i; -- i)
		for (int j = s[b].size() - 1; ~j; -- j)
			if (s[a][i] == s[b][j] || s[a][i] == '?' || s[b][j] == '?')
				lcp[a][b][i][j] = lcp[a][b][i + 1][j + 1] + 1;
}

int main() {
	ios :: sync_with_stdio(0);
	cin >> s[0] >> s[1] >> s[2];
	for (int i = 0; i < 3; ++ i) for (int j = 0; j < 3; ++ j) if (i != j) build_lcp(i, j);
	int id[3]; for (int i = 0; i < 3; ++ i) id[i] = i;
	int ans = 1e9;
	do {
		int a = id[0], b = id[1], c = id[2];
		int asiz = s[a].size();
		int bsiz = s[b].size();
		int csiz = s[c].size();
		int sa = 0;
		for (int sb = 0; sb <= asiz; ++ sb) {
			for (int sc = b; sc <= sb + bsiz || sc <= asiz; ++ sc) {
				if (sb - sa < asiz && lcp[a][b][sb - sa][0] < min(asiz - sb + sa, bsiz)) continue;
				if (sc - sb < bsiz && lcp[b][c][sc - sb][0] < min(bsiz - sc + sb, csiz)) continue;
				if (sc - sa < asiz && lcp[a][c][sc - sa][0] < min(asiz - sc + sa, csiz)) continue;
				ans = min(ans, max(sa + asiz, max(sb + bsiz, sc + csiz)));
			}
		}
	} while (next_permutation(id, id + 3)) ;
	cout << ans << endl;
	return 0;
}

```