- Time limit: 1.00 s
- Memory limit: 512 MB
You are given an array . Let denote the number of distinct values in the subarray .
Your task is to calculate the sum , i.e., the sum of for all subarrays.
Input
The first line has an integer : the array size.
The next line has integers : the array contents.
Output
Print one integer: the required sum.
Constraints
Example
Input:
5 1 2 3 1 1
Output:
29
Explanation: In this array, subarrays have distinct value, subarrays have distinct values and subarrays have distinct values. Thus, the sum is .