Array of SubarraysMedium

Array of Subarrays

Medium+30 XP · +10 Aurahash maptwo pointerssubarray

UptoSkills Arena is organizing a coding challenge. As a warm-up, participants are given an array of integers and asked to find the number of subarrays that contain only unique elements. A subarray is a contiguous part of the array. For example, in [1, 2, 3], [1, 2] and [2, 3] are subarrays, but [1, 3] is not. Help us count these unique-element subarrays!

Input

The first line contains an integer n, the size of the array. The second line contains n integers, the elements of the array.

Output

Print a single integer: the total count of subarrays with unique elements.

Constraints

1 <= n <= 200000 Elements of the array are integers between -10^9 and 10^9.

Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests

Example 1

Input
5
1 2 3 2 1
Output
11

Subarrays with unique elements are: [1], [2], [3], [2], [1], [1, 2], [2, 3], [3, 2], [2, 1], [1, 2, 3], [2, 3, 2](invalid), [3, 2, 1]. Total = 11.

Example 2

Input
3
1 1 1
Output
3

Subarrays with unique elements are: [1], [1], [1]. Total = 3.

Hints