To find the sum of length of subarray(only 1 test case is passed) plz help

https://hack.codingblocks.com/app/contests/1483/734/problem