class Array
def insert k
x,l,r=self
x ?(k<x ?l:r).insert(k):self<<k<<[]<<[]
end
def print
$x,$y=[],[]
w
puts $y*" ",$x*" "
end
def w
x,l,r=self
x&&($x<<x
l.w
$y<<x
r.w)
end
end
t=[]
gets
eval"t.#$_"while gets