#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n = 0;
    cin >> n;
    unordered_map<int, int> planks;
    int length = 0;
    for (int i = 0; i < n; i++) {
        cin >> length;
        planks[length]++;
    }
    int q = 0;
    cin >> q;
    char option;
    int x = 0;
    bool square = false, rect = false;
    for (int i = 0; i < q; i++) {
        cin >> option;
        cin >> x;
        if (option == '+')
            planks[x]++;
        else
            planks[x]--;
        int chosen = -1;
        for (auto &plank : planks) {
            if (plank.second >= 4) {
                square = true; chosen = plank.first;
                planks[chosen] -= 4;
                break;
            }
        }
        if (square) {
            int a = -1, b = -1;
            for (const auto &plank : planks) {
                if (plank.second >= 4) {
                    rect = true;
                    break;
                }
                if (plank.second >= 2 && a == -1)
                    a = plank.first;
                if (plank.second >= 2 && a != -1 && a != plank.first && b == -1) {
                    b = plank.first;
                    rect = true;
                    break;
                }
            }
            planks[chosen] += 4;
        }
        cout << (square && rect ? "YES" : "NO") << '\n';
        square = false; rect = false;
    }
}

void solve2() {
    int n = 0;
    cin >> n;
    vector<int> planks(n);
    for (int i = 0; i < n; i++) {
        cin >> planks[i];
    }
    sort(planks.rbegin(), planks.rend());
    map<int, int> ocurrences;
    for (auto plank : planks) {
        ocurrences[plank]++;
    }
    int q = 0;
    cin >> q;
    char option;
    int x = 0;
    bool square = false, rect = false;
    for (int i = 0; i < q; i++) {
        cin >> option;
        cin >> x;
        if (option == '+')
            ocurrences[x]++;
        else
            ocurrences[x]--;
        int chosen = -1;
        int a = -1;
        for (auto &o : ocurrences) {
            if (o.second >= 4 && !square) {
                square = true; chosen = o.first;
                ocurrences[chosen] -= 4;
            }
            if (o.second >= 4 && chosen != -1) {
                rect = true;
                break;
            }
            if (o.second >= 2 && a == -1) {
                a = o.first;
                ocurrences[o.first] -= 2;
            }
            if (o.second >= 2 && a != -1) {
                rect = true;
            }
        }
        if (chosen != -1)
            ocurrences[chosen] += 4;
        if (a != -1)
            ocurrences[a] += 2;
        cout << (square && rect ? "YES" : "NO") << '\n';
        square = false; rect = false;
    }
}

bool compare(pair<int, int> &a, pair<int, int> &b) {
    return a.second >= b.second;
}

bool compare2(pair<int, int> &a, pair<int, int> &b) {
    return a.first < b.first;
}

int contains(vector<pair<int,int>> &planks, int plank) {
    sort(planks.begin(), planks.end(), compare2);
    int l = 0;
    int r = planks.size() - 1;
    while (l <= r) {
        int k = (l + r) / 2;
        if (planks[k].first == plank)
            return k;
        if (planks[k].first > plank)
            r = k - 1;
        else
            l = k + 1;
    }
    return -1;
}

void solve3() {
    int n = 0;
    cin >> n;
    vector<pair<int, int>> planks;
    int plank;
    int pos = -1;
    for (int i = 0; i < n; i++) {
        cin >> plank;
        pos = contains(planks, plank);
        if (pos != -1)
            planks[pos].second++;
        else
            planks.push_back({plank, 1});
    }
    int q = 0;
    cin >> q;
    char option;
    int x;
    for (int i = 0; i < q; i++) {
        cin >> option;
        cin >> x;
        int index = contains(planks, x);
        int change = 0;
        if (option == '+')
            change = 1;
        else
            change = -1;
        if (index != -1) {
            planks[index].second += change;
        } else {
            planks.push_back({x, 1});
        }
        sort(planks.begin(), planks.end(), compare);
        bool s = false;
        bool first = false, sec = false;
        if (planks[0].second >= 4) {
            int ocurrences = -1;
            if (planks[0].second - 4 >= 4) {
                cout << "YES\n";
                continue;
            }
            if (planks[0].second - 4 >= 2)
                first = true;
            for (int k = 1; k < planks.size(); k++) {
                if (planks[k].first == 0 || planks[k].second < 2)
                    break;
                ocurrences = planks[k].second;
                if (ocurrences >= 4) {
                    s = true;
                    cout << "YES\n";
                    break;
                } else if (ocurrences >= 2){
                    if (first) {
                        sec = true;
                        cout << "YES\n";
                        break;
                    } else {
                        first = true;
                    }
                }
            }
        } else {
            /*for (auto &x : planks) {
                if (x.first != 0)
                    cout << x.first << " " << x.second << '\n';
            }*/
            cout << "NO\n";
            //sort(planks.begin(), planks.end(), compare);
            continue;
        }
        /*for (auto &x : planks) {
            if (x.first != 0)
                cout << x.first << " " << x.second << '\n';
        }*/
        if (!s && !sec)
            cout << "NO\n";
    }
}

pair<int, int> search_two(vector<pair<int, int>> &planks, int avoid) {
    pair<int, int> res = {-1, -1};
    int l = 1;
    int r = planks.size() - 1;
    while (l <= r) {
        int k = (l + r) / 2;
        if (planks[k].second >= 4)
            return {4, k};
        else
            r = k - 1;
    }
    if (avoid == 0) {
        l = 1;
        r = planks.size() - 1;
    } else {
        l = 0;
        r = planks.size() - 1;
    }
    while (l <= r) {
        int k = (l + r) / 2;
        int aux = planks[k].second;
        if (k == 0)
            aux -= 4;
        if (aux >= 2 && k != avoid) {
            return {2, k};
        } else {
            r = k - 1;
        }
    }
    return res;
}

void solve4() {
    int n = 0;
    cin >> n;
    vector<pair<int, int>> planks;
    int plank;
    int pos = -1;
    for (int i = 0; i < n; i++) {
        cin >> plank;
        pos = contains(planks, plank);
        if (pos != -1)
            planks[pos].second++;
        else
            planks.push_back({plank, 1});
    }
    int q = 0;
    cin >> q;
    char option;
    int x;
    for (int i = 0; i < q; i++) {
        cin >> option;
        cin >> x;
        int index = contains(planks, x);
        int change = 0;
        if (option == '+')
            change = 1;
        else
            change = -1;
        if (index != -1) {
            planks[index].second += change;
        } else {
            planks.push_back({x, 1});
        }
        sort(planks.begin(), planks.end(), compare);
        int first = -1;
        if (planks[0].second >= 4) {
            int ocurrences = -1;
            if (planks[0].second - 4 >= 4) {
                cout << "YES\n";
                continue;
            }
            if (planks[0].second - 4 >= 2)
                first = 0;
            pair<int, int> res = search_two(planks, first);
            if (res.first == 4) {
                cout << "YES\n";
            } else if (res.first == 2) {
                if (first) {
                    cout << "YES\n";
                } else {
                    first = true;
                    res = search_two(planks, res.second);
                    if (res.first != -1) {
                        cout << "YES\n";
                    } else {
                        cout << "NO\n";
                    }
                }
            } else {
                cout << "NO\n";
            }
        } else {
            /*for (auto &x : planks) {
                if (x.first != 0)
                    cout << x.first << " " << x.second << '\n';
            }*/
            cout << "NO\n";
            //sort(planks.begin(), planks.end(), compare);
        }
        /*for (auto &x : planks) {
            if (x.first != 0)
                cout << x.first << " " << x.second << '\n';
        }*/
    }
}

int main() {
    solve4();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n = 0;
    cin >> n;
    unordered_map<int, int> planks;
    int length = 0;
    for (int i = 0; i < n; i++) {
        cin >> length;
        planks[length]++;
    }
    int q = 0;
    cin >> q;
    char option;
    int x = 0;
    bool square = false, rect = false;
    for (int i = 0; i < q; i++) {
        cin >> option;
        cin >> x;
        if (option == '+')
            planks[x]++;
        else
            planks[x]--;
        int chosen = -1;
        for (auto &plank : planks) {
            if (plank.second >= 4) {
                square = true; chosen = plank.first;
                planks[chosen] -= 4;
                break;
            }
        }
        if (square) {
            int a = -1, b = -1;
            for (const auto &plank : planks) {
                if (plank.second >= 4) {
                    rect = true;
                    break;
                }
                if (plank.second >= 2 && a == -1)
                    a = plank.first;
                if (plank.second >= 2 && a != -1 && a != plank.first && b == -1) {
                    b = plank.first;
                    rect = true;
                    break;
                }
            }
            planks[chosen] += 4;
        }
        cout << (square && rect ? "YES" : "NO") << '\n';
        square = false; rect = false;
    }
}

void solve2() {
    int n = 0;
    cin >> n;
    vector<int> planks(n);
    for (int i = 0; i < n; i++) {
        cin >> planks[i];
    }
    sort(planks.rbegin(), planks.rend());
    map<int, int> ocurrences;
    for (auto plank : planks) {
        ocurrences[plank]++;
    }
    int q = 0;
    cin >> q;
    char option;
    int x = 0;
    bool square = false, rect = false;
    for (int i = 0; i < q; i++) {
        cin >> option;
        cin >> x;
        if (option == '+')
            ocurrences[x]++;
        else
            ocurrences[x]--;
        int chosen = -1;
        int a = -1;
        for (auto &o : ocurrences) {
            if (o.second >= 4 && !square) {
                square = true; chosen = o.first;
                ocurrences[chosen] -= 4;
            }
            if (o.second >= 4 && chosen != -1) {
                rect = true;
                break;
            }
            if (o.second >= 2 && a == -1) {
                a = o.first;
                ocurrences[o.first] -= 2;
            }
            if (o.second >= 2 && a != -1) {
                rect = true;
            }
        }
        if (chosen != -1)
            ocurrences[chosen] += 4;
        if (a != -1)
            ocurrences[a] += 2;
        cout << (square && rect ? "YES" : "NO") << '\n';
        square = false; rect = false;
    }
}

bool compare(pair<int, int> &a, pair<int, int> &b) {
    return a.second >= b.second;
}

bool compare2(pair<int, int> &a, pair<int, int> &b) {
    return a.first < b.first;
}

int contains(vector<pair<int,int>> &planks, int plank) {
    sort(planks.begin(), planks.end(), compare2);
    int l = 0;
    int r = planks.size() - 1;
    while (l <= r) {
        int k = (l + r) / 2;
        if (planks[k].first == plank)
            return k;
        if (planks[k].first > plank)
            r = k - 1;
        else
            l = k + 1;
    }
    return -1;
}

void solve3() {
    int n = 0;
    cin >> n;
    vector<pair<int, int>> planks;
    int plank;
    int pos = -1;
    for (int i = 0; i < n; i++) {
        cin >> plank;
        pos = contains(planks, plank);
        if (pos != -1)
            planks[pos].second++;
        else
            planks.push_back({plank, 1});
    }
    int q = 0;
    cin >> q;
    char option;
    int x;
    for (int i = 0; i < q; i++) {
        cin >> option;
        cin >> x;
        int index = contains(planks, x);
        int change = 0;
        if (option == '+')
            change = 1;
        else
            change = -1;
        if (index != -1) {
            planks[index].second += change;
        } else {
            planks.push_back({x, 1});
        }
        sort(planks.begin(), planks.end(), compare);
        bool s = false;
        bool first = false, sec = false;
        if (planks[0].second >= 4) {
            int ocurrences = -1;
            if (planks[0].second - 4 >= 4) {
                cout << "YES\n";
                continue;
            }
            if (planks[0].second - 4 >= 2)
                first = true;
            for (int k = 1; k < planks.size(); k++) {
                if (planks[k].first == 0 || planks[k].second < 2)
                    break;
                ocurrences = planks[k].second;
                if (ocurrences >= 4) {
                    s = true;
                    cout << "YES\n";
                    break;
                } else if (ocurrences >= 2){
                    if (first) {
                        sec = true;
                        cout << "YES\n";
                        break;
                    } else {
                        first = true;
                    }
                }
            }
        } else {
            /*for (auto &x : planks) {
                if (x.first != 0)
                    cout << x.first << " " << x.second << '\n';
            }*/
            cout << "NO\n";
            //sort(planks.begin(), planks.end(), compare);
            continue;
        }
        /*for (auto &x : planks) {
            if (x.first != 0)
                cout << x.first << " " << x.second << '\n';
        }*/
        if (!s && !sec)
            cout << "NO\n";
    }
}

