Exact Arithmetic

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Let XX be the set of all rational numbers and all numbers of form qrq \sqrt{r}, where qq is a non-zero rational number and rr is an integer greater than 11. Here, rr must not have a square number except for 11 as its divisor. Also, let X\*X^{\*} be the set of all numbers which can be expressed as a sum of one or more elements in XX.

Consider the machine YY which is a stack-based calculator operating on the values in X\*X^{\*} and has the instructions shown below.

  • push nn: pushes an integer specified in the operand onto the stack.
  • add: pops two values x_1x\_1 and x_2x\_2 from the top of the stack in this order, then pushes (x_2+x_1)(x\_2 + x\_1).
  • sub: pops two values x_1x\_1 and x_2x\_2 from the top of the stack in this order, then pushes (x_2x_1)(x\_2 - x\_1).
  • mul: pops two values x_1x\_1 and x_2x\_2 from the top of the stack in this order, then pushes (x_2x_1)(x\_2 \cdot x\_1).
  • div: pops two values x_1x\_1 and x_2x\_2 from the top of the stack in this order, then pushes (x2/x1)(x2 / x1). Here, x_1x\_1 must be a non-zero value from XX (not from X\*X^{\*}).
  • sqrt: pops one value xx from the stack and pushes the square root of xx. Here, xx must be a non-negative rational number.
  • disp: pops one value xx from the stack, and outputs the string representation of the value xx to the display. The representation rules are stated later.
  • stop: terminates calculation. The stack must be empty when this instruction is called.

Initially, the stack is empty. A sufficient number of values must exist in the stack on execution of every instruction. In addition, due to the limitation of the machine YY, no more values can be pushed when the stack already stores as many as 256256 values. Also, there exist several restrictions on values to be pushed onto the stack:

  • For rational numbers, neither numerator nor denominator in the  irreducible form may exceed 32,76832\\,768 in its absolute value.
  • For any element in XX of the form qr=(a/b)rq \sqrt{r} = (a / b) \sqrt{r}, the following must hold: ar32,768|a \sqrt{r}| \le 32\\,768 and b32,768|b| \le 32\\,768.

For any element in X\*X^{\*}, each term in the sum must satisfy the above conditions.

The rules for the string representations of the values (on the machine YY) are as follows:

  • A rational number is represented as either an integer or an irreducible fraction with a denominator greater than 11.
  • A fraction is represented as num\mathit{num}/den\mathit{den}. Here, num\mathit{num} is the numerator, and den\mathit{den} is the denominator. The sign character - precedes negative numbers.
  • A number of the form qrq \sqrt{r} is represented as rep\mathit{rep}*sqrt(rr) except for the case with q=1|q| = 1, in which the number is represented as sqrt(rr) for q=1q = 1 or -sqrt(rr) for q=1q = -1. Here, rep\mathit{rep} is the string representation of qq.
  • For a sum of two or more elements of XX, string representations of all the (non-zero) elements are connected using the binary operator +. In this case, all terms with the same rooted number are merged into a single term, and the terms must be shown in the ascending order of their root component. For the purpose of this rule, all rational numbers are regarded to accompany 1\sqrt{1}. There is exactly one space character before and after each of the binary operators +. No space characters appear at any other place.

The followings are a few examples of valid string representations:

0
1
-1/10
2*sqrt(2) + 1/2*sqrt(3) + -1/2*sqrt(5)
1/2 + sqrt(10) + -sqrt(30)

Your task is to write a program that simulates the machine YY.

입력

The input is a sequence of no more than 3000 instructions. Each line contains a single instruction. You may assume that every instruction is called in a legal way. The instruction "stop" appears only once, at the end of the entire input.

출력

Output the strings which the machine YY will display. Write each string on a separate line.