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

#FT0000081. Bộ ba tăng nghiêm ngặt (Increasing Triples)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Bộ ba tăng nghiêm ngặt (Increasing Triples)

Increasing Triples

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer sequence a1,a2,…,ana_1,a_2,\ldots,a_n, count triples of distinct positions i,j,ki,j,k satisfying

1≤i<j<k≤n,ai<aj<ak.1\le i<j<k\le n,\qquad a_i<a_j<a_k.

Triples are identified by their index triples, so identical values chosen from different positions count separately. Both inequalities must be strict; equal values do not satisfy the requirement.

Input

The first line contains nn.

The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print one integer: the number of valid increasing triples of positions.

Subtasks

  • Subtask 1 (30 points): 1≤n≤1001\le n\le 100; 1≤ai≤1051\le a_i\le 10^5 for every ii.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤ai≤1051\le a_i\le 10^5 for every ii.
  • Subtask 3 (40 points): 1≤n≤300001\le n\le 30000; 1≤ai≤1051\le a_i\le 10^5 for every ii.

Examples

Input

5
1 2 2 3 4

Output

7

Explanation

The two occurrences of value 22 at positions 22 and 33 are separate choices. The valid index triples are (1,2,4)(1,2,4), (1,3,4)(1,3,4), (1,2,5)(1,2,5), (1,3,5)(1,3,5), (1,4,5)(1,4,5), (2,4,5)(2,4,5) and (3,4,5)(3,4,5).

Thus the answer is 77. A triple using both occurrences of 22 is invalid because the inequalities are strict.