Draw Brackets!
Contest: VK Cup 2017 - Qualification 2
Difficulty rating: 1400
Tags: *special, implementation

A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[]]][" — are irregular.

Draw the given sequence using a minimalistic pseudographics in the strip of the lowest possible height — use symbols '+', '-' and '|'. For example, the sequence "[[][]][]" should be represented as:

Each bracket should be represented with the hepl of one or more symbols '|' (the vertical part) and symbols '+' and '-' as on the example which is given above.

Brackets should be drawn without spaces one by one, only dividing pairs of consecutive pairwise brackets with a single-space bar (so that the two brackets do not visually merge into one symbol). The image should have the minimum possible height.

The enclosed bracket is always smaller than the surrounding bracket, but each bracket separately strives to maximize the height of the image. So the pair of final brackets in the example above occupies the entire height of the image.

Study carefully the examples below, they adequately explain the condition of the problem. Pay attention that in this problem the answer (the image) is unique.

Input format:
The first line contains an even integer n (2 ≤ n ≤ 100) — the length of the sequence of brackets.

The second line contains the sequence of brackets — these are n symbols "[" and "]". It is guaranteed that the given sequence of brackets is regular.

Output format:
Print the drawn bracket sequence in the format which is given in the condition. Don't print extra (unnecessary) spaces.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Example input:
8
[[][]][]

Example output:
+-        -++- -+
|+- -++- -+||   |
||   ||   |||   |
|+- -++- -+||   |
+-        -++- -+

Example input:
6
[[[]]]

Example output:
+-     -+
|+-   -+|
||+- -+||
|||   |||
||+- -+||
|+-   -+|
+-     -+

Editorial:
It is necessary to draw brackets carefully according to the condition to solve this problem. Draw brackets in a two-dimensional array. Firstly, you need to determine the size of the array and then start to draw. To determine the height of the image, you need to find the maximum nesting of the brackets x. Then the height of the image (it means the number of necessary strings) is equal to 2 * x + 1. The width of the image (it means the number of necessary columns) will be counted in the process of drawing. Also initially you need to fill the entire resulting array with spaces.
To simplify the solution, it is possible to implement a function that draws the next bracket in two parameters. Here are parameters: the cell which should contain the left upper bracket and the type of it — opening or closing.
Thus, to solve this problem, you need to iterate among all brackets from left to right while mantaining the balance of brackets and draw the next bracket using the described auxiliary function. Also check the situation when the current bracket is closing and the previous bracket is opening. In this case it is necessary to leave an empty column according to the condition.