#include <bits/stdc++.h>      
using namespace std;            

#define  int               long long int
#define  ld                long double
#define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)           for(int i = n; i >= j; i--)
#define  all(container)       container.begin() , container.end()
#define  sz(container)        (int)container.size()
#define  ff                first
#define  ss                second
#define  pii               pair <int , int>
#define  sp(x)              setprecision(x)
#define  mod              1000000007
#define  endl            "\n"
#define  pb              push_back
#define  mp             make_pair
#define  T             int ttt; cin >> ttt; while(ttt--)
#define fast           ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int32_t main()
{
    fast
    int n;  cin>>n;
    int a[n+1],b[n+1];
    f(i,1,n)    cin>>a[i];
    f(i,1,n)    cin>>b[i];
    int ans=0,id=0;
    f(i,1,n){
        id=max(id,a[i]);
        ans=max(ans,id*b[i]);
        cout<<ans<<endl;
    }
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+10;
struct BIT{
	int n,tr[N];
	void init(int _n){
		n=_n;
		memset(tr,0,sizeof tr);
	}
	void add(int x,int v){
		for(int i=x;i<=n;i+=i&-i)
		tr[i]+=v;
	}
	int sum(int x){
		int ans=0; 
		for(int i=x;i;i-=i&-i)
		ans+=tr[i];
		return ans;
	}
}tr;
int n,a[N];
ll ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		a[i]++;
	}
	tr.init(n+2);
	for(int i=1;i<=n;++i){
		int v=i-1-tr.sum(a[i]);
		ans+=v;
		tr.add(a[i],1);
	}
	for(int i=1;i<=n;++i){
		printf("%lld\n",ans);
		tr.add(a[i],-1);
		int v=tr.sum(a[i]);
		ans-=v;
		v=tr.sum(n+2)-tr.sum(a[i]);
		ans+=v;
		tr.add(a[i],1);
	}
	return 0;
}