What is the problem in this code the formula mentioned in hint vedio does not works

@rohitkandpal683
ans+=((j-i)*(j-i+1))/2; this is the correct formula. I think that other formula works with 1 based indexing