실버4 문제
n = int(input()) arr = [] for i in range(n): num = int(input()) if (num != 0): arr.append(num) else: if (arr == []): pass else: arr.pop() print(sum(arr))