pair<int, pair<int, int>> search_two(vector<pair<int, int>> &planks) {
    pair<int, pair<int, int>> res = {-1, {-1, -1}};
    int l = 1;
    int r = planks.size() - 1;
    while (l <= r) {
        int k = (l + r) / 2;
        if (planks[k].second >= 4)
            return {4, {k, 0}};
        else
            r = k - 1;
    }
    l = 0;
    r = planks.size() - 1;
    while (l <= r) {
        int k = (l + r) / 2;
        int aux = planks[k].second;
        if (k == 0)
            aux -= 4;
        if (aux >= 2) {
            if (k != 0) {
                if (planks[k - 1].second >= 2)
                    return {2, {k - 1, k}};
                if (planks[k + 1].second >= 2)
                    return {2, {k, k + 1}};
                break;
            } else {
                if (planks[k + 1].second >= 2)
                    return {2, {k, k + 1}};
                break;
            }
        } else {
            r = k - 1;
        }
    }
    return res;
}

void solve4() {
    int n = 0;
    cin >> n;
    vector<pair<int, int>> planks;
    int plank;
    int pos = -1;
    for (int i = 0; i < n; i++) {
        cin >> plank;
        pos = contains(planks, plank);
        if (pos != -1)
            planks[pos].second++;
        else
            planks.push_back({plank, 1});
    }
    int q = 0;
    cin >> q;
    char option;
    int x;
    for (int i = 0; i < q; i++) {
        cin >> option;
        cin >> x;
        int index = contains(planks, x);
        int change = 0;
        if (option == '+')
            change = 1;
        else
            change = -1;
        if (index != -1) {
            planks[index].second += change;
        } else {
            planks.push_back({x, 1});
        }
        sort(planks.begin(), planks.end(), compare);
        bool first = false;
        if (planks[0].second >= 4) {
            if (planks[0].second - 4 >= 4) {
                cout << "YES\n";
                continue;
            }
            pair<int, pair<int, int>> res = search_two(planks);
            if (res.first == 4 || res.first == 2) {
                cout << "YES\n";
            } else {
                cout << "NO\n";
            }
        } else {
            /*for (auto &x : planks) {
                if (x.first != 0)
                    cout << x.first << " " << x.second << '\n';
            }*/
            cout << "NO\n";
            //sort(planks.begin(), planks.end(), compare);
            continue;
        }
        /*for (auto &x : planks) {
            if (x.first != 0)
                cout << x.first << " " << x.second << '\n';
        }*/
    }
}

int main() {
    solve4();
    return 0;
}


// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cmath>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int t;

    t=1;
    for(int i=0;i<t;i++){
        long long int  ans=0,n=0,m=0,a=0,b=0,k=0,count=0,tmp=0,tmp1=0,tmp2=0,tmp3=0,count_1=0,flag=0,flag_1=0,x=0,y,z,c,w,h;
		long long int count_2=0,count_4=0,count_6=0,count_3=0,count_5=0;
		m=1e5;
        cin>>n;
		long long int sum=0,arr[m]={0};
		for(int j=0;j<n;j++){
			cin>>x;
			arr[x]++;
		}
		//sort(arr,arr+n,greater<int>());
		int j=0;
		for(int j=0;j<m;j++){
			if(arr[j]>=2){
				count_2++;
			}
			if(arr[j]>=4){
				count_4++;
			}
			if(arr[j]>=6){
				count_6++;
			}
			//cout<<arr[j]<<"\n";

		}
		//cout<<count_2<<" "<<count_4<<" "<<count_6;
		cin>>m;
		string s2;
		for(int j=0;j<m;j++){
			cin>>s2;
			if(s2[0]=='+'){
				cin>>x;
				arr[x]++;
				if(arr[x]==2){
					count_2++;
				}
				if(arr[x]==4){
					count_4++;
				}
				if(arr[x]==6){
					count_6++;
				}

			}
			else{
				cin>>x;
				arr[x]--;
				if(arr[x]==1){
					count_2--;
				}
				if(arr[x]==3){
					count_4--;
				}
				if(arr[x]==5){
					count_6--;
				}
			}
			flag=0;
			//cout<<count_2<<" "<<count_4<<" "<<count_6<<"\n";
			if(count_6>1){
				flag=1;
			}
			else if(count_6==1){
				if(count_4>0||count_2>0){
					flag=1;
				}
			}
			else if(count_4>1){
				flag=1;
			}
			if(flag==1){
				cout<<"YES\n";
			}
			else{
				cout<<"NO\n";
			}
		}
		//cout<<count_2<<" "<<count_4<<" "<<count_6;

		//cout<<ans;

    }
}


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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string) s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #_VA_ARGS_ << "]:", debug_out(_VA_ARGS_)
#else
#define debug(...) 42
#endif

const int m = 1e5 + 5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long int t;

	t = 1;
	for (int i = 1; i <= t; i++) {
		long long int  ans = 0, n = 0, a = 0, b = 0, k = 0, count = 0, tmp = 0, tmp1 = 0, tmp2 = 0, tmp3 = 0, count_1 = 0, flag = 0, flag_1 = 0, x = 0, y, z, c, w, h;
		long long int count_2 = 0, count_4 = 0, count_6 = 0, count_8 = 0, count_5 = 0;
		cin >> n;

		long long int sum = 0, arr[m];
		memset(arr, 0, sizeof arr);
		for (int j = 1; j <= n; j++) {
			cin >> x;
			arr[x]++;
		}

		//cout<<arr[1]<<" "<<arr[2]<<"\n";
		for (int j = 1; j <= m; j++) {
			if (arr[j] >= 8) {
				count_8++;
			}
			else if (arr[j] >= 6) {
				count_6++;
			}
			else if (arr[j] >= 4) {
				count_4++;
			}
			else if (arr[j] >= 2) {
				count_2++;
			}
		}

		long long int m1;
		cin >> m1;
		string s2;
		for (int j = 1; j <= m1; j++) {
			cin >> s2;
			if (s2[0] == '+') {
				cin >> x;
				arr[x]++;
				if (arr[x] == 8) {
					count_8++;
					count_6--;
				}
				else if (arr[x] == 6) {
					count_6++;
					count_4--;
				}
				else if (arr[x] == 4) {
					count_4++;
					count_2--;
				}
				else if (arr[x] == 2) {
					count_2++;
				}

			}
			else {
				cin >> x;
				arr[x]--;
				//cout<<arr[x]<<"\n";
				if (arr[x] == 7) {
					count_8--;
					count_6++;
				}
				else if (arr[x] == 5) {
					count_6--;
					count_4++;
				}
				else if (arr[x] == 3) {
					count_4--;
					count_2++;
				}
				else if (arr[x] == 1) {
					count_2--;
				}
			}

			//debug_out(count_2, count_4, count_6, count_8);

			flag = 0;
			if (count_8 > 0) {
				flag = 1;
			}
			else if (count_6 > 0) {
				if (count_4 > 0 || count_2 > 0) {
					flag = 1;
				}
			}
			else if (count_4 > 1) {
				flag = 1;
			}
			else if (count_4 > 0 && count_2 > 1) {
				flag = 1;
			}

			if (flag == 1) {
				cout << "YES\n";
			}
			else {
				cout << "NO\n";
			}
		}
	}
}


// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cmath>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int t;

    t=1;
    for(int i=0;i<t;i++){
        long long int  ans=0,n=0,m=0,a=0,b=0,k=0,count=0,tmp=0,tmp1=0,tmp2=0,tmp3=0,count_1=0,flag=0,flag_1=0,x=0,y,z,c,w,h;
		long long int count_2=0,count_4=0,count_6=0,count_8=0,count_5=0;
		m=1e5+5;
        cin>>n;

		long long int sum=0,arr[m]={0};
		for(int j=0;j<n;j++){
			cin>>x;
			arr[x]++;
		}

		//cout<<arr[1]<<" "<<arr[2]<<"\n";
		for(int j=0;j<m;j++){
		    if(arr[j]>=8){
				count_8++;
			}
			else if(arr[j]>=6){
				count_6++;
			}
			else if(arr[j]>=4){
				count_4++;
			}
			else if(arr[j]>=2){
				count_2++;
			}
		}
		long long int m1;
		cin>>m1;
		string s2;
		for(int j=0;j<m1;j++){
			cin>>s2;
			if(s2[0]=='+'){
				cin>>x;
                arr[x]++;
                if(arr[x]==8){
					count_8++;
					count_6--;
				}
				else if(arr[x]==6){
					count_6++;
					count_4--;
				}
				else if(arr[x]==4){
					count_4++;
					count_2--;
				}
				else if(arr[x]==2){
					count_2++;
				}

			}
			else{
				cin>>x;
				arr[x]--;
				//cout<<arr[x]<<"\n";
				if(arr[x]==7){
					count_8--;
					count_6++;
				}
				else if(arr[x]==5){
					count_6--;
					count_4++;
				}
				else if(arr[x]==3){
					count_4--;
					count_2++;
				}
				else if(arr[x]==1){
					count_2--;
				}
			}
			flag=0;
			if(count_8>0||count_6>1){
				flag=1;
			}
			else if(count_6>0){
				if(count_4>0||count_2>0){
					flag=1;
				}
			}
			else if(count_4>1){
				flag=1;
			}
			else if(count_4>0&&count_2>1){
				flag=1;
			}
			if(flag==1){
				cout<<"YES\n";
			}
			else{
				cout<<"NO\n";
			}
		}
    }
}


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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string) s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #_VA_ARGS_ << "]:", debug_out(_VA_ARGS_)
#else
#define debug(...) 42
#endif

