#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int n; cin>>n; vector a(n),b(n); rep(i,n)cin>>a[i]; rep(i,n)cin>>b[i]; vector c(n); scc_graph S(n); rep(i,n){ cin>>c[i]; c[i]--; S.add_edge(c[i],i); } auto s = S.scc(); vector pos(n); vector aa(s.size()),bb(s.size()); vector> E(s.size()); rep(i,s.size()){ rep(j,s[i].size()){ pos[s[i][j]] = i; aa[i] += a[s[i][j]]; bb[i] += b[s[i][j]]; //cout<1LL){ long long mid =(ok+ng)/2; bool f = true; auto ta = aa,tb = bb; rep(i,s.size()){ __int128 t = bb[i]; t *= mid; if(t>ta[i]){ f = false; break; } ta[i] -= t; rep(j,E[i].size()){ ta[E[i][j]] += ta[i]; } } if(f)ok = mid; else ng = mid; } cout<