How does ((j-i+1)*(j-i+2))/2 this formula works

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,

for this condition ans is 6

for whole array ans is 10

to get ans for complete array you have to run a loop where i varies from 0 to n-1

in this case
from 0 to 2 ans is 6
from 1 to 2 ans is 3
from 2 to 2 ans is 1
so total ans is 10

i hope you got the point