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:
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$:
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.
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.
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.