eolymp
bolt
Try our new interface for solving problems
Problems

Squirrel and bamboo

published at 4/10/24, 4:35:20 pm

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])