Histogram area stack - Wrong ans

Can someone please point out why I am getting wrong answer for the code?

@Aniruddha use long long instead of int.