#include <stdio.h>
#include <algorithm>
using namespace std;

char S[3][2020]; int L[3];
bool D[3][8080];
const int bias = 4004;

void mk(int u, int p, int q)
{
	for (int j = -bias; j <= bias; j++){
		bool good = true;
		for (int i = 0; i < L[q]; i++){
			if (j + i < 0 || j + i >= L[p]) continue;
			if (S[q][i] == '?' || S[p][j + i] == '?') continue;
			if (S[q][i] != S[p][j + i]){ good = false; break; }
		}
		D[u][j + bias] = good;
	}
}

int main()
{
	scanf ("%s %s %s", S[0], S[1], S[2]);
	for (int k = 0; k < 3; k++) while (S[k][L[k]]) L[k]++;

	mk(0, 0, 1);
	mk(1, 0, 2);
	mk(2, 1, 2);

	int ans = bias * 3;
	for (int j = -bias; j <= bias; j++) if (D[0][j + bias]){
		for (int k = -bias; k <= bias; k++) if (D[1][k + bias]){
			if (k - j < -bias || k - j > bias || D[2][k - j + bias]){
				int l = min({ 0, j, k });
				int r = max({ L[0], j + L[1], k + L[2] });
				ans = min(ans, r - l);
			}
		}
	}
	printf ("%d\n", ans);

	return 0;
}
### 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 <stdio.h>
#include <algorithm>
using namespace std;

char S[3][2020]; int L[3];
bool D[3][8080];
const int bias = 4004;

void mk(int u, int p, int q)
{
	for (int j = -bias; j <= bias; j++){
		bool good = true;
		for (int i = 0; i < L[q]; i++){
			if (j + i < 0 || j + i >= L[p]) continue;
			if (S[q][i] == '?' || S[p][j + i] == '?') continue;
			if (S[q][i] != S[p][j + i]){ good = false; break; }
		}
		D[u][j + bias] = good;
	}
}

int main()
{
	scanf ("%s %s %s", S[0], S[1], S[2]);
	for (int k = 0; k < 3; k++) while (S[k][L[k]]) L[k]++;

	mk(0, 0, 1);
	mk(1, 0, 2);
	mk(2, 1, 2);

	int ans = bias * 3;
	for (int j = -bias; j <= bias; j++) if (D[0][j + bias]){
		for (int k = -bias; k <= bias; k++) if (D[1][k + bias]){
			if (k - j < -bias || k - j > bias || D[2][k - j + bias]){
				int l = min({ 0, j, k });
				int r = max({ L[0], j + L[1], k + L[2] });
				ans = min(ans, r - l);
			}
		}
	}
	printf ("%d\n", ans);

	return 0;
}
```