n=int(input())

a=[]

for i,j in enumerate(map(int,input().split())):

    a.append([j,i])

a.sort(reverse=True)

now=0

nx=0

ans=[0]*n

cnt=0

idx=10**6

while now<n:

    while nx<n and a[now][0]==a[nx][0]:

        idx=min(idx,a[nx][1])

        cnt+=1

        nx+=1

    if nx==n:

        ans[idx]+=cnt*a[now][0]

    else:

        ans[idx]+=(a[now][0]-a[nx][0])*cnt

    now=nx

for i in range(n):

    print(ans[i])
from collections import defaultdict

class BIT():

    def __init__(self,size):

        self.size=size

        self.node=[0]*(size+1)



    def sum(self,idx):

        ret=0

        while idx>0:

            ret+=self.node[idx]

            idx-=idx&(-idx)

        return ret



    def add(self,idx,x):

        while idx<=self.size:

            self.node[idx]+=x

            idx+=idx&(-idx)



n=int(input())

a=list(map(int,input().split()))

check=[]

d=defaultdict(int)

li=set([])

now=0

for i in range(n):

    if now<a[i]:

        now=a[i]

        check.append(i)

    d[a[i]]+=1

    li.add(a[i])

li=sorted(list(li))

b=[0]*(n+5)

i=0

idx=dict()

for key in li:

    b[i]=d[key]

    idx[key]=i

    i+=1

ans=[0]*(n+1)

for i in range(len(check)-2,-1,-1):

    cnt=0

    for j in range(idx[a[check[i]]]+1,idx[a[check[i+1]]]+1):

        ans[check[i+1]]+=b[j]*(li[j]-a[check[i]])

        cnt+=b[j]

    b[idx[a[check[i]]]]+=cnt

for i in range(1,n):

    if a[0]<a[i]:

        a[i]=a[0]

ans[0]=sum(a)

for i in range(n):

    print(ans[i])

n = int(input())
a = []
for i, j in enumerate(map(int, input().split())):
    a.append([j, i])
a.sort(reverse=True)
now = 0
nx = 0
ans = [0] * n
cnt = 0
idx = 10**6
while now < n:
    while nx < n and a[now][0] == a[nx][0]:
        idx = min(idx, a[nx][1])
        cnt += 1
        nx += 1
    if nx == n:
        ans[idx] += cnt * a[now][0]
    else:
        ans[idx] += (a[now][0] - a[nx][0]) * cnt
    now = nx
for i in range(n):
    print(ans[i])

from collections import defaultdict


class BIT:
    def __init__(self, size):
        self.size = size
        self.node = [0] * (size + 1)

    def sum(self, idx):
        ret = 0
        while idx > 0:
            ret += self.node[idx]
            idx -= idx & (-idx)
        return ret

    def add(self, idx, x):
        while idx <= self.size:
            self.node[idx] += x
            idx += idx & (-idx)


n = int(input())
a = list(map(int, input().split()))
check = []
d = defaultdict(int)
li = set([])
now = 0
for i in range(n):
    if now < a[i]:
        now = a[i]
        check.append(i)
    d[a[i]] += 1
    li.add(a[i])
li = sorted(list(li))
b = [0] * (n + 5)
i = 0
idx = dict()
for key in li:
    b[i] = d[key]
    idx[key] = i
    i += 1
ans = [0] * (n + 1)
for i in range(len(check) - 2, -1, -1):
    cnt = 0
    for j in range(idx[a[check[i]]] + 1, idx[a[check[i + 1]]] + 1):
        ans[check[i + 1]] += b[j] * (li[j] - a[check[i]])
        cnt += b[j]
    b[idx[a[check[i]]]] += cnt
for i in range(1, n):
    if a[0] < a[i]:
        a[i] = a[0]
ans[0] = sum(a)
for i in range(n):
    print(ans[i])

+from collections import defaultdict + + +class BIT: +    def __init__(self, size): +        self.size = size +        self.node = [0] * (size + 1) + +    def sum(self, idx): +        ret = 0 +        while idx > 0: +            ret += self.node[idx] +            idx -= idx & (-idx) +        return ret + +    def add(self, idx, x): +        while idx <= self.size: +            self.node[idx] += x +            idx += idx & (-idx) + + -a = [] -for i, j in enumerate(map(int, input().split())): -    a.append([j, i]) -a.sort(reverse=True) +a = list(map(int, input().split())) +check = [] +d = defaultdict(int) +li = set([]) -nx = 0 -ans = [0] * n -cnt = 0 -idx = 10**6 -while now < n: -    while nx < n and a[now][0] == a[nx][0]: -        idx = min(idx, a[nx][1]) -        cnt += 1 -        nx += 1 -    if nx == n: -        ans[idx] += cnt * a[now][0] -    else: -        ans[idx] += (a[now][0] - a[nx][0]) * cnt -    now = nx +for i in range(n): +    if now < a[i]: +        now = a[i] +        check.append(i) +    d[a[i]] += 1 +    li.add(a[i]) +li = sorted(list(li)) +b = [0] * (n + 5) +i = 0 +idx = dict() +for key in li: +    b[i] = d[key] +    idx[key] = i +    i += 1 +ans = [0] * (n + 1) +for i in range(len(check) - 2, -1, -1): +    cnt = 0 +    for j in range(idx[a[check[i]]] + 1, idx[a[check[i + 1]]] + 1): +        ans[check[i + 1]] += b[j] * (li[j] - a[check[i]]) +        cnt += b[j] +    b[idx[a[check[i]]]] += cnt +for i in range(1, n): +    if a[0] < a[i]: +        a[i] = a[0] +ans[0] = sum(a)