PF

Time limit: 0.1s Memory limit: 256MB Input: Output:

The simple architecture of the nanoprocessor Perfect Function (briefly PF) includes an input register ININ and three integer registers AA, BB and CC. ININ is connected to the standard input, and the result from the calculation is expected in AA . A non-negative integer and one of the characters +,,+, -, * and == can be read in ININ from the standard input.

The elementary operations, which PF is able to perform, are shown in the table below.

The following notation is used:

  • <Reg>\text{<Reg>} - any of the four registers;
  • <R>, <R1>, <R2>\text{<R>, <}R_1\text{>, <}R_2\text{>} - any of the three integer registers AA, BB or CC
  • <number>\text{<number>} - a non-negative integer;
  • <const>\text{<const>} - any of the characters allowed, or a non-negative integer.

(You can notice that for the binary operations, which change a register, the changing register is the second parameter.)

Code of the operation Action
ReadInt A non-negative integer is read in ININ from the standard input. An error occurs, if after cleaning up the delimiters, something else comes from the standard input.
ReadChar One of the characters +, -, * or = is read in ININ from the standard input. An error occurs, if after cleaning up the delimiters, there is some other character or a number on the standard input.
If <Reg>\text{<Reg>} Is <const>\text{<const>} The beginning of a block to be executed if the content of Reg is equal to the constant const. An attempt to compare a character and a number leads to an error.
EndIf End of the If-block
Store <number> <R>\text{<number> <R>} The content of R becomes equal to the non-negative integer <number><number>.
Copy IN <R>\text{IN <R>} The content of ININ is copied into R. An error occurs if there is a character in ININ, and not a number.
Copy <R1> <R2>\text{<}R_1\text{> <}R_2\text{>} The content of R1R_1 is copied into R2R_2.
Add <Reg> <R>\text{<Reg> <R>} The content of Reg is added to the content of R. If there is a character in Reg, an error occurs.
Sub <Reg> <R>\text{<Reg> <R>} The content of Reg is subtracted from the content of R. If there is a character in Reg, an error occurs.
Mul <Reg> <R>\text{<Reg> <R>} The content of Reg is multiplied by the content of R. If there is a character in Reg, an error occurs.
Repeat Beginning of a cycle block
Loop End of the cycle block
Stop End of the calculation process. The result is the content of AA.

In the beginning of the calculation all registers contain the number 0.

Task

Write a program for the processor PF to correctly calculate an arithmetic expression, containing non-negative integers and the arithmetic operations +, - and *. The result should be obtained in register AA. By "correct", we mean to follow the accepted standard priority of operations: multiplication first, then addition and subtraction from left to right. Thus, the input 2 + 2 * 2 = should leave in AA result 6, not 8.

The input for your program is correct and will look as follows:

Numbers, alternatively followed by a character, are coming from the standard input to the ININ register. This sequence begins with a number. All the numbers are non-negative integers. The character following each of them is one amongst +, -, \ and =. Any non-empty set of spaces, tabs or new line symbols can serve as a delimiter between the members of the sequence. The end of the sequence is marked by reading the character =. The characters +, - and * denote the standard numerical operations: addition, subtraction, and multiplication, respectively.

Output

The problem is of "output-only" type. Send to the testing system a text file PF.txt, containing the program for PF-processor that you have coded, which solves the described problem. Each line of the file PF.txt should be a correct operation for the processor PF.

Constraints

The file PF.txt should not exceed 255 program lines and 64 KB in size. The calculated result of any subsequence of the given one, starting and ending at a number, is a positive or negative integer, or zero, but contains no more than 18 decimal digits.

Evaluation

Each test is evaluated separately. Only operations + and - or only operation * will occur in 30% of the tests.

Interpreter

You are provided with an interpreter of programs for the nanoprocessor PF - the file PFI.cpp. It reads from the folder, where it is compiled, the PF.txt file, which represents a program for the PF-processor, and waits for data from the standard input. If trace mode is switched on (#define TRACE 1), the instructions are executed step by step, after each instruction the registers' content is shown on the standard output, and <ENTER> key is expected. On error, the process terminates with a corresponding message sent to the standard error device. Of course, you can redesign this interpreter as you see comfortable.

Example

Input

12 – 0 * 12345678 * 5 + 3 * 6 – 43 =

Output: The content of register A should be

-13

For faster orientation, we show you below a sample program for PF (the identation is also sample), which for a correctly input sequence of 4 members: a non-negative integer xx, a sign ++ or -, a non-negative integer yy and the sign == calculates the expression 2x±y2^x±y:

ReadInt
Copy IN B
Store 1 A
Copy A C
If B is 0
	ReadChar
	If IN is +
		ReadInt
		Add IN A
		ReadChar
		Stop
	EndIf
	ReadInt
	Sub IN A
	ReadChar
	Stop
EndIf
Add A A
Repeat
	Sub C B
	If B is 0
		ReadChar
		If IN is +
			ReadInt
			Add IN A
			ReadChar
			Stop
		EndIf
		ReadInt
		Sub IN A
		ReadChar
		Stop
	EndIf
	Add C C
	Mul C A
	Store 1 C
Loop

Log in or sign up to be able to send submissions!