#include <bits/stdc++.h>
#include "robots.h"
using namespace std;
int a,b,t,x[1048576],y[1048576],w[1048576],s[1048576];
bool check(int tx)
{
int p=1;
int i=1;
while(i<=t&&p<=a)
{
if(w[min(i+tx-1,t)]<x[p])
{
i+=tx;
}
else
{
while(i<=t&&w[i]<x[p])i++;
}
p++;
}
if(p>a&&i<=t)return false;
return true;
}
int bin()
{
int l=1,r=t,mid,ans=-1;
while(l<=r)
{
mid=(l+r)/2;
if(check(mid))
{
ans=mid;
r=mid-1;
}
else l=mid+1;
}
return ans;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
a=A;
b=B;
t=T;
for(int i=0;i<a;i++)
{
x[i+1]=X[i];
}
sort(x+1,x+a+1);
for(int i=0;i<b;i++)
{
y[i+1]=Y[i];
}
sort(y+1,y+b+1);
for(int i=0;i<t;i++)
{
w[i+1]=W[i];
s[i+1]=S[i];
}
if(a+b==2&&t==2)
{
if(a==0)
{
sort(s+1,s+t+1);
if(y[1]>s[1]&&y[2]>s[2])return 1;
else if(y[2]>s[1]&&y[2]>s[2])return 2;
else return -1;
}
if(b==0)
{
sort(w+1,w+t+1);
if(x[1]>w[1]&&x[2]>w[2])return 1;
else if(x[2]>w[1]&&x[2]>w[2])return 2;
else return -1;
}
if((x[1]>w[1]&&y[1]>s[2])||(x[1]>w[2]&&y[1]>s[1]))return 1;
else if(x[1]>max(w[2],w[1])||y[1]>max(s[2],s[1]))return 2;
else return -1;
}
return bin();
}