import java.util.*;
import java.math.*;

public class Permutaatio {
    public static int p = 1000000;
    public static int[] kohta;
    public static BigInteger[] puu;
    public static int n;

    public static BigInteger summa(int a, int b) {
        a += n; b += n;
        BigInteger s = BigInteger.ZERO;
        while (a < b) {
            if (a%2 == 1) s = s.add(puu[a++]);
            if (b%2 == 0) s = s.add(puu[b--]);
            a /= 2; b /= 2;
        }
        if (a == b) s = s.add(puu[a]);
        return s;
    }

    public static void paivita(int k, BigInteger x) {
        puu[n+k] = x;
        k = (n+k)/2;
        while (k >= 1) {
            puu[k] = puu[2*k].add(puu[2*k+1]);
            k /= 2;
        }
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        kohta = new int[p+1];
        n = 1;
        while (n < p) n *= 2;
        puu = new BigInteger[2*n];
        for (int i = 0; i < 2*n; i++) puu[i] = BigInteger.ZERO;
        for (int i = 0; i < p; i++) {
            int luku = input.nextInt();
            kohta[luku] = i;
        }
        BigInteger tulos = BigInteger.ZERO;
        for (int i = 1; i <= p; i++) {
            BigInteger uusi = BigInteger.ONE.add(summa(0, kohta[i]));
            paivita(kohta[i], uusi);
            tulos = tulos.add(uusi);
        }
        System.out.println(tulos);
    }
}
