import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
    foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = pred();
    return res;
}

void main() {
    int N = readln.chomp.to!int;
    int[] ary = readln.split.to!(int[]);
    int[] t = new int[N];
    int[] left = new int[N];
    int[] right = new int[N];
    foreach(i, e; ary) {
        left[i] = t[e-1];
        t[] += 1;
        t[e-1..$] = 0;
    }
    t[] = 0;
    foreach(j; 0..N) {
        auto i = N-j-1;
        auto e = ary[i];
        right[i] = t[e-1];
        t[] += 1;
        t[e-1..$] = 0;
    }

    N.iota.map!(i => ary[i]*(left[i]+1)*(right[i]+1)).sum.writeln;
}
