#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
	int *ass;
	for (;;)
	{
		ass = new int[2500000];
		for (int i = 0; i < 2500000; i++)
			ass[i] = rand();
	}
}

string str;
int n;
void LoAd()
{
	cin >> str;
	n = (int) str.size();
}

vector< vector<char> > a;
vector<char> st;

void fix(vector<char> &s)
{
	st.clear();
	vector<char> res;
	for (int i = (int) s.size() - 1; i >= 0; i--)
	{
		if (!st.empty())
		{
			if ((st[st.size() - 1] == ']' && '[' == s[i]) || (st[st.size() - 1] == ')' && '(' == s[i]))
			{
				res.push_back(s[i]);
				st.pop_back();
			}
			else if(str[i] == ')' || s[i] == ']')
			{
				res.push_back(s[i]);
				st.push_back(s[i]);
			}
			else
			{
				break;
			}
		}
		else if (']' == s[i] || ')' == s[i])
		{
			st.push_back(s[i]);
			res.push_back(s[i]);
		}
	}
	s.clear();
	s.reserve(res.size());
	for (int i = (int) res.size() - 1; i >= 0; i--)
	{
		s.push_back(res[i]);
	}
}

void SoLvE()
{
	int j = 0;
	a.resize(1);
	for (int i = 0; i < n; i++)
	{
		switch(str[i])
		{
		case '(':
		case '[':
			a[j].push_back(str[i]);
			st.push_back(str[i]);
			break;
		case ']':
			if (st.empty())
			{
				j++;
				a.push_back(vector<char>());
				break;
			}
			if (st[st.size() - 1] == '[')
			{
				st.pop_back();
				a[j].push_back(str[i]);
			}
			else
			{
				st.clear();
				j++;
				a.push_back(vector<char>());
			}
			break;
		case ')':
			if (st.empty())
			{
				j++;
				a.push_back(vector<char>());
				break;
			}
			if (st[st.size() - 1] == '(')
			{
				st.pop_back();
				a[j].push_back(str[i]);
			}
			else
			{
				st.clear();
				j++;
				a.push_back(vector<char>());
			}
			break;
		}
	}
	for (int i = 0; i < (int) a.size(); i++)
	{
		fix(a[i]);
	}

	int ind = -1;
	int bres = -1;
	for (int i = 0; i < (int) a.size(); i++)
	{
		int cnt = 0;
		for (int j = 0; j < (int) a[i].size(); j++)
		{
			if ('[' == a[i][j])
				cnt++;
		}
		if (cnt > bres)
		{
			bres = cnt;
			ind = i;
		}
	}
	if (-1 == ind)
	{
		cout << "-1";
		return;
	}
	cout << bres << endl;
	for (int i = 0; i < (int) a[ind].size(); i++)
		printf("%c", a[ind][i]);
}

int main()
{
	srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
	LoAd();
	SoLvE();
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
	int *ass;
	for (;;)
	{
		ass = new int[2500000];
		for (int i = 0; i < 2500000; i++)
			ass[i] = rand();
	}
}

string str;
int n;
void LoAd()
{
	cin >> str;
	n = (int) str.size();
}

vector< string > a;
vector<char> st;

void addstr(string &res)
{
	if (res.empty())
		return;
	reverse(res.begin(), res.end());
	a.push_back(res);
	res.clear();
}

bool check(const string &s)
{
	st.clear();

	for (int i = 0; i < (int) s.size(); i++)
	{
		switch(s[i])
		{
		case '(':
		case '[':
			st.push_back(s[i]);
			break;
		case ']':
			if (st.empty())
			{
				return false;
			}
			if (st[st.size() - 1] == '[')
			{
				st.pop_back();
			}
			else
			{
				return false;
			}
			break;
		case ')':
			if (st.empty())
			{
				return false;;
			}
			if (st[st.size() - 1] == '(')
			{
				st.pop_back();
			}
			else
			{
				return false;
			}
			break;
		}
	}
	return (st.empty());

}

void fix(string s)
{
	reverse(s.begin(), s.end());
	string res;
	st.clear();

	for (int i = 0; i < (int) s.size(); i++)
	{
		switch(s[i])
		{
		case ')':
		case ']':
			res.push_back(s[i]);
			st.push_back(s[i]);
			break;
		case '[':
			if (st.empty())
			{
				addstr(res);
				break;
			}
			if (st[st.size() - 1] == ']')
			{
				st.pop_back();
				res.push_back(s[i]);
			}
			else
			{
				addstr(res);
				break;
			}
			break;
		case '(':
			if (st.empty())
			{
				addstr(res);
				break;
			}
			if (st[st.size() - 1] == ')')
			{
				st.pop_back();
				res.push_back(s[i]);
			}
			else
			{
				addstr(res);
				break;
			}
			break;
		}
	}
	addstr(res);
}

void SoLvE()
{
	int j = 0;
	a.resize(1);
	for (int i = 0; i < n; i++)
	{
		switch(str[i])
		{
		case '(':
		case '[':
			a[j].push_back(str[i]);
			st.push_back(str[i]);
			break;
		case ']':
			if (st.empty())
			{
				j++;
				a.push_back(string());
				break;
			}
			if (st[st.size() - 1] == '[')
			{
				st.pop_back();
				a[j].push_back(str[i]);
			}
			else
			{
				st.clear();
				j++;
				a.push_back(string());
			}
			break;
		case ')':
			if (st.empty())
			{
				j++;
				a.push_back(string());
				break;
			}
			if (st[st.size() - 1] == '(')
			{
				st.pop_back();
				a[j].push_back(str[i]);
			}
			else
			{
				st.clear();
				j++;
				a.push_back(string());
			}
			break;
		}
	}
	for (int i = 0; i < (int) a.size(); i++)
	{
		if (!check(a[i]))
		{
			fix(a[i]);
			a[i] = "";
		}
	}

	int ind = -1;
	int bres = -1;
	for (int i = 0; i < (int) a.size(); i++)
	{
		if (a[i].empty())
			continue;
		int cnt = 0;
		for (int j = 0; j < (int) a[i].size(); j++)
		{
			if ('[' == a[i][j])
				cnt++;
		}
		if (cnt > bres)
		{
			bres = cnt;
			ind = i;
		}
	}
	if (-1 == ind)
	{
		cout << "0";
		return;
	}
	cout << bres << endl;
	for (int i = 0; i < (int) a[ind].size(); i++)
		printf("%c", a[ind][i]);
}

int main()
{
	srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
	LoAd();
	SoLvE();
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
	int *ass;
	for (;;)
	{
		ass = new int[2500000];
		for (int i = 0; i < 2500000; i++)
			ass[i] = rand();
	}
}

string str;
int n;
void LoAd()
{
	cin >> str;
	n = (int) str.size();
}

vector< vector<char> > a;
vector<char> st;

void fix(vector<char> &s)
{
	st.clear();
	vector<char> res;
	for (int i = (int) s.size() - 1; i >= 0; i--)
	{
		if (!st.empty())
		{
			if ((st[st.size() - 1] == ']' && '[' == s[i]) || (st[st.size() - 1] == ')' && '(' == s[i]))
			{
				res.push_back(s[i]);
				st.pop_back();
			}
			else if(str[i] == ')' || s[i] == ']')
			{
				res.push_back(s[i]);
				st.push_back(s[i]);
			}
			else
			{
				break;
			}
		}
		else if (']' == s[i] || ')' == s[i])
		{
			st.push_back(s[i]);
			res.push_back(s[i]);
		}
	}
	s.clear();
	s.reserve(res.size());
	for (int i = (int) res.size() - 1; i >= 0; i--)
	{
		s.push_back(res[i]);
	}
}

void SoLvE()
{
	int j = 0;
	a.resize(1);
	for (int i = 0; i < n; i++)
	{
		if (!st.empty())
		{
			if ((st[st.size() - 1] == '[' && ']' == str[i]) || (st[st.size() - 1] == '(' && ')' == str[i]))
			{
				a[j].push_back(str[i]);
				st.pop_back();
			}
			else if(str[i] == '(' || str[i] == '[')
			{
				a[j].push_back(str[i]);
				st.push_back(str[i]);
			}
			else
			{
				j++;
				a.push_back(vector<char>());
				st.clear();
			}
		}
		else if ('[' == str[i] || '(' == str[i])
		{
			st.push_back(str[i]);
			a[j].push_back(str[i]);
		}
		else
		{
			j++;
			a.push_back(vector<char>());
			st.clear();
		}
	}
	for (int i = 0; i < (int) a.size(); i++)
	{
		fix(a[i]);
	}

	int ind = -1;
	int bres = -1;
	for (int i = 0; i < (int) a.size(); i++)
	{
		int cnt = 0;
		for (int j = 0; j < (int) a[i].size(); j++)
		{
			if ('[' == a[i][j])
				cnt++;
		}
		if (cnt > bres)
		{
			bres = cnt;
			ind = i;
		}
	}
	if (-1 == ind)
	{
		cout << "-1";
		return;
	}
	cout << bres << endl;
	for (int i = 0; i < (int) a[ind].size(); i++)
		printf("%c", a[ind][i]);
}

int main()
{
	srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
	LoAd();
	SoLvE();
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
	int *ass;
	for (;;)
	{
		ass = new int[2500000];
		for (int i = 0; i < 2500000; i++)
			ass[i] = rand();
	}
}

string str;
int n;
void LoAd()
{
	cin >> str;
	n = (int) str.size();
}

vector< vector<char> > a;
vector<char> st;

void fix(vector<char> &s)
{
	st.clear();
	vector<char> res;
	for (int i = (int) s.size() - 1; i >= 0; i--)
	{
		if (!st.empty())
		{
			if ((st[st.size() - 1] == ']' && '[' == s[i]) || (st[st.size() - 1] == ')' && '(' == s[i]))
			{
				res.push_back(s[i]);
				st.pop_back();
			}
			else if(str[i] == ')' || s[i] == ']')
			{
				res.push_back(s[i]);
				st.push_back(s[i]);
			}
			else
			{
				break;
			}
		}
		else if (']' == s[i] || ')' == s[i])
		{
			st.push_back(s[i]);
			res.push_back(s[i]);
		}
	}
	s.clear();
	s.reserve(res.size());
	for (int i = (int) res.size() - 1; i >= 0; i--)
	{
		s.push_back(res[i]);
	}
}

void SoLvE()
{
	int j = 0;
	a.resize(1);
	for (int i = 0; i < n; i++)
	{
		if (!st.empty())
		{
			if ((st[st.size() - 1] == '[' && ']' == str[i]) || (st[st.size() - 1] == '(' && ')' == str[i]))
			{
				a[j].push_back(str[i]);
				st.pop_back();
			}
			else if(str[i] == '(' || str[i] == '[')
			{
				a[j].push_back(str[i]);
				st.push_back(str[i]);
			}
			else
			{
				j++;
				a.push_back(vector<char>());
				st.clear();
			}
		}
		else if ('[' == str[i] || '(' == str[i])
		{
			st.push_back(str[i]);
			a[j].push_back(str[i]);
		}
	}
	for (int i = 0; i < (int) a.size(); i++)
	{
		fix(a[i]);
	}

	int ind = -1;
	int bres = -1;
	for (int i = 0; i < (int) a.size(); i++)
	{
		int cnt = 0;
		for (int j = 0; j < (int) a[i].size(); j++)
		{
			if ('[' == a[i][j])
				cnt++;
		}
		if (cnt > bres)
		{
			bres = cnt;
			ind = i;
		}
	}
	if (-1 == ind)
	{
		cout << "-1";
		return;
	}
	cout << bres << endl;
	for (int i = 0; i < (int) a[ind].size(); i++)
		printf("%c", a[ind][i]);
}

int main()
{
	srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
	LoAd();
	SoLvE();
	return 0;
}


#include <iostream>
#include <vector>
#include <stack>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    stack<char> p;
    vector<int> cnt(s.size()),h(s.size());
    for(int i=0;i<s.size();i++){
        if(s[i]=='(' || s[i]=='[')
            p.push(s[i]);
        else{
            if(!p.empty())
            {
                if((s[i]==']' && p.top()=='[') || (s[i]==')' && p.top()=='('))
                {
                //cout<<i<<endl;
                    cnt[i]=cnt[i-1];
                    if(s[i]==']') cnt[i]=cnt[i-1]+1;
                    h[i]=h[i-1]+1;
                    int g=i-h[i]-h[i];
                    if(g<0) g=0;
                    h[i]=h[g]+h[i];
                    cnt[i]+=cnt[g];
                    p.pop();
                }
                else
                {
                    while(!p.empty()) p.pop();
                }
            }
        }
    }
    int j=0,sh=0;
    for(int i=0;i<s.size();i++)
        if(cnt[i]>sh){
            sh=cnt[i];
            j=i;
        }
    cout<<cnt[j]<<endl;
    cout<<s.substr(j-h[j]-h[j]+1,h[j]+h[j])<<endl;

     // for(int i=0;i<s.size();i++)
    //  cout<<h[i]<<" ";
}


