Under construction

Still being built. Things may change

Unique Values

Interview

Time limit1sMemory limit1024 MB

Summary
Count the contiguous subarrays of a given array in which no value appears more than once.
Level

Medium4 of 10

Topics
Sliding window, Two pointers, Hash map
Solved
No attempts yet

Problem

Arup has to make many practice questions for his Computer Science 1 students. Many of the questions deal with arrays, so he has to generate arrays for them. He does not want to give difficult practice problems, so he always guarantees that every array given to the students has unique values. No value appears twice in any of his arrays.

Unfortunately, Arup is too lazy to generate arrays. About 20 years ago, when he started teaching Computer Science 1, he made one very long array to reuse. This long array may contain duplicate values. For each problem, he takes a contiguous subsequence of the long array as the problem's array, but the subsequence must not contain duplicates. If the long array is a[0],a[1],…,a[n−1]a[0], a[1], \ldots, a[n-1], a contiguous subsequence is any sequence a[i],a[i+1],…,a[j]a[i], a[i+1], \ldots, a[j] with 0≤i≤j≤n−10 \le i \le j \le n-1.

Given an array of nn integers, count the contiguous subsequences that do not contain any repeated values. Two subsequences with the same contents count as different if they start at different positions in the original array.

Input

The first line contains a single positive integer nn (1≤n≤1051 \le n \le 10^5), the size of the input array. The next line contains nn space-separated integers, the values of the array in order. Each value is an integer between 11 and 10910^9, inclusive.

Output

Print the number of contiguous subsequences that do not contain any repeated values, on a line by itself.

Examples2

  1. Example 1

    Input
    5
    1 1 2 1 5
    
    Expected output
    9
    
  2. Example 2

    Input
    8
    2 12 3 12 3 2 6 9
    
    Expected output
    22