As in the hint it is given that to calculate the sum of lengths of subarrays of an array of distinct elements starting from i index up to j index is = ( ( j-i+1 ) * ( j-i+2 ) )/2

if we apply this on an array indexed from 0 to 2

and the array is lets say arr[] = { 1 ,2,3 }

value we get from the formula is 6 but the actual value is 10 also given in the sample output,