Company: Adobe_13_dec
Difficulty: medium
Good Subarrays You are given an array arr of n integers and an integer X . A subarray arr[L..r] -- the elements arr[L], arr[L+1], ..., arr[r] at consecutive positions -- is GOOD when exactly X distinct values occur at least 3 times inside that subarray. A value that occurs 3, 4 or more times inside the subarray counts once, whatever its number of occurrences; values occurring once or twice do not count at all; and the number of such values must equal X exactly, not merely reach it. Count the good subarrays of arr . Input Format Line 1 contains a single integer n , the size of the array. Line 2 contains n space separated integers, the elements of arr . Line 3 contains a single integer X . Output Format Print a single integer: the number of good subarrays. Print 0 when there is none. Constraints 1 <= n <= 28000 *(inferred -- the source states n <= 10^5, which cannot be submitted: 10^5 six-digit values need about 600 KB of input against the judge's 200,000 B limit. 28000 is