Run errror in my code

https://ide.codingblocks.com/s/152962 For custom input its displaying output but when code is submitted it shows run error

Hi @tanjuljain19,
You need to use long everywhere. Because the range of int will be exceeded.

After changing int to long I am still getting run time error

Hi @tanjuljain19,
I have removed the run time errors from your code. You need to create stacks of the size of max N to avoid errors. https://ide.codingblocks.com/s/153395

Also your code is wrong. It will give wrong answer for the input:
5
4 3 5 2 1
Correct Answer : 9
Your answer = 20

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.