#877. Brainfuck

Brainfuck

Background

Brainfuck is a minimal programming language, which contains only 8 kinds of characters.

In the memory model of Brainfuck, there is an infinitely large array and a data pointer p.

The table below illustrates the semantics of each brainfuck instruction.

image

Now you are given a brainfuck code, you need to translate it into C++.

It’s quite easy to finish this task, so the optimizations below are required for you to do

  1. You need to merge consecutive ++ and ,<-, < and >> instructions into one C++ statement. For example,

+++++++++-+ should be simplified to p+=4*p += 4;.

  1. For [[ and ]] command, [][] should be ignored if there are no statements between [[ and ]]. For

example, [[+]][[+-]] should be simplified to nothing.

  1. Any characters other than the eight characters in the table should be ignored.
  2. You need an indention of two spaces for do-while code block.
  3. If [[and ]] are mismatched, just output Error!.

Input

One string representing the code in Brainfuck.

It is guaranteed the length of the input code does not exceed 1100011000

Output

Output the translated Brainfuck code in C++.

Samples

++<<>[]--,
*p += 2;
p -= 1;
*p -= 2;
*p = getchar();
[[+]
Error!
[++[+>+]+]
if (*p) do {
  *p += 2;
  if (*p) do {
    *p += 1;
    p += 1;
    *p += 1;
  } while (*p);
  *p += 1;
} while (*p);