const int m = 1e5 + 5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long int t;

	t = 1;
	for (int i = 1; i <= t; i++) {
		long long int  ans = 0, n = 0, a = 0, b = 0, k = 0, count = 0, tmp = 0, tmp1 = 0, tmp2 = 0, tmp3 = 0, count_1 = 0, flag = 0, flag_1 = 0, x = 0, y, z, c, w, h;
		long long int count_2 = 0, count_4 = 0, count_6 = 0, count_8 = 0, count_5 = 0;
		cin >> n;

		long long int sum = 0, arr[m];
		memset(arr, 0, sizeof arr);
		for (int j = 1; j <= n; j++) {
			cin >> x;
			arr[x]++;
		}

		//cout<<arr[1]<<" "<<arr[2]<<"\n";
		for (int j = 1; j <= m; j++) {
			if (arr[j] >= 8) {
				count_8++;
			}
			else if (arr[j] >= 6) {
				count_6++;
			}
			else if (arr[j] >= 4) {
				count_4++;
			}
			else if (arr[j] >= 2) {
				count_2++;
			}
		}

		long long int m1;
		cin >> m1;
		string s2;
		for (int j = 1; j <= m1; j++) {
			cin >> s2;
			if (s2[0] == '+') {
				cin >> x;
				arr[x]++;
				if (arr[x] == 8) {
					count_8++;
					count_6--;
				}
				else if (arr[x] == 6) {
					count_6++;
					count_4--;
				}
				else if (arr[x] == 4) {
					count_4++;
					count_2--;
				}
				else if (arr[x] == 2) {
					count_2++;
				}

			}
			else {
				cin >> x;
				arr[x]--;
				//cout<<arr[x]<<"\n";
				if (arr[x] == 7) {
					count_8--;
					count_6++;
				}
				else if (arr[x] == 5) {
					count_6--;
					count_4++;
				}
				else if (arr[x] == 3) {
					count_4--;
					count_2++;
				}
				else if (arr[x] == 1) {
					count_2--;
				}
			}

			//debug_out(count_2, count_4, count_6, count_8);

			flag = 0;
			if (count_8 > 0||count_6>1) {
				flag = 1;
			}
			else if (count_6 > 0) {
				if (count_4 > 0 || count_2 > 0) {
					flag = 1;
				}
			}
			else if (count_4 > 1) {
				flag = 1;
			}
			else if (count_4 > 0 && count_2 > 1) {
				flag = 1;
			}

			if (flag == 1) {
				cout << "YES\n";
			}
			else {
				cout << "NO\n";
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cstdio>
using namespace std;

void speedUp(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

}
int main(){
	speedUp();

	long long n,m;
	cin>>n>>m;
	long long *A = new long long[n];
	long long *B = new long long[m];
	long long C[100];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<m;i++){
		long long b;
		cin>>b;
		for(int j=0;j<n;j++){
		    C[j] = max(C[i],A[j]*b);
		}
	}
	sort(C,C+n);
	cout<<C[n-2];

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cstdio>
using namespace std;

void speedUp(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

}
int main(){
	speedUp();

	int n,m;
	cin>>n>>m;
	long long *A = new long long[n];
	long long *B = new long long[m];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<m;i++){
		cin>>B[i];
	}
	sort(A,A+n);
	sort(B,B+m);
	long long ans = A[0]*B[0];
	for(int i=n-2;i>=;i--){
		for(int j=0;j<m;j++){
			ans = max(ans,A[i]*B[j]);
		}
	}
	cout<<ans;

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cstdio>
using namespace std;

void speedUp(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

}
int main(){
	speedUp();

	int n,m;
	cin>>n>>m;
	long long *A = new long long[n];
	long long *B = new long long[m];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<m;i++){
		cin>>B[i];
	}
	sort(A,A+n);
	sort(B,B+m);

// -5 -4 -3 0
// 1 2 3 4
//
	long long ans = A[0]*B[0];
	ans = max(ans,A[0]*B[m-1]);
	ans = max(ans,A[n-2]*B[m-1]);
	ans = max(ans,A[n-2]*B[0]);
	cout<<ans;
    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cstdio>
using namespace std;

void speedUp(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

}
int main(){
	speedUp();

	int n,m;
	cin>>n>>m;
	long long *A = new long long[n];
	long long *B = new long long[m];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<m;i++){
		cin>>B[i];
	}
	sort(A,A+n);
	sort(B,B+m);
	long long ans = A[0]*B[0];
	for(int i=0;i<n-1;i++){
		for(int j=0;j<m;j++){
			ans = max(ans,A[i]*B[j]);
		}
	}
	cout<<ans;

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cstdio>
using namespace std;

void speedUp(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

}
struct tt{
	long long n;
	int idx;
};
int cmp(tt a,tt b){
	return a.n<b.n;
}
int main(){
	speedUp();

	int n,m;
	cin>>n>>m;
	long long *A = new long long[n];
	long long *B = new long long[m];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<m;i++){
		cin>>B[i];
	}
	sort(A,A+n);
	sort(B,B+m);
	vector<tt> b;
	for(int i=0;i<n;i++)
	{
		tt t;
		t.n = A[i]*B[0];
		t.idx = i;
		for(int j=0;j<m;j++){
			t.n = max(t.n,A[i]*B[j]);
		}
		b.push_back(t);
	}

	sort(b.begin(),b.end(),cmp);

	for(int i=b.size()-1;i>=0;i--){
		if(b[i].idx==n-1)continue;

		cout<<b[i].n;
		break;

	}

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cstdio>
using namespace std;

void speedUp(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

}

int main(){
	speedUp();

	int n,m;
	cin>>n>>m;
	long long *A = new long long[n];
	long long *B = new long long[m];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<m;i++){
		cin>>B[i];
	}
	sort(A,A+n);
	sort(B,B+m);
	long long *C = new long long[n];
	for(int i=0;i<n;i++)
	{
		long long ttt= A[i]*B[0];
		for(int j=0;j<m;j++){
			ttt = max(ttt,A[i]*B[j]);
		}
		C[i] = ttt;
	}

	long long ans = C[n-2];
	for(int i=n-2;i>=0;i--){
		long long t = C[n-2];
		for(int j=0;j<i;j++){
			t= max(t,A[j]);
		}
		ans = max(t,ans);
	}
	cout<<ans;

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cstdio>
using namespace std;

void speedUp(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

}
int main(){
	speedUp();

	int n,m;
	cin>>n>>m;
	long long *A = new long long[n];
	long long *B = new long long[m];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<m;i++){
		cin>>B[i];
	}
	sort(A,A+n);
	sort(B,B+m);
	long long ans = A[0]*B[0];
	for(int i=n-2;i>=0;i--){
		for(int j=0;j<m;j++){
			ans = max(ans,A[i]*B[j]);
		}
	}
	cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a[64],c[64];
int main()
{
	cin>>n>>m;
	for(int i=0; i!=n; ++i)
		cin>>a[i],c[i]=-2e18;
	for(int j=0,b; j!=m; ++j)
	{
		cin>>b;
		for(int i=0; i!=n; ++i)
			c[i]=max(c[i],a[i]*b);
	}
	sort(c,c+n);
	cout<<c[n-2];
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cstdio>
using namespace std;

void speedUp(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

}
int main(){
	speedUp();

	long long n,m;
	cin>>n>>m;
	long long *A = new long long[n];
	long long *B = new long long[m];
	long long C[100]={-2e18};
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<m;i++){
		long long b;
		cin>>b;
		for(int j=0;j<n;j++){
		    C[j] = max(C[i],A[j]*b);
		}
	}
	sort(C,C+n);
	cout<<C[n-2];

    return 0;
}


//934A
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
vector < long > a,b;
vector < long long > c;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		long t;
		cin >> t;

		a.push_back(t);
	}

	for (int i=0;i<m;++i)
	{
		long t;
		cin >> t;

		b.push_back(t);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	if ((long long) *a.begin() * *b.begin() > (long long) *a.rbegin() * *b.rbegin())
		a.erase(a.begin());
	else
		a.erase(a.begin()+(n-1));

	for (vector < long >::iterator ia = a.begin(); ia != a.end(); ++ia)
	{
		for (vector < long >::iterator ib = b.begin(); ib != b.end(); ++ib)
		{
			c.push_back( (long long) *ia * *ib );
		}
	}

	sort(c.begin(), c.end());

	cout << *c.rbegin();

	getchar();getchar();
	return 0;
}


//934A
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
vector < long > a,b;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		long t;
		cin >> t;

		a.push_back(t);
	}

	for (int i=0;i<m;++i)
	{
		long t;
		cin >> t;

		b.push_back(t);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	cout << *(next(a.rbegin(),1)) * (*b.rbegin());

	getchar();getchar();
	return 0;
}


//934A
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
vector < long > a,b;
vector < long long > c;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		long t;
		cin >> t;

		a.push_back(t);
	}

	for (int i=0;i<m;++i)
	{
		long t;
		cin >> t;

		b.push_back(t);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	if (*a.begin() * *b.begin() > *a.rbegin() * *b.rbegin())
		a.erase(a.begin());
	else
		a.erase(a.begin()+(n-1));

	for (vector < long >::iterator ia = a.begin(); ia != a.end(); ++ia)
	{
		for (vector < long >::iterator ib = b.begin(); ib != b.end(); ++ib)
		{
			c.push_back( (long long) *ia * *ib );
		}
	}

	sort(c.begin(), c.end());

	cout << *c.rbegin();

	getchar();getchar();
	return 0;
}


//934A
#include <iostream>

using namespace std;

int n,m;
long a[50],b[50];
long long ans, inf = 1000000000000000001;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		cin >> a[i];
	}

	for (int i=0;i<m;++i)
	{
		cin >> b[i];
	}

	ans = inf;

	for (int i=0;i<n;++i)
	{
		long long now = -inf;

		for (int j=0;j<n;++j)if (j!=i)
			for (int k=0;k<m;++k)
			{
				if (now < (long long) a[j] * b[k])
					now = (long long) a[j] * b[k];
			}

		if (ans > now)
			ans = now;
	}

	cout << ans;

	getchar();getchar();
	return 0;
}


//934A
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
vector < long > a,b;
vector < long long > c;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		long t;
		cin >> t;

		a.push_back(t);
	}

	for (int i=0;i<m;++i)
	{
		long t;
		cin >> t;

		b.push_back(t);
	}

	//sort(a.begin(), a.end());
	//sort(b.begin(), b.end());

	for (vector < long >::iterator ia = a.begin(); ia != a.end(); ++ia)
	{
		for (vector < long >::iterator ib = b.begin(); ib != b.end(); ++ib)
		{
			c.push_back( (long long) *ia * *ib );

		}
	}

	sort(c.begin(), c.end());

	cout << *next(c.rbegin(), 1);

	getchar();getchar();
	return 0;
}


//934A
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
vector < long > a,b;
long long ans;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		long t;
		cin >> t;

		a.push_back(t);
	}

	for (int i=0;i<m;++i)
	{
		long t;
		cin >> t;

		b.push_back(t);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	for (vector < long >::iterator ia = a.begin(); ia+1 != a.end(); ++ia)
	{
		for (vector < long >::iterator ib = b.begin(); ib != b.end(); ++ib)
		{
			if (ans < (long long)*ia * *ib)
				ans = (long long)*ia * *ib;

		}
	}

	cout << ans;

	getchar();getchar();
	return 0;
}


//934A
#include <iostream>
#include <set>

using namespace std;

int n,m;
set < long > a,b;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		long t;
		cin >> t;

		a.insert(t);
	}

	for (int i=0;i<m;++i)
	{
		long t;
		cin >> t;

		b.insert(t);
	}

	cout << *(next(a.rbegin(),1)) * (*b.rbegin());

	getchar();getchar();
	return 0;
}


//934A
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
vector < long > a,b;
vector < long long > c;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		long t;
		cin >> t;

		a.push_back(t);
	}

	for (int i=0;i<m;++i)
	{
		long t;
		cin >> t;

		b.push_back(t);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	if (*a.begin() * *b.begin() > *a.rbegin() * *b.rbegin())
		a.erase(a.begin());
	else
		a.erase(a.begin()+(n-1));

	for (vector < long >::iterator ia = a.begin(); ia != a.end(); ++ia)
	{
		for (vector < long >::iterator ib = b.begin(); ib != b.end(); ++ib)
		{
			c.push_back( (long long) *ia * *ib );
		}
	}

	sort(c.begin(), c.end());

	cout << *next(c.rbegin(), 1);

	getchar();getchar();
	return 0;
}


//934A
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
vector < long > a,b;
vector < long long > c;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		long t;
		cin >> t;

		a.push_back(t);
	}

	for (int i=0;i<m;++i)
	{
		long t;
		cin >> t;

		b.push_back(t);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	if ((long long) *a.rbegin() < 0 && (long long) *b.begin() > 0)
	{
		a.erase(a.begin()+(n-1));
	}
	else
	{
		if ((long long) *a.begin() * *b.begin() > (long long) *a.rbegin() * *b.rbegin())
			a.erase(a.begin());
		else
			a.erase(a.begin()+(n-1));
	}

	for (vector < long >::iterator ia = a.begin(); ia != a.end(); ++ia)
	{
		for (vector < long >::iterator ib = b.begin(); ib != b.end(); ++ib)
		{
			c.push_back( (long long) *ia * *ib );
		}
	}

	sort(c.begin(), c.end());

	cout << *c.rbegin();

	getchar();getchar();
	return 0;
}


//934A
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
vector < long > a,b;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		long t;
		cin >> t;

		a.push_back(t);
	}

	for (int i=0;i<m;++i)
	{
		long t;
		cin >> t;

		b.push_back(t);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	cout << (long long)*(next(a.rbegin(),1)) * (*b.rbegin());

	getchar();getchar();
	return 0;
}


//934A
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m;
vector < long > a,b;
long long ans = -1000000000000000001;

