#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
//#include<atcoder/all>
//using namespace atcoder;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
typedef __int128_t llint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
//vector<int> bucket[MAX_N/1000];
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;

lint inverse(int *A,int N){
  lint ans=0;
  lint a[N+1000]={};
  rep(i,N){
    for(int j=A[i];j;j-=(j&(-j))) ans-=a[j];ans+=i;
    for(int j=A[i];j<=N;j+=(j&(-j))) a[j]++;
  }
  return ans;
}

int main(void){
    lint N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i],A[i]++;
    lint ans=inverse(A,N);
    cout << ans << endl;
    rep(i,N-1){
        ans+=N+1-A[i]*2;
        cout << ans << 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;
}