import std.algorithm;
import std.range;
import std.math;
import std.regex;
import std.array;
import std.container;
import std.stdio;
import std.string;
import std.conv;
import std.traits;
import std.typecons;


void main()
{
    writefln("%(%s\n%)", solve());
}


int[] solve()
{
    int N = readInt;
    auto list = readInts.enumerate(cast(size_t)1).array();

    list.sort!"a.value > b.value"();
    Entry[] entries;
    foreach(e; list){
        if(entries.length == 0)
            entries ~= Entry(e.value, redBlackTree(e.index));
        else if(entries[$-1].value == e.value)
            entries[$-1].idxList.insert(e.index);
        else
            entries ~= Entry(e.value, redBlackTree(e.index));
    }

    writeln(entries);

    int[] result = new int[N];
    auto M = entries.length;
    foreach(i; 0 .. M){
        writeln(entries);
        writeln(result);
        writeln();

        if(i != M-1){
            int diff = entries[i].value - entries[i+1].value;
            auto idx = entries[i].idxList.front;
            result[idx-1] += diff * entries[i].idxList.length;

            entries[i+1].idxList.insert(entries[i].idxList[]);
        }else{
            int diff = entries[i].value;
            auto idx = entries[i].idxList.front;
            result[idx-1] += diff * entries[i].idxList.length;
        }
    }


    return result;
}


struct Entry
{
    int value;
    RedBlackTree!size_t idxList;
}



string[] readStrs() { return readln.chomp.split(' '); }
T[] readInts(T = int)() { return readStrs.map!(to!T).array(); }
T readInt(T = int)() { return readln.chomp.to!T; }
Tuple!Ts readTuple(Ts...)()
{
    auto ss = readStrs();
    typeof(return) dst;
    foreach(i, U; Ts)
        dst[i] = ss[i].to!U;

    return dst;
}

struct ModIntT(T = int, T MOD = 1_000_000_007)
if(isIntegral!T)
{
    alias value this;
    T value;


    this(U)(U u)
    if(isIntegral!U)
    {
        value = cast(T)(u % MOD);
    }


    ModInt opBinary(string op, U)(U u)
    if(op == "+" || op == "-" || op == "*" || op == "/")
    {
      static if(is(U : typeof(this)))
      {
        static if(op == "+")
          return typeof(this)((this.value + u.value));
        else static if(op == "-")
          return typeof(this)((this.value + MOD - u.value));
        else static if(op == "*")
          return typeof(this)((cast(long)this.value * cast(long)u.value));
        else static if(op == "/")
          return u^^(MOD-2) * this.value;
        else static assert(0);
      }
      else static if(isIntegral!U)
        return this.opBinary!op(typeof(this)(u));
      else static assert(0);
    }


    ModInt opBinary(string op : "^^", U)(U u)
    if(isIntegral!U)
    {
        if(u == 0) return ModInt(1);
        else if(u % 2 == 0){
            long d = cast(long)this.opBinary!"^^"(u / 2);
            return ModInt(d * d);
        }else
            return ModInt((cast(long)this) * cast(long)this.opBinary!"^^"(u-1));
    }


    string toString() { return value.to!string; }

    U opCast(U)() { return cast(U)value; }

    void opAssign(U)(U u) if(isIntegral!U) { value = u % MOD; }
}


alias ModInt = ModIntT!int;
alias ModLong = ModIntT!long;

unittest
{
    enum MOD = 1_000_000_007;

    ModInt a = 123;
    assert(a.value == 123);

    a = MOD - 1;
    ModInt b = a;

    long v = MOD-1;
    assert((a * a).value == (v * v) % MOD);
    assert((a + a).value == (v + v) % MOD);
    assert((a - a).value == (v - v) % MOD);
    assert((a - a).value == (v - v) % MOD);
    assert((a^^2).value == (v^^2) % MOD);
    a = 10;
    v = 10;
    assert((a^^10).value == (v^^10) % MOD);
    assert(((a^^10)/10).value == (v^^9) % MOD);
    a = 2;
    v = 2;
    assert((a^^40).value == (v^^40) % MOD);
    assert(((a^^40)/2).value == (v^^39) % MOD);
}

pure bool isPrime(T)(T src)
if(isIntegral!T)
{
    if(src <= 1)return false;
    else if(src < 4)return true;
    else if(!(src&1))return false;
    else if(((src+1)%6) && ((src-1)%6))return false;
    
    T root = cast(T)sqrt(cast(float)src) + 1;
    
    for(T i=5;i<root;i+=6)
        if(!((src%i) && ((src)%(i+2))))
            return false;

    return true;
}