int main()
{
	cin >> n >> m;

	for (int i=0;i<n;++i)
	{
		long t;
		cin >> t;

		a.push_back(t);
	}

	for (int i=0;i<m;++i)
	{
		long t;
		cin >> t;

		b.push_back(t);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	for (vector < long >::iterator ia = a.begin(); ia+1 != a.end(); ++ia)
	{
		for (vector < long >::iterator ib = b.begin(); ib != b.end(); ++ib)
		{
			if (ans < (long long)*ia * *ib)
				ans = (long long)*ia * *ib;

		}
	}

	cout << ans;

	getchar();getchar();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n; cin >>n >>m;
    vector<long long> v,v1,v2;
    for(int i=0; i< n; i++)
    {
        int x; cin >> x;
        v1.push_back(x);
    }
    for(int i=0; i< m; i++)
    {
        int x; cin >> x;
        v2.push_back(x);
    }
    for(int i=0; i< v1.size(); i++)
    {
        long long Max=INT_MIN;
        for(int j=0; j< v2.size(); j++)
        {
            long long res=v1[i]*v2[j];
            if(res>Max) Max=res;
        }
        v.push_back(Max);
    }
    long long Max=INT_MIN,Max1=INT_MIN;
    for(int i=0; i< v.size(); i++)
    {
        if(Max<=v[i])
        {
            Max1=Max;
            Max=v[i];
        }
        else
        {
            if(Max1<v[i]&& Max>v[i])
                Max1=v[i];
        }
    }
    cout << Max1 <<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    //dm=i;
    int m,n; cin >>n >>m;
    vector<int> v,v1,v2;
    for(int i=0; i< n; i++)
    {
        int x; cin >> x;
        v1.push_back(x);
    }
    for(int i=0; i< m; i++)
    {
        int x; cin >> x;
        v2.push_back(x);
    }
    int Max=INT_MIN,Max1=INT_MIN;
    for(int i=0; i< v1.size(); i++)
    {
        for(int j=0; j< v2.size(); j++)
        {
            long long res=v1[i]*v2[j];
            if(res>=Max)
            {
                if(Max>Max1)
                    Max1=Max;
                Max=res;
            }
            else
                if(res>Max1)
                    Max1=res;
            if(v1[i]==0)
                break;
        }
    }
    cout << Max1<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    //dm=i;
    int m,n; cin >>n >>m;
    vector<int> v,v1,v2;
    for(int i=0; i< n; i++)
    {
        int x; cin >> x;
        v1.push_back(x);
    }
    for(int i=0; i< m; i++)
    {
        int x; cin >> x;
        v2.push_back(x);
    }
    int Max=INT_MIN,Max1=INT_MIN;
    for(int i=0; i< v1.size(); i++)
    {
        for(int j=0; j< v2.size(); j++)
        {
            long long res=v1[i]*v2[j];
            if(res>Max)
            {
                if(Max>Max1)
                    Max1=Max;
                Max=res;
            }
            else
                if(res>Max1)
                    Max1=res;
        }
    }
    cout << Max1<<endl;
//    for(int i=0; i< v.size(); i++)
//        cout << v[i]<< " ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    //dm=i;
    int m,n; cin >>n >>m;
    vector<int> v,v1,v2;
    for(int i=0; i< n; i++)
    {
        int x; cin >> x;
        v1.push_back(x);
    }
    for(int i=0; i< m; i++)
    {
        int x; cin >> x;
        v2.push_back(x);
    }
    int Max=INT_MIN,Max1=INT_MIN, Max2=INT_MIN;
    for(int i=0; i< v1.size(); i++)
    {
        int Max=INT_MIN;
        for(int j=0; j< v2.size(); j++)
        {
            long long res=v1[i]*v2[j];
            if(res>Max) Max=res;
        }
        v.push_back(Max);
    }

    for(int i=0; i< v.size(); i++)
    {
        for(int j=i+1; j<v.size(); j++)
        {
            if(v[j]>v[i])
                swap(v[i],v[j]);
        }
    }
//    for(int i=0; i< v.size(); i++)
//    {
//        cout << v[i]<<endl;
//    }
    cout << v[1]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n; cin >>n >>m;
    vector<long long> v,v1,v2;
    for(int i=0; i< n; i++)
    {
        int x; cin >> x;
        v1.push_back(x);
    }
    for(int i=0; i< m; i++)
    {
        int x; cin >> x;
        v2.push_back(x);
    }
    for(int i=0; i< v1.size(); i++)
    {
        int Max=INT_MIN;
        for(int j=0; j< v2.size(); j++)
        {
            long long res=v1[i]*v2[j];
            if(res>Max) Max=res;
        }
        v.push_back(Max);
    }
    int Max=INT_MIN,Max1=INT_MIN;
    for(int i=0; i< v.size(); i++)
    {
        if(Max<=v[i])
        {
            Max1=Max;
            Max=v[i];
        }
        else
        {
            if(Max1<v[i]&& Max>v[i])
                Max1=v[i];
        }
    }
    cout << Max1 <<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    dm=i;
    int m,n; cin >>n >>m;
    vector<int> v,v1,v2;
    for(int i=0; i< n; i++)
    {
        int x; cin >> x;
        v1.push_back(x);
    }
    for(int i=0; i< m; i++)
    {
        int x; cin >> x;
        v2.push_back(x);
    }
    int Max=INT_MIN,Max1=INT_MIN;
    for(int i=0; i< v1.size(); i++)
    {
        for(int j=0; j< v2.size(); j++)
        {
            long long res=v1[i]*v2[j];
            if(res>=Max)
            {
                if(Max>Max1)
                    Max1=Max;
                Max=res;
            }
            else
                if(res>Max1)
                    Max1=res;
            if(v1[i]==0)
                break;
        }
    }
    cout << Max1<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n; cin >>n >>m;
    vector<int> v,v1,v2;
    for(int i=0; i< n; i++)
    {
        int x; cin >> x;
        v1.push_back(x);
    }
    for(int i=0; i< m; i++)
    {
        int x; cin >> x;
        v2.push_back(x);
    }
    for(int i=0; i< v1.size(); i++)
    {
        int Max=INT_MIN;
        for(int j=0; j< v2.size(); j++)
        {
            long long res=v1[i]*v2[j];
            if(res>Max) Max=res;
        }
        v.push_back(Max);
    }
    int Max=INT_MIN,Max1=INT_MIN;
    for(int i=0; i< v.size(); i++)
    {
        if(Max<v[i])
        {
            Max1=Max;
            Max=v[i];
        }
        else
        {
            if(Max==v[i])
                Max=v[i];
            if(Max1<v[i]&& Max>v[i])
                Max1=v[i];
        }
    }
    cout << Max1 <<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n; cin >>n >>m;
    vector<long long> v,v1,v2;
    for(int i=0; i< n; i++)
    {
        int x; cin >> x;
        v1.push_back(x);
    }
    for(int i=0; i< m; i++)
    {
        int x; cin >> x;
        v2.push_back(x);
    }
    for(int i=0; i< v1.size(); i++)
    {
        long long Max=-1000000000000000001;
        for(int j=0; j< v2.size(); j++)
        {
            long long res=v1[i]*v2[j];
            if(res>Max) Max=res;
        }
        v.push_back(Max);
    }
    long long Max=-1000000000000000001,Max1=-1000000000000000001;
    for(int i=0; i< v.size(); i++)
    {
        if(Max<=v[i])
        {
            Max1=Max;
            Max=v[i];
        }
        else
        {
            if(Max1<v[i]&& Max>v[i])
                Max1=v[i];
        }
    }
    cout << Max1 <<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m; cin >> n >> m;
    //vector<int> v,v1;
    set<int,greater<int> > s,s1;
    int Max=INT_MIN;
    for(int i=0; i< n; i++)
    {
        int x; cin >> x;
        s.insert(x);
    }
    set<int,greater<int> >::iterator i=s.begin();
    i++;
    for(int i=0; i< m; i++)
    {
        int x; cin >> x;
        s1.insert(x);
    }
    set<int,greater<int> >::iterator j=s1.begin();
    long long res=0;
    res=(*i)*(*j);
    cout << res <<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll  long long int

#define inf 0x7fffffff

#define N (int)1e4+7

#define ff first

#define ss second

#define ump unordered_map<int,int>

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> v(n),x(m);
  ll maior = -1;
  int quem;
  for(int i = 0; i < n; i++){
    cin >> v[i];
    if(v[i] > maior){
      maior = v[i];
      quem = i;
    }
  }
  for(int i = 0; i < m; i++) cin >> x[i];
  vector<ll> resp;
  int idx = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      if(i == quem) continue;
      resp.pb(v[i]*x[j]);
    }
  }
  sort(resp.begin(), resp.end());
  cout << resp[resp.size()-1] << endl;

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll  long long int

#define inf 0x7fffffff

#define N (int)1e4+7

#define ff first

#define ss second

#define ump unordered_map<int,int>

int main(){
  int n,m;
  cin >> n >> m;
  int v[n];
  int x[m];
  for(int i = 0; i < n; i++) scanf("%d", v+i);
  for(int i = 0; i < m; i++) scanf("%d", x+i);
  sort(v,v+n);
  printf("%lld\n",v[n-2]*x[m-1]);

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll  long long int

#define inf 0x7fffffff

#define N (int)1e4+7

#define ff first

#define ss second

#define ump unordered_map<int,int>

int main(){
  int n,m;
  cin >> n >> m;
  int v[n];
  int x[m];
  for(int i = 0; i < n; i++) scanf("%d" v+i);
  for(int i = 0; i < m; i++) scanf("%d" x+i);
  sort(v,v+n);
  printf("%lld\n",v[n-2]*x[m-1]);

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll  long long int

#define inf 0x7fffffff

#define N (int)1e4+7

#define ff first

#define ss second

#define ump unordered_map<int,int>

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> v(n),x(m);
  for(int i = 0; i < n; i++) cin >> v[i];
  for(int i = 0; i < m; i++) cin >> x[i];
  vector<ll> resp;
  int idx = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      resp.pb(v[i]*x[j]);
    }
  }
  sort(resp.begin(), resp.end());
  cout << resp[resp.size() - m - 1] << endl;

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll  long long int

#define inf 0x7fffffff

#define N (int)1e4+7

#define ff first

#define ss second

#define ump unordered_map<int,int>

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> v(n),x(m);
  ll maior = -1;
  int quem;
  for(int i = 0; i < n; i++){
    cin >> v[i];
    if(v[i] > maior){
      maior = v[i];
      quem = i;
    }
  }
  for(int i = 0; i < m; i++) cin >> x[i];
  vector<ll> resp;
  int idx = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      if(i == quem) continue;
      resp.pb(v[i]*x[j]);
    }
  }
  sort(resp.begin(), resp.end());
  cout << resp[res.size()-1] << endl;

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll  long long int

#define inf 0x7fffffff

#define N (int)1e4+7

#define ff first

#define ss second

#define ump unordered_map<int,int>

int main(){
  int n,m;
  cin >> n >> m;
  ll v[n];
  ll x[m];
  for(int i = 0; i < n; i++) cin >> v[i];
  for(int i = 0; i < m; i++) cin >> x[i];
  ll resp[m*n];
  int idx = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      resp[idx++] = v[i]*x[j];
    }
  }
  sort(resp, resp + (m*n));
  cout << resp[(m*n)-2] << endl;

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll  long long int

#define inf 0x7fffffff

#define N (int)1e4+7

#define ff first

#define ss second

#define ump unordered_map<int,int>

int main(){
  int n,m;
  cin >> n >> m;
  ll v[n];
  ll x[m];
  for(int i = 0; i < n; i++) cin >> v[i];
  for(int i = 0; i < m; i++) cin >> x[i];
  sort(v,v+n);
  sort(x,x+m);
  cout << v[n-2]*x[m-1] << endl;

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll  long long int

#define inf 0x7fffffff

#define N (int)1e4+7

#define ff first

#define ss second

#define ump unordered_map<int,int>

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> v(n),x(m);
  for(int i = 0; i < n; i++) cin >> v[i];
  for(int i = 0; i < m; i++) cin >> x[i];
  vector<ll> resp;
  int idx = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      resp.pb(v[i]*x[j]);
    }
  }
  sort(resp.begin(), resp.end());
  ll maior = resp[resp.size()-1];
  for(int i = resp.size()-1; i >= 0; i--){
    if(resp[i] == maior) continue;
    return cout << resp[i] << endl,0;
  }

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll  long long int

#define inf 0x7fffffff

#define N (int)1e4+7

#define ff first

#define ss second

#define ump unordered_map<int,int>

#define ii pair<ll,int>

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> v(n),x(m);
  int quem;
  for(int i = 0; i < n; i++)cin >> v[i];
  for(int i = 0; i < m; i++) cin >> x[i];
  vector<ii> resp;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      resp.pb(v[i]*x[j],i);
    }
  }
  sort(resp.begin(), resp.end());
  int quem = resp[resp.size()-1].ss;
  for(int i = resp.size()-1; i >= 0; i--){
    if(resp[i].ss == quem) continue;
    return cout << resp[i].ff << endl,0;
  }

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll  long long int

#define inf 0x7fffffff

#define N (int)1e4+7

#define ff first

#define ss second

#define ump unordered_map<int,int>

#define ii pair<ll,int>

#define mp make_pair

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> v(n),x(m);
  for(int i = 0; i < n; i++)cin >> v[i];
  for(int i = 0; i < m; i++) cin >> x[i];
  vector<ii> resp;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      resp.pb(mp(v[i]*x[j],i) );
    }
  }
  sort(resp.begin(), resp.end());
  int quem = resp[resp.size()-1].ss;
  for(int i = resp.size()-1; i >= 0; i--){
    if(resp[i].ss == quem) continue;
    return cout << resp[i].ff << endl,0;
  }

}


#include <bits/stdc++.h>
#define pb push_back
#define MAXN 10010
#define vii vector < pair < int, int > >
#define vi vector < int >
#define ll long long
#define INF INT_MAX
#define f(b) for(int i = 0;i < b;i++)
#define fp(a,b) for(int i = a;i < b;i++)
#define spn << " " <<
#define sp << " "
#define el << '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	ll x;
	cin >> n >> m;
	vector <ll > v1, v2;
	ll res = 0, res2 = 0;
	for(int i = 0;i < n;i++){
		cin >> x;
		v1.pb(x);
	}
	for(int i = 0;i < m;i++){
		cin >> x;
		v2.pb(x);
		for(int j = 0;j < n;j++){
			res = max(res,v2[i] * v1[j]);
		}
	}
	int tr = 1;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			if(v1[i] *v2[j] < res && tr){
				res2 = max(res2, v1[i]*v2[j]);
			}
			else if(v1[i]*v2[j] <= res && !tr){
				res2 = max(res2,v1[i]*v2[j]);
			}
			else if(v1[i]*v2[j] == res) tr = 0;
		}
	}
	cout << res2 el;
}


#include <bits/stdc++.h>
#define pb push_back
#define MAXN 10010
#define vii vector < pair < int, int > >
#define vi vector < int >
#define ll long long
#define INF INT_MAX
#define f(b) for(int i = 0;i < b;i++)
#define fp(a,b) for(int i = a;i < b;i++)
#define spn << " " <<
#define sp << " "
#define el << '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	ll x;
	cin >> n >> m;
	vector <ll > v1, v2;
	ll res = LLONG_MIN, res2 = LLONG_MIN;
	for(int i = 0;i < n;i++){
		cin >> x;
		v1.pb(x);
	}
	for(int i = 0;i < m;i++){
		cin >> x;
		v2.pb(x);
		for(int j = 0;j < n;j++){
			res = max(res,v2[i] * v1[j]);
		}
	}
	int tr = 1;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			if(v1[i] *v2[j] < res && tr){
				res2 = max(res2, v1[i]*v2[j]);
			}
			else if(v1[i]*v2[j] <= res && !tr){
				res2 = max(res2,v1[i]*v2[j]);
			}
			else if(v1[i]*v2[j] == res) tr = 0;
		}
	}
	cout << res2 el;
}


#include <bits/stdc++.h>
#define pb push_back
#define MAXN 10010
#define vii vector < pair < int, int > >
#define vi vector < int >
#define ll long long
#define INF INT_MAX
#define f(b) for(int i = 0;i < b;i++)
#define fp(a,b) for(int i = a;i < b;i++)
#define spn << " " <<
#define sp << " "
#define el << '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	ll x;
	cin >> n >> m;
	vector <ll > v1, v2;
	ll res = LLONG_MIN, res2 = LLONG_MIN;
	for(int i = 0;i < n;i++){
		cin >> x;
		v1.pb(x);
	}
	ll erase;
	for(int i = 0;i < m;i++){
		cin >> x;
		v2.pb(x);
		for(int j = 0;j < n;j++){
			if(v2[i]*v1[j] > res){
				res = v2[i]*v1[j];
				erase = v1[j];
			}

		}
	}
	int tr = 1;
	for(int i = 0;i < n;i++){
		if(v1[i] == erase && tr){
			tr = 0;
			continue;
		}
		for(int j = 0;j < m;j++){
			if(v1[i]*v2[j] <= res){
				res2 = v1[i]*v2[j];
			}
		}
	}
	cout << res2 el;
}


#include <bits/stdc++.h>
#define pb push_back
#define MAXN 10010
#define vii vector < pair < int, int > >
#define vi vector < int >
#define ll long long
#define INF INT_MAX
#define f(b) for(int i = 0;i < b;i++)
#define fp(a,b) for(int i = a;i < b;i++)
#define spn << " " <<
#define sp << " "
#define el << '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	ll x;
	cin >> n >> m;
	vector <ll > v1, v2;
	ll res = -INF, res2 = -INF;
	for(int i = 0;i < n;i++){
		cin >> x;
		v1.pb(x);
	}
	for(int i = 0;i < m;i++){
		cin >> x;
		v2.pb(x);
		for(int j = 0;j < n;j++){
			res = max(res,v2[i] * v1[j]);
		}
	}
	int tr = 1;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			if(v1[i] *v2[j] < res && tr){
				res2 = max(res2, v1[i]*v2[j]);
			}
			else if(v1[i]*v2[j] <= res && !tr){
				res2 = max(res2,v1[i]*v2[j]);
			}
			else if(v1[i]*v2[j] == res) tr = 0;
		}
	}
	cout << res2 el;
}


#include <bits/stdc++.h>
#define pb push_back
#define MAXN 10010
#define vii vector < pair < int, int > >
#define vi vector < int >
#define ll long long
#define INF INT_MAX
#define f(b) for(int i = 0;i < b;i++)
#define fp(a,b) for(int i = a;i < b;i++)
#define spn << " " <<
#define sp << " "
#define el << '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	ll x;
	cin >> n >> m;
	vector <ll > v1, v2;
	ll res = LLONG_MIN, res2 = LLONG_MIN;
	for(int i = 0;i < n;i++){
		cin >> x;
		v1.pb(x);
	}
	for(int i = 0;i < m;i++){
		cin >> x;
		v2.pb(x);
		for(int j = 0;j < n;j++){
			res = max(res,v2[i] * v1[j]);
		}
	}
	int tr = 1;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			if(v1[i] *v2[j] < res && tr){
				res2 = max(res2, v1[i]*v2[j]);
			}
			else if(v1[i]*v2[j] <= res && !tr){
				res2 = max(res2,v1[i]*v2[j]);
			}
			else if(v1[i]*v2[j] == res){
				tr = 0;
				break;
			}
		}
	}
	cout << res2 el;
}


#include <bits/stdc++.h>
#define pb push_back
#define MAXN 10010
#define vii vector < pair < int, int > >
#define vi vector < int >
#define ll long long
#define INF INT_MAX
#define f(b) for(int i = 0;i < b;i++)
#define fp(a,b) for(int i = a;i < b;i++)
#define spn << " " <<
#define sp << " "
#define el << '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	ll x;
	cin >> n >> m;
	vector <ll > v1, v2;
	ll res = LLONG_MIN, res2 = LLONG_MIN;
	for(int i = 0;i < n;i++){
		cin >> x;
		v1.pb(x);
	}
	ll erase;
	for(int i = 0;i < m;i++){
		cin >> x;
		v2.pb(x);
		for(int j = 0;j < n;j++){
			if(v2[i]*v1[j] > res){
				res = v2[i]*v1[j];
				erase = v1[j];
			}

		}
	}
	int tr = 1;
	for(int i = 0;i < n;i++){
		if(v1[i] == erase && tr){
			tr = 0;
			continue;
		}
		for(int j = 0;j < m;j++){
			if(v1[i]*v2[j] <= res){
				res2 = max(res2,v1[i]*v2[j]);
			}
		}
	}
	cout << res2 el;
}


#include <bits/stdc++.h>
#define pb push_back
#define MAXN 10010
#define vii vector < pair < int, int > >
#define vi vector < int >
#define ll long long
#define INF INT_MAX
#define f(b) for(int i = 0;i < b;i++)
#define fp(a,b) for(int i = a;i < b;i++)
#define spn << " " <<
#define sp << " "
#define el << '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	vector <ll > v1, v2;
	for(int i = 0;i < n;i++){
		ll x;
		cin >> x;
		v1.pb(x);
	}
	sort(v1.rbegin(),v1.rend());
	for(int i = 0;i < m;i++){
		ll x;
		cin >> x;
		v2.pb(x);
	}
	sort(v2.rbegin(),v2.rend());
	cout << v1[1] * v2[0] el;
}


#include <bits/stdc++.h>
#define pb push_back
#define MAXN 10010
#define vii vector < pair < int, int > >
#define vi vector < int >
#define ll long long
#define INF INT_MAX
#define f(b) for(int i = 0;i < b;i++)
#define fp(a,b) for(int i = a;i < b;i++)
#define spn << " " <<
#define sp << " "
#define el << '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	ll x;
	cin >> n >> m;
	vector <ll > v1, v2;
	for(int i = 0;i < n;i++){
		cin >> x;
		v1.pb(x);
	}
	sort(v1.rbegin(),v1.rend());
	for(int i = 0;i < m;i++){
		cin >> x;
		v2.pb(x);
	}
	if(v1[1] < 0) sort(v2.begin(),v2.end());
	else sort(v2.rbegin(),v2.rend());
	ll res = v1[1] * v2[0];
	cout << res el;
}


#include <bits/stdc++.h>
#define pb push_back
#define MAXN 10010
#define vii vector < pair < int, int > >
#define vi vector < int >
#define ll long long
#define INF INT_MAX
#define f(b) for(int i = 0;i < b;i++)
#define fp(a,b) for(int i = a;i < b;i++)
#define spn << " " <<
#define sp << " "
#define el << '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	ll x;
	cin >> n >> m;
	vector <ll > v1, v2;
	ll res = 0, res2 = 0;
	for(int i = 0;i < n;i++){
		cin >> x;
		v1.pb(x);
	}
	for(int i = 0;i < m;i++){
		cin >> x;
		v2.pb(x);
		for(int j = 0;j < n;j++){
			res = max(res,v2[i] * v1[j]);
		}
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			if(v1[i] *v2[j] < res){
				res2 = max(res2, v1[i]*v2[j]);
			}
		}
	}
	cout << res2 el;
}


