stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<queue>

#include<vector>

#define pb push_back

using namespace std;

const int N=2100;

priority_queue<int> Q;

vector<int> E[N],W[N];

int n,a[N],d[N],vis[N];

void dfs(int x)

{

	vis[x]=1;

	for(auto R:E[x]) if(!vis[R]) W[x].pb(R);

	for(auto R:E[x]) if(!vis[R]) dfs(R);

}

int main()

{

	cin>>n;

	for(int i=1;i<=n;i++) cin>>a[i];

	sort(a+1,a+n+1);

	for(int i=1;i<=n;i++)

		for(int j=i+1;j<=n;j++)

			if(__gcd(a[i],a[j])>1) E[i].pb(j),E[j].pb(i);

	for(int i=1;i<=n;i++) sort(E[i].begin(),E[i].end());

	for(int i=1;i<=n;i++) if(!vis[i]) dfs(i);

	for(int i=1;i<=n;i++) for(auto R:W[i]) d[R]++;

	for(int i=1;i<=n;i++) if(!d[i]) Q.push(i);

	while(!Q.empty())

	{

		int x=Q.top();Q.pop();

		printf("%d ",a[x]);

		for(auto R:W[x])

			if(--d[R]==0) Q.push(R);

	}

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<queue>

#include<vector>

using namespace std;

const int N=2333;

int a[N];

int g[N][N];

int n;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

struct sumireko{int to,ne;}e[N*1000];

int he[N],ecnt;

void addline(int f,int t)

{

	e[++ecnt].to=t;

	e[ecnt].ne=he[f];

	he[f]=ecnt;

}



bool vv[N];

int bi;

int sp[N];

vector<int> to[N];

void dfs(int x)

{

	vv[x]=1;

	for(int i=he[x],t;i;i=e[i].ne)

	{

		t=e[i].to;

		if(!vv[t])

		{

			to[x].push_back(t);

			dfs(t);

		}

	}

}



priority_queue<int> q;



int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	sort(a+1,a+1+n);

	for(int i=n;i;i--)

		for(int j=i-1;j;j--)

			if(gcd(a[i],a[j])!=1)

				addline(i,j),addline(j,i)/*,printf("line %d %d\n",i,j)*/;

	for(int i=1;i<=n;i++) if(!vv[i])

	{

		bi++;

		sp[bi]=i;

		dfs(i);

	}

	/*printf("%d\n",bi);

	for(int i=1;i<=bi;i++) printf("%d ",sp[i]);

	puts("\n----------------------------------");

	for(int i=1;i<=n;i++)

	{

		printf("%d:",i);

		for(int j=0;j<to[i].size();j++) printf("%d ",to[i][j]);

		putchar('\n');

	}

	puts("\n----------------------------------");*/

	for(int i=1;i<=bi;i++)

		q.push(sp[i]);

	while(!q.empty())

	{

		int g=q.top();

		q.pop();

		printf("%d ",a[g]);

		for(int i=0;i<to[g].size();i++) q.push(to[g][i]);

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define mp make_pair

#define pb push_back

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef vector<int > vi;

typedef pair<int ,int > pii;

typedef vector<pii> vii;

const int inf=0x3f3f3f3f, maxn=100007, mod=1e9+7;

const ll linf=0x3f3f3f3f3f3f3f3fLL;

int n,a[2007];

vi e[2007];

vi e2[2007];

bool vis[2007];

int deg[2007];

void dfs(int x){

	if(vis[x])return ;

	vis[x]=true;

	for(int i=0;i<e[x].size();i++){

		if(!vis[e[x][i]]){

			e2[x].pb(e[x][i]);

			deg[e[x][i]]++;

			dfs(e[x][i]);

		}

	}

}

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++)scanf("%d",&a[i]);

	sort(a+1,a+n+1);

	for(int i=1;i<=n;i++){

		for(int j=i+1;j<=n;j++){

			if(__gcd(a[i],a[j])>1)e[i].pb(j),e[j].pb(i);

		}

	}

	for(int i=1;i<=n;i++)sort(e[i].begin(),e[i].end());

	for(int i=1;i<=n;i++)if(!vis[i])dfs(i);

	memset(vis,0,sizeof(vis));

	for(int i=1;i<=n;i++){

		for(int j=n;j>=1;j--){

			if(!deg[j]&&!vis[j]){

				vis[j]=true;

				printf("%d ",a[j]);

				for(int k=0;k<e2[j].size();k++)deg[e2[j][k]]--;

				break;

			}

		}

	}

	

	return 0;

}


