#include using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N[4]; LL S; int A[4][600]; vector> X; vector> Y; const LL INF=1ll<<60; pair> constructans(int xp,int yp){ return {X[xp].first*Y[yp].first,{X[xp].second,Y[yp].second}}; } // x 以下を数える pair> search(LL x){ LL cnt=0; pair> ans={INF,{-1,-1}}; if(x>=0){ int j=Y.size(), k=Y.size(); rep(i,X.size()){ if(X[i].first<0){ while((j>0)?X[i].first*Y[j-1].first<=x:false) j--; cnt+=Y.size()-j; if(j>0) ans=min(ans,constructans(i,j-1)); } else if(X[i].first>0){ while((k>0)?X[i].first*Y[k-1].first>x:false) k--; cnt+=k; if(kx:false) j++; cnt+=Y.size()-j; if(j>0) ans=min(ans,constructans(i,j-1)); } else if(X[i].first>0){ while((k>N[i]; cin>>S; rep(i,4) rep(j,N[i]) cin>>A[i][j]; rep(i,N[0]) rep(j,N[1]) X.push_back({A[0][i]*A[1][j],i*600+j}); sort(X.begin(),X.end()); rep(i,N[2]) rep(j,N[3]) Y.push_back({A[2][i]*A[3][j],i*600+j}); sort(Y.begin(),Y.end()); LL l=-INF, r=INF; pair ans; while(r-l>1){ LL m=(l+r)/2; auto res=search(m); if(res.first