#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(n);i++)
void chmax(ll& a, ll b) {if (b>a) a=b;}

int main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  rep(i,N) cin >> a[i];
  rep(i,N) cin >> b[i];
  ll ans = 0, maxa = 0;
  rep(i,N) {
    chmax(maxa, a[i]);
    chmax(ans, maxa*b[i]);
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main() {
  
  long long N;
  cin >> N;
  
  vector<long long> A(N);
  map<long long,long long> mpA;
  
  rep(i,N) {
    cin >> A[i];
    mpA[A[i]]++;
  }
  
  vector<pair<long long,long long>> B(N);
  rep(i,N) {
    B[i].first = A[i];
    B[i].second = mpA[A[i]];
  }
  sort(B.begin(), B.end());
  
  long long ans = 0LL;
  ans = N * (N-1LL) / 2LL;
  
  rep(i,N) {
    if(i>0 && B[i].first==B[i-1].first) continue;
    else if(B[i].second>=2) {
      ans -= B[i].second * (B[i].second-1LL) / 2LL;
    }
  }
  
  cout << ans << endl;
  
}