// Optimized solution to the same problem (faster):
// =================================

//   author: M_sea

//   website: http://m-sea-blog.com/

// =================================

#include <algorithm>

#include <iostream>

#include <cstdlib>

#include <cstring>

#include <cstdio>

#include <cmath>

#include <queue>

#define re register

using namespace std;



inline int read() {

    int X=0,w=1; char c=getchar();

    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }

    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();

    return X*w;

}



const int N=2000+10;



struct Edge { int v,nxt; } e[N];

int head[N];



inline void addEdge(int u,int v) {

    static int cnt=0;

    e[++cnt]=(Edge){v,head[u]},head[u]=cnt;

}



int n;

int a[N],vis[N],deg[N];

int G[N][N];



inline void dfs(int u) {

    vis[u]=1;

    for (re int i=1;i<=n;++i) {

        if (vis[i]||!G[u][i]) continue;

        ++deg[i],addEdge(u,i);

        dfs(i);

    }

}



inline void topsort() {

    priority_queue<int> Q;

    for (re int i=1;i<=n;++i)

        if (!deg[i]) Q.push(i);

    while (!Q.empty()) {

        int u=Q.top(); Q.pop();

        printf("%d ",a[u]);

        for (re int i=head[u];i;i=e[i].nxt) Q.push(e[i].v);

    }

}



