#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll MOD = 1000000007LL;


bool eq(char a, char b) {
	return a=='?' || b=='?' || a==b || a==0 || b==0;
}

const int SZ = 2033;
char A[SZ], B[SZ], C[SZ];
int LA, LB, LC;

bool arr1[SZ*8], arr2[SZ*8], arr3[SZ*8];
bool *AB, *BC, *AC;

void process(char*S, char*T, bool *shift) {
	int LS = strlen(S);
	int LT = strlen(T);
	for (int sh=-LS; sh<=LT; sh++) {
		bool ok = true;
		for (int i=0; i<LS && ok; i++) if (0 <= sh+i && sh+i < LT)
			ok = eq(S[i], T[sh+i]);
		shift[sh] = ok;
	}
}


int main() {
	cin >> A >> B >> C;
	LA = strlen(A);
	LB = strlen(B);
	LC = strlen(C);

	memset(arr1, true, sizeof(arr1));
	memset(arr2, true, sizeof(arr2));
	memset(arr3, true, sizeof(arr3));
	AB = arr1 + SZ*4;
	BC = arr2 + SZ*4;
	AC = arr3 + SZ*4;


	process(A, B, AB);
	process(B, C, BC);
	process(A, C, AC);

	int ans = 1e9;
	for (int ab=-4000; ab<=4000; ab++) for (int bc=-4000; bc<=4000; bc++) {
		if (AB[ab] && BC[bc] && AC[ab+bc]) {
			int a = max(LA, max(-ab+LB, -ab-bc+LC)) - min(0, min(-ab, -ab-bc));
			ans = min(a, ans);
		}
	}


	cout << ans << endl;


	return 0;
}
### Prompt

Generate 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
#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll MOD = 1000000007LL;


bool eq(char a, char b) {
	return a=='?' || b=='?' || a==b || a==0 || b==0;
}

const int SZ = 2033;
char A[SZ], B[SZ], C[SZ];
int LA, LB, LC;

bool arr1[SZ*8], arr2[SZ*8], arr3[SZ*8];
bool *AB, *BC, *AC;

void process(char*S, char*T, bool *shift) {
	int LS = strlen(S);
	int LT = strlen(T);
	for (int sh=-LS; sh<=LT; sh++) {
		bool ok = true;
		for (int i=0; i<LS && ok; i++) if (0 <= sh+i && sh+i < LT)
			ok = eq(S[i], T[sh+i]);
		shift[sh] = ok;
	}
}


int main() {
	cin >> A >> B >> C;
	LA = strlen(A);
	LB = strlen(B);
	LC = strlen(C);

	memset(arr1, true, sizeof(arr1));
	memset(arr2, true, sizeof(arr2));
	memset(arr3, true, sizeof(arr3));
	AB = arr1 + SZ*4;
	BC = arr2 + SZ*4;
	AC = arr3 + SZ*4;


	process(A, B, AB);
	process(B, C, BC);
	process(A, C, AC);

	int ans = 1e9;
	for (int ab=-4000; ab<=4000; ab++) for (int bc=-4000; bc<=4000; bc++) {
		if (AB[ab] && BC[bc] && AC[ab+bc]) {
			int a = max(LA, max(-ab+LB, -ab-bc+LC)) - min(0, min(-ab, -ab-bc));
			ans = min(a, ans);
		}
	}


	cout << ans << endl;


	return 0;
}
```