Apply a Cold Compress

Time limit1sMemory limit128 MB

Problem

Many digital-image compression techniques work by finding and describing regions of a single uniform color. Here is a simple scheme for compressing black-and-white images (it extends easily to color). The idea is to repeatedly split the picture in half — either vertically or horizontally — until every sub-picture contains just one color.

A rectangular image is described by a compression-expression, defined as follows. Every compression-expression begins with a two-bit tag, which may be followed by more compression-expressions depending on the tag:

  • 00 — a square region of entirely black pixels. Depending on context this square may be a single pixel, a $2\times2$ square, a $3\times3$ square, and so on.
  • 11 — a square region of entirely white pixels, again of any size depending on context.
  • 10 — a horizontal split, followed by two compression-expressions. The picture is formed by placing the first picture on the left and the second on the right. A horizontal split is only possible between two pictures of the same height.
  • 01 — a vertical split, followed by two compression-expressions. The picture is formed by placing the first picture on top and the second underneath. A vertical split is only possible between two pictures of the same width.

When interpreting a split, the two components may need to be rescaled so that their shared dimension matches. For example, given a $2\times6$ picture $A$ (2 wide, 6 tall) and a $3\times4$ picture $B$:

  • A vertical split is possible only if we scale $A$ by 3 (to $6\times18$) and $B$ by 2 (to $6\times8$); the combined picture is then $6\times26$.
  • A horizontal split is possible only if we scale $A$ by 2 (to $4\times12$) and $B$ by 3 (to $9\times12$); the combined picture is then $13\times12$.

Using X for a black pixel and a space for a white pixel, the expression 00 denotes

---
|X|
---

and the expression 1000010011 denotes

-----
|XXX|
|XX |
-----

For any compression-expression there is a unique smallest picture it can denote; the same expression can also denote pictures twice that size, three times that size, and so on.

Input

Each line of input contains one compression-expression: a single line of an arbitrary number of 0s and 1s. Input continues until end of file.

Every expression in the input is a valid compression-expression.

Output

For each input expression, print the smallest black-and-white picture it denotes, drawing black pixels as X and white pixels as spaces, and framing it with - and | characters exactly as in the pictures above. Print nothing — no characters and no extra whitespace — outside the frame, apart from the newline that ends each line.

Your output must contain no blank lines.