Yes, I can explain what I thought -

continue to Getting wrong answer in EURON problem

Let we have, 5 4 3 2 1 and

pre = 0, total = 0

input = 5;

pop = 0

here, stack is empty, push 5

total = pre + pop + total = 0

pre = pre + pop = 0

again, input = 4

pop = 0; // I initialized pop with 0 every time, when I have new input

top of stack is greater than input, thus pop from stack

so, pop = 1

now, stack is empty, push

total = pre + pop + total = 0 + 1 + 0 = 1

pre = pre + pop = 0 + 1 = 1

input = 3;

pop = 0

again, top of stack is greater than input, thus pop from stack

pop = 1;

now, stack is empty, push

total = pre + pop + total = 1 + 1 + 1 = 3

pre = pre + pop = 2

input = 2;

pop = 0;

agaib, top of stack is greater than input, thus pop from stack

pop = 1;

now, stack is empty, push

total = pre + pop + total = 2 + 1 + 3 = 6

pre = pre + pop = 2 + 1 = 3

input = 1;

pop = 0;

again, top of stack is greater than input, thus pop from stack

pop = 1;

now, stack is empty, push

total = pre + pop + total = 3 + 1 + 6 = 10