Input: arr[] = {1, 1, 2, 2, 2}
Output: 6
Explanation: Subarrays having each element occurring at least twice are :{{1, 1}, {1, 1, 2, 2}, {1, 1, 2, 2, 2}, {2, 2}, {2, 2, 2}, {2, 2}}.
Therefore, the required output is 6.
Input: arr[] = {1, 2, 1, 2, 3}
Output: 1