#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; vector a(n),b(n); for(int i = 0;i>a[i]; for(int i = 0;i>b[i]; vector> use; for(int i = 0;i now(n,0); int ans = 1e9; sort(use.begin(),use.end()); int l = 0,r = 0; while(l=r){ int ni = use[r].second; now[ni]++; if(now[ni]==1) cnt++; r++; } while(cnt!=n&&r