#include <iostream>
#include <vector>
#include <stack>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans=0,k=0,id=0,sh=0,h=0;
    stack<char> p;
    for(int i=0;i<s.size();i++){
        if(s[i]=='(' || s[i]=='[')
            p.push(s[i]);
        else{
            if(p.empty())
            {
                if(k>ans)
                {
                    ans=k;
                    sh=h;
                    k=0;
                    h=0;
                    id=i;
                }
            }
            else
            {
                if((s[i]==']' && p.top()=='[') || (s[i]==')' && p.top()=='('))
                {
                    h++;
                    if(s[i]==']')
                        k++;
                    p.pop();
                }
                else
                {
                    if(k>ans){
                        ans=k;
                        k=0;
                        sh=h;
                        h=0;
                        id=i;
                    }
                    while(!p.empty()) p.pop();
                }
            }
        }
    }
    if(k>ans){
        ans=k;
        sh=h;
        id=s.size();
    }
    cout<<ans<<endl;
    cout<<s.substr(id-sh-sh,sh+sh)<<endl;
}


#include <iostream>
#include <vector>
#include <stack>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    stack<char> p;
    vector<int> cnt(s.size()),h(s.size());
    for(int i=0;i<s.size();i++){
        if(s[i]=='(' || s[i]=='[')
            p.push(s[i]);
        else{
            if(!p.empty())
            {
                if((s[i]==']' && p.top()=='[') || (s[i]==')' && p.top()=='('))
                {
                //cout<<i<<endl;
                    if(s[i]==']') cnt[i]=cnt[i-1]+1;
                    h[i]=h[i-1]+1;
                    int g=i-h[i]-h[i];
                    if(g<0) g=0;
                    h[i]=h[g]+h[i];
                    cnt[i]+=cnt[g];
                    p.pop();
                }
                else
                {
                    while(!p.empty()) p.pop();
                }
            }
        }
    }
    int j=0,sh=0;
    for(int i=0;i<s.size();i++)
        if(cnt[i]>sh){
            sh=cnt[i];
            j=i;
        }
    cout<<cnt[j]<<endl;
    cout<<s.substr(j-h[j]-h[j]+1,h[j]+h[j])<<endl;
}


#include <iostream>
#include <vector>
#include <stack>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    stack<char> p;
    vector<int> cnt(s.size()),h(s.size());
    for(int i=0;i<s.size();i++){
        if(i){ cnt[i]=cnt[i-1];         h[i]=h[i-1]; }
        if(s[i]=='(' || s[i]=='[')
            p.push(s[i]);
        else{
            if(!p.empty())
            {
                if((s[i]==']' && p.top()=='[') || (s[i]==')' && p.top()=='('))
                {
                    cnt[i]=cnt[i-1];
                    if(s[i]==']') cnt[i]=cnt[i-1]+1;
                    h[i]=h[i-1]+1;
                    int g=i-h[i]-h[i];
                    if(g<0) g=0;
                    h[i]=h[g]+h[i];
                    cnt[i]+=cnt[g];
                    p.pop();
                }
                else
                {
                    while(!p.empty()) p.pop();
                }
            }
        }
    }
    int j=0,sh=0;
    for(int i=0;i<s.size();i++)
        if(cnt[i]>sh){
            sh=cnt[i];
            j=i;
        }
    cout<<cnt[j]<<endl;
    cout<<s.substr(j-h[j]-h[j]+1,h[j]+h[j])<<endl;
}


#include <iostream>
#include <vector>
#include <stack>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    stack<char> p;
    vector<int> cnt(s.size()),h(s.size());
    for(int i=0;i<s.size();i++){

        if(s[i]=='(' || s[i]=='['){
        if(i){ cnt[i]=cnt[i-1];         h[i]=h[i-1]; }
            p.push(s[i]);
            }
        else{
            if(!p.empty())
            {
                if((s[i]==']' && p.top()=='[') || (s[i]==')' && p.top()=='('))
                {
                    cnt[i]=cnt[i-1];
                    if(s[i]==']') cnt[i]=cnt[i-1]+1;
                    h[i]=h[i-1]+1;
                    int g=i-h[i]-h[i];
                    if(g<0) g=0;
                    h[i]=h[g]+h[i];
                    cnt[i]+=cnt[g];
                    p.pop();
                }
                else
                {
                    while(!p.empty()) p.pop();
                }
            }
        }
    }
    int j=0,sh=0;
    for(int i=0;i<s.size();i++)
        if(cnt[i]>sh){
            sh=cnt[i];
            j=i;
        }
    cout<<cnt[j]<<endl;
    cout<<s.substr(j-h[j]-h[j]+1,h[j]+h[j])<<endl;
}


#include <stdio.h>
#include <string.h>
#define MAX 110000
#define min(a,b) (a)<(b)?(a):(b)

int st[MAX],top,arr[MAX],cnt;
int n,m,ans,ansi,anscnt;
char str[MAX];

int main()
{
    int i,j,k;

    while (scanf("%s",str+1) != EOF) {

        n = strlen(str+1);
        top = cnt = 0;
        ans = -1,ansi = 0;

        for (i = 1; i <= n; ++i) {

            if (str[i] == '(' || str[i] == '[')
                st[++top] = i;
            else {

                if (str[i] == ')') {

                    if (top == 0 || str[st[top]] == '[') {

                        top = 0;
                        int temp = 0,in = n+1;
                        if (cnt != 0) {

                            for (j = 1; j <= cnt; ++j) {

                                if (str[arr[j]] == '[') temp++;
                                in = min(arr[j],in);
                            }
                            if (temp >= ans) ans = temp,ansi = in,anscnt = cnt;
                        }
                        top = cnt = 0;
                    }
                    else {

                        arr[++cnt] = st[top];
                        arr[++cnt] = i;
                        top--;
                    }
                }
                else {

                    if (top == 0 || st[top] == '(') {

                        top = 0;
                        int temp = 0,in = n+1;
                        if (cnt != 0) {

                            for (j = 1; j <= cnt; ++j) {

                                if (str[arr[i]] == '[') temp++;
                                in = min(arr[i],in);
                            }
                            if (temp >= ans) ans = temp,ansi = in,anscnt = cnt;
                        }
                        top = cnt = 0;
                    }
                    else {

                        arr[++cnt] = st[top];
                        arr[++cnt] = i;
                        top--;
                    }
                }
            }
        }

        if (cnt != 0) {

            int in = n + 1,temp = 0;
            for (i = 1; i <= cnt; ++i) {

                if (str[arr[i]] == '[') temp++;
                in = min(arr[i],in);
            }
            if (temp >= ans) ans = temp,ansi = in,anscnt = cnt;
        }

        if (ans == -1) printf("%d\n\n",0);
        else {

            printf("%d\n",ans);
            for (i = ansi; i <= ansi + anscnt - 1; ++i)
                printf("%c",str[i]);
            printf("\n");
        }
    }
}
/*
[[])()]
*/


#include <stdio.h>
#include <string.h>
#define MAX 110000
#define min(a,b) (a)<(b)?(a):(b)

int st[MAX],top,arr[MAX],cnt;
int n,m,ans,ansi,anscnt;
char str[MAX];

int main()
{
    int i,j,k;

    while (scanf("%s",str+1) != EOF) {

        n = strlen(str+1);
        top = cnt = 0;
        ans = -1,ansi = 0;

        for (i = 1; i <= n; ++i) {

            if (str[i] == '(' || str[i] == '[')
                st[++top] = i;
            else {

                if (str[i] == ')') {

                    if (top == 0 || str[st[top]] == '[') {

                        top = 0;
                        int temp = 0,in = n+1;
                        if (cnt != 0) {

                            for (j = 1; j <= cnt; ++j) {

                                if (str[arr[j]] == '[') temp++;
                                in = min(arr[j],in);
                            }
                            if (temp >= ans) ans = temp,ansi = in,anscnt = cnt;
                        }
                    }
                    else {

                        arr[++cnt] = st[top];
                        arr[++cnt] = i;
                        top--;
                    }
                }
                else {

                    if (top == 0 || st[top] == '(') {

                        top = 0;
                        int temp = 0,in = n+1;
                        if (cnt != 0) {

                            for (j = 1; j <= cnt; ++j) {

                                if (str[arr[i]] == '[') temp++;
                                in = min(arr[i],in);
                            }
                            if (temp >= ans) ans = temp,ansi = in,anscnt = cnt;
                        }
                    }
                    else {

                        arr[++cnt] = st[top];
                        arr[++cnt] = i;
                        top--;
                    }
                }
            }
        }

        if (cnt != 0) {

            int in = n + 1,temp = 0;
            for (i = 1; i <= cnt; ++i) {

                if (str[arr[i]] == '[') temp++;
                in = min(arr[i],in);
            }
            if (temp >= ans) ans = temp,ansi = in,anscnt = cnt;
        }

        if (ans == -1) printf("%d\n\n",0);
        else {

            printf("%d\n",ans);
            for (i = ansi; i <= ansi + anscnt - 1; ++i)
                printf("%c",str[i]);
            printf("\n");
        }
    }
}


#include <stdio.h>
#include <string.h>
#define MAX 110000
#define min(a,b) (a)<(b)?(a):(b)

int st[MAX],top,arr[MAX],cnt;
int n,m,ans,ansi,anscnt;
char str[MAX];

int main()
{
    int i,j,k;

    while (scanf("%s",str+1) != EOF) {

        n = strlen(str+1);
        top = cnt = 0;
        ans = -1,ansi = 0;

        for (i = 1; i <= n; ++i) {

            if (str[i] == '(' || str[i] == '[')
                st[++top] = i;
            else {

                if (str[i] == ')') {

                    if (top == 0 || str[st[top]] == '[') {

                        top = 0;
                        int temp = 0,in = n+1;
                        if (cnt != 0) {

                            for (i = 1; i <= cnt; ++i) {

                                if (str[arr[i]] == '[') temp++;
                                in = min(arr[i],in);
                            }
                            if (temp >= ans) ans = temp,ansi = in,anscnt = cnt;
                        }
                    }
                    else {

                        arr[++cnt] = st[top];
                        arr[++cnt] = i;
                        top--;
                    }
                }
                else {

                    if (top == 0 || st[top] == '(') {

                        top = 0;
                        int temp = 0,in = n+1;
                        if (cnt != 0) {

                            for (i = 1; i <= cnt; ++i) {

                                if (str[arr[i]] == '[') temp++;
                                in = min(arr[i],in);
                            }
                            if (temp >= ans) ans = temp,ansi = in,anscnt = cnt;
                        }
                    }
                    else {

                        arr[++cnt] = st[top];
                        arr[++cnt] = i;
                        top--;
                    }
                }
            }
        }

        if (cnt != 0) {

            int in = n + 1,temp = 0;
            for (i = 1; i <= cnt; ++i) {

                if (str[arr[i]] == '[') temp++;
                in = min(arr[i],in);
            }
            if (temp >= ans) ans = temp,ansi = in,anscnt = cnt;
        }

        if (ans == -1) printf("%d\n\n",0);
        else {

            printf("%d\n",ans);
            for (i = ansi; i <= ansi + anscnt - 1; ++i)
                printf("%c",str[i]);
            printf("\n");
        }
    }
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define MAX 110000
#define min(a,b) (a)<(b)?(a):(b)

int hash[MAX];
int st[MAX],top,arr[MAX],cnt;
int n,m,ans,ansi,anscnt;
char str[MAX];

int main()
{
    int i,j,k;

    while (scanf("%s",str+1) != EOF) {

        n = strlen(str+1);
        top = cnt = 0;
        ans = -1,ansi = 0;

        for (i = 1; i <= n; ++i) {

            if (str[i] == '(' || str[i] == '[')
                st[++top] = i;
            else {

                if (str[i] == ')') {

                    if (top == 0 || str[st[top]] == '[') {
                        top = 0;
                    }
                    else {

                        arr[++cnt] = st[top];
                        arr[++cnt] = i;
                        top--;
                    }
                }
                else {

                    if (top == 0 || str[st[top]] == '(') {
                        top = 0;
                    }
                    else {

                        arr[++cnt] = st[top];
                        arr[++cnt] = i;
                        top--;
                    }
                }
            }
        }

        memset(hash,0,sizeof(hash));
        for (i = 1; i <= cnt; ++i)
            hash[arr[i]] = 1;
        for (i = 1; i <= n; )
            if (hash[i]) {

                int temp = 0;
                for (j = i; j <= n && hash[j]; ++j)
                    if (str[j] == '[') temp++;
                if (temp >= ans) ans = temp,ansi = i,anscnt = j;
                i = j;
            }
            else i++;

        if (ans == -1) printf("%d\n\n",0);
        else {

            printf("%d\n",ans);
            for (i = ansi; i < anscnt; ++i)
                printf("%c",str[i]);
            printf("\n");
        }
    }
}
/*
[[])()]
([]([]]
*/


#include <iostream>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cmath>

using namespace std;

const int MAXN = 110000;
int L[MAXN], R[MAXN];
char array[MAXN];
int cnt[MAXN];

void DEL(int x)
{
	L[R[x]] = L[x];
	R[L[x]] = R[x];
}

int main()
{
	//freopen("input.txt", "r", stdin);

	cin >> array;

	int len = strlen(array);

	int c = 0;
	for(int i = 0; i < len; i++)
	{
		if('[' == array[i]) c++;
		cnt[i] = c;
	}

	for(int i = 0; i <= len; i++) L[i] = i - 1;
	for(int i = 0; i <= len; i++) R[i] = i + 1;
	L[0] = len;
	R[len] = 0;

	while(true)
	{
		bool bingo = false;
		for(int x = R[len]; x != len; x = R[x])
		{
			if(array[x] == '(')
			{
				int y = R[x];
				if(y == len) break;
				if(array[y] == ')')
				{
					DEL(y);
					DEL(x);
					bingo = true;
				}
			}
			else if(array[x] == '[')
			{
				int y = R[x];
				if(y == len) break;
				if(array[y] == ']')
				{
					DEL(y);
					DEL(x);
					bingo = true;
				}
			}
		}
		if(!bingo) break;
	}
	if(R[len] == len)
	{
		cout << cnt[len - 1] << endl;
		cout << array << endl;
		return 0;
	}
	int l = -1, r = -1;
	int nMax = 0;
	for(int x = R[len]; x != len; x = R[x])
	{
		int y = L[x];
		int tmp = cnt[x] - cnt[y];
		if(0 == x && cnt[x]) tmp -= 1;
		else if(cnt[x] > cnt[x - 1]) tmp -= 1;

		if(nMax < tmp)
		{
			nMax = tmp;
			l = y + 1, r = x - 1;
			if(l > r) l = 0;
		}
	}

	cout << nMax << endl;
	if(l >= r)
	{
		return 0;
	}
	for(int i = l; i <= r; i++) cout << array[i];
	cout << endl;

	return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cmath>

using namespace std;

const int MAXN = 110000;
int L[MAXN], R[MAXN];
char array[MAXN];
int cnt[MAXN];

void DEL(int x)
{
	L[R[x]] = L[x];
	R[L[x]] = R[x];
}

int main()
{
	//freopen("input.txt", "r", stdin);

	cin >> array;

	int len = strlen(array);

	int c = 0;
	for(int i = 0; i < len; i++)
	{
		if('[' == array[i]) c++;
		cnt[i] = c;
	}

	for(int i = 0; i <= len; i++) L[i] = i - 1;
	for(int i = 0; i <= len; i++) R[i] = i + 1;
	L[0] = len;
	R[len] = 0;

	while(true)
	{
		bool del = false;
		bool bingo = false;
		for(int x = R[len]; x != len; x = R[x])
		{
			if(del)
			{
				del = false;
				//cout << "jackie" << endl;
				if(L[x] != len)
				{
					x = L[x];
				}
			}
			if(array[x] == '(')
			{
				int y = R[x];
				if(y == len) break;
				if(array[y] == ')')
				{
					DEL(y);
					DEL(x);
					bingo = true;
					del = true;
				}

				//x = L[L[x]];
			}
			else if(array[x] == '[')
			{
				int y = R[x];
				if(y == len) break;
				if(array[y] == ']')
				{
					DEL(y);
					DEL(x);
					bingo = true;
					del = true;
				}

				//x = L[L[x]];
			}
		}
		if(!bingo) break;
	}
	if(R[len] == len)
	{
		cout << cnt[len - 1] << endl;
		cout << array << endl;
		return 0;
	}
	int l = -1, r = -1;
	int nMax = 0;
	for(int x = R[len]; x != len; x = R[x])
	{
		int y = L[x];
		int tmp = cnt[x] - cnt[y];
		if(0 == x && cnt[x]) tmp -= 1;
		else if(cnt[x] > cnt[x - 1]) tmp -= 1;

		if(nMax < tmp)
		{
			nMax = tmp;
			l = y + 1, r = x - 1;
			if(l > r) l = 0;
		}
	}
	int tmp = cnt[len - 1] - cnt[L[len]];
	if(cnt[len - 1] > cnt[len - 2]) tmp --;
	if(nMax < tmp)
	{
		nMax = tmp;
		l = L[len] + 1;
		r = len - 1;
	}

	cout << nMax << endl;
	if(l >= r)
	{
		return 0;
	}
	for(int i = l; i <= r; i++) cout << array[i];
	cout << endl;
	return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cmath>

using namespace std;

const int MAXN = 110000;
int L[MAXN], R[MAXN];
char array[MAXN];
int cnt[MAXN];

void DEL(int x)
{
	L[R[x]] = L[x];
	R[L[x]] = R[x];
}

int main()
{
	//freopen("input.txt", "r", stdin);

	cin >> array;

	int len = strlen(array);

	int c = 0;
	for(int i = 0; i < len; i++)
	{
		if('[' == array[i]) c++;
		cnt[i] = c;
	}

	for(int i = 0; i <= len; i++) L[i] = i - 1;
	for(int i = 0; i <= len; i++) R[i] = i + 1;
	L[0] = len;
	R[len] = 0;

	while(true)
	{
		bool bingo = false;
		for(int x = R[len]; x != len; x = R[x])
		{
			if(array[x] == '(')
			{
				int y = R[x];
				if(y == len) break;
				if(array[y] == ')')
				{
					DEL(y);
					DEL(x);
					bingo = true;
				}
			}
			else if(array[x] == '[')
			{
				int y = R[x];
				if(y == len) break;
				if(array[y] == ']')
				{
					DEL(y);
					DEL(x);
					bingo = true;
				}
			}
		}
		if(!bingo) break;
	}
	if(R[len] == len)
	{
		cout << cnt[len - 1] << endl;
		cout << array << endl;
		return 0;
	}
	int l = -1, r = -1;
	int nMax = 0;
	for(int x = R[len]; x != len; x = R[x])
	{
		int y = L[x];
		int tmp = cnt[x] - cnt[y];
		if(0 == x && cnt[x]) tmp -= 1;
		else if(cnt[x] > cnt[x - 1]) tmp -= 1;

		if(nMax < tmp)
		{
			nMax = tmp;
			l = y + 1, r = x - 1;
			if(l > r) l = 0;
		}
	}
	int tmp = cnt[len - 1] - cnt[L[len]];
	if(cnt[len - 1] > cnt[len - 2]) tmp --;
	if(nMax < tmp)
	{
		nMax = tmp;
		l = L[len] + 1;
		r = len - 1;
	}

	cout << nMax << endl;
	if(l >= r)
	{
		return 0;
	}
	for(int i = l; i <= r; i++) cout << array[i];
	cout << endl;

	return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cmath>

using namespace std;

const int MAXN = 110000;
int L[MAXN], R[MAXN];
char array[MAXN];
int cnt[MAXN];

void DEL(int x)
{
	L[R[x]] = L[x];
	R[L[x]] = R[x];
}

int main()
{
	//freopen("input.txt", "r", stdin);

	cin >> array;

	int len = strlen(array);

	int c = 0;
	for(int i = 0; i < len; i++)
	{
		if('[' == array[i]) c++;
		cnt[i] = c;
	}

	for(int i = 0; i <= len; i++) L[i] = i - 1;
	for(int i = 0; i <= len; i++) R[i] = i + 1;
	L[0] = len;
	R[len] = 0;

	while(true)
	{
		bool bingo = false;
		for(int x = R[len]; x != len; x = R[x])
		{
			if(array[x] == '(')
			{
				int y = R[x];
				if(y == len) break;
				if(array[y] == ')')
				{
					DEL(y);
					DEL(x);
					bingo = true;
				}
			}
			else if(array[x] == '[')
			{
				int y = R[x];
				if(y == len) break;
				if(array[y] == ']')
				{
					DEL(y);
					DEL(x);
					bingo = true;
				}
			}
		}
		if(!bingo) break;
	}
	if(R[len] == len)
	{
		cout << cnt[len - 1] << endl;
		cout << array << endl;
		return 0;
	}
	int l = -1, r = -1;
	int nMax = 0;
	for(int x = R[len]; x != len; x = R[x])
	{
		int y = L[x];
		int tmp = cnt[x] - cnt[y];
		if(0 == x && cnt[x]) tmp -= 1;
		else if(cnt[x] > cnt[x - 1]) tmp -= 1;

		if(nMax < tmp)
		{
			nMax = tmp;
			l = y + 1, r = x - 1;
			if(l > r) l = 0;
		}
	}

	cout << nMax << endl;
	for(int i = l; i <= r; i++) cout << array[i];
	cout << endl;

	return 0;
}


#pragma warning (disable:4996)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char str[100000],str2[100000];

void makeGood(int a, int b)
{
    if (str[a] == '[')
        str[a] = '1';
    else
        str[a] = '0';
    str[b] = '0';
    int pre = a;
    while (pre > 0 && str[pre] !='[' && str[pre] != '(' && str[pre] != ')' && str[pre] !=']')
    {
        --pre;
    }

    if ((str[pre] == '(' && str[b + 1] == ')') || (str[pre] == '[' && str[b + 1] == ']'))
    {
        makeGood(pre, b+ 1);
    }

}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%s", str);
    int i,l = strlen(str);
    strcpy(str2, str);
    for (i = 0; i < l; ++i)
    {

        if ((str[i] == '(' && str[i + 1] == ')') || (str[i] == '[' && str[i + 1] == ']'))
        {
            makeGood(i, i + 1);
            ++i;
        }
    }

    int curr = 0, max = 0;
    int s1 = 0, s2=0, t = 0;
    for (i = 0; i < l; ++i)
    {
        if (str[i] == '0' || str[i] == '1')
        {
            if (str[i] == '1')
                curr++;

        }
        else
        {
            if (max < curr)
            {
                max = curr;
                s1 = t;
                s2 = i -1;
            }
            while (str[i+1] != '0' && str[i+1] != '1' && i < l)
                ++i;
            curr = 0;
            t = i+1;
        }
    }
    if (max < curr)
    {
        max = curr;
        s1 = t;
        s2 = i -1;
    }

    t = i;
    if (s1 == s2)
    {
        printf("0");
        exit(0);
    }
    printf("%d\n", max);
    for (i = s1; i <= s2; ++i )
    {
        printf("%c", str2[i]);
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

string s;
vector<pair<char, int>> stack;
int n;
int cnt[100001];
int nxt[100001];
int ans, start, len;

int main()
{
    cin >> s;
    n = s.length();
    for (int i = 0; i < n; ++i)
    {
        switch (s[i])
        {
        case '(':
        case '[': stack.push_back(make_pair(s[i], i)); break;
        case ')':
            if (stack.empty())
                break;
            if (stack.back().first != '(')
            {
                stack.clear();
                break;
            }
            nxt[stack.back().second] = i;
            stack.pop_back();
            break;
        case ']':
            if (stack.empty())
                break;
            if (stack.back().first != '[')
            {
                stack.clear();
                break;
            }
            nxt[stack.back().second] = i;
            stack.pop_back();
        }
        cnt[i] = (i ? cnt[i - 1] : 0) + (s[i] == '[');
    }
    int it = 0;
    for (int i = 0; i < n; ++i)
    {
        if (!nxt[i])
            continue;
        if (i > it)
            it = i;
        while (nxt[nxt[it] + 1])
            it = nxt[it] + 1;
        int tmp = cnt[nxt[it]] - (i ? cnt[i - 1] : 0);
        if (tmp > ans)
            ans = tmp, start = i, len = nxt[it] - i + 1;
    }
    cout << ans << endl;
    cout << s.substr(start, len) << endl;
    return 0;
}


#include <iostream>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
using namespace std;
#define eps 1e-9
#define VI vectir<int>
#define MP make_pair
#define f0(i,n) for (i = 0; i < n; i++)
#define f1(i,n) for (i = 1; i <= n; i++)
#define fab(i , a , b) for (i = a; i <= b; i++)
#define PII pair<int,int>
#define inf 1000000005
#define ll long long
#define VI vector<int>

int x , y , n , m, i , j , k , l;
string s;
vector<pair<char , int> > st;
int sum[1000000];
int good;
vector<PII> v;

int count(int i , int j)
{
    return sum[j] - sum[i] + (s[i] == '[');
}

int main()
{
    cin>>s;
    n = s.size();
    sum[0] = (s[0] == '[');
    for (i = 1; i < n; i++)
        sum[i] = sum[i-1] + (s[i] == '[');

    int ans = 0;
    int l = 0 , r = 0;

    for (i = 0; i < n; i++)
    {
        int num = st.size() - 1;
        if (s[i] == '(')
            st.push_back(MP(s[i] , i));
        else
        if (s[i] == '[')
            st.push_back(MP(s[i] , i));
        else
            if (s[i] == ')' && num >= 0 && st[num].first == '(' || s[i] == ']' && num >= 0 && st[num].first == '[')
            {
                l = st[num].second;
                r = i;
                int sz = v.size() - 1;
                while (v.size() > 0 && v[sz].first > l)
                {
                    v.pop_back();
                    sz--;
                }

                v.push_back(MP(l  , r));
                st.pop_back();
            } else
            {
                st.clear();
            }
    }

    if (v.size() == 0)
    {
        cout<<0<<endl<<endl;
        return 0;
    }
    sort(v.begin() , v.end());

    i = 0;
    int start = v[0].first;
    while (i < v.size())
    {
        j = i + 1;
        while (j < v.size() && v[j].first == v[j-1].second + 1)
            j++;

        if (count(v[i].first , v[j-1].second) > ans)
        {
            ans = count(v[i].first , v[j-1].second);
            l = v[i].first;
            r = v[j-1].second;
        }

        i = j;
    }

    cout<<ans<<endl<<s.substr(l , r - l + 1)<<endl;

    return 0;
}


#include <iostream>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define eps 1e-9
#define VI vectir<int>
#define MP make_pair
#define f0(i,n) for (i = 0; i < n; i++)
#define f1(i,n) for (i = 1; i <= n; i++)
#define fab(i , a , b) for (i = a; i <= b; i++)
#define PII pair<int,int>
#define inf 1000000005
#define ll long long
#define VI vector<int>

int x , y , n , m, i , j , k , l;
string s;
int good[200][200] , cnt[200][200];
int main()
{
    cin>>s;
    n = s.size();
    for (i = 0; i < n - 1; i++)
    {
        if (s[i] == '(' && s[i+1] == ')' || s[i] == '[' && s[i+1] == ']' )
        {
            good[i][i+1] = 1;
            if (s[i] == '[')
                cnt[i][i+1] = 1;
        }
    }

    for (l = 4; l <= n; l += 2)
    {
        for (i = 0; i <= n - l; i++)
        {
            if ((s[i] == '(' && s[i+l - 1] == ')' || s[i] == '[' && s[i+l - 1] == ']') && good[i + 1][i + l - 2])
            {
                good[i][i + l - 1] = 1;
                if (s[i] == '[')
                    cnt[i][i+l - 1] = cnt[i+1][i + l - 2] + 1;
                else
                    cnt[i][i+l - 1] = cnt[i+1][i + l - 2];
            }

            for (j = i + 1; j < i + l - 1; j++)
            {
                if (good[i][j] && good[j+1][i + l - 1])
                {
                    good[i][i + l - 1] = 1;
                    cnt[i][i + l - 1] = max(cnt[i][i + l - 1] , cnt[i][j] + cnt[j + 1][i + l - 1]);
                }
            }

        }
    }
    /*
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
            for (k = j + 1; k < n; k++)
            {
                if (good[i][j] && good[j+1][k])
                {
                    good[i][k] = 1;
                    cnt[i][k] = cnt[i][j] + cnt[j+1][k];
                }
            }
    }
    */

    string ans = "";
    int c = 0;
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            if (good[i][j] && cnt[i][j] > c)
            {
                c = cnt[i][j];
                ans = s.substr(i , j - i + 1);
            }

        }
    }

    cout<<c<<endl<<ans<<endl;

    return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

#define fill(a, x) memset(a, x, sizeof(a))

int ls, d[111111], ans, str, fin, tp, st[111111][2], x, curr, kk;
char s[111111];

inline int cnt(int l, int r) {
    if (r <= l) return 0;
    return d[r] - d[l] + (s[l] == '[');
}

int main() {
    gets(s);
    ls = strlen(s);
    fill(d, 0);
    d[0] = (s[0] == '[');
    for (int i = 1; i < ls; ++i)
        d[i] = d[i - 1] + (s[i] == '[');
    ans = str = fin = 0;
    x = 0;
    while (x < ls) {
        if (s[x] == '[' || s[x] == '(') {
            st[tp = 0][1] = x - 1;
            while (x < ls) {
                if (s[x] == '(' || s[x] == '[') st[++tp][1] = x;
                if (s[x] == '(') st[tp][0] = 1; else
                if (s[x] == '[') st[tp][0] = 0; else
                if (s[x] == ')') {
                    if (!tp || !st[tp][0]) {
                        kk = cnt(st[tp][1] + 1, x - 1);
                        if (ans < kk) {
                            ans = kk;
                            str = st[tp][1] + 1;
                            fin = x - 1;
                        }
                        break;
                    }
                    kk = cnt(st[tp][1], x);
                    if (ans < kk) {
                        ans = kk;
                        str = st[tp][1];
                        fin = x;
                    }
                    kk = cnt(st[--tp][1] + 1, x);
                    if (ans < kk) {
                        ans = kk;
                        str = st[tp][1] + 1;
                        fin = x;
                    }
                } else {
                    if (!tp || st[tp][0]) {
                        kk = cnt(st[tp][1] + 1, x - 1);
                        if (ans < kk) {
                            ans = kk;
                            str = st[tp][1] + 1;
                            fin = x - 1;
                        }
                        break;
                    }
                    kk = cnt(st[tp][1], x);
                    if (ans < kk) {
                        ans = kk;
                        str = st[tp][1];
                        fin = x;
                    }
                    kk = cnt(st[--tp][1] + 1, x);
                    if (ans < kk) {
                        ans = kk;
                        str = st[tp][1] + 1;
                        fin = x;
                    }
                }
                ++x;
            }
        }
        ++x;
    }
    printf("%d\n", ans);
    if (!ans) return 0;
    for (int i = str; i <= fin; ++i)
        putchar(s[i]);
    return 0;
}


s, st, se, q = input(), [], [], []

for i in range(len(s)):
    t = s[i]
    if not st and (t ==')' or t == ']'):
        continue
    if t == '(' or t == '[':
        st.append(t)
        se.append(t)
    elif t == ')' or t == ']':
        p = st.pop()
        if p == '(' and t == ')':
            se.append(t)
            if i == len(s)-1:
                lo = "".join(se)
                q.append(lo)
        elif p == '[' and t == ']':
            se.append(t)
            if i == len(s)-1:
                lo = "".join(se)
                q.append(lo)
        elif (p == '(' and t == ']' )or (p == '[' and t == ')'):
            se.pop(0)
            if se:
                se.pop()
            st = []
            lo = "".join(se)
            q.append(lo)
            se = []
if q:
    length =[]
    for i in q:
        length.append(i.count('['))
    print(max(length))
    print(q[length.index(max(length))])
else:
    print(0)


s, st, se, q = input(), [], [], []

for i in range(len(s)):
    t = s[i]
    if not st and (t ==')' or t == ']'):
        continue
    if t == '(' or t == '[':
        st.append(t)
        se.append(t)
    elif t == ')' or t == ']':
        p = st.pop()
        if p == '(' and t == ')':
            se.append(t)
            if i == len(s)-1:
                lo = "".join(se)
                q.append(lo)
        elif p == '[' and t == ']':
            se.append(t)
            if i == len(s)-1:
                lo = "".join(se)
                q.append(lo)
        elif p == '(' and t == ']' or p == '[' and t == ']':
            se.pop(0)
            st = []
            lo = "".join(se)
            q.append(lo)
            q = []
if q:
    length =[]
    for i in q:
        length.append(i.count('['))
    print(max(length))
    print(q[length.index(max(length))])
else:
    print(0)


s, st, se, q = input(), [], [], []

for i in range(len(s)):
    t = s[i]
    if not st and (t ==')' or t == ']'):
        continue
    if t == '(' or t == '[':
        st.append(t)
        se.append(t)
    elif t == ')' or t == ']':
        p = st.pop()
        if p == '(' and t == ')':
            se.append(t)
            if i == len(s)-1:
                lo = "".join(se)
                q.append(lo)
        elif p == '[' and t == ']':
            se.append(t)
            if i == len(s)-1:
                lo = "".join(se)
                q.append(lo)
        elif (p == '(' and t == ']' )or (p == '[' and t == ')'):
            se.pop(0)
            se.pop()
            st = []
            lo = "".join(se)
            q.append(lo)
            se = []
if q:
    length =[]
    for i in q:
        length.append(i.count('['))
    print(max(length))
    print(q[length.index(max(length))])
else:
    print(0)


s, st, v, vi, vj, vc = input(), [], [], 0, 0, 0
for i, ch in enumerate(s):
    if ch in '[(':
        st.append(i)
    else:
        if st and s[st[-1]] + ch in ('()', '[]'):
            b = (st[-1], i + 1)
            if v and v[-1][1] == i:
                v[-1] = b
            else:
                v.append(b)
            if len(v) >= 2 and v[-2][1] == v[-1][0]:
                v[-2:] = [(v[-2][0], v[-1][1])]
            st.pop()
        else:
            st = []
for b in v:
    c = s.count('[', b[0], b[1])
    if c > vc:
        vi, vj, vc = b[0], b[1], c
print(vc)
print(s[vi:vj])

# Made By Mostafa_Khaled


S=input().strip()

sub=[]

for i in range(len(S)):
    if len(sub)!=0 and (((S[sub[-1]]=='[' and S[i]==']') or (S[sub[-1]]=='(' and S[i]==')'))):
        sub.pop()
    else:
        sub.append(i)

print(sub)

'tamamı doğru olan S'
if not len(sub):
    print(S.count('['))
    print(S)


S=input().strip()

subIndex=[]

for i in range(len(S)):
    if len(subIndex)!=0 and (((S[subIndex[-1]]=='[' and S[i]==']') or (S[subIndex[-1]]=='(' and S[i]==')'))):
        subIndex.pop()
    else:
        subIndex.append(i)

'tamamı doğru olan S'
if not len(subIndex):
    print(S.count('['))
    print(S)

else:

    'print(subIndex)'

    'index out of range'
    subIndex.append(subIndex[-1])

    subString=S[:subIndex[0]]
    subStringSquaredBracketCount=subString.count('[')
    for i in range(len(subIndex)-1):
        tempCount=S[subIndex[i]+1:subIndex[i+1]].count('[')
        if tempCount>subStringSquaredBracketCount:
            subStringSquaredBracketCount=tempCount
            subString=S[subIndex[i]+1:subIndex[i+1]]

    print(subStringSquaredBracketCount)
    print(subString)


S=input().strip()

subIndex=[]

for i in range(len(S)):
    if len(subIndex)!=0 and (((S[subIndex[-1]]=='[' and S[i]==']') or (S[subIndex[-1]]=='(' and S[i]==')'))):
        subIndex.pop()
    else:
        subIndex.append(i)

'tamamı dogru olan S'
if not len(subIndex):
    print(S.count('['))
    print(S)

else:

    'index out of range'
    subIndex.append(len(S))

    'print(subIndex)'

    subString=S[:subIndex[0]]
    subStringSquaredBracketCount=subString.count('[')
    for i in range(len(subIndex)-1):
        tempCount=S[subIndex[i]+1:subIndex[i+1]].count('[')
        if tempCount>subStringSquaredBracketCount:
            subStringSquaredBracketCount=tempCount
            subString=S[subIndex[i]+1:subIndex[i+1]]

    print(subStringSquaredBracketCount)
    print(subString)

"""

([])
1
([])

(((

(][)
0

(()[))()[]
1
()[]

"""


S=input().strip()

subIndex=[]

for i in range(len(S)):
    if len(subIndex)!=0 and (((S[subIndex[-1]]=='[' and S[i]==']') or (S[subIndex[-1]]=='(' and S[i]==')'))):
        subIndex.pop()
    else:
        subIndex.append(i)

'tamamı doğru olan S'
if not len(subIndex):
    print(S.count('['))
    print(S)
else:

    'index out of range'
    subIndex.append(subIndex[-1])

    subString=S[:subIndex[0]]
    subStringSquaredBracketCount=subString.count('[')
    for i in range(len(subIndex)-1):
        temp=S[subIndex[i]+1:subIndex[i+1]].count('[')
        if temp>subStringSquaredBracketCount:
            subStringSquaredBracketCount=temp
            subString=S[subIndex[i]:subIndex[i+1]]

    print(subStringSquaredBracketCount)
    print(subString)


S=input().strip()

subIndex=[]

for i in range(len(S)):
    if len(subIndex)!=0 and (((S[subIndex[-1]]=='[' and S[i]==']') or (S[subIndex[-1]]=='(' and S[i]==')'))):
        subIndex.pop()
    else:
        subIndex.append(i)

print(subIndex)

'tamamı doğru olan S'
if not len(subIndex):
    print(S.count('['))
    print(S)
else:
    'index out of range'
    subIndex.append(subIndex[-1])

    subString=S[:subIndex[0]]
    subStringSquaredBracketCount=subString.count('[')
    for i in range(len(subIndex)-1):
        temp=S[subIndex[i]:subIndex[i+1]].count('[')
        if temp>subStringSquaredBracketCount:
            subStringSquaredBracketCount=temp
            subString=S[subIndex[i]:subIndex[i+1]]

    print(subStringSquaredBracketCount)
    print(subString)


S=input().strip()

subIndex=[]

for i in range(len(S)):
    if len(subIndex)!=0 and (((S[subIndex[-1]]=='[' and S[i]==']') or (S[subIndex[-1]]=='(' and S[i]==')'))):
        subIndex.pop()
    else:
        subIndex.append(i)

'tamamı doğru olan S'
if not len(subIndex):
    print(S.count('['))
    print(S)
else:
    'index out of range'
    subIndex.append(subIndex[-1])

    subString=S[:subIndex[0]]
    subStringSquaredBracketCount=subString.count('[')
    for i in range(len(subIndex)-1):
        temp=S[subIndex[i]:subIndex[i+1]].count('[')
        if temp>subStringSquaredBracketCount:
            subStringSquaredBracketCount=temp
            subString=S[subIndex[i]:subIndex[i+1]]

    print(subStringSquaredBracketCount)
    print(subString)


S=input().strip()

subIndex=[]

for i in range(len(S)):
    if len(subIndex)!=0 and (((S[subIndex[-1]]=='[' and S[i]==']') or (S[subIndex[-1]]=='(' and S[i]==')'))):
        subIndex.pop()
    else:
        subIndex.append(i)

'tamamı doğru olan S'
if not len(subIndex):
    print(S.count('['))
    print(S)
else:

    print(subIndex)

    'index out of range'
    subIndex.append(subIndex[-1])

    subString=S[:subIndex[0]]
    subStringSquaredBracketCount=subString.count('[')
    for i in range(len(subIndex)-1):
        temp=S[subIndex[i]+1:subIndex[i+1]].count('[')
        if temp>subStringSquaredBracketCount:
            subStringSquaredBracketCount=temp
            subString=S[subIndex[i]:subIndex[i+1]]

    print(subStringSquaredBracketCount)
    print(subString)


#include<cmath>
#include<cstdio>
#include<iostream>
#define inf 1000000000
using namespace std;
typedef long long ll;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,cl,ce,v,l[100050],e[100050];
int find(int l[],int c,int x1,int x2)
{
	int L=1,R=c,res=R;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(l[mid]>=x1)res=mid,R=mid-1;
		else L=mid+1;
	}
	if(fabs(x1-l[res])+fabs(x2-l[res])>fabs(x1-l[res-1])+fabs(x2-l[res-1]))
	  if(res!=1)res--;
	return l[res];
}
int calc1(int y1,int x1,int y2,int x2)
{
	int x=find(l,cl,x1,x2);
	return fabs(x1-x)+fabs(x2-x)+fabs(y1-y2);
}
int calc2(int y1,int x1,int y2,int x2)
{
	int x=find(e,ce,x1,x2);
	return fabs(x1-x)+fabs(x2-x)+(int(fabs(y1-y2))+v-1)/v;
}
int main()
{
	n=read(),m=read(),cl=read(),ce=read(),v=read();
	for(int i=1;i<=cl;i++)l[i]=read();
	for(int i=1;i<=ce;i++)e[i]=read();
	int q=read();
	while(q--)
	{
		int x1=read(),y1=read(),x2=read(),y2=read();
		if(x1==x2){printf("%d\n",fabs(y1-y2));continue;}
		int ans=inf;
		if(cl)ans=min(ans,calc1(x1,y1,x2,y2));
		if(ce)ans=min(ans,calc2(x1,y1,x2,y2));
		printf("%d\n",ans);
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<iostream>
#define inf 1000000000
using namespace std;
typedef long long ll;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,cl,ce,v,l[100050],e[100050];
int find(int l[],int c,int x1,int x2)
{
	int L=1,R=c,res=R;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(l[mid]>=x1)res=mid,R=mid-1;
		else L=mid+1;
	}
	if(fabs(x1-l[res])+fabs(x2-l[res])>fabs(x1-l[res-1])+fabs(x2-l[res-1]))
	  if(res!=1)res--;
	return l[res];
}
int calc1(int y1,int x1,int y2,int x2)
{
	int x=find(l,cl,x1,x2);
	return fabs(x1-x)+fabs(x2-x)+fabs(y1-y2);
}
int calc2(int y1,int x1,int y2,int x2)
{
	int x=find(e,ce,x1,x2);
	return fabs(x1-x)+fabs(x2-x)+(int(fabs(y1-y2))+v-1)/v;
}
int main()
{
	n=read(),m=read(),cl=read(),ce=read(),v=read();
	for(int i=1;i<=cl;i++)l[i]=read();
	for(int i=1;i<=ce;i++)e[i]=read();
	int q=read();
	while(q--)
	{
		int x1=read(),y1=read(),x2=read(),y2=read();
		if(x1==x2){printf("%d\n",(int)fabs(y1-y2));continue;}
		int ans=inf;
		if(cl)ans=min(ans,calc1(x1,y1,x2,y2));
		if(ce)ans=min(ans,calc2(x1,y1,x2,y2));
		printf("%d\n",ans);
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<iostream>
#define inf 100000000000000ll
using namespace std;
typedef long long ll;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll n,m,cl,ce,v,l[100050],e[100050];
ll find(ll l[],ll c,ll x1,ll x2)
{
	ll L=1,R=c,res=R;
	while(L<=R)
	{
		ll mid=(L+R)>>1;
		if(l[mid]>=x1)res=mid,R=mid-1;
		else L=mid+1;
	}
	if(fabs(x1-l[res])+fabs(x2-l[res])>fabs(x1-l[res-1])+fabs(x2-l[res-1]))
	  if(res!=1)res--;
	return l[res];
}
ll calc1(ll y1,ll x1,ll y2,ll x2)
{
	ll x=find(l,cl,x1,x2);
	return fabs(x1-x)+fabs(x2-x)+fabs(y1-y2);
}
ll calc2(ll y1,ll x1,ll y2,ll x2)
{
	ll x=find(e,ce,x1,x2);
	return fabs(x1-x)+fabs(x2-x)+(ll(fabs(y1-y2))+v-1)/v;
}
int main()
{
	n=read(),m=read(),cl=read(),ce=read(),v=read();
	for(int i=1;i<=cl;i++)l[i]=read();
	for(int i=1;i<=ce;i++)e[i]=read();
	int q=read();
	while(q--)
	{
		ll x1=read(),y1=read(),x2=read(),y2=read();
		if(x1==x2){printf("%I64d\n",fabs(y1-y2));continue;}
		ll ans=inf;
		if(cl)ans=min(ans,calc1(x1,y1,x2,y2));
		if(ce)ans=min(ans,calc2(x1,y1,x2,y2));
		printf("%I64d\n",ans);
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,cl,ce,v,l[100050],e[100050];
int find(int l[],int c,int x1,int x2)
{
	int L=1,R=c,res=R;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(l[mid]>=x1)res=mid,R=mid-1;
		else L=mid+1;
	}
	if(fabs(x1-l[res])+fabs(x2-l[res])>fabs(x1-l[res-1])+fabs(x2-l[res-1]))
	  if(res!=1)res--;
	return l[res];
}
int calc1(int y1,int x1,int y2,int x2)
{
	int x=find(l,cl,x1,x2);
	return fabs(x1-x)+fabs(x2-x)+fabs(y1-y2);
}
int calc2(int y1,int x1,int y2,int x2)
{
	int x=find(e,ce,x1,x2);
	return fabs(x1-x)+fabs(x2-x)+(int(fabs(y1-y2))+v-1)/v;
}
int main()
{
	n=read(),m=read(),cl=read(),ce=read(),v=read();
	for(int i=1;i<=cl;i++)l[i]=read();
	for(int i=1;i<=ce;i++)e[i]=read();
	int q=read();
	while(q--)
	{
		int x1=read(),y1=read(),x2=read(),y2=read();
		if(x1==x2){printf("%d\n",fabs(y1-y2));continue;}
		int ans=min(calc1(x1,y1,x2,y2),calc2(x1,y1,x2,y2));
		printf("%d\n",ans);
	}
	return 0;
}


//It is coded by Ning_Mew on 4.29
#include<bits/stdc++.h>
using namespace std;

const int maxn=1e5+7,INF=1e9+7;

int n,m,cl,ce,v,q,ans=0;
int tol[maxn][2];

int col(int x){if(x%v)return x/v+1;else return x/v;}
int find(int ll,int rr,int num,int ql,int qr,int st){
  int mid = (ll+rr)/2 , TT = 0 , ans;

  if(st==1)ans=-INF;else ans=INF;

  while(ll<=rr){
    //cout<<ll<<' '<<rr<<endl;
    if(ll==rr)TT++;if(TT==2)break;
    mid=(ll+rr)/2;
    if(st==1){
      if(tol[mid][num]>=ql&&tol[mid][num]<=qr)ll=mid+1,ans=max(ans,mid);
      else {
	if(tol[mid][num]<ql)ll=mid+1;
	else rr=mid-1;
      }
    }else{
      if(tol[mid][num]>=ql&&tol[mid][num]<=qr)rr=mid-1,ans=min(ans,mid);
      else {
	if(tol[mid][num]<ql)ll=mid+1;
	else rr=mid-1;
      }
    }
  }
  if(ans!=INF&&ans!=-INF)return tol[ans][num];return ans;
}
int main(){
  scanf("%d%d%d%d%d",&n,&m,&cl,&ce,&v);
  for(int i=1;i<=cl;i++){scanf("%d",&tol[i][0]);}
  for(int i=1;i<=ce;i++){scanf("%d",&tol[i][1]);}

  scanf("%d",&q);
  for(int i=1;i<=q;i++){
    int x,y,xx,yy;
    scanf("%d%d%d%d",&x,&y,&xx,&yy);
    if(x==xx){printf("%d\n",abs(y-yy));continue;}
    ans=INF;
    //l r num ql qr max/min
    int el=find(1,ce,1,1,y,1),er=find(1,ce,1,y,m,0);
    int fl=find(1,cl,0,1,y,1),fr=find(1,cl,0,y,m,0);

    //cout<<x<<' '<<el<<' '<<er<<' '<<fl<<' '<<fr<<endl;

    //if(el!=-INF&&el>=min(y,yy)&&el<=max(y,yy)){printf("%d\n",abs(yy-y)+col(xx-x));continue;}
    //if(er!=INF&&er>=min(y,yy)&&er<=max(y,yy)){printf("%d\n",abs(yy-y)+col(xx-x));continue;}

    if(el!=-INF){ans=min(ans,abs(y-el)+abs(yy-el)+col(abs(xx-x)));}
    if(er!=INF){ans=min(ans,abs(y-er)+abs(yy-er)+col(abs(xx-x)));}
    if(fl!=-INF){ans=min(ans,abs(y-fl)+abs(yy-fl)+abs(xx-x));}
    if(fr!=INF){ans=min(ans,abs(y-fr)+abs(yy-fr)+abs(xx-x));}
    printf("%d\n",ans);
  }
  return 0;
}


//It is coded by Ning_Mew on 4.29
#include<bits/stdc++.h>
using namespace std;

const int maxn=1e8+7,INF=1e9+7;

int n,m,cl,ce,v,q,ans=0;
int tol[maxn][2];

int col(int x){if(x%v)return x/v+1;else return x/v;}
int find(int l,int r,int num){
  int ll = l, rr = r , mid = (l+r)/2 , TT = 0 , goal , ans;

  if(l==1)goal=r+1,ans=INF;
  else goal=l-1,ans=INF;

  if(l==1&&tol[goal][num]==0)return INF;

  while(ll<=rr){
    if(ll==rr)TT++;if(TT==2)break;
    mid=(ll+rr)/2;
    if(l==1){
      if(tol[mid][num]==tol[goal][num])rr=mid-1,ans=min(ans,mid);
      else ll=mid+1;
    }else{
      if(tol[mid][num]>tol[goal][num])rr=mid-1,ans=min(ans,mid);
      else ll=mid+1;
    }
  }return ans;
}
int main(){
  scanf("%d%d%d%d%d",&n,&m,&cl,&ce,&v);
  for(int i=1;i<=cl;i++){int box;scanf("%d",&box);tol[box][0]=1;}
  for(int i=1;i<=ce;i++){int box;scanf("%d",&box);tol[box][1]=1;}
  //int l=0;
  for(int i=1;i<=m;i++){
    tol[i][0]+=tol[i-1][0],tol[i][1]+=tol[i-1][1];
    //if(tool[i])l=i;el[i]=l;
  }//l=n+1;
  //for(int i=n;i>=1;i--){if(tool[i])l=i;er[i]=i;}

  scanf("%d",&q);
  for(int i=1;i<=q;i++){
    int x,y,xx,yy;
    scanf("%d%d%d%d",&x,&y,&xx,&yy);
    ans=INF;
    if(tol[max(yy,y)][1]-tol[min(yy,y)-1][1]>0){printf("%d\n",abs(yy-y)+col(xx-x));continue;}
    if(tol[max(yy,y)][0]-tol[min(yy,y)-1][0]>0)ans=abs(xx-x)+abs(yy-y);
    int el=find(1,y-1,1),er=find(y+1,n,1),fl=find(1,y-1,0),fr=find(y+1,n,0);
    //cout<<x<<' '<<el<<' '<<er<<' '<<fl<<' '<<fr<<endl;
    if(el!=INF){ans=min(ans,abs(y-el)+abs(yy-el)+col(abs(xx-x)));}
    if(er!=INF){ans=min(ans,abs(y-er)+abs(yy-er)+col(abs(xx-x)));}
    if(fl!=INF){ans=min(ans,abs(y-fl)+abs(yy-fl)+abs(xx-x));}
    if(fr!=INF){ans=min(ans,abs(y-fr)+abs(yy-fr)+abs(xx-x));}
    printf("%d\n",ans);
  }
  return 0;
}


//It is coded by Ning_Mew on 4.29
#include<bits/stdc++.h>
using namespace std;

const int maxn=1e8+7,INF=1e9+7;

int n,m,cl,ce,v,q,ans=0;
int tol[maxn][3];

int col(int x){if(x%v)return x/v+1;else return x/v;}
int find(int l,int r,int num){
	int ll = l, rr = r , mid = (l+r)/2 , TT = 0 , goal , ans;

	if(l==1)goal=r+1,ans=INF;
	else goal=l-1,ans=INF;

	if(l==1&&tol[goal][num]==0)return INF;

	while(ll<=rr){
		if(ll==rr)TT++;if(TT==2)break;
		mid=(ll+rr)/2;
		if(l==1){
			if(tol[mid][num]==tol[goal][num])rr=mid-1,ans=min(ans,mid);
			else ll=mid+1;
		}else{
			if(tol[mid][num]>tol[goal][num])rr=mid-1,ans=min(ans,mid);
			else ll=mid+1;
		}
	}return ans;
}
int main(){
	scanf("%d%d%d%d%d",&n,&m,&cl,&ce,&v);
	for(int i=1;i<=cl;i++){int box;scanf("%d",&box);tol[box][1]=1;}
	for(int i=1;i<=ce;i++){int box;scanf("%d",&box);tol[box][2]=1;}
	//int l=0;
	for(int i=1;i<=m;i++){
		tol[i][1]+=tol[i-1][1],tol[i][2]+=tol[i-1][2];
		//if(tool[i])l=i;el[i]=l;
	}//l=n+1;
	//for(int i=n;i>=1;i--){if(tool[i])l=i;er[i]=i;}

	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int x,y,xx,yy;
		scanf("%d%d%d%d",&x,&y,&xx,&yy);
		ans=INF;
		if(tol[max(yy,y)][2]-tol[min(yy,y)-1][2]>0){printf("%d\n",abs(yy-y)+col(xx-x));continue;}
		if(tol[max(yy,y)][1]-tol[min(yy,y)-1][1]>0)ans=abs(xx-x)+abs(yy-y);
		int el=find(1,y-1,2),er=find(y+1,n,2),fl=find(1,y-1,1),fr=find(y+1,n,1);
		//cout<<x<<' '<<el<<' '<<er<<' '<<fl<<' '<<fr<<endl;
		if(el!=INF){ans=min(ans,abs(y-el)+abs(yy-el)+col(abs(xx-x)));}
		if(er!=INF){ans=min(ans,abs(y-er)+abs(yy-er)+col(abs(xx-x)));}
		if(fl!=INF){ans=min(ans,abs(y-fl)+abs(yy-fl)+abs(xx-x));}
		if(fr!=INF){ans=min(ans,abs(y-fr)+abs(yy-fr)+abs(xx-x));}
		printf("%d\n",ans);
	}
	return 0;
}


//It is coded by Ning_Mew on 4.29
#include<bits/stdc++.h>
using namespace std;

const int maxn=1e5+7,INF=1e9+7;

int n,m,cl,ce,v,q,ans=0;
int tol[maxn][2];

int col(int x){if(x%v)return x/v+1;else return x/v;}
int find(int ll,int rr,int num,int ql,int qr,int st){
  int mid = (ll+rr)/2 , TT = 0 , ans;

  if(st==1)ans=-INF;else ans=INF;

  while(ll<=rr){
    //cout<<ll<<' '<<rr<<endl;
    if(ll==rr)TT++;if(TT==2)break;
    mid=(ll+rr)/2;
    if(st==1){
      if(tol[mid][num]>=ql&&tol[mid][num]<=qr)ll=mid+1,ans=max(ans,mid);
      else {
	if(tol[mid][num]<ql)ll=mid+1;
	else rr=mid-1;
      }
    }else{
      if(tol[mid][num]>=ql&&tol[mid][num]<=qr)rr=mid-1,ans=min(ans,mid);
      else {
	if(tol[mid][num]<ql)ll=mid+1;
	else rr=mid-1;
      }
    }
  }
  if(ans!=INF&&ans!=-INF)return tol[ans][num];return ans;
}
int main(){
  scanf("%d%d%d%d%d",&n,&m,&cl,&ce,&v);
  for(int i=1;i<=cl;i++){scanf("%d",&tol[i][0]);}
  for(int i=1;i<=ce;i++){scanf("%d",&tol[i][1]);}

  scanf("%d",&q);
  for(int i=1;i<=q;i++){
    int x,y,xx,yy;
    scanf("%d%d%d%d",&x,&y,&xx,&yy);
    ans=INF;
    //l r num ql qr max/min
    int el=find(1,ce,1,1,y-1,1),er=find(1,ce,1,y+1,m,0);
    int fl=find(1,cl,0,1,y-1,1),fr=find(1,cl,0,y+1,m,0);

    //cout<<x<<' '<<el<<' '<<er<<' '<<fl<<' '<<fr<<endl;

    //if(el!=-INF&&el>=min(y,yy)&&el<=max(y,yy)){printf("%d\n",abs(yy-y)+col(xx-x));continue;}
    //if(er!=INF&&er>=min(y,yy)&&er<=max(y,yy)){printf("%d\n",abs(yy-y)+col(xx-x));continue;}

    if(el!=-INF){ans=min(ans,abs(y-el)+abs(yy-el)+col(abs(xx-x)));}
    if(er!=INF){ans=min(ans,abs(y-er)+abs(yy-er)+col(abs(xx-x)));}
    if(fl!=-INF){ans=min(ans,abs(y-fl)+abs(yy-fl)+abs(xx-x));}
    if(fr!=INF){ans=min(ans,abs(y-fr)+abs(yy-fr)+abs(xx-x));}
    printf("%d\n",ans);
  }
  return 0;
}


//It is coded by Ning_Mew on 4.29
#include<bits/stdc++.h>
using namespace std;

const int maxn=1e8+7,INF=1e9+7;

int n,m,cl,ce,v,q,ans=0;
int tol[maxn][2];

int col(int x){if(x%v)return x/v+1;else return x/v;}
int find(int l,int r,int num){
  int ll = l, rr = r , mid = (l+r)/2 , TT = 0 , goal , ans;

  if(l==1)goal=r+1,ans=INF;
  else goal=l-1,ans=INF;

  if(l==1&&tol[goal][num]==0)return INF;

  while(ll<=rr){
    if(ll==rr)TT++;if(TT==2)break;
    mid=(ll+rr)/2;
    if(l==1){
      if(tol[mid][num]==tol[goal][num])rr=mid-1,ans=min(ans,mid);
      else ll=mid+1;
    }else{
      if(tol[mid][num]>tol[goal][num])rr=mid-1,ans=min(ans,mid);
      else ll=mid+1;
    }
  }return ans;
}
int main(){
  scanf("%d%d%d%d%d",&n,&m,&cl,&ce,&v);
  for(int i=1;i<=cl;i++){int box;scanf("%d",&box);tol[box][0]=1;}
  for(int i=1;i<=ce;i++){int box;scanf("%d",&box);tol[box][1]=1;}
  for(int i=1;i<=m;i++){
    tol[i][0]+=tol[i-1][0];tol[i][1]+=tol[i-1][1];
  }
  //for(int i=1;i<=m;i++)cout<<tol[i][1]<<' ';cout<<endl;
  scanf("%d",&q);
  for(int i=1;i<=q;i++){
    int x,y,xx,yy;
    scanf("%d%d%d%d",&x,&y,&xx,&yy);
    ans=INF;
    if(tol[max(yy,y)][1]-tol[min(yy,y)-1][1]>0){printf("%d\n",abs(yy-y)+col(xx-x));continue;}
    if(tol[max(yy,y)][0]-tol[min(yy,y)-1][0]>0)ans=abs(xx-x)+abs(yy-y);
    int el=find(1,y-1,1),er=find(y+1,n,1),fl=find(1,y-1,0),fr=find(y+1,n,0);
    //cout<<x<<' '<<el<<' '<<er<<' '<<fl<<' '<<fr<<endl;
    if(el!=INF){ans=min(ans,abs(y-el)+abs(yy-el)+col(abs(xx-x)));}
    if(er!=INF){ans=min(ans,abs(y-er)+abs(yy-er)+col(abs(xx-x)));}
    if(fl!=INF){ans=min(ans,abs(y-fl)+abs(yy-fl)+abs(xx-x));}
    if(fr!=INF){ans=min(ans,abs(y-fr)+abs(yy-fr)+abs(xx-x));}
    printf("%d\n",ans);
  }
  return 0;
}


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

#ifdef LOCAL
	#define de(x) cout<<#x<<"="<<x<<endl
	#define rff freopen("input.txt","r",stdin)
#else
	#define de(x)
	#define rff
#endif

//#define abs(x) ((x)>0?x:-x)
#define PQ priority_queue
#define setp setprecision
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define el cout<<endl
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF=(int)INFINITY;

int n,m,S,E,s[100003],e[100003],q;
double v;
int t,tmp,p;
int x_1,x_2,y_1,y_2;

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m>>S>>E>>v;
	for (int i=0;i<S;i++){
		cin>>s[i];
	}
	sort(s,s+S);
	for (int i=0;i<E;i++){
		cin>>e[i];
	}
	sort(e,e+E);
	cin>>q;
	while (q--){
		cin>>x_1>>y_1>>x_2>>y_2;
		p=upper_bound(s,s+S,y_1)-s;
		t=INF;
		if (x_1==x_2){
			t=abs(y_1-y_2);
		}
		tmp=0;
		if (p){
			tmp+=abs(y_1-s[p-1]);
			tmp+=abs(x_1-x_2);
			tmp+=abs(s[p-1]-y_2);
		}
		if (tmp) t=min(t,tmp);
		tmp=0;
		if (p<S){
			tmp+=abs(y_1-s[p]);
			tmp+=abs(x_1-x_2);
			tmp+=abs(s[p]-y_2);
		}
		if (tmp) t=min(t,tmp);

		p=upper_bound(e,e+E,y_1)-e;
		tmp=0;
		if (p){
			tmp+=abs(y_1-e[p-1]);
			tmp+=ceil(double(abs(x_1-x_2))/v);
			tmp+=abs(e[p-1]-y_2);
		}
		if (tmp) t=min(t,tmp);
		tmp=0;
		if (p<E){
			tmp+=abs(y_1-e[p]);
			tmp+=ceil(double(abs(x_1-x_2))/v);
			tmp+=abs(e[p]-y_2);
		}
		if (tmp) t=min(t,tmp);
		cout<<t<<endl;
	}
	re 0;
}


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

#ifdef LOCAL
	#define de(x) cout<<#x<<"="<<x<<endl
	#define rff freopen("input.txt","r",stdin)
#else
	#define de(x)
	#define rff
#endif

//#define abs(x) ((x)>0?x:-x)
#define PQ priority_queue
#define setp setprecision
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define el cout<<endl
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF=(int)INFINITY;

int n,m,S,E,s[10003],e[10003],q;
double v;
int t,tmp,p;
int x_1,x_2,y_1,y_2;

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m>>S>>E>>v;
	for (int i=0;i<S;i++){
		cin>>s[i];
	}
	for (int i=0;i<E;i++){
		cin>>e[i];
	}
	cin>>q;
	while (q--){
		cin>>x_1>>y_1>>x_2>>y_2;
		p=upper_bound(s,s+S,y_1)-s;
		t=INF;

		tmp=0;
		if (p){
			tmp+=abs(y_1-s[p-1]);
			tmp+=abs(x_1-x_2);
			tmp+=abs(s[p-1]-y_2);
		}
		if (tmp) t=min(t,tmp);
		tmp=0;
		if (p<S){
			tmp+=abs(y_1-s[p]);
			tmp+=abs(x_1-x_2);
			tmp+=abs(s[p]-y_2);
		}
		if (tmp) t=min(t,tmp);

		p=upper_bound(e,e+E,y_1)-e;
		tmp=0;
		if (p){
			tmp+=abs(y_1-e[p-1]);
			tmp+=ceil(double(abs(x_1-x_2))/v);
			tmp+=abs(e[p-1]-y_2);
		}
		if (tmp) t=min(t,tmp);
		tmp=0;
		if (p<E){
			tmp+=abs(y_1-e[p]);
			tmp+=ceil(double(abs(x_1-x_2))/v);
			tmp+=abs(e[p]-y_2);
		}
		if (tmp) t=min(t,tmp);
		cout<<t<<endl;
	}
}


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

#ifdef LOCAL
	#define de(x) cout<<#x<<"="<<x<<endl
	#define rff freopen("input.txt","r",stdin)
#else
	#define de(x)
	#define rff
#endif

//#define abs(x) ((x)>0?x:-x)
#define PQ priority_queue
#define setp setprecision
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define el cout<<endl
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF=(int)INFINITY;

int n,m,S,E,s[10003],e[10003],q;
double v;
int t,tmp,p;
int x1,x2,y1,y2;

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m>>S>>E>>v;
	for (int i=0;i<S;i++){
		cin>>s[i];
	}
	for (int i=0;i<E;i++){
		cin>>e[i];
	}
	cin>>q;
	while (q--){
		cin>>x1>>y1>>x2>>y2;
		p=upper_bound(s,s+S,y1)-s;
		t=INF;

		tmp=0;
		if (p){
			tmp+=abs(y1-s[p-1]);
			tmp+=abs(x1-x2);
			tmp+=abs(s[p-1]-y2);
		}
		if (tmp) t=min(t,tmp);
		tmp=0;
		if (p<S){
			tmp+=abs(y1-s[p]);
			tmp+=abs(x1-x2);
			tmp+=abs(s[p]-y2);
		}
		if (tmp) t=min(t,tmp);

		p=upper_bound(e,e+E,y1)-e;
		tmp=0;
		if (p){
			tmp+=abs(y1-e[p-1]);
			tmp+=ceil(double(abs(x1-x2))/v);
			tmp+=abs(e[p-1]-y2);
		}
		if (tmp) t=min(t,tmp);
		tmp=0;
		if (p<E){
			tmp+=abs(y1-e[p]);
			tmp+=ceil(double(abs(x1-x2))/v);
			tmp+=abs(e[p]-y2);
		}
		if (tmp) t=min(t,tmp);
		cout<<t<<endl;
	}
}


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

#ifdef LOCAL
	#define de(x) cout<<#x<<"="<<x<<endl
	#define rff freopen("input.txt","r",stdin)
#else
	#define de(x)
	#define rff
#endif

//#define abs(x) ((x)>0?x:-x)
#define PQ priority_queue
#define setp setprecision
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define el cout<<endl
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF=(int)INFINITY;

int n,m,S,E,s[100003],e[100003],q;
double v;
int t,tmp,p;
int x_1,x_2,y_1,y_2;

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m>>S>>E>>v;
	for (int i=0;i<S;i++){
		cin>>s[i];
	}
	sort(s,s+S);
	for (int i=0;i<E;i++){
		cin>>e[i];
	}
	sort(e,e+E);
	cin>>q;
	while (q--){
		cin>>x_1>>y_1>>x_2>>y_2;
		p=upper_bound(s,s+S,y_1)-s;
		t=INF;

		tmp=0;
		if (p){
			tmp+=abs(y_1-s[p-1]);
			tmp+=abs(x_1-x_2);
			tmp+=abs(s[p-1]-y_2);
		}
		if (tmp) t=min(t,tmp);
		tmp=0;
		if (p<S){
			tmp+=abs(y_1-s[p]);
			tmp+=abs(x_1-x_2);
			tmp+=abs(s[p]-y_2);
		}
		if (tmp) t=min(t,tmp);

		p=upper_bound(e,e+E,y_1)-e;
		tmp=0;
		if (p){
			tmp+=abs(y_1-e[p-1]);
			tmp+=ceil(double(abs(x_1-x_2))/v);
			tmp+=abs(e[p-1]-y_2);
		}
		if (tmp) t=min(t,tmp);
		tmp=0;
		if (p<E){
			tmp+=abs(y_1-e[p]);
			tmp+=ceil(double(abs(x_1-x_2))/v);
			tmp+=abs(e[p]-y_2);
		}
		if (tmp) t=min(t,tmp);
		cout<<t<<endl;
	}
	re 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<memory>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <set>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
int qq[maxn];
int q1[maxn];
int q2[maxn];
int c1,c2,c3;
int louz(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q1[min1];
}

int louy(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q1[max1];
}

int dianz(int x){
    int left1,right1,mid1;
    left1=0;right1=c2+2;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q2[min1];
}

int diany(int x){
    int left1,right1,mid1;
    left1=0;right1=c2+2;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q2[max1];
}
int main()
{
    //e����Note���ᵽ�ĺϷ�����ʽ
    //freopen("in.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    int i,j;
    int T,k,t2,t3,t4,f1,f2,f3,f4;
    int r,c;
    int n,m,K;
    int v;
    cin >> n>> m >> c1>> c2>> v;
    for(i=1;i<=c1;i++)
    cin >> q1[i]; //¥��
    q1[0]=-1e9;
    q1[c1+1]=2e9;
    q1[c1+2]=2e9;
    for(i=1;i<=c2;i++)
    cin >> q2[i];
    q2[0]=-1e9;
    q2[c2+1]=2e9;
    q2[c2+2]=2e9;
    int left1,left2,right1,right2,mid1,mid2;
    int Q;
    cin >> Q;
    int x,y,x1,y1;
    int res;
    for(i=1;i<=Q;i++){
    cin >> x >> y >>x1 >>y1;
    //cout << x << "  "<<y <<"   " <<x1 <<"   " <<y1<< endl;
    swap(x,y);
    swap(x1,y1);
    if(y==y1){
    cout << abs(x1-x)<< endl;continue;
    }
    res=1e9;
    int min1,max1;
    int cha=abs(y1-y); //�ߵ����ߵ�
   // cout <<" ~ " << y1 <<"      "<<y << endl;
    int l1,r1; //louz,louy.dianz,diany
    l1=louz(x);
    r1=louy(x);
    if(l1!=-1e9)res=min(res,abs(x-l1)+abs(x1-l1)+abs(y1-y));
    if(r1!=2e9)res=min(res,abs(x-r1)+abs(x1-r1)+abs(y1-y));
    //cout <<l1 <<"  ¥�� " <<r1<< endl;
    //cout <<"emmmm  " <<abs(x-r1) <<"  "<<abs(x1-r1) <<"  "<<abs(y1-y) << endl;
    //cout << "before" << res<< "  and " <<l1 <<"   "<<r1<<endl;
    int time1=0;
    l1=dianz(x);
    r1=diany(x);
    if(cha%v==0){
        time1=cha/v;
    }else{
        time1=cha/v+1;
    }
   // cout <<"~~ " <<l1 <<"    " <<r1 << endl;
    //cout <<"~ " << time1<<"   " <<res<< endl;
    if(l1!=-1e9)res=min(res,time1+abs(x-l1)+abs(x1-l1));
    if(r1!=2e9)res=min(res,time1+abs(x-r1)+abs(x1-r1));
  //  cout <<x<<"  to "<<l1 <<"  ���� " <<r1<< endl;
   //cout << time1 <<"   " << abs(x-r1) <<  "    " <<  abs(x1-r1) <<"  "<<x1<< endl;
    if(res<0)
    while(1);
    if(res>1e9)
    while(1);
    cout << res << endl;
    }
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<memory>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <set>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
int qq[maxn];
int q1[maxn];
int q2[maxn];
int c1,c2,c3;
int louz(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q1[min1];
}

int louy(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q1[max1];
}

int dianz(int x){
    int left1,right1,mid1;
    left1=0;right1=c2+2;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q2[min1];
}

int diany(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q2[max1];
}
int main()
{
    //e����Note���ᵽ�ĺϷ�����ʽ
    //freopen("in.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    int i,j;
    int T,k,t2,t3,t4,f1,f2,f3,f4;
    int r,c;
    int n,m,K;
    int v;
    cin >> n>> m >> c1>> c2>> v;
    for(i=1;i<=c1;i++)
    cin >> q1[i]; //¥��
    q1[0]=-1e9;
    q1[c1+1]=2e9;
    q1[c1+2]=2e9;
    for(i=1;i<=c2;i++)
    cin >> q2[i];
    q2[0]=-1e9;
    q2[c2+1]=2e9;
    q2[c2+2]=2e9;
    int left1,left2,right1,right2,mid1,mid2;
    int Q;
    cin >> Q;
    sort(q1,q1+c1+3);
    sort(q2,q2+c2+3);
    int x,y,x1,y1;
    int res;
    for(i=1;i<=Q;i++){
    cin >> x >> y >>x1 >>y1;
    //cout << x << "  "<<y <<"   " <<x1 <<"   " <<y1<< endl;
    swap(x,y);
    swap(x1,y1);
    if(y==y1){
    cout << abs(x1-x)<< endl;continue;
    }
    res=1e9;
    int min1,max1;
    int cha=abs(y1-y); //�ߵ����ߵ�
   // cout <<" ~ " << y1 <<"      "<<y << endl;
    int l1,r1; //louz,louy.dianz,diany
    l1=louz(x);
    r1=louy(x);
    if(l1!=-1e9)res=min(res,abs(x-l1)+abs(x1-l1)+abs(y1-y));
    if(r1!=2e9)res=min(res,abs(x-r1)+abs(x1-r1)+abs(y1-y));
    //cout <<l1 <<"  ¥�� " <<r1<< endl;
    //cout <<"emmmm  " <<abs(x-r1) <<"  "<<abs(x1-r1) <<"  "<<abs(y1-y) << endl;
    //cout << "before" << res<< "  and " <<l1 <<"   "<<r1<<endl;
    int time1=0;
    l1=dianz(x);
    r1=diany(x);
    if(cha%v==0){
        time1=cha/v;
    }else{
        time1=cha/v+1;
    }
   // cout <<"~~ " <<l1 <<"    " <<r1 << endl;
    //cout <<"~ " << time1<<"   " <<res<< endl;
    if(l1!=-1e9)res=min(res,time1+abs(x-l1)+abs(x1-l1));
    if(r1!=2e9)res=min(res,time1+abs(x-r1)+abs(x1-r1));
  //  cout <<x<<"  to "<<l1 <<"  ���� " <<r1<< endl;
   //cout << time1 <<"   " << abs(x-r1) <<  "    " <<  abs(x1-r1) <<"  "<<x1<< endl;
    //if(res<0)
    //while(1);
    //if(res>1e9)
    //while(1);
    cout << res << endl;
    }
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<memory>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <set>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
const int L=1e8+5;
int qq[maxn];
int q1[maxn];
int q2[maxn];
int c1,c2,c3;
int louz(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q1[min1];
}

int louy(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q1[max1];
}

int dianz(int x){
    int left1,right1,mid1;
    left1=0;right1=c2+2;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q2[min1];
}

int diany(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q2[max1];
}
int main()
{
    //e����Note���ᵽ�ĺϷ�����ʽ
    //freopen("in.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    int i,j;
    int T,k,t2,t3,t4,f1,f2,f3,f4;
    int r,c;
    int n,m,K;
    int v;
    cin >> n>> m >> c1>> c2>> v;
    for(i=1;i<=c1;i++)
    cin >> q1[i]; //¥��
    q1[0]=0;
    q1[c1+1]=1e8+5;
    q1[c1+2]=1e8+5;
    for(i=1;i<=c2;i++)
    cin >> q2[i];
    q2[0]=0;
    q2[c2+1]=1e8+5;
    q2[c2+2]=1e8+5;
    int left1,left2,right1,right2,mid1,mid2;
    int Q;
    cin >> Q;
    sort(q1,q1+c1+2);
    sort(q2,q2+c2+2);
    int x,y,x1,y1;
    int res;
    for(i=1;i<=Q;i++){
    cin >> x >> y >>x1 >>y1;
    //cout << x << "  "<<y <<"   " <<x1 <<"   " <<y1<< endl;
    swap(x,y);
    swap(x1,y1);
    if(y==y1){
    cout << abs(x1-x)<< endl;continue;
    }
    res=1e9;
    int min1,max1;
    int cha=abs(y1-y); //�ߵ����ߵ�
   // cout <<" ~ " << y1 <<"      "<<y << endl;
    int l1,r1; //louz,louy.dianz,diany
    l1=louz(x);
    r1=louy(x);
    if(l1!=0)res=min(res,abs(x-l1)+abs(x1-l1)+abs(y1-y));
    if(r1!=L)res=min(res,abs(x-r1)+abs(x1-r1)+abs(y1-y));
    //cout <<l1 <<"  ¥�� " <<r1<< endl;
    //cout <<"emmmm  " <<abs(x-r1) <<"  "<<abs(x1-r1) <<"  "<<abs(y1-y) << endl;
    //cout << "before" << res<< "  and " <<l1 <<"   "<<r1<<endl;
    int time1=0;
    l1=dianz(x);
    r1=diany(x);
    if(cha%v==0){
        time1=cha/v;
    }else{
        time1=cha/v+1;
    }
   // cout <<"~~ " <<l1 <<"    " <<r1 << endl;
    //cout <<"~ " << time1<<"   " <<res<< endl;
    if(l1!=0)res=min(res,time1+abs(x-l1)+abs(x1-l1));
    if(r1!=L)res=min(res,time1+abs(x-r1)+abs(x1-r1));
  //  cout <<x<<"  to "<<l1 <<"  ���� " <<r1<< endl;
   //cout << time1 <<"   " << abs(x-r1) <<  "    " <<  abs(x1-r1) <<"  "<<x1<< endl;
    //if(res<0)
    //while(1);
    //if(res>1e9)
    //while(1);
    cout << max(res,0) << endl;
    }
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<memory>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <set>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
int qq[maxn];
int q1[maxn];
int q2[maxn];
int c1,c2,c3;
int louz(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+1;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q1[min1];
}

int louy(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+1;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q1[max1];
}

int dianz(int x){
    int left1,right1,mid1;
    left1=0;right1=c2+1;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q2[min1];
}

int diany(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+1;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q2[max1];
}

int up(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+1;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q2[max1];
}

int main()
{
    //e����Note���ᵽ�ĺϷ�����ʽ
    //freopen("in.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    int i,j;
    int T,k,t2,t3,t4,f1,f2,f3,f4;
    int r,c;
    int n,m,K;
    int v;
    cin >> n>> m >> c1>> c2>> v;
    for(i=1;i<=c1;i++)
    cin >> q1[i]; //¥��
    q1[0]=0;
    q1[c1+1]=1e9;
    for(i=1;i<=c2;i++)
    cin >> q2[i];
    q2[0]=0;
    q2[c2+1]=1e9;
    int left1,left2,right1,right2,mid1,mid2;
    int Q;
    cin >> Q;
    int x,y,x1,y1;
    int res;
    for(i=1;i<=Q;i++){
    cin >> x >> y >>x1 >>y1;
    swap(x,y);
    swap(x1,y1);
    if(y==y1){
    cout << abs(x1-x)<< endl;continue;
    }
    res=1e9+7;
    left1=0;right1=c1+1;
    int min1,max1;
    int cha=abs(y1-y); //�ߵ����ߵ�
    int l1,r1; //louz,louy.dianz,diany
    l1=louz(x);
    r1=louy(x);
    if(l1!=0)res=min(res,abs(x-l1)+abs(x1-l1)+abs(y1-y));
    if(r1!=1e9)res=min(res,abs(x-r1)+abs(x1-r1)+abs(y1-y));
    //cout <<"emmmm  " <<abs(x-r1) <<"  "<<abs(x1-r1) <<"  "<<abs(y1-y) << endl;
    //cout << "before" << res<< "  and " <<l1 <<"   "<<r1<<endl;
    int time1=0;
    int time2=0;
    l1=dianz(x);
    r1=diany(x);
    if(cha%v==0){
        time1=cha/v;
    }else{
        time1=cha/v+1;
    }
    //cout <<"~~ " <<l1 <<"    " <<r1 << endl;
    //cout <<"~ " << time1<< endl;
    if(l1!=0)res=min(res,time1+abs(x-l1)+abs(x1-l1));
    if(r1!=1e9)res=min(res,time1+abs(x-r1)+abs(x1-r1));
   //cout << time1 <<"   " << abs(x-r1) <<  "    " <<  abs(x1-r1) <<"  "<<x1<< endl;
    cout << res << endl;
    }
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<memory>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <set>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
int qq[maxn];
int q1[maxn];
int q2[maxn];
int c1,c2,c3;
int louz(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q1[min1];
}

int louy(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q1[max1];
}

int dianz(int x){
    int left1,right1,mid1;
    left1=0;right1=c2+2;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q2[min1];
}

int diany(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q2[max1];
}
int main()
{
    //e����Note���ᵽ�ĺϷ�����ʽ
    //freopen("in.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    int i,j;
    int T,k,t2,t3,t4,f1,f2,f3,f4;
    int r,c;
    int n,m,K;
    int v;
    cin >> n>> m >> c1>> c2>> v;
    for(i=1;i<=c1;i++)
    cin >> q1[i]; //¥��
    q1[0]=-1e9;
    q1[c1+1]=2e9;
    q1[c1+2]=2e9;
    for(i=1;i<=c2;i++)
    cin >> q2[i];
    q2[0]=-1e9;
    q2[c2+1]=2e9;
    q2[c2+2]=2e9;
    int left1,left2,right1,right2,mid1,mid2;
    int Q;
    cin >> Q;
    sort(q1,q1+c1+3);
    sort(q2,q2+c2+3);
    int x,y,x1,y1;
    int res;
    for(i=1;i<=Q;i++){
    cin >> x >> y >>x1 >>y1;
    //cout << x << "  "<<y <<"   " <<x1 <<"   " <<y1<< endl;
    swap(x,y);
    swap(x1,y1);
    if(y==y1){
    cout << abs(x1-x)<< endl;continue;
    }
    res=1e9;
    int min1,max1;
    int cha=abs(y1-y); //�ߵ����ߵ�
   // cout <<" ~ " << y1 <<"      "<<y << endl;
    int l1,r1; //louz,louy.dianz,diany
    l1=louz(x);
    r1=louy(x);
    if(l1!=-1e9)res=min(res,abs(x-l1)+abs(x1-l1)+abs(y1-y));
    if(r1!=2e9)res=min(res,abs(x-r1)+abs(x1-r1)+abs(y1-y));
    //cout <<l1 <<"  ¥�� " <<r1<< endl;
    //cout <<"emmmm  " <<abs(x-r1) <<"  "<<abs(x1-r1) <<"  "<<abs(y1-y) << endl;
    //cout << "before" << res<< "  and " <<l1 <<"   "<<r1<<endl;
    int time1=0;
    l1=dianz(x);
    r1=diany(x);
    if(cha%v==0){
        time1=cha/v;
    }else{
        time1=cha/v+1;
    }
   // cout <<"~~ " <<l1 <<"    " <<r1 << endl;
    //cout <<"~ " << time1<<"   " <<res<< endl;
    if(l1!=-1e9)res=min(res,time1+abs(x-l1)+abs(x1-l1));
    if(r1!=2e9)res=min(res,time1+abs(x-r1)+abs(x1-r1));
  //  cout <<x<<"  to "<<l1 <<"  ���� " <<r1<< endl;
   //cout << time1 <<"   " << abs(x-r1) <<  "    " <<  abs(x1-r1) <<"  "<<x1<< endl;
    //if(res<0)
    //while(1);
    //if(res>1e9)
    //while(1);
    cout << max(res,0) << endl;
    }
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<memory>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <set>
using namespace std;
const int maxn=1e7+7;
typedef long long ll;
const int L=1e8+5;
int qq[maxn];
int q1[maxn];
int q2[maxn];
int c1,c2,c3;
int louz(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q1[min1];
}

int louy(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+2;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q1[max1];
}

int dianz(int x){
    int left1,right1,mid1;
    left1=0;right1=c2+2;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q2[min1];
}

int diany(int x){
    int left1,right1,mid1;
    left1=0;right1=c2+2;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q2[max1];
}
int main()
{
    //e����Note���ᵽ�ĺϷ�����ʽ
    //freopen("in.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    int i,j;
    int T,k,t2,t3,t4,f1,f2,f3,f4;
    int r,c;
    int n,m,K;
    int v;
    cin >> n>> m >> c1>> c2>> v;
    for(i=1;i<=c1;i++)
    cin >> q1[i]; //¥��
    q1[0]=0;
    for(i=c1+1;i<=c1+1e5;i++)
    q1[i]=1e8+5;
    q1[c1+2]=1e8+5;
    for(i=1;i<=c2;i++)
    cin >> q2[i];
    q2[0]=0;
    for(i=c2+1;i<=c2+1e5;i++)
    q2[i]=1e8+5;
    q2[c2+2]=1e8+5;
    int left1,left2,right1,right2,mid1,mid2;
    int Q;
    cin >> Q;
    sort(q1,q1+c1+100000);
    sort(q2,q2+c2+100000);
    int x,y,x1,y1;
    int res;
    for(i=1;i<=Q;i++){
    cin >> x >> y >>x1 >>y1;
    //cout << x << "  "<<y <<"   " <<x1 <<"   " <<y1<< endl;
    swap(x,y);
    swap(x1,y1);
    if(y==y1){
    cout << abs(x1-x)<< endl;continue;
    }
    res=1e9;
    int min1,max1;
    int cha=abs(y1-y); //�ߵ����ߵ�
   // cout <<" ~ " << y1 <<"      "<<y << endl;
    int l1,r1; //louz,louy.dianz,diany
    l1=louz(x);
    r1=louy(x);
    if(l1!=0)res=min(res,abs(x-l1)+abs(x1-l1)+abs(y1-y));
    if(r1!=L)res=min(res,abs(x-r1)+abs(x1-r1)+abs(y1-y));
    //cout <<l1 <<"  ¥�� " <<r1<< endl;
    //cout <<"emmmm  " <<abs(x-r1) <<"  "<<abs(x1-r1) <<"  "<<abs(y1-y) << endl;
    //cout << "before" << res<< "  and " <<l1 <<"   "<<r1<<endl;
    int time1=0;
    l1=dianz(x);
    r1=diany(x);
    if(cha%v==0){
        time1=cha/v;
    }else{
        time1=cha/v+1;
    }
   // cout <<"~~ " <<l1 <<"    " <<r1 << endl;
    //cout <<"~ " << time1<<"   " <<res<< endl;
    if(l1!=0)res=min(res,time1+abs(x-l1)+abs(x1-l1));
    if(r1!=L)res=min(res,time1+abs(x-r1)+abs(x1-r1));
  //  cout <<x<<"  to "<<l1 <<"  ���� " <<r1<< endl;
   //cout << time1 <<"   " << abs(x-r1) <<  "    " <<  abs(x1-r1) <<"  "<<x1<< endl;
    if(res<0)
    while(1);
    if(res>1e9)
    while(1);
    cout << res << endl;
    }
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<memory>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <set>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
int qq[maxn];
int q1[maxn];
int q2[maxn];
int c1,c2,c3;
int louz(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+1;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q1[min1];
}

int louy(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+1;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q1[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q1[max1];
}

int dianz(int x){
    int left1,right1,mid1;
    left1=0;right1=c2+1;
    int min1=1e9;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]<=x){
        min1=min(min1,mid1);
        left1=mid1+1;
        }else{
        right1=mid1-1;
        }
    }
    return q2[min1];
}

int diany(int x){
    int left1,right1,mid1;
    left1=0;right1=c2+1;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q2[max1];
}

int up(int x){
    int left1,right1,mid1;
    left1=0;right1=c1+1;
    int max1=0;
    while(right1>=left1){
        mid1=(left1+right1)/2;
        if(q2[mid1]>=x){
        max1=max(max1,mid1);
        right1=mid1-1;
        }else{
        left1=mid1+1;
        }
    }
    return q2[max1];
}

int main()
{
    //e����Note���ᵽ�ĺϷ�����ʽ
    //freopen("in.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    int i,j;
    int T,k,t2,t3,t4,f1,f2,f3,f4;
    int r,c;
    int n,m,K;
    int v;
    cin >> n>> m >> c1>> c2>> v;
    for(i=1;i<=c1;i++)
    cin >> q1[i]; //¥��
    q1[0]=0;
    q1[c1+1]=1e9;
    for(i=1;i<=c2;i++)
    cin >> q2[i];
    q2[0]=0;
    q2[c2+1]=1e9;
    int left1,left2,right1,right2,mid1,mid2;
    int Q;
    cin >> Q;
    int x,y,x1,y1;
    int res;
    for(i=1;i<=Q;i++){
    cin >> x >> y >>x1 >>y1;
    swap(x,y);
    swap(x1,y1);
    if(y==y1){
    cout << abs(x1-x)<< endl;continue;
    }
    res=1e9+7;
    left1=0;right1=c1+1;
    int min1,max1;
    int cha=abs(y1-y); //�ߵ����ߵ�
    int l1,r1; //louz,louy.dianz,diany
    l1=louz(x);
    r1=louy(x);
    if(l1!=0)res=min(res,abs(x-l1)+abs(x1-l1)+abs(y1-y));
    if(r1!=1e9)res=min(res,abs(x-r1)+abs(x1-r1)+abs(y1-y));
    //cout <<"emmmm  " <<abs(x-r1) <<"  "<<abs(x1-r1) <<"  "<<abs(y1-y) << endl;
    //cout << "before" << res<< "  and " <<l1 <<"   "<<r1<<endl;
    int time1=0;
    int time2=0;
    l1=dianz(x);
    r1=diany(x);
    if(cha%v==0){
        time1=cha/v;
    }else{
        time1=cha/v+1;
    }
    //cout <<"~~ " <<l1 <<"    " <<r1 << endl;
    //cout <<"~ " << time1<< endl;
    if(l1!=0)res=min(res,time1+abs(x-l1)+abs(x1-l1));
    if(r1!=1e9)res=min(res,time1+abs(x-r1)+abs(x1-r1));
   //cout << time1 <<"   " << abs(x-r1) <<  "    " <<  abs(x1-r1) <<"  "<<x1<< endl;
    cout << res << endl;
    }
    return 0;
}