United Cows of Farmer John
Time limit1sMemory limit512 MB
Count intervals of length at least two where the leftmost and rightmost cows have breeds that appear nowhere else inside the interval.
- Level
Medium7 of 10
- Topics
- Array, Prefix sum, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
The United Cows of Farmer John (UCFJ) are sending a delegation to the International bOvine olympIad (IOI).
There are cows participating in delegation selection (). They are standing in a line, and cow has breed .
The delegation will consist of a contiguous interval of at least two cows, that is, cows for integers and satisfying . The two outermost cows of the chosen interval will be designated as "leaders." To avoid intra-breed conflict, every leader must be of a different breed from the rest of the delegation (leaders or not).
Help the UCFJ determine (for tax reasons) the number of ways they might choose a delegation to send to the IOI.
Input
The first line contains .
The second line contains integers , each in the range .
Output
The number of possible delegations, on a single line.
Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).
Hint
Each delegation corresponds to one of the following pairs of leaders: