Problem:
Score : 700 points

Problem Statement

Snuke loves constructing integer sequences.

There are N piles of stones, numbered 1 through N.
The pile numbered i consists of a_i stones.

Snuke will construct an integer sequence s of length Σa_i, as follows:

Among the piles with the largest number of stones remaining, let x be the index of the pile with the smallest index. Append x to the end of s.

Select a pile with one or more stones remaining, and remove a stone from that pile.

If there is a pile with one or more stones remaining, go back to step 1. Otherwise, terminate the process.

We are interested in the lexicographically smallest sequence that can be constructed. For each of the integers 1,2,3,...,N, how many times does it occur in the lexicographically smallest sequence?

Constraints

1 ≤ N ≤ 10^{5}

1 ≤ a_i ≤ 10^{9}

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{N}

Output

Print N lines. The i-th line should contain the number of the occurrences of the integer i in the lexicographically smallest sequence that can be constructed.

Sample Input 1

2
1 2

Sample Output 1

2
1

The lexicographically smallest sequence is constructed as follows:

Since the pile with the largest number of stones remaining is pile 2, append 2 to the end of s. Then, remove a stone from pile 2.

Since the piles with the largest number of stones remaining are pile 1 and 2, append 1 to the end of s (we take the smallest index). Then, remove a stone from pile 2.

Since the pile with the largest number of stones remaining is pile 1, append 1 to the end of s. Then, remove a stone from pile 1.

The resulting sequence is (2,1,1). In this sequence, 1 occurs twice, and 2 occurs once.

Sample Input 2

10
1 2 1 3 2 4 2 5 8 1

Sample Output 2

10
7
0
4
0
3
0
2
3
0

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            ARC069.E();
        }
        class ARC069
        {
            public static void C()
            {
                var N = Read.Long();
                var M = Read.Long();
                long scc1 = Math.Min(N, M / 2);
                long scc2 = (M - scc1 * 2) / 4;
                Console.WriteLine(scc1 + scc2);
            }
            public static void D()
            {
                var N = Read.Int();
                var S = Read.Str();

                Func<bool, bool, bool[]> func = (S0, S1) => {
                    var X = new bool[N];
                    X[0] = S0; X[1] = S1;
                    for(int i = 2; i < N; ++i)
                    {
                        X[i] = S[i - 1] == 'o' ^ X[i - 1] ^ X[i - 2];
                    }
                    if (X[0] != (S[N - 1] == 'o' ^ X[N - 1] ^ X[N - 2])) { return null; }
                    if (X[1] != (S[0] == 'o' ^ X[0] ^ X[N - 1])) { return null; }
                    return X;
                };
                var res = func(true, true);
                if (res == null) { res = func(true, false); }
                if (res == null) { res = func(false, true); }
                if (res == null) { res = func(false, false); }
                if (res == null) { Console.WriteLine(-1); return; }
                Console.WriteLine(String.Join("", res.Select(x => x ? "S" : "W")));
            }
            public static void E()
            {
                var N = Read.Int();
                var A = Read.LongN();
                List<long> list1 = new List<long>();
                List<int> list2 = new List<int>();
                long max = 0;
                for(int i = 0; i < N; ++i)
                {
                    if (A[i] > max)
                    {
                        list1.Add(A[i]);
                        list2.Add(i);
                        max = A[i];
                    }
                }
                long[] ans = new long[list1.Count];
                int[] count = new int[list1.Count];
                for(int i = 0; i < N; ++i)
                {
                    var a = A[i];
                    var idx = Bound.Lowerbound(list1, a);
                    if (list1[idx] > a)
                    {
                        ans[idx] += a - list1[idx - 1];
                        count[idx - 1]++;
                    }
                    else
                    {
                        count[idx]++;
                    }
                }
                int cum = 0;
                for (int i = list1.Count - 1; i >= 0; --i)
                {
                    cum += count[i];
                    ans[i] += cum * (list1[i] - (i > 0 ? list1[i - 1] : 0));
                }
                var dict = new Dictionary<int, int>();
                for(int i = 0; i < list1.Count; ++i)
                {
                    dict.Add(list2[i], i);
                }
                var sb = new System.Text.StringBuilder();
                for(int i = 0; i < N; ++i)
                {
                    sb.AppendLine((dict.ContainsKey(i) ? ans[dict[i]] : 0).ToString());
                }
                Console.Write(sb.ToString());
            }
        }
        class Util
        {

        }
        class Bound
        {
            public static int Lowerbound<T>(IList<T> list, T x) where T : IComparable<T>
            {
                int min = 0;
                int max = list.Count;
                while (min < max)
                {
                    var mid = (min + max) / 2;
                    if (list[mid].CompareTo(x) >= 0)
                    {
                        max = mid;
                    }
                    else
                    {
                        min = mid + 1;
                    }
                }
                return max;
            }
        }

        static class Read
        {
            static Queue<string> queue = new Queue<string>();
            static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
            public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
            public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
            public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
            public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
            public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
            public static ulong[] ULongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToUInt64(s)).ToArray(); }
            public static string[] StrN() { return Console.ReadLine().Split(' '); }
            public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
            public static long[,] LongMatrix(int r, int c)
            {
                var mat = new long[r, c];
                for (int i = 0; i < r; ++i)
                {
                    var x = Read.LongN();
                    for (int j = 0; j < c; ++j)
                    {
                        mat[i, j] = x[j];
                    }
                }
                return mat;
            }
            public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false)
            {
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN(); dict[ab[0]].Add(ab[1]);
                    if (!isDirectional) { dict[ab[1]].Add(ab[0]); }
                }
                return dict;
            }
            public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
            {
                Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new Dictionary<int, long>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1], ab[2]);
                    dict[ab[1]].Add(ab[0], ab[2]);
                }
                return dict;
            }
        }
    }
}