#include <bits/stdc++.h> 
#define lowbit(x) x&(-x)
using namespace std;
const int N = 5e4;
const int M = 2e3;

bool ab[N << 1],ac[N << 1],bc[N << 1];

inline bool check(char x,char y){
	return (x == '?' || y == '?' || x == y);
}

void init(string a,string b,int n,int m,bool *vis){
	for(int i = 0;i < n;++i)
		for(int j = 0;j < m;++j)
			if(!check(a[i],b[j])) vis[i-j+N] = 1;
	return ;
}

int main(){
	int A,B,C;
    string a,b,c;
    cin >> a;A = a.size();
    cin >> b;B = b.size();
    cin >> c;C = c.size();
    
    init(a,b,A,B,ab);
    init(a,c,A,C,ac);
    init(b,c,B,C,bc);
    
    int ans = 3*M;
    for(int i = -(M << 1);i <= (M << 1);++i){
    	for(int j = -(M << 1);j <= (M << 1);++j){
    		if(!ab[i+N] && !ac[j+N] && !bc[j-i+N]){
    			int l = min(0,min(i,j));
    			int r = max(A,max(B+i,C+j));
    			ans = min(ans,r-l);
			}
		}
	}
	printf("%d\n",ans);
    return 0;
}
### Prompt

Please formulate 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> 
#define lowbit(x) x&(-x)
using namespace std;
const int N = 5e4;
const int M = 2e3;

bool ab[N << 1],ac[N << 1],bc[N << 1];

inline bool check(char x,char y){
	return (x == '?' || y == '?' || x == y);
}

void init(string a,string b,int n,int m,bool *vis){
	for(int i = 0;i < n;++i)
		for(int j = 0;j < m;++j)
			if(!check(a[i],b[j])) vis[i-j+N] = 1;
	return ;
}

int main(){
	int A,B,C;
    string a,b,c;
    cin >> a;A = a.size();
    cin >> b;B = b.size();
    cin >> c;C = c.size();
    
    init(a,b,A,B,ab);
    init(a,c,A,C,ac);
    init(b,c,B,C,bc);
    
    int ans = 3*M;
    for(int i = -(M << 1);i <= (M << 1);++i){
    	for(int j = -(M << 1);j <= (M << 1);++j){
    		if(!ab[i+N] && !ac[j+N] && !bc[j-i+N]){
    			int l = min(0,min(i,j));
    			int r = max(A,max(B+i,C+j));
    			ans = min(ans,r-l);
			}
		}
	}
	printf("%d\n",ans);
    return 0;
}
```