#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const int inf=1e9+7;
const ll INF=9e18/2;
const long double PI = acos(-1.0); 
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

vvin g;
int cnt[1000000];
int ans=0;

int N=660000;

void dfs2(int);
void dfs(int);

void dfs2 (int now){
  for(auto v:g[now])cnt[v]--;
  for(auto v:g[now])if(cnt[v]==1)dfs(v);
}

void dfs(int now){
  for(auto v:g[now]){
    if(cnt[v])continue;
    cnt[v]=1;
    ans++;
    dfs2(v);
  }
}
int main(){//cout<<fixed<<setprecision(20);
  int n;
  cin>>n;
  g.resize(N);
  rep(i,0,n){
    int a,b;
    cin>>a>>b;
    g[i].pb(a+n);
    g[i].pb(b+n);
    g[a+n].pb(i);
    g[b+n].pb(i);
    cnt[a+n]++;
    cnt[b+n]++;
  }
  rep(i,n+1,N)if(cnt[i]==1)dfs(i);
  rep(i,n+1,N)if(cnt[i])ans++;
  cout<<ans<<endl;
}
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 10000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct status {
	ll y;
	ll high;
	ll cost;

	bool operator<(const status& rhs) const { return cost < rhs.cost; };
	bool operator>(const status& rhs) const { return cost > rhs.cost; };
};


signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	//cout << fixed << setprecision(15);

	//input
	ll n;
	cin >> n;
	vector<ll> a(n), b(n), maa(n);
	rep(i, n) { cin >> a[i]; }
	rep(i, n) { cin >> b[i]; }
	rep(i, n) {
		if (i == 0) { maa[i] = a[i]; continue; }
		else { maa[i] = max(maa[i - 1], a[i]); }
	}
	ll ma = 0;
	rep(i, n) {
		ma = max(ma, maa[i] * b[i]);
		cout << ma << endl;
	}
	return 0;
}