Wrong output coming

for input-
4
1 2 3 4
output should be 6, but it is coming 4

Please help

refer to this code ur code requires some update

I got the top down approach, I want bottom up solution, also specifically , what’s wrong in my code, Please help in that

i hope u have understood the approach since the question has been resolved from ur end