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

const int INF=1e9;
int ab[123456],bc[123456],ca[123456],ans=INF;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
bool check(char a,char b){
  return (a!='?'&&b!='?'&&a!=b);
}

signed main(){
  string a,b,c;cin>>a>>b>>c;
  int A=a.size(),B=b.size(),C=c.size();
  for(int i=-4000;i<=4000;i++)//aをbに比べてi文字だけ手前に置く（a[j+i]とb[j]が重なる）
    for(int j=0;j<B;j++)
      if(j+i>=0&&j+i<A&&check(a[j+i],b[j]))
        ab[5000+i]=1;
  for(int i=-4000;i<=4000;i++)//bをcに
    for(int j=0;j<C;j++)
      if(j+i>=0&&j+i<B&&check(b[j+i],c[j]))
        bc[5000+i]=1;
  for(int i=-4000;i<=4000;i++)//aをcに
    for(int j=0;j<C;j++)
      if(j+i>=0&&j+i<A&&check(a[j+i],c[j]))
        ca[5000+i]=1;
  for(int i=-4000;i<=4000;i++){//aをbに
    for(int j=-4000;j<=4000;j++){//bをcに
      if(ab[5000+i])continue;
      if(bc[5000+j])continue;
      if(abs(i+j)<=4000&&ca[5000+i+j])continue;
      chmin(ans,max({-i-j+A,-j+B,C})-min({-i-j,-j,0}));
    }
  }
  cout<<ans<<endl;
}

### 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
#include <bits/stdc++.h>
using namespace std;

const int INF=1e9;
int ab[123456],bc[123456],ca[123456],ans=INF;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
bool check(char a,char b){
  return (a!='?'&&b!='?'&&a!=b);
}

signed main(){
  string a,b,c;cin>>a>>b>>c;
  int A=a.size(),B=b.size(),C=c.size();
  for(int i=-4000;i<=4000;i++)//aをbに比べてi文字だけ手前に置く（a[j+i]とb[j]が重なる）
    for(int j=0;j<B;j++)
      if(j+i>=0&&j+i<A&&check(a[j+i],b[j]))
        ab[5000+i]=1;
  for(int i=-4000;i<=4000;i++)//bをcに
    for(int j=0;j<C;j++)
      if(j+i>=0&&j+i<B&&check(b[j+i],c[j]))
        bc[5000+i]=1;
  for(int i=-4000;i<=4000;i++)//aをcに
    for(int j=0;j<C;j++)
      if(j+i>=0&&j+i<A&&check(a[j+i],c[j]))
        ca[5000+i]=1;
  for(int i=-4000;i<=4000;i++){//aをbに
    for(int j=-4000;j<=4000;j++){//bをcに
      if(ab[5000+i])continue;
      if(bc[5000+j])continue;
      if(abs(i+j)<=4000&&ca[5000+i+j])continue;
      chmin(ans,max({-i-j+A,-j+B,C})-min({-i-j,-j,0}));
    }
  }
  cout<<ans<<endl;
}

```