Magical Array

5

1 votes
, Algorithms, Math, Basic Math, Arrays
Problem

Problem Statement : 

You are given an array A of N integers. You have to find the number of the magical array's that are a subarray of the given array.

A magical array is one which does not have distinct elements.

For example, [2 2 2], [1 1 1] are magical arrays while [2 2 2 3], [3 3 1 3] are not magical arrays.

Input format 

The first line contains one integer N — the number of elements in the array.

The second line contains N spaced integers A0,A1,A2,.....An1 .

Output format :

              Print one integer, the number of magical subarrays. 

Constraints :

1N1051Ai109

Sample Input
4
5 5 4 4 
Sample Output
6
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Here, n = 4 and a = [5, 5, 4, 4].

So, The magical arrays are [5], [5], [4], [4], [5, 5], [4, 4].

The count of magical arrays is 6. 

Editor Image

?