class Calc
    def initialize
	@stack = []
    end

    def push (n)
	@stack.push(n)
    end

    def pop
	if @stack.size < 1
	    raise("Stack is Empty")
	end
	return @stack.pop
    end

    def add
	x = pop
	begin
	    y = pop
	    z = x + y
	    push(z)
	rescue
	    push(x)
	    raise
	end
    end

    def sub
	x = pop
	begin
	    y = pop
	    z = y - x
	    push(z)
	rescue
	    push(x)
	    raise
	end
    end

    def mul
	x = pop
	begin
	    y = pop
	    z = x * y
	    push(z)
	rescue
	    push(x)
	    raise
	end
    end

    def div
	x = pop
	begin
	    y = pop
	    begin
		z = y / x
	    rescue
		push(y)
		raise
	    end
	    push(z)
	rescue
	    push(x)
	    raise
	end
    end

    def top
	return @stack.last
    end
end
