/** Fucc :/
 - doanphuc : /
	** author: doanphuc. **
**/
#include <bits/stdc++.h>
#define TASK ""
#define inpf freopen(TASK".inp", "r", stdin)
#define outf freopen(TASK".out", "w", stdout)
#define FOR(i,x,y) for(int i = x; i <= y ; i ++)
#define FORT(i,x,y) for(int i = x; i < y ; i ++)
#define FORD(i,x,y) for(int i = x; i >= y ; i --)
#define clean(x) memset(x, 0, sizeof(x))
#define F first
#define S second
#define maxn 3000005
#define pii pair<ll,ll>
#define ll long long
#define pb push_back
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define all(x) (x).begin(), (x).end()
#define pia pair<pii, int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std; const ll MOD = 1e9 + 7 ;
ll n, a[maxn], b[maxn], gt[maxn], d[maxn] ;
int main()
{
    cin >> n;
    FOR(i, 1, n) cin >> a[i] ; FOR(i, 1, n) cin >> b[i] ;
    ll res = 0 ;
    FOR(i, 1, n)
    {
        res = max(res, a[i]) ; gt[i] = res ;
    }
    res = 0 ;
    FOR(i, 1, n)
    {
        ll x = b[i] * gt[i] ;
        if(x > res) res = x ;
        d[i] = res ;
    }
    FOR(i, 1, n) cout << d[i] << endl ;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
// const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L
// static const double e = 2.718281828459045;
//cout << fixed << setprecision(10) << ans << endl;
vector<ll> A, B;
struct UnionFind {
    vector<int> par, rnk, mem;
    vector<ll> sum_a, sum_b;
    UnionFind(int n) {
        par.resize(n); fill(par.begin(), par.end(), -1);
        rnk.resize(n); fill(rnk.begin(), rnk.end(),  0);
        mem.resize(n); fill(mem.begin(), mem.end(),  1);
        sum_a.resize(n);
        rep(i, n) sum_a[i] = A[i];
        sum_b.resize(n);
        rep(i, n) sum_b[i] = B[i];
    }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    void merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return;
        if (rnk[x] < rnk[y]) {
            par[x] = y; mem[y] += mem[x];
            sum_a[y] += sum_a[x];
            sum_b[y] += sum_b[x];
        } else {
            par[y] = x; mem[x] += mem[y];
            sum_a[x] += sum_a[y];
            sum_b[x] += sum_b[y];
            if (rnk[x] == rnk[y]) rnk[x]++;
        }
    }
    int size(int x) {
        return mem[root(x)];
    }
    ll size_a(int x) {
        return sum_a[root(x)];
    }
    ll size_b(int x) {
        return sum_b[root(x)];
    }
};


int main() {
    int N, M; cin >> N >> M;
    A.resize(N); B.resize(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    
    UnionFind uf(N);
    rep(i, M) {
        int c, d; cin >> c >> d; c--; d--;
        uf.merge(c, d);
    }
    int flg = 1;
    rep(i, N) {
        if (uf.size_a(i) != uf.size_b(i)) flg = 0;
    }
    if (flg == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}