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

const int maxN = 6005;

int ans, tot;
int len[3];
bool f[3][3][maxN + 1];
char s[3][maxN + 1];

int main()
{
	for(int i = 0; i < 3; i++)
		scanf("%s", s[i] + 1), len[i] = strlen(s[i] + 1);

	tot = ans = len[0] + len[1] + len[2];
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
		{
			if(i == j) continue;
			for(int p = 1; p <= tot; p++)
			{
				f[i][j][p] = true;
				for(int l = 1, r = p; l <= len[i] && r <= len[j]; l++, r++)
					if(s[i][l] != s[j][r] && s[i][l] != '?' && s[j][r] != '?')
					{
						f[i][j][p] = false;
						break;
					}
			}
		}

	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
		{
			if(i == j) continue;
			int k = 3 - i - j;
			for(int l = 1; l <= tot; l++)
			{
				if(!f[j][i][l]) continue;
				for(int r = 1; r <= tot; r++)
				{
					if(!f[k][j][r]) continue;
					int t = l + r - 1;
					if(!f[k][i][t]) continue;
					ans = min(ans, t - 1 + max(len[k], max(len[j] - r + 1, len[i] - t + 1)));
				}
			}
						
		}

	printf("%d", ans);
	return 0;
}

### Prompt

Create a solution in CPP for 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;

const int maxN = 6005;

int ans, tot;
int len[3];
bool f[3][3][maxN + 1];
char s[3][maxN + 1];

int main()
{
	for(int i = 0; i < 3; i++)
		scanf("%s", s[i] + 1), len[i] = strlen(s[i] + 1);

	tot = ans = len[0] + len[1] + len[2];
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
		{
			if(i == j) continue;
			for(int p = 1; p <= tot; p++)
			{
				f[i][j][p] = true;
				for(int l = 1, r = p; l <= len[i] && r <= len[j]; l++, r++)
					if(s[i][l] != s[j][r] && s[i][l] != '?' && s[j][r] != '?')
					{
						f[i][j][p] = false;
						break;
					}
			}
		}

	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
		{
			if(i == j) continue;
			int k = 3 - i - j;
			for(int l = 1; l <= tot; l++)
			{
				if(!f[j][i][l]) continue;
				for(int r = 1; r <= tot; r++)
				{
					if(!f[k][j][r]) continue;
					int t = l + r - 1;
					if(!f[k][i][t]) continue;
					ans = min(ans, t - 1 + max(len[k], max(len[j] - r + 1, len[i] - t + 1)));
				}
			}
						
		}

	printf("%d", ans);
	return 0;
}

```