#include <bits/stdc++.h>
#define pb push_back
#define MAXN 10010
#define vii vector < pair < int, int > >
#define vi vector < int >
#define ll long long
#define INF INT_MAX
#define f(b) for(int i = 0;i < b;i++)
#define fp(a,b) for(int i = a;i < b;i++)
#define spn << " " <<
#define sp << " "
#define el << '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n,m;
	ll x;
	cin >> n >> m;
	vector <ll > v1, v2;
	for(int i = 0;i < n;i++){
		cin >> x;
		v1.pb(x);
	}
	sort(v1.rbegin(),v1.rend());
	for(int i = 0;i < m;i++){
		cin >> x;
		v2.pb(x);
	}
	sort(v2.rbegin(),v2.rend());
	ll res = v1[1] * v2[0];
	cout << res el;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    int a[x],b[y];
    for (int i=0;i<x;i++)
        cin>>a[i];
    for (int i=0;i<y;i++)
        cin>>b[i];
    sort(a,a+x);
    sort(b,b+y);
    if ((ll)b[y-1]*a[x-1]>(ll)b[0]*a[0])
        cout<<(ll)max((ll)a[x-2]*b[y-1],(ll)a[0]*b[0]);
        else if (ll)b[y-1]*a[x-1]<(ll)b[0]*a[0])
            cout<<(ll)max((ll)b[0]*a[1],(ll)b[y-1]*a[x-1]);
        else
            cout<<(ll)max((ll)b[y-1]*a[x-2],(ll)a[1]*b[0]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    int a[x],b[y];
    for (int i=0;i<x;i++)
        cin>>a[i];
    for (int i=0;i<y;i++)
        cin>>b[i];
    sort(a,a+x);
    sort(b,b+y);
    if ((ll)b[y-1]*a[x-1]>(ll)b[0]*a[0])
        cout<<(ll)a[x-2]*b[y-1];
        else
            cout<<(ll)max((ll)b[0]*a[1],(ll)b[x-1]*a[x-1]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    int a[x],b[y];
    for (int i=0;i<x;i++)
        cin>>a[i];
    for (int i=0;i<y;i++)
        cin>>b[i];
    sort(a,a+x);
    sort(b,b+y);
    if ((ll)b[y-1]*a[x-1]>(ll)b[0]*a[0])
        cout<<(ll)max((ll)a[x-2]*b[y-1],(ll)a[0]*b[0]);
        else if ((ll)b[y-1]*a[x-1]<(ll)b[0]*a[0])
            cout<<(ll)max((ll)b[0]*a[1],(ll)b[y-1]*a[x-1]);
        else
            cout<<(ll)max((ll)b[y-1]*a[x-2],(ll)a[1]*b[0]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    int a[x],b[y];
    for (int i=0;i<x;i++)
        cin>>a[i];
    for (int i=0;i<y;i++)
        cin>>b[i];
    sort(a,a+x);
    sort(b,b+y);
    if ((ll)b[y-1]*a[x-1]>(ll)b[0]*a[0])
        cout<<(ll)max((ll)a[x-2]*b[y-1],(ll)a[0]*b[0]);
        else
            cout<<(ll)max((ll)b[0]*a[1],(ll)b[y-1]*a[x-1]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    int a[x],b[y];
    for (int i=0;i<x;i++)
        cin>>a[i];
    for (int i=0;i<y;i++)
        cin>>b[i];
    sort(a,a+x);
    sort(b,b+y);
    if ((ll)b[y-1]*a[x-1]>(ll)b[0]*a[0])
        cout<<(ll)max(a[x-2]*b[y-1],(ll)a[0]*b[0]);
        else
            cout<<(ll)max((ll)b[0]*a[1],(ll)b[x-1]*a[x-1]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    int a[x],b[y];
    for (int i=0;i<x;i++)
        cin>>a[i];
    for (int i=0;i<y;i++)
        cin>>b[i];
    sort(a,a+x);
    sort(b,b+y);
    vector <ll>v(3000);
    fill(v.begin(), v.end(), (ll)-1e18);
        for (int i=0;i<x;i++){
        for (int j=0;j<y;j++)
        {

            v.push_back(max((ll)v[i],(ll)a[i]*b[j]));
        }
    }
    sort(v.begin(),v.end());
    cout<<v[v.size()-2]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    int a[x],b[y];
    for (int i=0;i<x;i++)
        cin>>a[i];
    for (int i=0;i<y;i++)
        cin>>b[i];
    sort(a,a+x);
    sort(b,b+y);
    vector <ll>v(2501);
        for (int i=0;i<x;i++){
        for (int j=0;j<y;j++)
        {

            v.push_back(max(v[i],(ll)a[i]*b[j]));
        }
    }
    sort(v.begin(),v.end());
    cout<<v[v.size()-2]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    int a[x],b[y];
    for (int i=0;i<x;i++)
        cin>>a[i];
    for (int i=0;i<y;i++)
        cin>>b[i];
    sort(a,a+x);
    sort(b,b+y);
    if ((ll)b[y-1]*a[x-1]>(ll)b[0]*a[0])
        cout<<(ll)max((ll)a[x-2]*b[y-1],(ll)a[0]*b[0]);
        else
            cout<<(ll)max((ll)b[0]*a[1],(ll)b[x-1]*a[x-1]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    int a[x],b[y];
    for (int i=0;i<x;i++)
        cin>>a[i];
    for (int i=0;i<y;i++)
        cin>>b[i];
    sort(a,a+x);
    sort(b,b+y);
    vector <ll>v;
    for (int i=0;i<x;i++){
        for (int j=0;j<y;j++)
        {
            v.push_back((ll)a[i]*b[j]);
        }
    }
    sort(v.begin(),v.end());
    cout<<v[v.size()-2]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    int a[x],b[y];
    for (int i=0;i<x;i++)
        cin>>a[i];
    for (int i=0;i<y;i++)
        cin>>b[i];
    sort(a,a+x);
    sort(b,b+y);
    vector <ll>v(3000);
    fill(v.begin(), v.end(), (ll)-1e18);
        for (int i=0;i<x;i++){
        for (int j=0;j<y;j++)
        {

            v[i]=(max((ll)v[i],(ll)a[i]*b[j]));
        }
    }
    sort(v.begin(),v.end());
    cout<<v[v.size()-2]<<endl;
    return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
int cmp(int a,int b){
	return a>b;
}
int main(){
	long long i,j,k,n,m,ans;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	cin>>a[i];
	for(j=1;j<=m;j++)
	cin>>b[j];
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	cout<<b[1]*a[2];
	return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
int cmp(int a,int b){
	return a>b;
}
int main(){
	long long i,j,k,n,m,ans;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	for(j=1;j<=m;j++)
	scanf("%lld",&b[j]);
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	printf("%lld",b[1]*a[2]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int cmp(long long a,long long b){
	return a>b;
}

int main(){
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF){
		long long a[100],b[100];
		for(int i=0;i<n;i++)
		  scanf("%lld",&a[i]);
		for(int i=0;i<m;i++)
		  scanf("%lld",&b[i]);
		sort(a,a+n,cmp);
		sort(b,b+m,cmp);
		printf("%lld\n",a[1]*b[0]);
	}
	return 0;
}


#include <bits/stdc++.h>
double a[51];
double b[51];
using namespace std;
int cmp(double a,double b){
	return a>b;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	   scanf("%lf",&a[i]);
	for(int j=1;j<=m;j++)
	   scanf("%lf",&b[j]);
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	printf("%.0lf",a[2]*b[1]);
	return 0;
}


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

bool cmp(long long a,long long b){
	return a>b;
}

int main(){
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF){
		long long a[51],b[51];
		for(int i=0;i<n;i++)
		  scanf("%lld",&a[i]);
		for(int i=0;i<m;i++)
		  scanf("%lld",&b[i]);
		sort(a,a+n,cmp);
		sort(b,b+m,cmp);
		printf("%lld\n",a[1]*b[0]);
	}
	return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
long long cmp(long long a,long long b){
	return a>b;
}
int main(){
	long long n,m;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	   scanf("%lld",&a[i]);
	for(int j=1;j<=m;j++)
	   scanf("%lld",&b[j]);
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	printf("%lld",a[2]*b[1]);
	return 0;
}


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

bool cmp(long long a,long long b){
	return a>b;
}

int main(){
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF){
		long long a[51],b[51];
		for(int i=0;i<n;i++)
		  scanf("%lld",&a[i]);
		for(int i=0;i<m;i++)
		  scanf("%lld",&b[i]);
		sort(a,a+n,cmp);
		sort(b,b+m,cmp);
		cout<<a[1]*b[0]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
long long cmp(long long a,long long b){
	return a>b;
}
int main(){
	long long n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	   scanf("%d",&a[i]);
	for(int j=1;j<=m;j++)
	   scanf("%d",&b[j]);
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	printf("%d",a[2]*b[1]);
	return 0;
}


#include <bits/stdc++.h>
double a[51];
double b[51];
using namespace std;
double cmp(double a,double b){
	return a>b;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	   scanf("%lf",&a[i]);
	for(int j=1;j<=m;j++)
	   scanf("%lf",&b[j]);
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	printf("%.0lf",a[2]*b[1]);
	return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
int cmp(int a,int b){
	return a>b;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	   scanf("%lld",&a[i]);
	for(int j=1;j<=m;j++)
	   scanf("%lld",&b[j]);
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	printf("%lld",a[2]*b[1]);
	return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
int cmp(int a,int b){
	return a>b;
}
int main(){
	long long i,j,k,n,m,ans;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	for(j=1;j<=m;j++)
	scanf("%lld",&b[j]);
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	cout<<b[1]*a[2];
	return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
long long cmp(long long a,long long b){
	return a>b;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	   scanf("%lld",&a[i]);
	for(int j=1;j<=m;j++)
	   scanf("%lld",&b[j]);
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	printf("%lld",a[2]*b[1]);
	return 0;
}


#include<bits/stdc++.h>
#define inf 0x7fffffffffffffff
using namespace std;
long long a[55],b[55];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	  scanf("%lld",&a[i]);
	for(int i=1;i<=m;i++)
	  scanf("%lld",&b[i]);
	long long res=inf;
	for(int i=1;i<=n;i++){
		long long now=-inf;
		for(int j=1;j<=n;j++){
			if(j!=i)
				for(int k=1;k<=m;k++)
				  now=max(now,a[j]*b[k]);
		}
		res=min(res,now);
	}
	printf("%lld\n",res);
	return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
int cmp(int a,int b){
 return a>b;
}
int main(){
 long long i,j,k,n,m,ans;
 scanf("%lld%lld",&n,&m);
 for(i=1;i<=n;i++)
 scanf("%lld",&a[i]);
 for(j=1;j<=m;j++)
 scanf("%lld",&b[j]);
 sort(a+1,a+1+n,cmp);
 sort(b+1,b+1+m,cmp);
 cout<<b[1]*a[2];
 return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
int cmp(long long a,long long b){
	return a>b;
}
int main(){
	int i,j,k,n,m;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	cin>>a[i];
	for(j=1;j<=m;j++)
	cin>>b[j];
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	cout<<b[1]*a[2];
	return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
long long cmp(long long a,long long b){
	return a>b;
}
int main(){
	long long n,m;
	scanf("%lld%lld",&n,&m);
	getchar();
	for(int i=1;i<=n;i++)
	   scanf("%lld",&a[i]);
	getchar();
	for(int j=1;j<=m;j++)
	   scanf("%lld",&b[j]);
	getchar();
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	printf("%lld",a[2]*b[1]);
	return 0;
}


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

bool cmp(int a,int b){
	return a>b;
}

int main(){
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF){
		long long a[51],b[51];
		for(int i=0;i<n;i++)
		  scanf("%lld",&a[i]);
		for(int i=0;i<m;i++)
		  scanf("%lld",&b[i]);
		sort(a,a+n,cmp);
		sort(b,b+m,cmp);
		printf("%lld\n",a[1]*b[0]);
	}
	return 0;
}


#include <bits/stdc++.h>
long long a[51];
long long b[51];
using namespace std;
int cmp(int a,int b){
 return a>b;
}
int main(){
 long long i,j,k,n,m,ans;
 cin>>n>>m;
 for(i=1;i<=n;i++)
 cin>>a[i];
 for(j=1;j<=m;j++)
 cin>>b[j];
 sort(a+1,a+1+n,cmp);
 sort(b+1,b+1+m,cmp);
 printf("%lld",b[1]*a[2]);
 return 0;
}


#include <bits/stdc++.h>
#define ld long double
#define ll long long int
using namespace std;
ll AAA[5555];
ll BBBB[5555];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    ll n1,m1;
    cin>>n1>>m1;
    for(auto i=0;i<n1;i++)
        cin>>AAA[i];
    for(auto i=0;i<m1;i++)
        cin>>BBBB[i];
    sort(AAA,AAA+n1);
    sort(BBBB,BBBB+m1);
    ll RESSSSSS1=BBBB[m1-1]*AAA[n1-2];
    ll RESSSSSS2,RESSSSSS3;
    RESSSSSS2=RESSSSSS3=LONG_MIN;
    if(n1!=2)
    {
        RESSSSSS2=BBBB[m1-1]*AAA[1];
        RESSSSSS3=BBBB[0]*AAA[1];
        ll ress = BBBB[0] * AAA[n1-1];
    }
    cout<<max(RESSSSSS1,max(RESSSSSS2,max(ress,RESSSSSS3)));
}


#include <bits/stdc++.h>
#define ld long double
#define ll long long int
using namespace std;
ll AAA[5555];
ll BBBB[5555];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    ll n1,m1;
    cin>>n1>>m1;
    for(auto i=0;i<n1;i++)
        cin>>AAA[i];
    for(auto i=0;i<m1;i++)
        cin>>BBBB[i];
    sort(AAA,AAA+n1);
    sort(BBBB,BBBB+m1);
    ll RESSSSSS1=BBBB[m1-1]*AAA[n1-2];
    ll RESSSSSS2,RESSSSSS3;
    RESSSSSS2=RESSSSSS3=LONG_MIN;
    ll ress;
    if(n1!=2)
    {
        RESSSSSS2=BBBB[m1-1]*AAA[1];
        RESSSSSS3=BBBB[0]*AAA[1];
         ress = BBBB[0] * AAA[n1-1];
    }
    cout<<max(RESSSSSS1,max(RESSSSSS2,max(ress,RESSSSSS3)));
}


#include <bits/stdc++.h>
#define ld long double
#define ll long long int
using namespace std;
ll AAA[5555];
ll BBBB[5555];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    ll n1,m1;
    cin>>n1>>m1;
    for(auto i=0;i<n1;i++)
        cin>>AAA[i];
    for(auto i=0;i<m1;i++)
        cin>>BBBB[i];
    sort(AAA,AAA+n1);
    sort(BBBB,BBBB+m1);
    ll RESSSSSS1=BBBB[m1-1]*AAA[n1-2];
    ll RESSSSSS2,RESSSSSS3;
    RESSSSSS2=RESSSSSS3=LONG_MIN;
    if(n1!=2)
    {
        RESSSSSS2=BBBB[m1-1]*AAA[1];
        RESSSSSS3=BBBB[0]*AAA[1];
    }
    cout<<max(RESSSSSS1,max(RESSSSSS2,RESSSSSS3));
}


#include <bits/stdc++.h>
#define ld long double
#define ll long long int
using namespace std;
ll AAA[5555];
ll BBBB[5555];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    ll n1,m1;
    cin>>n1>>m1;
    for(auto i=0;i<n1;i++)
        cin>>AAA[i];
    for(auto i=0;i<m1;i++)
        cin>>BBBB[i];
    sort(AAA,AAA+n1);
    sort(BBBB,BBBB+m1);
    ll RESSSSSS1=BBBB[m1-1]*AAA[n1-2];
    ll RESSSSSS2,RESSSSSS3;
    RESSSSSS2=RESSSSSS3=LONG_MIN;
    if(n1!=2)
    {
        RESSSSSS2=BBBB[m1-1]*AAA[1];
        RESSSSSS3=BBBB[0]*AAA[1];
        ll ress = BBBB[0] * AAA[n-1;]
    }
    cout<<max(RESSSSSS1,max(RESSSSSS2,max(ress,RESSSSSS3)));
}


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

const int N=555;
int Arr[N];
int Brr[N];
int main()
{
    int n,m;
    cin>>n>>m;
    int i,j;
    vector<int>myvec;
    for(i=0;i<n;i++)    cin>>Arr[i];
    for(i=0;i<m;i++)    cin>>Brr[i];
    sort(Arr,Arr+n);sort(Brr,Brr+m);
    long long int  ans1=Brr[m-1]*Arr[n-2];
    long long int ans2,ans3;
    if(n!=2)
    {
        ans2=Brr[m-1]*Arr[1];
        ans3=Brr[0]*Arr[1];
    }
    else
    {
        ans2=ans3=LONG_MIN;
    }
    cout<<max(ans1,max(ans2,ans3));
}


#include <bits/stdc++.h>
#include<string>
#define ld long double
#define ll long long int
#define fastIO ios::sync_with_stdio(false);cin.tie(0)
#define sii(x) scanf("%d",&x)
#define pii(x) printf("%d\n",x)
#define present_set_map(container, element) (container.find(element) != container.end())
#define present_vec(container, element) (find(all(container),element) != container.end())
#define mp make_pair
#define all(x) x.begin(),x.end()
#define all_rev(x) x.rbegin(),x.rend()
#define pb push_back
#define fr first
#define se second
#define MAX 200005
#define INF 1<<60
#define TC int tc;cin>>tc;while(tc--)
#define DEBUG(x) {cout << #x << "=" << x <<endl;}
#define DEBUG2(x, y) {cout << #x << "=" << x << " " << #y << "=" << y <<endl;}
#define DEBUG3(x, y, z) {cout << #x << "=" << x << " " << #y << "=" << y << " " << #z << "=" << z << endl;}
#define clr(x) memset(x,0,sizeof(x))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define RFOR(i,a,b) for(i=(a);i>=(b);i--)
#define LOOP(itr,x) for(auto itr: x)
#define decimalpoints(x) cout<<setprecision(x)<<fixed;
#define pint pair<int,int>
#define plll pair<ll,ll>
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll modPow(ll a,ll b,ll MOD){ll x=1,y=a;while(b>0){if(b%2 == 1){x=(x*y)%MOD;}b/=2;y = (y*y)%MOD;}return x;}
ll modInverse(ll a,ll p){return modPow(a,p-2,p);}
using namespace std;
#define MOD 1000000007
ll i,j,x,n,h,m,cnt,k,ans,sum;
ll arr[2000015], brr[300007];
char a[1000001];
vector< pair<char, int> > vec[1001];
int main(){
    cin>>n>>m;
    int f1 = 0;
    int f2 = 0;
    for(i=0;i<n;i++){
        cin>>arr[i];
        if(arr[i] > 0) f1 = 1;
    }
    sort(arr,arr+n);
    ll val1 = arr[n-2];
    ll val2 = arr[1];
    for(i=0;i<m;i++){
        cin>>brr[i];
        if(brr[i] > 0) f2 = 1;
    }
    sort(brr,brr+m);
    ll mini = INT_MAX;
    ans = INT_MIN;
    for(i=0;i<n;i++){
        ans = INT_MIN;
        for(j=0;j<n;j++){
            for(k=0;k<m;k++){
                if(j == i) continue;
                ans = max(ans, arr[j] * brr[k]);
            }
        }
        mini = min(mini, ans);
    }
    cout<<mini;
}


#include <bits/stdc++.h>
#include<string>
#define ld long double
#define ll long long int
#define fastIO ios::sync_with_stdio(false);cin.tie(0)
#define sii(x) scanf("%d",&x)
#define pii(x) printf("%d\n",x)
#define present_set_map(container, element) (container.find(element) != container.end())
#define present_vec(container, element) (find(all(container),element) != container.end())
#define mp make_pair
#define all(x) x.begin(),x.end()
#define all_rev(x) x.rbegin(),x.rend()
#define pb push_back
#define fr first
#define se second
#define MAX 200005
#define INF 1<<60
#define TC int tc;cin>>tc;while(tc--)
#define DEBUG(x) {cout << #x << "=" << x <<endl;}
#define DEBUG2(x, y) {cout << #x << "=" << x << " " << #y << "=" << y <<endl;}
#define DEBUG3(x, y, z) {cout << #x << "=" << x << " " << #y << "=" << y << " " << #z << "=" << z << endl;}
#define clr(x) memset(x,0,sizeof(x))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define RFOR(i,a,b) for(i=(a);i>=(b);i--)
#define LOOP(itr,x) for(auto itr: x)
#define decimalpoints(x) cout<<setprecision(x)<<fixed;
#define pint pair<int,int>
#define plll pair<ll,ll>
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll modPow(ll a,ll b,ll MOD){ll x=1,y=a;while(b>0){if(b%2 == 1){x=(x*y)%MOD;}b/=2;y = (y*y)%MOD;}return x;}
ll modInverse(ll a,ll p){return modPow(a,p-2,p);}
using namespace std;
#define MOD 1000000007
ll i,j,x,n,h,m,cnt,k,ans,sum;
ll arr[2000015], brr[300007];
char a[1000001];
vector< ll > vec;
int main(){
    cin>>n>>m;
    int f1 = 0;
    int f2 = 0;
    for(i=0;i<n;i++){
        cin>>arr[i];
        if(arr[i] > 0) f1 = 1;
    }
    ll val1 = arr[n-2];
    ll val2 = arr[1];
    for(i=0;i<m;i++){
        cin>>brr[i];
        if(brr[i] > 0) f2 = 1;
    }
    ll mini = LLONG_MAX;
    ans = LLONG_MIN;
    for(i=0;i<n;i++){
        ans = LLONG_MIN;
        for(j=0;j<n;j++){
            for(k=0;k<m;k++){
                if(j == i) continue;
                ans = max(ans, arr[j] * brr[k]);
            }
        }
        mini = min(mini, ans);
    }
    cout<<mini;
}


#include <bits/stdc++.h>
#include<string>
#define ld long double
#define ll long long int
#define fastIO ios::sync_with_stdio(false);cin.tie(0)
#define sii(x) scanf("%d",&x)
#define pii(x) printf("%d\n",x)
#define present_set_map(container, element) (container.find(element) != container.end())
#define present_vec(container, element) (find(all(container),element) != container.end())
#define mp make_pair
#define all(x) x.begin(),x.end()
#define all_rev(x) x.rbegin(),x.rend()
#define pb push_back
#define fr first
#define se second
#define MAX 200005
#define INF 1<<60
#define TC int tc;cin>>tc;while(tc--)
#define DEBUG(x) {cout << #x << "=" << x <<endl;}
#define DEBUG2(x, y) {cout << #x << "=" << x << " " << #y << "=" << y <<endl;}
#define DEBUG3(x, y, z) {cout << #x << "=" << x << " " << #y << "=" << y << " " << #z << "=" << z << endl;}
#define clr(x) memset(x,0,sizeof(x))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define RFOR(i,a,b) for(i=(a);i>=(b);i--)
#define LOOP(itr,x) for(auto itr: x)
#define decimalpoints(x) cout<<setprecision(x)<<fixed;
#define pint pair<int,int>
#define plll pair<ll,ll>
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll modPow(ll a,ll b,ll MOD){ll x=1,y=a;while(b>0){if(b%2 == 1){x=(x*y)%MOD;}b/=2;y = (y*y)%MOD;}return x;}
ll modInverse(ll a,ll p){return modPow(a,p-2,p);}
using namespace std;
#define MOD 1000000007
ll i,j,x,n,h,m,cnt,k,ans,sum;
ll arr[2000015], brr[300007];
char a[1000001];
vector< pair<char, int> > vec[1001];
int main(){
    cin>>n>>m;
    for(i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    ll val1 = arr[n-2];
    ll val2 = arr[1];
    for(i=0;i<m;i++) cin>>arr[i];
    sort(arr,arr+m);
    cout<<max(arr[m-1] * val1, val2 * arr[0]);
}


#include <bits/stdc++.h>
#include<string>
#define ld long double
#define ll long long int
#define fastIO ios::sync_with_stdio(false);cin.tie(0)
#define sii(x) scanf("%d",&x)
#define pii(x) printf("%d\n",x)
#define present_set_map(container, element) (container.find(element) != container.end())
#define present_vec(container, element) (find(all(container),element) != container.end())
#define mp make_pair
#define all(x) x.begin(),x.end()
#define all_rev(x) x.rbegin(),x.rend()
#define pb push_back
#define fr first
#define se second
#define MAX 200005
#define INF 1<<60
#define TC int tc;cin>>tc;while(tc--)
#define DEBUG(x) {cout << #x << "=" << x <<endl;}
#define DEBUG2(x, y) {cout << #x << "=" << x << " " << #y << "=" << y <<endl;}
#define DEBUG3(x, y, z) {cout << #x << "=" << x << " " << #y << "=" << y << " " << #z << "=" << z << endl;}
#define clr(x) memset(x,0,sizeof(x))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define RFOR(i,a,b) for(i=(a);i>=(b);i--)
#define LOOP(itr,x) for(auto itr: x)
#define decimalpoints(x) cout<<setprecision(x)<<fixed;
#define pint pair<int,int>
#define plll pair<ll,ll>
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll modPow(ll a,ll b,ll MOD){ll x=1,y=a;while(b>0){if(b%2 == 1){x=(x*y)%MOD;}b/=2;y = (y*y)%MOD;}return x;}
ll modInverse(ll a,ll p){return modPow(a,p-2,p);}
using namespace std;
#define MOD 1000000007
ll i,j,x,n,h,m,cnt,k,ans,sum;
ll arr[2000015], brr[300007];
char a[1000001];
vector< ll > vec;
int main(){
    cin>>n>>m;
    int f1 = 0;
    int f2 = 0;
    for(i=0;i<n;i++){
        cin>>arr[i];
        if(arr[i] > 0) f1 = 1;
    }
    ll val1 = arr[n-2];
    ll val2 = arr[1];
    for(i=0;i<m;i++){
        cin>>brr[i];
        if(brr[i] > 0) f2 = 1;
    }
    ll mini = LLONG_MAX;
    ans = LLONG_MIN;
    for(i=0;i<n;i++){
        ans = INT_MIN;
        for(j=0;j<n;j++){
            for(k=0;k<m;k++){
                if(j == i) continue;
                ans = max(ans, arr[j] * brr[k]);
            }
        }
        mini = min(mini, ans);
    }
    cout<<mini;
}


#include <bits/stdc++.h>
#define ld long double
#define ll long long int
using namespace std;
ll AAA[5555];
ll BBBB[5555];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    ll n1,m1;
    cin>>n1>>m1;
    for(auto i=0;i<n1;i++)
        cin>>AAA[i];
    for(auto i=0;i<m1;i++)
        cin>>BBBB[i];
    sort(AAA,AAA+n1);
    sort(BBBB,BBBB+m1);
    ll RESSSSSS1=BBBB[m1-1]*AAA[n1-2];
    ll RESSSSSS2,RESSSSSS3;
    RESSSSSS2=RESSSSSS3=LONG_MIN;
    if(n1!=2)
    {
        RESSSSSS2=BBBB[m1-1]*AAA[1];
        RESSSSSS3=BBBB[0]*AAA[1];
        ll ress = BBBB[0] * AAA[n1-1;]
    }
    cout<<max(RESSSSSS1,max(RESSSSSS2,max(ress,RESSSSSS3)));
}


#include <iostream>
#include <algorithm>
using namespace std;
long long t[60],b[60],tu,td,tn,bu,bn,bd;

main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>t[i];
		if(t[i]<0) tu++;
		else if(t[i]==0) tn++;
		else td++;
	}

	for(int i=0;i<m;i++){
		cin>>b[i];
		if(b[i]<0) bu++;
		else if(b[i]==0) bn++;
		else bd++;
	}
	sort(t,t+n);
	sort(b,b+m);

	//cout<<b[0]*t[1]<<" "<<b[m-1]*t[n-2]<<endl;
	cout<<max(b[0]*t[1],b[m-1]*t[n-2]);
}


#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
int t[60],b[60];

vector <int> ans;

 main() {
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>t[i];
	}

	for(int i=0;i<m;i++){
		cin>>b[i];
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			ans.push_back(t[i]*b[j]);
		}
	}
	sort(ans.begin(),ans.end());
	cout<<ans[ans.size()-2]<<endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
long long t[60],b[60];

main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>t[i];

	}

	for(int i=0;i<m;i++){
		cin>>b[i];

	}
	sort(t,t+n);
	sort(b,b+m);

	cout<<max(max(b[0]*t[1],b[m-1]*t[n-2]),min(b[0]*t[0],b[m-1]*t[n-1]));
}


#include <iostream>
#include <algorithm>
using namespace std;
long long t[60],b[60];

main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>t[i];

	}

	for(int i=0;i<m;i++){
		cin>>b[i];

	}
	sort(t,t+n);
	sort(b,b+m);

	cout<<max(max(b[0]*t[1],b[m-1]*t[n-2]),min(b[0]*t[0],b[m-1]*t[n-1])) ;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int t[60],b[60];
vector <int> ans;

int main() {
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>t[i];
	}

	for(int i=0;i<m;i++){
		cin>>b[i];
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			ans.push_back(t[i]*b[j]);
		}
	}
	sort(ans.begin(),ans.end());
	cout<<ans[ans.size()-2]<<endl;

	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long t[60],b[60];

main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>t[i];

	}

	for(int i=0;i<m;i++){
		cin>>b[i];

	}
	sort(t,t+n);
	sort(b,b+m);

	cout<<max(max(b[0]*t[1],b[m-1]*t[n-2]),min(b[0]*t[0],b[m-1]*t[n-1]));
}


