//#define _GLIBCXX_DEBUG #include using namespace std; #define endl '\n' #define lfs cout<= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9+7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair; template bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} template bool chmax(T1 &a,T2 b){if(a void ans(bool x,T1 y,T2 z){if(x)cout< void debug(vector>&v,ll h,ll w){for(ll i=0;i&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cout< vector>vec(ll x, ll y, T w){ vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vectordx={1,-1,0,0,1,1,-1,-1}; vectordy={0,0,1,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } template ostream &operator<<(ostream &os, const pair&p){ return os << p.first << " " << p.second; } //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); struct SCC{ ll n; vector>G,Gr; vectorindex;//各ノードが属する強連結成分の番号 vectorret;//dfsに使う SCC(vector>g):G(g),n(g.size()){ index.assign(n,-1LL); build(); } void build(){ Gr.assign(n,vector()); for(ll i=0;i>edges; void build_edges(){ edges.assign(*max_element(ALL(index))+1,vector()); for(ll i=0;ioutput(){return index;}; }; struct TwoSat{ ll n; vector>g; TwoSat(ll N):n(N){ g.assign(2*n,vector()); } void add_or(ll x,ll y){ g[(x+n)%(2*n)].PB(y); g[(y+n)%(2*n)].PB(x); } vectorans; bool solve(bool isConstruct = false){ SCC scc(g); for(ll i=0;i scc.index[i+n]); } return true; } }; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res=0,buf=0; bool judge = true; ll n;cin>>n; TwoSat sat(n*n); vectors(n),t(n),u(n); rep(i,0,n)cin>>s[i],s[i]--; rep(i,0,n)cin>>t[i],t[i]--; rep(i,0,n)cin>>u[i]; rep(i,0,n){ rep(j,0,n){ sat.add_or(s[i]*n+j+n*n*!!(u[i]&1),j*n+t[i]+n*n*!!(u[i]&2)); } } if(!sat.solve(true)){ cout<<-1<i*n+j); cout<