CSES - Distinct Values Sum
  • Time limit: 1.00 s
  • Memory limit: 512 MB

You are given an array x1,x2,,xnx_1,x_2,\dots,x_n. Let d(a,b)d(a,b) denote the number of distinct values in the subarray xa,xa+1,,xbx_a,x_{a+1},\dots,x_b.

Your task is to calculate the sum a=1nb=and(a,b)\sum_{a=1}^n \sum_{b=a}^n d(a,b), i.e., the sum of d(a,b)d(a,b) for all subarrays.

Input

The first line has an integer nn: the array size.

The next line has nn integers x1,x2,,xnx_1,x_2,\dots,x_n: the array contents.

Output

Print one integer: the required sum.

Constraints

  • 1n21051 \le n \le 2 \cdot 10^5
  • 1xi1091 \le x_i \le 10^9

Example

Input:

5
1 2 3 1 1

Output:

29

Explanation: In this array, 66 subarrays have 11 distinct value, 44 subarrays have 22 distinct values and 55 subarrays have 33 distinct values. Thus, the sum is 61+42+53=296\cdot1+4\cdot2+5\cdot3=29.