PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000017. Đếm bộ ba giảm nghiêm ngặt (Enemy is weak)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Đếm bộ ba giảm nghiêm ngặt (Enemy is weak)

Enemy is weak

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a sequence of pairwise distinct integers, count triples of positions i<j<ki<j<k satisfying ai>aj>aka_i>a_j>a_k. The positions need not be consecutive.

Input

The first line contains nn. The next line contains nn pairwise distinct positive integers a1,…,ana_1,\ldots,a_n.

Output

Print one 64-bit integer: the number of qualifying index triples.

Subtasks

  • Subtask 1 (20 points): 3≤n≤123\le n\le 12; 1≤ai≤1091\le a_i\le 10^9 for every ii; all aia_i are pairwise distinct.
  • Subtask 2 (30 points): 3≤n≤8003\le n\le 800; 1≤ai≤1091\le a_i\le 10^9 for every ii; all aia_i are pairwise distinct.
  • Subtask 3 (50 points): 3≤n≤10000003\le n\le 1000000; 1≤ai≤1091\le a_i\le 10^9 for every ii; all aia_i are pairwise distinct.

Examples

Input

4
10 8 3 1

Output

4

Explanation

The array is strictly decreasing, so every choice of three positions qualifies. The four triples are (10,8,3)(10,8,3), (10,8,1)(10,8,1), (10,3,1)(10,3,1), and (8,3,1)(8,3,1). Hence the output is 44.