#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset>
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fio ios_base::sync_with_stdio(false)
#define li long long int  
#define ll long long int 
//#define readi(x) scanf("%lld",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%lld",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 100000000000000005
#define MINN -10000000000000000
#define INTMAX 1000001000
#define pii pair<li,li> 
#define pdd pair<double,double>
#define pic pair<int,char>
//#define N 5005
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
using namespace std;
//li bit[300004];
li mod=1000000007;
li mod2=998244353;

li pp(li a,li b,li modd){
    if(b==0) return(1);
    li ans=pp(a,b/2,modd);ans=(ans*ans)%modd;if(b%2) ans=(ans*a)%modd;return(ans);
}

li gcd(li a,li b){
    if(a<b) return(gcd(b,a));
    if(b==0) return(a);
    return(gcd(b,a%b));
}

vector<li> z_function(string s){
     li n=s.size();
     vector<li>z(n);
     for(li i=1,l=0,r=0;i<n;i++){
         if(i<=r){z[i]=min(r-i+1,z[i-l]);}
         while((i+z[i])<n && s[z[i]]==s[i+z[i]]){++z[i];}
         if((i+z[i]-1)>r){l=i;r=i+z[i]-1;}
     }
     return(z);    
}
/*vector<li>p(2005,0);
li parent(li a){
    if(p[a]==0 || p[a]==a){p[a]=a;return(a);}
    return(p[a]=parent(p[a]));
}

void unionn(li a,li b){p[a]=b;}*/

/*vector<pii>MM;li N;*/


li ff(li pos,li bit,vector<vector<pii>>& v,vector<li>& P,vector<li>& dp,li& n,vector<li>& C)
{
    if(pos>=n)
    {
        return(1);
    }
    if(dp[bit]!=-1) return(dp[bit]);
    li i,j,ans=0;
    for(i=0;i<n;i++)
    {
        if((bit>>i)&1){}
        else
        {
            for(j=i;j<n;j++)
            {
                P[j]++;
            }
            for(j=0;j<C[pos];j++)
            {
                if(P[v[pos][j].fi]>v[pos][j].sec)
                {
                    break;
                }
            }
            if(j>=C[pos])
            {
                ans=ans+ff(pos+1,bit|(1<<i),v,P,dp,n,C);
            }
            for(j=i;j<n;j++)
            {
                P[j]--;
            }
        }
    }
    dp[bit]=ans;
    return(ans);
}



int main(){
li i,j,a,b,c,d,g,h,k,m,n,q,s,t,x,y,z,X,Y,sz,st,end,mid,ans,W,pa,pb,l,r,p;
    string T,SN,S,TN;
    //char S1[100004];
    t=1;
    //readl(t);
    n=100005;
    /*vector<li>v(n+2,0);
    for(i=2;i<=n;i++)
    {
        if(v[i]==0)
        {
            for(j=i;j<=n;j+=i)
            {
                v[j]=i;
            }
            //cout<<v[i]<<" ";
        }
    }*/
    
    x=0;
    while(t--)
    {  
        readl(n);readl(m);
        //vector<li>A(n);
        //vector<li>L(n,-1);
        vector<vector<pii>>v(n+1);
        vector<li>C(n+1,0);
        for(i=0;i<m;i++)
        {
            readl(a);readl(b);readl(c);
            b--;
            v[a-1].pb({b,c});
            C[a-1]++;
        }
        vector<li>P(n,0);
        vector<li>dp((1<<n)+2,-1);
        ans=ff(0,0,v,P,dp,n,C);
        cout<<ans<<endl;
       //x++;   
       //cout<<"Case #"<<x<<": "<<    
    }
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ATwoSequences2 {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> a(N), b(N);
        REP(i, N) cin >> a[i];
        REP(i, N) cin >> b[i];

        int maxa = 0;
        int cur = 0;
        REP(i, N) {
            maxa = max(maxa, a[i]);
            cur = max(cur, b[i] * maxa);
            cout << cur << endl;
        }

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ATwoSequences2 solver;
    solver.solve(in, out);
    return 0;
}
