CodeEff/ECCO huggingface dataset:
# Original solution
from sys import stdin

def main():
	N = int(stdin.readline().strip())
	i,card = 0,[-1 for x in range(N)]
	while i < N:
		x = int(stdin.readline().strip())
		card[i] = x
		i+=1
	i,ans = 0,0
	while i < N:
		if card[i]%2==0:
			ans+= card[i]//2
			card[i] = 0
		else:
			ans+=(card[i]-1)//2
			card[i] = 1
			if i+1 < N and card[i+1] >=1:
				ans+=1
				card[i],card[i+1] = 0, card[i+1]-1
		i+=1
	print(ans)
main()

# Optimized solution
from sys import stdin

def main():
    nums = int(stdin.readline())
    l = []
    actual = int(stdin.readline())
    total = 0
    for x in range(nums-1):
        total += actual//2
        temp = int(stdin.readline())
        if temp != 0:
            actual = actual%2 + temp
        else:
            actual = temp

    print((total+actual//2))
        
        
    
main()
# Original solution
#y,m,d=map(int,input().split())
#a,b=map(int,input().split())
n=int(eval(input()))
#a=int(input())
#b=int(input())
#s=list(input())
#T=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
#b=list(map(int,input().split()))
#b=list(map(int,input().split()))
#a=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#a=[list(input().split())for _ in range(n)]
a=[int(eval(input()))for _ in range(n)]
ans=0
total=0
judge=False
for i in range(n):
    total+=a[i]
    if a[i]==0:
        ans+=total//2
        total=0
        judge=True
if judge:
    print((ans+total//2))
else:
    print((sum(a)//2))



# Optimized solution
#y,m,d=map(int,input().split())
#a,b=map(int,input().split())
n=int(eval(input()))
#a=int(input())
#b=int(input())
#s=list(input())
#T=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
#b=list(map(int,input().split()))
#b=list(map(int,input().split()))
#a=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#a=[list(input().split())for _ in range(n)]
a=[int(eval(input()))for _ in range(n)]
ans=0
total=0
noncardin_judge=False#カードが0枚のものがないかを記録する
for i in range(n):
    total+=a[i]
    if a[i]==0:
        ans+=total//2
        total=0
        noncardin_judge=True
if noncardin_judge:
    print((ans+total//2))
else:
    print((sum(a)//2))
# Original solution

# 直感的に分かる貪欲（下から組を作る）だと思うんだけど、これでdiff1185は数字が高すぎじゃない? 

n = int(eval(input()))
nums = [int(eval(input())) for _ in range(n)]

ans = 0
for idx, m in enumerate(nums):
    if m > 0:
        ans += m // 2
        # m -= (m // 2) * 2
        m = m & 1
    if m == 1 and idx != n-1 and nums[idx+1] >= 1:
        ans += 1
        m -= 1
        nums[idx+1] -= 1

print(ans)


# Optimized solution
# 直感的に分かる貪欲（下から組を作る）だと思うんだけど、これでdiff1185は数字が高すぎじゃない? 
# 貪欲で取っていくのを考えると、非ゼロの区間が連続する場合、その連続に対して下からペアを作って、最後に0か1だけ残ることがわかり、
# 単純に書ける。こんなふうに。

n = int(eval(input()))
nums = [int(eval(input())) for _ in range(n)]

ans = 0
temp = 0
for m in nums:
    if m == 0:
        ans += temp // 2
        temp = 0
    else:
        temp += m
ans += temp // 2
print(ans)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
ans = 0
for i in range(N):
    tmp = A[i]
    while tmp > 1:
        ans += 1
        tmp -= 2
    if i < N - 1 and tmp == 1 and A[i + 1] > 0:
        ans += 1
        A[i + 1] -= 1
print(ans)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
ans = 0
for i in range(N):
    tmp = A[i]
    ans += (tmp // 2)
    if i < N -1 and tmp % 2 and A[i + 1] > 0:
        ans += 1
        A[i + 1] -= 1
print(ans)
# Original solution
import sys
N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]
ans = 0
for i in range(1, N):
    ans += (A[i - 1] + A[i]) // 2
    if A[i]:
        A[i] = (A[i - 1] + A[i]) % 2
print((A[0] // 2 if N == 1 else ans))

# Optimized solution
import sys
N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]
ans = 0
for i in range(1, N):
    ans += (A[i - 1] + A[i]) >> 1
    if A[i]:
        A[i] = (A[i - 1] + A[i]) & 1
print((A[0] >> 1 if N == 1 else ans))
# Original solution
import sys
N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]
ans = 0
for i in range(1, N):
    ans += (A[i - 1] + A[i]) >> 1
    if A[i]:
        A[i] = (A[i - 1] + A[i]) & 1
print((A[0] >> 1 if N == 1 else ans))

# Optimized solution
from sys import stdin
def main():
    N = int(stdin.readline())
    ans = c = 0
    for _ in range(N):
        a = int(stdin.readline())
        if a:
            c += a
        else:
            ans += c >> 1
            c = 0
    print((ans + (c >> 1)))
if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))
A = list(int(eval(input())) for _ in range(n))
ans = 0
for i in range(n):
    tmp = A[i]
    ans += (tmp//2)
    if i < n-1 and tmp %2 and A[i+1] > 0:
        ans += 1
        A[i+1] -= 1
print(ans)

# Optimized solution
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
ans = 0
for i in range(n-1):
    x,y = A[i], A[i+1]
    ans += x//2
    if x%2!=0 and y > 0:
        ans += 1
        A[i+1] -= 1
ans += A[-1]//2

print(ans)
# Original solution
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]

ans = A[0] // 2
A[0] %= 2

for i in range(1, n):
    ans += (A[i-1] + A[i]) // 2
    if A[i] == 0:
        pass
    elif A[i-1] == 1:
        if A[i] % 2 == 0:
            A[i] = 1
        else:
            A[i] = 0
    else:
        A[i] %= 2

print(ans)

# Optimized solution
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]

ans = 0
s = 0

for a in A:
  s += a
  
  if a == 0:
    ans += s//2
    s = 0

print((ans + s//2))
# Original solution
N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)] + [0]
ans = 0

for i in range(N):
    if a[i] != 0:
        add, mod = divmod(a[i], 2)
        ans += add
        if a[i + 1] != 0:
            a[i + 1] += mod

print(ans)

# Optimized solution
N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
ans = 0
for i in range(N):
    cnt, mod = divmod(a[i], 2)
    ans += cnt
    if i < N - 1 and a[i + 1] != 0:
        a[i + 1] += mod

print(ans)
# Original solution
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]

prev_mod = 0
ans = 0
for a in A:
    if prev_mod == 1 and a > 0:
        a += 1
        prev_mod = 0
    ans += a // 2
    mod = a % 2
    if mod+prev_mod == 2:
        ans += 1
        mod = 0
    prev_mod = mod

print(ans)

# Optimized solution
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]

mod = 0
ans = 0
for a in A:
    if mod == 1 and a > 0:
        a += 1
        mod = 0
    ans += a // 2
    mod = a % 2

print(ans)
# Original solution
#貪欲の手順がおかしかった
#同一ペアを組むのはそれ以下の数を除いた後
#editorial参照、さらに単純に0で区切ってn//2になる
n = int(eval(input()))
a = []
for _ in range(n):
    a_ = int(eval(input()))
    a.append(a_)
#print(a)
ans = 0
"""
for i in range(n-1):
    if a[i]&1:
        ans += a[i]//2
        a[i] = 1
    elif a[i] ==0:
        pass
    else:
        ans += a[i]//2-1
        a[i] = 2
print(a)
print(ans)
"""
for i in range(n-1):
    ans += a[i]//2
    a[i] -= (a[i]//2)*2
    ad = min(a[i],a[i+1])
    ans += ad
    a[i+1] -= ad
##この時点で最後まだ残っている
ans += a[n-1]//2
print(ans)

# Optimized solution
#旧版のa[n-1]分を訂正してテスト
n = int(eval(input()))
a = []
for _ in range(n):
    a_ = int(eval(input()))
    a.append(a_)

ans = 0

for i in range(n-1):
    if a[i]&1:
        ans += a[i]//2
        a[i] = 1
    elif a[i] ==0:
        pass
    else:
        ans += a[i]//2-1
        a[i] = 2

for i in range(n-1):
    if a[i] == 2:
        ans += 1
        a[i] = 0
    else:
        ad = min(a[i],a[i+1])
        ans += ad
        a[i+1] -= ad
ans += a[n-1]//2
print(ans)
# Original solution
N = int(eval(input()))
A = []
a = []
for i in range(N):
    x = int(eval(input()))
    if x==0:
        b = a[:]
        A.append(b)
        a = []
    else:
        a.append(x)
A.append(a)
cnt = 0
for a in A:
    c = sum(a)
    cnt += c//2
print(cnt)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
cnt = 0
for i in range(N):
    if A[i]%2==1:
        cnt += A[i]//2
        A[i] = 1
    else:
        a = A[i]//2
        if a>0:
            cnt += a-1
            A[i] = 2
for i in range(1,N):
    if A[i-1]!=1:
        cnt += A[i-1]//2+A[i]//2
        A[i-1]=0
        A[i]=A[i]%2
    elif A[i-1]==1 and A[i]>=1:
        cnt += 1
        A[i-1]=0
        A[i] -= 1
if N==1:
    cnt = A[0]//2
print(cnt)
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
    ai = int(eval(input()))
    a.append(ai)

cnt = 0
i = 0
while True:
    if a[i] >= 2:
        cnt += 1
        a[i] -= 2

    elif a[i] == 1:
        if i + 1 >= n:
            break

        if a[i + 1] > 0:
            cnt += 1
            a[i] -= 1
            a[i + 1] -= 1

        else:
            i += 1

    else:
        i += 1

print(cnt)

# Optimized solution
#B
n = int(eval(input()))
a = []
for i in range(n):
    ai = int(eval(input()))
    a.append(ai)

cnt = 0
i = 0
while i < n:
    if a[i] >= 2:
        pairs = a[i] // 2
        cnt += pairs
        a[i] -= (pairs * 2)

    elif a[i] == 1:
        if i + 1 >= n:
            break

        if a[i + 1] > 0:
            cnt += 1
            a[i] -= 1
            a[i + 1] -= 1

        else:
            i += 1

    else:
        i += 1

print(cnt)
# Original solution
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

ans = 0
prev = 0
for i in range(N):
    if prev == 1 and A[i] > 0:
        A[i] -= 1
        ans += 1
    q, mod = divmod(A[i], 2)
    ans += q
    prev = mod

print(ans)

# Optimized solution
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())


def main():
    n = II()
    A = [II() for _ in range(n)]

    res = 0
    mod = 0
    for a in A:
        if not a:
            mod = 0
            continue
        q, mod = divmod(a + mod, 2)
        res += q

    return res


print((main()))
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    N = int(input().rstrip('\n'))
    A = [int(input().rstrip('\n')) for _ in range(N)]
    t = 0
    cnt = 0
    for a in A:
        t += a
        if a == 0:
            cnt += (t // 2)
            t = 0
    cnt += (t // 2)
    print(cnt)


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    cnt = 0
    t = 0
    for v in a:
        if v == 0:
            cnt += (t // 2)
            t = 0
        else:
            t += v
    cnt += (t // 2)
    print(cnt)


if __name__ == '__main__':
    slove()
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

ans = rem = 0
for a in A:
    if a == 0:
        rem = 0
        continue
    a += rem
    ans += a//2
    rem = a%2
print(ans)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
rem = 0
ans = 0
for a in A:
    ans += (rem+a)//2
    rem = 0 if a==0 else (rem+a)%2
print(ans)
# Original solution
from collections import defaultdict

def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)] + [0]

    ans = 0
    for i in range(N):
        ans += A[i] // 2
        if A[i] % 2 == 1:
            if A[i+1] >= 1:
                ans += 1
                A[i+1] -= 1

    print(ans)



    
    


if __name__ == "__main__":
    main()

# Optimized solution
def main():
    N = int(eval(input()))
    A = list(int(eval(input())) for _ in range(N))
    cnt = 0
    for i in range(N):
        if i == N-1:
            cnt += A[i] // 2
            break
        cnt += A[i] // 2
        mod = A[i] % 2
        if A[i+1] >= mod:
            cnt += mod
            A[i+1] -= mod

    print(cnt)



if __name__ == "__main__":
    main()
# Original solution
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]
ans = 0

for i in range(N-1):
    d, m = divmod(A[i], 2)
    if m and A[i+1]>0:
        d += 1
        A[i+1] -= 1
    ans += d

ans += A[-1]//2
print(ans)

# Optimized solution
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
C = [int(eval(input())) for _ in range(N)] + [0]
ans = 0
for k in range(N):
    c = C[k]
    ans += c//2
    if c%2 and C[k+1]:
        ans += 1
        C[k+1] -= 1
print(ans)
# Original solution
N = int(eval(input()))
ans = 0
B = 0
for i in range(N):
    A = int(eval(input()))
    C = A+B
    ans += C//2
    if B == 1 and C == 1:
        B = 0
        continue
    B = C % 2
print(ans)


# Optimized solution
N = int(eval(input()))
A = int(eval(input()))
ans = A//2
amari = A % 2
for _ in range(N-1):
    A = int(eval(input()))
    ans += (amari+A)//2
    if A == 0:
        amari = 0
    else:
        amari = (amari+A) % 2
print(ans)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]

res = 0
for i in range(n):
    res += a[i] // 2
    a[i] %= 2
    if i!=n-1:
        if a[i] and a[i+1]:
            res += 1
            a[i] -= 1
            a[i+1] -= 1
print(res)


# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a.append(0)

res = 0
for i in range(n):
    # a[i] と a[i+1]
    res += a[i] // 2
    a[i] %= 2
    if a[i]==1 and a[i+1]!=0:
        res += 1
        a[i] -= 1
        a[i+1] -= 1
print(res)
# Original solution
N=int(eval(input()))
pre=int(eval(input()))
ans=pre//2
pre=pre&1
for i in range(2,N+1):
    Ai=int(eval(input()))
    if pre and Ai>=1:
        ans+=1
        Ai-=1
    ans+=Ai//2
    pre=Ai&1
print(ans)

# Optimized solution
N=int(eval(input()))
ans=0
s=0
for i in range(1,N+1):
    Ai=int(eval(input()))
    if Ai==0:
        ans+=s//2
        s=0
    else:
        s+=Ai
ans+=s//2
print(ans)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]+[0]

ans=0
cnt=0

for aa in a:
    if aa==0:
        ans+=cnt//2
        cnt=0
    else:
        cnt+=aa

print(ans)

# Optimized solution
n=int(eval(input()))

cnt=0
ans=0
for _ in range(n):
    a=int(eval(input()))

    if a>0:
        cnt+=a
    else:
        ans+=cnt//2
        cnt=0
    
print((ans+cnt//2))
# Original solution
N, *A = list(map(int, open(0).read().split()))
ans = 0
for i in range(N):
    q, r = divmod(A[i], 2)
    ans += q
    if r == 0 or i == N - 1:
        continue
    elif A[i + 1] != 0:
        A[i + 1] += 1
print(ans)


# Optimized solution
N, *A = list(map(int, open(0).read().split()))

r = 0
ans = 0
for a in A:
    if a == 0:
        r = 0
        continue
    q, r = divmod(a + r, 2)
    ans += q
print(ans)
# Original solution
n = int(eval(input()))
a = [0]
for _ in range(n):
    a.append(int(eval(input())))

ans = 0
for i in range(n):

    # (x,x)のペア
    ans += a[i] // 2
    a[i] -= a[i] // 2 * 2

    # (x,x+1)のペア
    ans += min(a[i], a[i + 1])
    a[i + 1] -= min(a[i], a[i + 1])

else:  # 最後にa[-1]でできるだけペアを作る
    ans += a[-1] // 2

print(ans)


# Optimized solution
import sys
input = sys.stdin.readline

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)] + [0]

ans = 0
for i in range(N):
    # できるだけ左でペアを作る
    Lpair = A[i] // 2
    ans += Lpair
    A[i] -= 2 * Lpair

    if A[i] > 0 and A[i + 1] > 0:
        ans += 1
        A[i] -= 1
        A[i + 1] -= 1


print(ans)
# Original solution
def gcd(a,b):
    return gcd(b,a%b) if b else a

def merge(a,us,vs):
    i,j,res=0,0,[]
    while i<len(us) and j<len(vs):
        if a[us[i]]>=a[vs[j]]:
            res.append(us[i])
            i+=1
        else:
            res.append(vs[j])
            j+=1
    return res+us[i:]+vs[j:]

def dfs(g,a,u,vis):
    vis[u]=True
    res=[]
    for v in g[u]:
        if not vis[v]:
            res=merge(a,res,dfs(g,a,v,vis))
    return [u]+res

while 1:
    try:
        n=int(eval(input()))
        a=sorted(map(int,input().split()))
    except: break

    g=[[j for j in range(n) if i!=j and gcd(a[i],a[j])!=1] for i in range(n)]
    vis=[False]*n
    res=[]
    for u in range(n):
        if not vis[u]:
            res=merge(a,res,dfs(g,a,u,vis))
    print((' '.join(str(a[u]) for u in res)))


# Optimized solution
import sys
sys.setrecursionlimit(1000000000)

def gcd(a: int, b:int):
    while b:
        a,b=b,a%b
    return a

def merge(a,us,vs):
    i,j,res=0,0,[]
    while i<len(us) and j<len(vs):
        if a[us[i]]>=a[vs[j]]:
            res.append(us[i])
            i+=1
        else:
            res.append(vs[j])
            j+=1
    return res+us[i:]+vs[j:]

def dfs(g,a,u,vis):
    vis[u]=True
    res=[]
    for v in g[u]:
        if not vis[v]:
            res=merge(a,res,dfs(g,a,v,vis))
    return [u]+res

while 1:
    try:
        n=int(eval(input()))
        a=sorted(map(int,input().split()))
    except: break

    g=[[] for _ in range(n)]
    for i in range(n):
        for j in range(i+1,n):
            if gcd(a[i],a[j])!=1:
                g[i].append(j)
                g[j].append(i)

    vis=[False]*n
    res=[]
    for u in range(n):
        if not vis[u]:
            res=merge(a,res,dfs(g,a,u,vis))
    print((' '.join(str(a[u]) for u in res)))
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    print((s[:4] + " " + s[4:]))


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    input = sys.stdin.readline
    s = list(str(input().rstrip('\n')))
    s.insert(4, " ")
    print(("".join(s)))


if __name__ == '__main__':
    slove()
# Original solution
def solve1(m,n):
    div=[]
    rem=[]
    r=m
    rem = [-1 for _ in range(n)]
    digit=0
    while True:
        (d,r) = divmod(r,n)
        div.append(d)
        if r==0:
            return(''.join(map(str, div))[1:],'')
        elif rem[r] != -1:
            le = digit - rem[r]
            s = ''.join(map(str,div[1:]))
            t = (' '*100 + '^'*le)[-len(s):]
            return(s,t)
        else:
            rem[r] = digit
            r *= 10
            digit += 1
        
while True:
    try:
        m,n = list(map(int, input().strip().split()))
        s,t = solve1(m, n)
        print(s)
        if t!='':
            print(t)
    except EOFError:
        break

# Optimized solution
from decimal import *
import re
def solve2(m, n):
    maxreplen = 160
    PREC=200
    getcontext().prec = PREC
    x = Decimal(m) / Decimal(n)
    s = x.to_eng_string()
    if len(s) < PREC:
        return(s[2:],'')
    rep = 1
    while True:
        r = r'(.{%d})\1{%d,}' % (rep, int(maxreplen/rep)-1)
        #r = r'(.{%d})\1{%d,}' % (rep, 20)
                                         #ex. '(.{6})\\1{12,}'
        a=re.search(r, s)
        if a:
            break
        rep += 1
        if rep > maxreplen:
            raise ValueError('This cannot happen.')

    u = s[2:a.start()+len(a.group(1))]
    v = (' '*PREC + '^'*len(a.group(1)))[-len(u):]
    return(u,v)

while True:
    try:
        m,n = list(map(int, input().strip().split()))
        s,t = solve2(m, n)
        print(s)
        if t!='':
            print(t)
    except EOFError:
        break
# Original solution
from collections import defaultdict
import sys
class BIT():
    def __init__(self, number):
        self.n = number
        self.list = [0] * (number + 1)

    def add(self, i, x):  # ith added x  1indexed
        while i <= self.n:
            self.list[i] += x
            i += i & -i

    def search(self, i):  # 1-i sum
        s = 0
        while i > 0:
            s += self.list[i]
            i -= i & -i
        return s

    def suma(self, i, j):  # i,i+1,..j sum
        return self.search(j) - self.search(i - 1)

N=int(eval(input()))
A=[int(i) for i in input().split()]
C=sorted(set(A))
ndd=defaultdict(int)
for i in range(len(C)):
    ndd[i+1]=C[i]
dd=defaultdict(int)
for i in range(len(C)):
    dd[C[i]]=i+1
#print(ndd,dd)
visit=[0]*N
visit[0]=1
s=A[0]
H=[]
H.append(s)
for i in range(1,N):
    if s<A[i]:
        s=A[i]
        H.append(s)
        visit[i]=1

BITI=BIT(N+1)
BITI2=BIT(N+1)
j=len(H)-1
l=dd[H[j]]
num=sum(A)
T=[0]*N
ans=0
for i in range(N-1,-1,-1):
    if l==dd[A[0]]:
        break
    BITI.add(dd[A[i]],A[i])
    BITI2.add(dd[A[i]],1)
    if dd[A[i]]==l and visit[i]==1:
        T[i]=BITI.suma(dd[H[j-1]],N+1)-BITI2.suma(dd[H[j-1]],N+1)*H[j-1]-ans
        ans+=T[i]
        #print(i,j,l,T[i],ans)
        j-=1
        l=dd[H[j]]
x=num-sum(T)
T[0]=x
#print(visit,T)
for t in T:
    print(t)






# Optimized solution
from operator import itemgetter
import sys
N=int(eval(input()))
A=[int(i) for i in input().split()]
B=[(A[i],i) for i in range(N)]
B=sorted(B,key=itemgetter(1))
B=sorted(B,key=itemgetter(0))
T=[0]*N
cos,pt=B.pop()
for i in range(1,N):
    cos2,pt2=B.pop()
    T[pt]+=(cos-cos2)*i
    pt=min(pt,pt2)
    cos=cos2
T[pt]+=cos*N
for i in T:
    print(i)
# Original solution
from collections import deque, defaultdict

N = int(input())
A = list(map(int, input().split()))

# 現在末尾に追加される山より若い山で，最も個数の大きいものが次の山になる
# 他の山を次の山の個数以下まで減らす

nextNumIndex = deque([0])

for i, a in enumerate(A[1:], start=1):
    if a > A[nextNumIndex[-1]]:
        nextNumIndex.append(i)

V = set()  # 大きい山
W = set(range(N))  # 小さい山
ansList = defaultdict(int)

while len(nextNumIndex) > 1:
    nowIndex = nextNumIndex.pop()
    nextIndex = nextNumIndex[-1]

    newW = set()
    cnt = len(V) * (A[nowIndex] - A[nextIndex])
    for w in W:
        if A[w] >= A[nextIndex]:
            V.add(w)
            cnt += A[w] - A[nextIndex]
        else:
            newW.add(w)
    W = newW
    ansList[nowIndex] = cnt

    if len(nextNumIndex) == 1:
        for i in range(N):
            A[i] = min(A[i], A[nextIndex])

ansList[0] = sum(A)

ans = []
for i in range(N):
    ans.append(ansList[i])

print(*ans, sep='\n')


# Optimized solution
N = int(input())
A = list(map(int, input().split()))

# 現在末尾に追加される山より若い山で，最も個数の大きいものが次の山になる
# 他の山を次の山の個数以下まで減らす

ans = [0] * N

numList = [(a, i) for i, a in enumerate(A)]
numList.sort(reverse=True)
numList.append((0, 0))

y = float('inf')
for c, (a, i) in enumerate(numList[: N], start=1):
    y = min(y, i)
    ans[y] += c * (a - numList[c][0])

print(*ans, sep='\n')
# Original solution
N = int(eval(input()))
A = [int(a) for a in input().split()]

S = sum(A)
for i in range(N):
    A[i] = [A[i], i+1]

A.sort(reverse=True)
ans = [0]*(N+1)
i = 0
num = N+1
while i < N-1:
    num = min(num, A[i][1])
    while i < N-1 and A[i][0] == A[i+1][0]:
        num = min(num, A[i+1][1])
        i += 1
    if i == N-1:
        break
    ans[num] += (i+1)*(A[i][0]-A[i+1][0])
    i += 1

ans[1] += S-sum(ans)
for i in range(1, N+1):
    print((ans[i]))

# Optimized solution
N = int(eval(input()))
A = [int(a) for a in input().split()]

ans = [0]*N
num = 0
B = sorted(A)
j = 0
for i in range(N):
    cnt = 0
    while j < N and B[j] <= A[i]:
        cnt += max(0, B[j]-num)
        j += 1
    ans[i] = cnt + max(0, (N-j)*(A[i]-num))
    num = max(num, A[i])

for a in ans:
    print(a)