#include <iostream>
#include <algorithm>
using namespace std;
int t[60],b[60],tu,td,tn,bu,bn,bd;

main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>t[i];
		if(t[i]<0) tu++;
		else if(t[i]==0) tn++;
		else td++;
	}

	for(int i=0;i<m;i++){
		cin>>b[i];
		if(b[i]<0) bu++;
		else if(b[i]==0) bn++;
		else bd++;
	}
	sort(t,t+n);
	sort(b,b+m);

	//cout<<b[0]*t[1]<<" "<<b[m-1]*t[n-2]<<endl;
	cout<<max(b[0]*t[1],b[m-1]*t[n-2]);
}


#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;
int n,m;
long long t[60],b[60];

main(){

	cin>>n>>m;
	for (int i=1;i<=n;i++)
          cin>>t[i];
	for (int i=1;i<=m;i++)
          cin>>b[i];
	long long ans=1LL<<60;

	for (int k=1;k<=n;k++)
	{
		long long Max=-1LL<<60;
		for (int i=1;i<=n;i++)
		if (i!=k)
			for (int j=1;j<=m;j++)
			{
				long long x=t[i]*b[j];
				if (x>Max) Max=x;
			}
		ans=min(Max,ans);
	}
	cout<<ans<<endl;
}


//In the name of God

#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ll n,m,a[100],b[100],c,d[2501],cnt=0,ans=-1e18;
    cin>>n>>m;
    for( ll i=0 ; i<n ; i++ ){
        cin>>a[i];
    }
    for( ll i=0 ; i<m ; i++ ){
        cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+m);
    for( ll i=0 ; i<n ; i++ ){
        for( ll j=0 ; j<m ; j++ ){
            c=a[i]*b[j];
            ans=max(ans,c);
        }
        d[cnt]=ans;
        ans=-1e18;
        cnt++;
    }
    sort(d,d+cnt);
    cout<<d[cnt-2];

}


//In The Name Of God
#include<bits/stdc++.h>

using namespace std;

int main(){
    long long n,m,a[60],b[60],c[3601],ans=0;
    cin>>n>>m;
    for( int i=0 ; i<n ; i++ ){
        cin>>a[i];
    }
    for( int i=0 ; i<m ; i++ ){
        cin>>b[i];
    }
    for( int i=0 ; i<n ; i++ ){
        for( int j=0 ; j<m ; j++ ){
            c[ans]=(a[i]*b[j]);
            ans++;
        }
    }
    sort(c,c+ans);
    cout<<c[ans-2];

}


//In the name of God
#include<iostream>
#include<algorithm>

using namespace std ;

int main()
{
    long long n,m,a[100],b[100],c[100],d[100],e[100];
    cin>>n>>m;
    for( int i=0 ; i<n ; i++ ){
        cin>>a[i];
    }
     for( int i=0 ; i<m ; i++ ){
        cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+m);
    for( int i=0 ; i<n ; i++ ){
        c[i]=a[i]*b[0];
    }
    for( int i=0 ; i<n ; i++ ){
        d[i]=a[i]*b[m-1];
    }
    e[0]=c[n-1];
    e[1]=d[n-1];
    e[2]=c[n-2];
    e[3]=d[n-2];
    sort(e,e+4);

    cout<<e[2]<<endl;
for( int i=0 ; i<n ; i++ ){
    cout<<e[i]<<" " ;
}

}


#include <iostream>
using namespace std;
int main()
{
    int n,k,o=0,a[102000];
    cin>>n>>k;
    bool ch=true;
    if(n==1)
    {
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i>k-1 && a[i]!=o && i)
            ch=false;
        o=a[i];
    }
    o=0;
    int i=n-2;
    while(a[i]==a[n-1])
        i--;
    i++;
    if(ch)
        cout<<i<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,k,l,o=0;
    cin>>n>>k;
    bool ch=true;
    if(n==1)
    {
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        cin>>l;
        if(i>k-1 && l!=o && i)
            ch=false;
        o=l;
    }
    if(ch)
        cout<<k-1<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,k,o=0,a[102];
    cin>>n>>k;
    bool ch=true;
    if(n==1)
    {
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i>k-1 && a[i]!=o && i)
            ch=false;
        o=a[i];
    }
    o=0;
    int i=n-2;
    while(a[i]==a[n-1])
        i--;
    i++;
    if(ch)
        cout<<i<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <deque>
using namespace std;
//ifstream cin("input.txt");
//ofstream cout("output.txt");
int n,k,i,j,b,e,kol;
deque <int> a;
bool prov(){
	if(kol>n){
		cout<<-1;
		exit(0);
	}
	for(int i = 0; i < n-1; i++){
		if(a[i] != a[i+1])
			return false;
	}
	return true;
}
int main(){
	cin>>n>>k;
	for (i =1 ; i <= n ;i ++){
		cin>>j;
		a.push_back(j);
	}
	b=1;
	e=n+1;
	while(!prov()){
		kol++;
		a.push_back(a[k-1]);
		a.pop_front();

	}
	cout<<kol;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <deque>
using namespace std;
//ifstream cin("input.txt");
//ofstream cout("output.txt");
int n,k,i,j,b,e,kol;
deque <int> a;
bool prov(){
	if(kol>n){
		cout<<-1;
		exit(0);
	}
	for(int i = 0; i < n-1; i++){
		if(a[i] != a[i+1])
			return false;
	}
	return true;
}
int main(){
	cin>>n>>k;
	for (i =1 ; i <= n ;i ++){
		cin>>j;
		a.push_back(j);
	}
	b=1;
	e=n+1;
	while(!prov()){
		kol++;
		a.push_back(a[k-1]);
		a.pop_front();

	}
	cout<<a[0];
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <deque>
using namespace std;
//ifstream cin("input.txt");
//ofstream cout("output.txt");
int n,k,i,j,b,e,kol;
deque <int> a;
bool prov(){
	if(kol>n){
		cout<<-1;
		exit(0);
	}
	for(int i = 0; i < n-1; i++){
		if(a[i] != a[i+1])
			return false;
	}
	return true;
}
int main(){
	cin>>n>>k;
	for (i =1 ; i <= n ;i ++){
		cin>>j;
		a.push_back(j);
	}
	b=1;
	e=n+1;
	while(!prov()){
		kol++;
		a.push_back(a[k-1]);
		a.pop_front();

	}
	for(i = 0 ;i < n ;i ++){
		cout<<a[i]<<" ";
	}
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <deque>
#include <set>
using namespace std;
//ifstream cin("input.txt");
//ofstream cout("output.txt");
int n,k,i,j,e,kol;
deque <int> a;
struct c{
	set <int> b;
	int ko[100001];
};
c f;
bool prov(){
	if(f.b.size()==1)
		return true;
	if(kol > n ){
		cout<<-1;
		exit(0);
	}
	return false;
}
int main(){
	cin>>n>>k;
	for (i =1 ; i <= n ;i ++){
		cin>>j;
		a.push_back(j);
		f.b.insert(a.back());
		f.ko[a.back()]++;
	}
	while(!prov()){
		kol++;
		a.push_back(a[k-1]);
		f.b.insert(a[k-1]);
		f.ko[a[k-1]]++;
		f.ko[a.front()]--;
		if(f.ko[a.front()]==0){
			f.b.erase(a.front());
		}
		a.pop_front();
	}
	cout<<kol;

    return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<unordered_map>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<tuple>
#include<map>
#include <new>
using namespace std;
void main()
{
	int n,i,k,c=0,num_of_moves=0,y=0;
	cin >> n>>k;
	vector<int> v(n),s(n);
	for (i = 0; i < n; i++)
	{
		cin >> v[i];
		if (i == k - 1)
			y = v[i];
		s[i] = v[i];
	}
	for (i = 0; i < k;i++)
	{
		c = count(v.begin(), v.end(), v[0]);
		if (c == n)
		{
			cout << num_of_moves << endl; return;
		}
		v.push_back(v[k-1]);
		v.erase(v.begin() + 0);
		if (v == s||y != v[k-1])
		{
			cout << -1 << endl; return;
		}
		num_of_moves++;
	}
	cout << -1 << endl;
}


#include<iostream>
#include<string>
#include<cstring>
#include<unordered_map>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<tuple>
#include<map>
#include <new>
using namespace std;
void main()
{
	int n,i,k,c=0,num_of_moves=0,y=0,num_co=0;
	cin >> n>>k;
	vector<int> v(n),s(n);
	for (i = 0; i < n; i++)
	{
		cin >> v[i];
		if (i == k - 1)
			y = v[i];
		s[i] = v[i];
	}
	c = count(v.begin()+k-1, v.end(), v[k-1]);
	if (c != (n - (k - 1)))
	{
		cout << -1 << endl; return;
	}
	for (i = k - 1; i >= 0; i--)
	{
		if (i == k - 1)
			continue;
		else if (v[i] != v[k - 1])
			break;
		else
			num_co++;
	}
	cout << n - (c + num_co) << endl;
}


#include<iostream>
#include<string>
#include<cstring>
#include<unordered_map>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<tuple>
#include<map>
#include <new>
using namespace std;
void main()
{
	int n,i,k,c=0,num_of_moves=0;
	cin >> n>>k;
	vector<int> v(n+1),s(n+1);
	for (i = 0; i < n; i++)
	{
		cin >> v[i];
		s[i] = v[i];
	}
	while (true)
	{
		c = count(v.begin(), v.end(), v[0]);
		if (c == n)
		{
			cout << num_of_moves << endl; break;
		}
		v.push_back(v[k - 1]);
		v.erase(v.begin() + 0);
		if (v == s)
		{
			cout << -1 << endl; break;
		}
		num_of_moves++;
	}
}


#include<iostream>
#include<string>
#include<cstring>
#include<unordered_map>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<tuple>
#include<map>
#include <new>
using namespace std;
void main()
{
	int n,i,k,c=0,num_of_moves=0;
	cin >> n>>k;
	vector<int> v(n),s(n);
	for (i = 0; i < n; i++)
	{
		cin >> v[i];
		s[i] = v[i];
	}
	for (i = 0; i < n;i++)
	{
		c = count(v.begin(), v.end(), v[0]);
		if (c == n)
		{
			cout << num_of_moves << endl; return;
		}
		v.push_back(v[k-1]);
		v.erase(v.begin() + 0);
		if (v == s)
		{
			cout << -1 << endl; return;
		}
		num_of_moves++;
	}
	cout << -1 << endl;
}