#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef pair pii; typedef pair pll; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "< P; // 1 <= n <= 1e5 // 1 <= a_i <= 1e5 // b_i in {0,1} int n; vi as; vi g[100001]; bitset<200000> b; bitset<200000> tmp,res; int main(){ scanf("%d",&n); as.resize(n); REP(i,n){ int a; scanf("%d",&a); as[i] = a; g[a].push_back(i); } sort(ALL(as)); as.erase(unique(ALL(as)),as.end()); REP(i,n){ int x; scanf("%d",&x); if(x==1)b.set(i); } REP(i,as.size()){ int a = as[i]; bitset<200000> tmp; REP(j,g[a].size()){ int x = g[a][j]; tmp |= b<