int main() {

    n=read();

    for (re int i=1;i<=n;++i) a[i]=read();

    sort(a+1,a+n+1);

    for (re int i=1;i<=n;++i)

        for (re int j=i+1;j<=n;++j) {

            if (__gcd(a[i],a[j])==1) continue;

            G[i][j]=G[j][i]=1;

        }

    for (re int i=1;i<=n;++i)

        if (!vis[i]) dfs(i);

    topsort();

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef pair<int, int> PII;



const int MM = 1e9 + 7;

const double eps = 1e-8;

const int MAXN = 2e6 + 10;



int n, m;



void prework(){



}



void read(){



}



class BITree{

public:

    static const int SIZE = 100010, BIAS = 5;

    long long u[SIZE];

    void clear(){

        memset(u,0,sizeof(u));

    }

    void modify(int x, long long v){

        for(x+=BIAS;x<SIZE;x+=x&-x) u[x]+=v;

    }

    long long getsum(int x){

        long long s=0;

        for(x+=BIAS;x;x-=x&-x) s+=u[x];

        return s;

    }

} hnk;



int a[MAXN];

int f[MAXN];

ll g[MAXN];



void solve(int casi){

	scanf("%d", &n);

	map<int, int> nico;

	for(int i = 1; i <= n; i++){

		scanf("%d", &a[i]);

		nico[a[i]] = 1;

	}

	int cnt = 0;

	for(auto &x : nico){

		x.second = ++cnt;

	}

	

//	for(auto &x : nico){

//		cout<<x.first<<' '<<x.second<<endl;

//	}

	

	hnk.clear();

	for(int i = 1; i <= n; i++){

		hnk.modify(1, 1);

		hnk.modify(nico[a[i]] + 1, -1);

	}

	cnt = 0;

	for(auto &x : nico){

		++cnt;

		f[cnt] = x.first;

		g[cnt] = hnk.getsum(x.second);

	}

	f[0] = 0;

	/*

	for(int i = 1; i <= cnt; i++){

		cout<<f[i]<<' ';

	} cout<<endl;

	for(int i = 1; i <= cnt; i++){

		cout<<g[i]<<' ';

	} cout<<endl;

	*/for(int i = 1, j = 1; i <= n; i++){

		ll ans = 0;

		while(j <= cnt && a[i] >= f[j]){

			ans += g[j] * (f[j] - f[j-1]);

			j++;

		}

		printf("%lld\n", ans);

	}

}



void printans(){



}





int main(){

	prework();

	int T = 1;

//	cin>>T;

	for(int i = 1; i <= T; i++){

		read();

		solve(i);

		printans();

	}

	return 0;

}






// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

#define MN 100005

using namespace std;

inline int in(){

    int x=0;bool f=0; char c;

    for (;(c=getchar())<'0'||c>'9';f=c=='-');

    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');

    return f?-x:x;

}

int st[MN],sum[MN],a[MN],b[MN],pos[MN],dif[MN];

int n,top,mx,cnt,cur;

ll res,ans[MN];

int main()

{

	n=in();top=0;st[top]=0;

	for (int i=1;i<=n;++i) a[i]=b[i]=in();b[n+1]=0x7fffffff;

	for (int i=1;i<=n;++i) if (!top||a[i]>a[st[top]]) st[++top]=i;

	sort(b+1,b+n+1);cnt=unique(b+1,b+n+1)-b-1;b[cnt+1]=0x7fffffff;

	for (int i=1;i<=n;++i) pos[i]=lower_bound(b+1,b+cnt+1,a[i])-b,++sum[pos[i]],mx=max(mx,pos[i]);

	for (int i=1;i<=cnt;++i) dif[i]=b[i]-b[i-1];

	for (int i=mx;i>=0;--i){

		sum[i]+=sum[i+1];res=1ll*dif[i]*sum[i];

		if (pos[st[top]]==i) cur=st[top],--top;ans[cur]+=res;

	}ans[1]+=ans[0]; 

	for (int i=1;i<=n;++i) printf("%lld\n",ans[i]);return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define name ""

#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)

#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)

#define long long long 

#define db double 

#define pii pair <int, int>

#define pll pair <long, long>

#define all(c) c.begin(), c.end()

#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)



const int INF = 1e9+7;

const int MOD = 1e9+7;

const int dx[4] = {0,0,-1,1};

const int dy[4] = {-1,1,0,0};



const int N = 1e5+1;



int n, a[N], val[N], b[N];

long res[N];

vector <int> pos[N];



int main()

{

	fastio;

	cin >> n;

	for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];

	sort(a + 1, a + 1 + n);

	for (int i = 1; i <= n; i++){

		int x = lower_bound(a + 1, a + 1 + n, b[i]) - a;

		val[x] = b[i];

		pos[x].push_back(i);

	}

	int pre = -INF, x = INF;

	long cnt = 0;

	for (int i = n; i >= 0; i--){

		if (i == 0){

			res[x] += cnt * pre;

			break;

		}

		if (pos[i].size() == 0) continue;

		if (pre == -INF){

			x = pos[i][0];

			pre = val[i];

			cnt += pos[i].size();

		}	

		else {

			res[x] += cnt * (pre - val[i]);

			if (pos[i][0] < x) x = pos[i][0];

			cnt += pos[i].size();

			pre = val[i];

		}

	}

	for (int i = 1; i <= n; i++) cout << res[i] << '\n';

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

typedef pair<int, int> pii;

int a[100005];

LL ans[100005];

pii p[100005];

int main(){

    int n;

    scanf("%d", &n);

    for(int i=1;i<=n;i++){

        scanf("%d", &a[i]);

        p[i] = pii(a[i], -i);

    }

    p[n+1] = pii(0, 0);

    sort(p+1, p+1+n);

    reverse(p+1, p+1+n);



    int mn = 1e9;

    for(int i=1;i<=n;i++){

        mn = min(mn, -p[i].second);

        if(a[-p[i].second] != a[-p[i+1].second]){

            int d = a[-p[i].second]-a[-p[i+1].second];

            ans[mn] += d*1ll*i;

        }

    }

    for(int i=1;i<=n;i++) printf("%lld\n", ans[i]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define Rep(i, N) for(int i = 0; i < N; i++)

#define Reps(i, x, N) for(int i = x; i < N; i++)

typedef pair<int, int> Pi;

#define fi first

#define se second



const int LLINF = 1LL << 60;



signed main()

{

  int N;

  Pi A[100005];

  int out[100005] = {0};



  cin >> N;

  A[N].fi = 0, A[N].se = -1;

  Rep(i, N) {

    cin >> A[i].fi; A[i].se = i;

  }



  sort(A, A + N + 1, greater< Pi >());



  int minv = LLINF;

  int i = 0;

  while(i < N) {

    int save = A[i].fi;

    while(save == A[i].fi && i < N) i++;

    minv = min(A[i - 1].se, minv);

    //cout << i << " " << minv << " " << A[i - 1].fi << endl;

    out[minv] += i * (A[i - 1].fi - A[i].fi);

  }



  Rep(i, N) {

    cout << out[i] << endl;

  }



  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



using ll = long long;

using Pi = pair<int, int>;

using Pl = pair<ll, ll>;

using vint = vector<int>;

using vll = vector<ll>;

template<typename T> using uset = unordered_set<T>;

template<typename T1, typename T2> using umap = unordered_map<T1, T2>;



constexpr int INF = (1 << 30) - 1;

constexpr ll LLINF = 1LL << 60;

constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};

constexpr char el = '\n';

constexpr int mod = 1000000007;



template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }

template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }

template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }



int main() {

        ll N;

        ll ans[100005] = {};

        map<ll,Pl> mp;



        cin >> N;

        for (ll i = 1; i <= N; i++) {

                ll a;

                cin >> a;

                if (mp.find(a) == mp.end()) mp[a].first = i;

                mp[a].second++;

        }



        ll total = 0;

        ll minv = N;

        for (auto itr = mp.rbegin(); itr != mp.rend(); itr++) {

                auto v = *itr;

                auto it2 = itr;

                it2++;



                ll prev;

                if (it2 == mp.rend()) prev = 0;

                else prev = it2->first;



                total += v.second.second; 

                minv = min(minv, v.second.first);

                ans[minv] += total * (v.first - prev);

        }



        for (ll i = 1; i <= N; i++) {

                cout << ans[i] << el;

        }



        return (0);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=100002;

struct node{

	int x,id;

}a[N];

int n,i,id[N],cnt,b[N],mx[N];

ll ans[N];

inline char gc(){

	static char buf[100000],*p1=buf,*p2=buf;

	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;

}

inline int rd(){

	int x=0,fl=1;char ch=gc();

	for (;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;

	for (;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);

	return x*fl;

}

inline void wri(ll a){if(a<0)a=-a,putchar('-');if(a>=10)wri(a/10);putchar(a%10|48);}

inline void wln(ll a){wri(a);puts("");}

bool cmp(node a,node b){return a.x<b.x || a.x==b.x && a.id<b.id;}

int main(){

	n=rd();

	for (i=1;i<=n;i++) a[i].x=rd(),a[i].id=i;

	sort(a+1,a+n+1,cmp);

	id[++cnt]=a[1].id;b[1]=1;mx[1]=a[1].x;

	for (i=2;i<=n;i++)

		if (a[i].x==a[i-1].x) b[cnt]++;

		else id[++cnt]=a[i].id,b[cnt]=1,mx[cnt]=a[i].x;

	for (i=cnt;i;i--) ans[id[i]]+=1ll*b[i]*(mx[i]-mx[i-1]),b[i-1]+=b[i],id[i-1]=min(id[i-1],id[i]);

	for (i=1;i<=n;i++) wln(ans[i]);

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <cstring>

#include <algorithm>

int read(){

	register int x = 0;

	register char f = 1, ch = getchar();

	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = 0;

	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');

	return f ? x : -x;

}

int n;

struct node{

	int val, id;

	bool operator < (const node &b) const {

		return val > b.val || val == b.val && id < b.id;

	}

}a[100005];

long long ans[100005];

int main(){

	n = read();

	for (register int i = 1; i <= n; ++i) a[i] = (node){read(), i};

	std :: sort(a + 1, a + 1 + n);

	for (register int i = 1, j, k = 0x3f3f3f3f; i <= n; i = j){

		for (j = i; j <= n && a[j].val == a[i].val; ++j) ;

		k = std :: min(k, a[i].id);

		ans[k] += 1ll * (j - 1) * (a[i].val - a[j].val);

	}

	for (register int i = 1; i <= n; ++i) printf("%lld\n", ans[i]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")

#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>

#define For(i,j,k)	for(int i=j;i<=k;++i)

#define Dow(i,j,k)	for(int i=k;i>=j;--i)

#define ll long long

#define int ll

#define pb push_back





using namespace std;



inline ll read()

{

    ll t=0,dp=1;char c=getchar();

    while(!isdigit(c))	{if(c=='-')	dp=-1;c=getchar();}

    while(isdigit(c))	t=t*10+c-48,c=getchar();

    return t*dp;

}

inline void write(ll x){if(x<0)	{putchar('-');x=-x;}	if(x>=10)	write(x/10);putchar(x%10+48);}

inline void writeln(ll x){write(x);puts("");}

inline void write_p(ll x){write(x);putchar(' ');}

/*------------------------------------------------------------------------------------------------------*/



const int N=1e5+5;	

int n;

struct node{int v,num;}	p[N];

int ans[N];

inline bool cmp(node x,node y){return x.v!=y.v?x.v>y.v:x.num<y.num;}

signed main()

{

	n=read();

	For(i,1,n)	p[i].v=read(),p[i].num=i;

	sort(p+1,p+n+1,cmp);

	int now=1,to=p[1].num;

//	For(i,1,n)	cout<<p[i].v<<' '<<p[i].num<<endl;

	For(i,2,n+1)

	{

		ans[to]+=(p[i-1].v-p[i].v)*now,now++;

		to=min(to,p[i].num);

	}

//	ans[to]=(p[n].v-p[n+1].v)*now,now++;

	For(i,1,n)	writeln(ans[i]);

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <cstring>

#include <algorithm>

int read(){

	register int x = 0;

	register char f = 1, ch = getchar();

	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = 0;

	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');

	return f ? x : -x;

}

int n;

struct node{

	int val, id;

	bool operator < (const node &b) const {

		return val > b.val || val == b.val && id < b.id;

	}

}a[100005];

long long ans[100005];

int main(){

	n = read();

	for (register int i = 1; i <= n; ++i) a[i] = (node){read(), i};

	std :: sort(a + 1, a + 1 + n);

	for (register int i = 1, j, k = 0x3f3f3f3f; i <= n; i = j){

		for (j = i; j <= n && a[j].val == a[i].val; ++j) ;

		k = std :: min(k, a[i].id);

		ans[k] += 1ll * (j - 1) * (a[i].val - a[j].val);

	}

	for (register int i = 1; i <= n; ++i) printf("%lld\n", ans[i]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<vector>

#define LL long long

using namespace std;

const int maxn=1e5+10;

struct node

{

    LL pos,val;

} a[maxn];

bool cmp(node a,node b)

{

    if(a.val==b.val)return a.pos<b.pos;

    return a.val>b.val;

}

int n;

LL ans[maxn];

int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        memset(ans,0,sizeof ans);

        for(int i=1; i<=n; i++)

        {

            scanf("%lld",&a[i].val);

            a[i].pos=i;

        }

        sort(a+1,a+n+1,cmp);

        a[n+1].val=0;

        LL tmp=1;

        int num=a[1].pos;

        for(int i=2; i<=n+1; i++)

        {

            if(a[i].val==a[i-1].val) tmp++;

            else ans[num]+=(a[i-1].val-a[i].val)*tmp,tmp++;

            if(a[i].pos<num) num=a[i].pos;

        }

        for(int i=1;i<=n;i++)printf("%lld\n",ans[i]);

    }

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <cstring>

#include <algorithm>

int read(){

	register int x = 0;

	register char f = 1, ch = getchar();

	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = 0;

	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');

	return f ? x : -x;

}

int n;

struct node{

	int val, id;

	bool operator < (const node &b) const {

		return val > b.val || val == b.val && id < b.id;

	}

}a[100005];

long long ans[100005];

int main(){

	n = read();

	for (register int i = 1; i <= n; ++i) a[i] = (node){read(), i};

	std :: sort(a + 1, a + 1 + n);

	for (register int i = 1, j, k = 0x3f3f3f3f; i <= n; i = j){

		for (j = i; j <= n && a[j].val == a[i].val; ++j) ;

		k = std :: min(k, a[i].id);

		ans[k] += 1ll * (j - 1) * (a[i].val - a[j].val);

	}

	for (register int i = 1; i <= n; ++i) printf("%lld\n", ans[i]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// AtCoder Regular Contest 069

// E - Frequency



#include <cstdio>

#include <cstring>

#include <queue>

#define MAX_N 100000

using namespace std;

typedef long long int ll;

typedef pair<ll, int> PLI;





int N;

priority_queue<PLI> q;

ll ans[MAX_N];



int main() {



  PLI p;

  ll a, cnt;

  int min_i;



  scanf("%d", &N);

  q.push(PLI(0, -1));

  for (int i = 0; i < N; i++) {

    scanf("%lld", &a);

    q.push(PLI(a, i));

  }

  memset(ans, 0, sizeof(ans));



  min_i = N;

  cnt = 0;

  while (q.size() > 1) {

    p = q.top(); q.pop();

    min_i = min(min_i, p.second);

    ans[min_i] += (p.first - q.top().first) * (cnt + 1);

    cnt++;

  }



  for (int i = 0; i < N; i++) {

    printf("%lld\n", ans[i]);

  }



  return 0;



}






// Optimized solution to the same problem (faster):
// AtCoder Regular Contest 069

// E - Frequency



#include <cstdio>

#include <cstring>

#include <algorithm>

#define MAX_N 100000

using namespace std;

typedef long long int ll;

typedef pair<ll, int> PLI;





int N;

PLI m[MAX_N + 1];

ll ans[MAX_N];



int main() {



  ll cnt;

  int min_i;



  scanf("%d", &N);

  for (int i = 0; i < N; i++) {

    scanf("%lld", &m[i].first);

    m[i].second = i;

  }

  m[N] = PLI(0, -1);

  memset(ans, 0, sizeof(ans));

  sort(m, m + N + 1);



  min_i = N;

  cnt = 0;

  for (int i = N; i > 0; i--) {

    min_i = min(min_i, m[i].second);

    ans[min_i] += (m[i].first - m[i - 1].first) * (cnt + 1);

    cnt++;

  }



  for (int i = 0; i < N; i++) {

    printf("%lld\n", ans[i]);

  }



  return 0;



}






// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define REP(i,a,b) for(int i=(a);i<(b);i++)

#define RREP(i,a,b) for(int i=(a);i>=(b);i--)

#define pq priority_queue

#define P pair<int,int>

#define P2 pair<int,P>

#define P3 pair<int,P2>

typedef long long ll; typedef long double ld;

using namespace std;

const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};

const ll LINF=1e18;

const ld PI=abs(acos(-1));



int a[100010];

vector<P> vec;



int main(){

	int n; cin >> n;

	REP(i,0,n) cin >> a[i], vec.push_back({a[i], i});

	vec.push_back({0, n});

	sort(vec.rbegin(), vec.rend());

	

	ll mi = n, li[100010] = {};

	REP(i,0,n){

		mi = min<ll>(mi, vec[i].second);

		li[mi] += (ll)(i+1) * (vec[i].first - vec[i+1].first);

	}

	

	REP(i,0,n) cout << li[i] << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using std::cout;

using std::endl;

using std::cin;



int main(){

	int n; cin >> n;

	std::priority_queue<std::pair<long, int>> qu;

	for(int i = 0; i < n; i++){

		int a; cin >> a;

		

		qu.push({a, i});

	}

	qu.push({0, n});

	

	std::vector<long> ans(n, 0); long c = 1; int pos = 1e9;

	while(!qu.empty()){

		auto p = qu.top(); qu.pop();

		auto q = qu.top();

		

		pos = std::min(pos, p.second);

		

		long dist = p.first - q.first;

		ans[pos] += dist * c; c++;

	}

	

	for(int i = 0; i < n; i++) cout << ans[i] << endl;

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

typedef long long ll;

typedef double db;

#define pa pair<int,int>

#define mk make_pair

#define LOG(format, args...) fprintf(stderr, format, args)

using namespace std;

inline int rd() {

	int x=0,f=1;char ch=getchar();

	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;

	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';

	return x*f;

}

const int MAXN=5e5+100;

ll N,a[MAXN];

ll l[MAXN];

ll but[MAXN],idx[MAXN];

ll ans[MAXN];

//main========================

int main() {

	memset(idx,0x3f,sizeof idx);

	N=rd();

	for(int i=1;i<=N;++i) a[i]=rd(),l[++*l]=a[i];

	sort(l+1,l+*l+1);

	*l=unique(l+1,l+*l+1)-l-1;

	for(int i=1;i<=N;++i) a[i]=lower_bound(l+1,l+*l+1,a[i])-l;

	for(int i=1;i<=N;++i) but[a[i]]++,idx[a[i]]=min((ll)i,idx[a[i]]);

	for(int i=*l;i>=1;--i) if(but[i]) {

		but[i-1]+=but[i];

		idx[i-1]=min(idx[i],idx[i-1]);

		ans[idx[i]]+=(ll)(l[i]-(i>1?l[i-1]:0) )*but[i];

	} 

	for(int i=1;i<=N;++i) printf("%lld\n",ans[i]);

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#define int long long

using namespace std;

struct arr

  {

   int aa,bb;

  }a[100010];

int n;

long long b[100010];

int cmp(arr x,arr y)

  {

   if (x.aa!=y.aa) return x.aa>y.aa;

   return x.bb<y.bb;

  }

signed main()

  {

   scanf("%lld",&n);

   for (int i=1;i<=n;i++)

     {

      scanf("%lld",&a[i].aa);

      a[i].bb=i;b[i]=0;

	 }

   sort(a+1,a+1+n,cmp);

   int maxa=1;int maxb=1;

   while (true)

     {

      while ((a[maxb].aa==a[maxa].aa) && (maxb<=n)) maxb=maxb+1;

      if (maxb>n) break;

      b[a[maxa].bb]+=(maxb-1)*(a[maxa].aa-a[maxb].aa);

      a[maxa].aa=a[maxb].aa;

	  if (a[maxa].bb>a[maxb].bb) maxa=maxb;

	 }

   b[a[maxa].bb]+=a[maxa].aa*n;

   for (int i=1;i<=n;i++) printf("%lld\n",b[i]);

   return 0;

  } 

// Fastest known solution for this problem: