# Pila
class Pila:
def __init__(self):
self.v = []
def push(self, x):
self.v.append(x)
def top(self):
return self.v[-1]
def pop(self):
self.v.pop()
def __nonzero__(self):
return len(self) > 0
def __len__(self):
return len(self.v)
def __str__(self):
return str(self.v)
p = Pila()
p.push(1)
p.push(2)
p.push(3)
while p:
print(p.top())
p.pop()
IyBQaWxhCmNsYXNzIFBpbGE6CglkZWYgX19pbml0X18oc2VsZik6CgkJc2VsZi52ID0gW10KCQkKCWRlZiBwdXNoKHNlbGYsIHgpOgoJCXNlbGYudi5hcHBlbmQoeCkKCQkKCWRlZiB0b3Aoc2VsZik6CgkJcmV0dXJuIHNlbGYudlstMV0KCQkKCWRlZiBwb3Aoc2VsZik6CgkJc2VsZi52LnBvcCgpCgkJCglkZWYgX19ub256ZXJvX18oc2VsZik6CgkJcmV0dXJuIGxlbihzZWxmKSA+IDAKCglkZWYgX19sZW5fXyhzZWxmKToKCQlyZXR1cm4gbGVuKHNlbGYudikKCQkKCWRlZiBfX3N0cl9fKHNlbGYpOgoJCXJldHVybiBzdHIoc2VsZi52KQoJCQpwID0gUGlsYSgpCnAucHVzaCgxKQpwLnB1c2goMikKcC5wdXNoKDMpCndoaWxlIHA6CglwcmludChwLnRvcCgpKQoJcC5wb3AoKQo=