Задачі
Білка та бамбук
import sys input = sys.stdin.read data = input().split()
n = int(data[0]) index = 1
s = [0] # Start with a stack initialized with a single element 0
while n > 0: n -= 1 value = int(data[index]) index += 1
if value > 0:
s.append(max(value, s[-1]))
else:
s.pop()
print(s[-1])