Only 1 test case is passing

please find the mistakes in my code as only 1 test case is passing out of 3,

Calculate the sum of length using formula: (j-i+1)*(j-i+2)/2

what is wrong in my logic as it is giving correct answer all the time