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-----

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-----

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


-----Examples-----
Input
8
[[][]][]

Output
+-        -++- -+
|+- -++- -+||   |
||   ||   |||   |
|+- -++- -+||   |
+-        -++- -+

Input
6
[[[]]]

Output
+-     -+
|+-   -+|
||+- -+||
|||   |||
||+- -+||
|+-   -+|
+-     -+

Input
6
[[][]]

Output
+-        -+
|+- -++- -+|
||   ||   ||
|+- -++- -+|
+-        -+

Input
2
[]

Output
+- -+
|   |
+- -+

Input
4
[][]

Output
+- -++- -+
|   ||   |
+- -++- -+

Difficulty: interview

Starter code:

Solutions:
n = int(input())
x = input()
d = [0] * n
cd = 0
xp = []
for i in range(n):
	if x[i] == '[':
		d[i] = cd
		cd = cd + 1
	else:
		cd = cd - 1
		d[i] = cd
for i in range(n-1):
	xp.append((x[i], d[i]))
	if x[i] == '[' and x[i+1] == ']':
		xp.extend([(' ', d[i]), (' ', d[i]), (' ', d[i])])
xp.append((x[n-1], d[n-1]))
md = max(d)
h = md * 2 + 3
res = []
for i in range(h):
	l = [' ' for j in xp]
	res.append(l)
for i in range(len(xp)):
	for j in range(h):
		if xp[i][0] == '[' and j > xp[i][1] and j < h - xp[i][1] - 1:
			res[j][i] = '|'
		elif xp[i][0] == ']' and j > xp[i][1] and j < h - xp[i][1] - 1:
			res[j][i] = '|'
		elif xp[i][0] == '[' and (j == xp[i][1] or j == h - xp[i][1] - 1):
			res[j][i] = '+'
			res[j][i+1] = '-'
		elif xp[i][0] == ']' and (j == xp[i][1] or j == h - xp[i][1] - 1):
			res[j][i] = '+'
			res[j][i-1] = '-'

for i in range(h):
	print(''.join(res[i]))



class Screen:
    def __init__(self, n_rows):
        self.rows = [[] for _ in range(n_rows)]
        self.height = n_rows

    def draw(self, x, y, c):
        row = self.rows[y]
        while x > len(row) - 1:
            row.append(' ')
        row[x] = c

    def draw_open(self, x, height):
        middle = self.height // 2
        self.draw(x, middle, '|')
        for dy in range(1, height + 1):
            self.draw(x, middle + dy, '|')
            self.draw(x, middle - dy, '|')
        self.draw(x, middle + height + 1, '+')
        self.draw(x + 1, middle + height + 1, '-')
        self.draw(x, middle - height - 1, '+')
        self.draw(x + 1, middle - height - 1, '-')

    def draw_close(self, x, height):
        middle = self.height // 2
        self.draw(x, middle, '|')
        for dy in range(1, height + 1):
            self.draw(x, middle + dy, '|')
            self.draw(x, middle - dy, '|')
        self.draw(x, middle + height + 1, '+')
        self.draw(x - 1, middle + height + 1, '-')
        self.draw(x, middle - height - 1, '+')
        self.draw(x - 1, middle - height - 1, '-')

    def strings(self):
        return [''.join(row) for row in self.rows]


def to_heights(seq):
    depths = []
    cur_depth = 0
    for par in seq:
        if par == '[':
            depths.append(cur_depth)
            cur_depth += 1
        else:
            cur_depth -= 1
            depths.append(cur_depth)
    max_depth = max(depths)
    heights = [max_depth - depth for depth in depths]
    return heights


def to_strings(seq, heights):
    n_rows = 2 * (max(heights) + 1) + 1
    screen = Screen(n_rows)
    cur_x = 0
    prev_par = None
    for par, height in zip(seq, heights):
        if par == '[':
            screen.draw_open(cur_x, height)
            cur_x += 1
        if par == ']':
            if prev_par == '[':
                cur_x += 3
            screen.draw_close(cur_x, height)
            cur_x += 1
        prev_par = par
    return screen.strings()





n = int(input())
seq = input()
heights = to_heights(seq)
strings = to_strings(seq, heights)
for string in strings:
    print(string)



N = int(input())
a = input()
spaces = a.count('[]')
a = list(map(lambda x: 1 if x=='[' else -1, [x for x in str(a) if x=='[' or x==']']))
maxdepth = max([sum(a[:i+1]) for i in range(len(a))])

dl = 5+(maxdepth-1)*2
maxdl = dl-2
#for i in a:
jj = [[' ' for i in range(N+spaces*3)] for j in range(maxdl)]
posx = 0
for i in range(len(a)):
    if a[i] == 1:
        dl -= 2
        for j in range((maxdl-dl)//2,maxdl-(maxdl-dl)//2):
                if j in [(maxdl-dl)//2,maxdl-(maxdl-dl)//2-1]:
                    jj[j][posx]='+'
                    jj[j][posx+1]='-'
                else:
                    jj[j][posx]='|'
        if i < len(a) and a[i+1] == -1:
            posx+=4
        else:
            posx+=1
    elif a[i] == -1:
        for j in range((maxdl-dl)//2,maxdl-(maxdl-dl)//2):
                if j in [(maxdl-dl)//2,maxdl-(maxdl-dl)//2-1]:
                    jj[j][posx]='+'
                    jj[j][posx-1]='-'
                else:
                    jj[j][posx]='|'
        dl += 2
        posx+=1
for j in jj:
    for i in j:
        print(i,end='')
    print()


n = int(input())
s = input()
d = 0 # depth
md = 0 # max depth
for i in s:
    if i == '[':
        d += 1
    else:
        d -= 1
    md = max(md, d)

#print(md)

nv = md * 2 - 1 # kol-vo palok at this moment
out = ""
res = []
i = 0
while i < n:
    out += '+'
    out += ('|' * nv)
    out += '+'
    res.append(out)
    out = ""
    while i != n-1 and s[i+1] == '[':
        nv -= 2
        
        out += '-'
        out += '+'
        out += ('|' * nv)
        out += '+'        
        out += '-' 
        
        res.append(out)
        out = ""     
        
        i += 1
    out += '-'
    out += ' ' * nv
    out += '-'
    res.append(out)
    out = ""
    
    res.append(" " * (nv + 2))
    i += 1
    
    out += '-'
    out += ' ' * nv
    out += '-'
    res.append(out)
    out = ""    
    
    while i != n-1 and s[i+1] == ']':        
        out += '-'
        out += '+'
        out += ('|' * nv)
        out += '+'        
        out += '-' 
        
        res.append(out)
        out = ""     
        
        nv += 2
        i += 1
    
    out += '+'
    out += ('|' * nv)
    out += '+'
    res.append(out)
    out = ""    
    #print(out)
    i += 1

norm = md * 2 + 1
for i in range(len(res)):
    if len(res[i]) == norm:
        continue
    else:
        otk = (norm - len(res[i])) // 2
        res[i] = (" " * otk) + res[i] + (" " * otk)

for i in range(norm):
    for j in range(len(res)):
        print(res[j][i], end="")
    print()

"""
8
[[][]][]

6
[[[]]]

6
[[][]]

2
[]

4
[][]
"""

import sys

n = int(input())
s = input()

height = [1] * n
matching = [-1] * n

for i, c in enumerate(s):
    if c == ']':
        height[i] = height[matching[i]]
        continue
    balance = 1
    for j in range(i + 1, n):
        if s[j] == '[':
            balance += 1
        elif s[j] == ']':
            balance -= 1
        height[i] = max(height[i], balance)
        if balance == 0:
            matching[i] = j
            matching[j] = i
            break

max_height = max(height)
cur_height, prev_height = max_height, -1
columns = []

m = 2 * max_height + 1

def draw_bar(pos, height):
    while len(columns) <= pos:
        columns.append([' ' for _ in range(m)])
    upper_plus = max_height - height
    lower_plus = m - upper_plus - 1
    
    columns[pos][upper_plus] = columns[pos][lower_plus] = '+'
    for i in range(upper_plus + 1, lower_plus):
        columns[pos][i] = '|'

def draw_lines(pos, height):
    while len(columns) <= pos:
        columns.append([' ' for _ in range(m)])

    upper_minus = max_height - height
    lower_minus = m - upper_minus - 1

    columns[pos][upper_minus] = columns[pos][lower_minus] = '-'

pos, h = 0, max_height
for i, c in enumerate(s):
    if i > 0:
        if c == ']' and s[i-1] == '[':
            pos += 3
        if c == '[' and s[i-1] == '[':
            h -= 1
        elif c == ']' and s[i-1] == ']':
            h += 1

    draw_bar(pos, h)
    if c == '[':
        draw_lines(pos + 1, h)
    elif c == ']':
        draw_lines(pos - 1, h)

    pos += 1

for i in range(m):
    line = ''.join(column[i] for column in columns).rstrip()
    print(line)


n=int(input())
a=input()
v=1
q=0
maxlen=0
for i in range(1,len(a)):
    if a[i]=='[':
        v+=1
    else:
        v-=1
    if(a[i-1]=='[' and a[i]==']'):
        q+=1
    maxlen=max(maxlen,v)
v=[[" "]*(q*3+n) for i in range(3+ (max(0,maxlen-1)*2))]
y=3+(max(0,maxlen-1)*2)
x=0
w=0
for i in range(n):
    if a[i]=='[':
        for j in range(w,y-w):
            if(j==w or j==y-1-w):
                v[j][x]='+'
                v[j][x+1]='-'
            else:
                v[j][x]='|'
        x+=1
        w+=1
    else:
        if(a[i-1]=='['):
            x+=3
        w-=1
        for j in range(w,y-w):
            if(j==w or j==y-1-w):
                v[j][x]='+'
                v[j][x-1]='-'
            else:
                v[j][x]='|'
        x+=1
for i in range(3+ (max(0,maxlen-1)*2)):
    for j in range(q*3+n):
        print(v[i][j],end="")
    print()    

lmap = lambda func, x: list(map(func, x))




_, scobes = input(), input()#'', '[[[][][][][][][][]][]][]'
scobes = scobes.replace('[]', '[   ]')

def empty_list(s):
	return [0] * s

def two_dim_array(size):
	return [empty_list(size[0]) for i in range(size[1])]

def process_scobes(scobes):

	depthes = []
	depth = 0
	for i, scobe in enumerate(scobes):
		if scobe == '[':
			depth+=1
		depthes.append(depth)

		if scobe == ']':
			depth-=1

	
	max_depth = max(depthes)
	depthes = lmap(lambda val: 2*(max_depth - val+1)+1, depthes)
	return depthes

def set_on_interval(from_, to_):
	pass

def draw_scobes_into_array(scobes, heights):
	picture = two_dim_array([len(scobes), max(heights)])
	middle = (max(heights) + 1)//2 

	for i, scobe in enumerate(scobes):
		h = heights[i] //2 - 1
		if scobe!=' ':
			for height in range(middle-h - 1, middle+h):
				picture[height][i] = 1

			picture[middle - h - 2][i] = 2
			picture[middle + h][i] = 2
			offset = 1 if scobe == '[' else -1
			picture[middle - h - 2][i + offset] = 3
			picture[middle + h][i + offset] = 3

	return picture



heights = process_scobes(scobes)

picture = draw_scobes_into_array(scobes, heights)


draw_line = lambda line: ''.join(lmap(str, line)).replace('0', ' ').replace('1', '|').replace('2', '+').replace('3', '-')
print('\n'.join(lmap(draw_line, picture)))

#Here was me!


input()
mas = input()
ans = [0] * len(mas)
stack = 0

maxx = 0

for i in mas:
    if(i == "["):
        stack += 1
    else:
        stack -= 1
    maxx = max(maxx, stack)


stack = []
for i in range(len(mas)):
    if(mas[i] == "["):
        stack.append(i)
    else:
        j = stack.pop()
        ans[i] = len(stack)
        ans[j] = len(stack)


for i in range(len(ans)):
    ans[i] = maxx - ans[i]

    
i = 0
while i != len(ans) - 1:
    if(mas[i] == "[" and mas[i + 1] == "]"):
        mas = mas[:i + 1] + "___" + mas[i + 1:]
        ans.insert(i + 1, "_")
        ans.insert(i + 1, "_")
        ans.insert(i + 1, "_")
        i += 2
    i += 1


for i in range(maxx, 0, -1):
    for x in range(len(ans)):
        if(ans[x] == "_"):
            if(ans[x - 1] == i or ans[x + 1] == i):
                print("-", end = "")
            else:
                print(" ", end = "")
        else:
            if(ans[x] == i):
                print("+", end = "")
            elif(ans[x] > i):
                print("|", end = "")
            elif(ans[x - 1] == i or ans[x + 1] == i):
                print("-", end = "")
            else:
                print(" ", end = "")
    print()


for i in range(0, maxx + 1):
    for x in range(len(ans)):
        if(ans[x] == "_"):
            if(ans[x - 1] == i or ans[x + 1] == i):
                print("-", end = "")
            else:
                print(" ", end = "")
        else:
            if(ans[x] == i):
                print("+", end = "")
            elif(ans[x] > i):
                print("|", end = "")
            elif(ans[x - 1] == i or ans[x + 1] == i):
                print("-", end = "")
            else:
                print(" ", end = "")
    print()

n = int(input())
s = list(input())

max_len = 0
cur_len = 0
for si in s:
    if si == '[':
        cur_len += 1
    if si == ']':
        cur_len -= 1
    if cur_len > max_len:
        max_len = cur_len

cur_len = 0
size = []
ans = []
for si in s:
    if si == '[':
        cur_len += 1
        size.append(max_len - cur_len + 1)
        ans.append(size[-1])
    if si == ']':
        cur_len -= 1
        ans.append(size[-1])
        size = size[:-1]


def draw_bracket(pos, size, picture, open):
    start = (len(picture) - 2*size - 1) // 2
    picture[start][pos] = '+'
    if open:
        picture[start][pos + 1] = '-'
    else:
        picture[start][pos - 1] = '-'
    
    picture[len(picture) - start - 1][pos] = '+'
    if open:
        picture[len(picture) - start - 1][pos + 1] = '-'
    else:
        picture[len(picture) - start - 1][pos - 1] = '-'
    
    for i in range(start + 1, len(picture) - start - 1):
        picture[i][pos] = '|'


def draw_picture(picture):
    for i in picture:
        print(''.join(i))


pic_size = 0
for i in range(n):
    pic_size += 1
    if i + 1 < n and s[i] == '[' and s[i + 1] == ']':
        pic_size += 3


picture = [[' ']*pic_size for i in range(2*max_len + 1)]
pos = 0
for i in range(n):
    if s[i] == '[':
        draw_bracket(pos, ans[i], picture, True)
        if i + 1 < n:
            if s[i + 1] == '[':
                pos += 1
            if s[i + 1] == ']':
                pos += 4
    if s[i] == ']':
        draw_bracket(pos, ans[i], picture, False)
        pos += 1


draw_picture(picture)


input()
br = input()
d = []
com = 0
hmax = 0
for i in range(len(br)):
	if br[i] == '[':
		d.append({
			'open': True,
			'com': com
		})
		com += 2
	else:
		com -= 2
		d.append({
			'open': False,
			'com': com
		})

	if com > hmax:
		hmax = com

hmax -= 1

a = [[] for j in range(hmax + 2)]
y = 0
x = 0
ap = True
for j in range(len(d)):

	if ap:
		for kek in range(len(a)):
			a[kek].append(' ')
	else:
		ap = True

	i = d[j]
	y = i['com'] // 2
	y0 = y
	a[y][x] = '+'
	for _ in range(hmax - i['com']):
		y += 1
		a[y][x] = '|'
	y += 1
	a[y][x] = '+'

	if i['open']:
		for kek in range(len(a)):
			a[kek].append(' ')
		ap = False
		a[y0][x + 1] = '-'
		a[y][x + 1] = '-'
	else:
		a[y0][x - 1] = '-'
		a[y][x - 1] = '-'
	try:
		if i['open'] and not d[j + 1]['open']:
			x += 3
			for kek in range(len(a)):
				for _ in range(3):
					a[kek].append(' ')
	except:
		pass

	x += 1

for i in a:
	print(*i, sep='')

import base64
code = "aW5wdXQgKCkjbGluZToxCmJyID1pbnB1dCAoKSNsaW5lOjIKZCA9W10jbGluZTozCmNvbSA9MCAjbGluZTo0CmhtYXggPTAgI2xpbmU6NQpmb3IgaSBpbiByYW5nZSAobGVuIChiciApKTojbGluZTo2CglpZiBiciBbaSBdPT0nWyc6I2xpbmU6NwoJCWQgLmFwcGVuZCAoeydvcGVuJzpUcnVlICwnY29tJzpjb20gfSkjbGluZToxMQoJCWNvbSArPTIgI2xpbmU6MTIKCWVsc2UgOiNsaW5lOjEzCgkJY29tIC09MiAjbGluZToxNAoJCWQgLmFwcGVuZCAoeydvcGVuJzpGYWxzZSAsJ2NvbSc6Y29tIH0pI2xpbmU6MTgKCWlmIGNvbSA+aG1heCA6I2xpbmU6MjAKCQlobWF4ID1jb20gI2xpbmU6MjEKaG1heCAtPTEgI2xpbmU6MjMKYSA9W1tdZm9yIE8wTzAwME8wTzAwTzAwMDBPIGluIHJhbmdlIChobWF4ICsyICldI2xpbmU6MjUKeSA9MCAjbGluZToyNgp4ID0wICNsaW5lOjI3CmFwID1UcnVlICNsaW5lOjI4CmZvciBqIGluIHJhbmdlIChsZW4gKGQgKSk6I2xpbmU6MjkKCWlmIGFwIDojbGluZTozMQoJCWZvciBrZWsgaW4gcmFuZ2UgKGxlbiAoYSApKTojbGluZTozMgoJCQlhIFtrZWsgXS5hcHBlbmQgKCcgJykjbGluZTozMwoJZWxzZSA6I2xpbmU6MzQKCQlhcCA9VHJ1ZSAjbGluZTozNQoJaSA9ZCBbaiBdI2xpbmU6MzcKCXkgPWkgWydjb20nXS8vMiAjbGluZTozOAoJeTAgPXkgI2xpbmU6MzkKCWEgW3kgXVt4IF09JysnI2xpbmU6NDAKCWZvciBfIGluIHJhbmdlIChobWF4IC1pIFsnY29tJ10pOiNsaW5lOjQxCgkJeSArPTEgI2xpbmU6NDIKCQlhIFt5IF1beCBdPSd8JyNsaW5lOjQzCgl5ICs9MSAjbGluZTo0NAoJYSBbeSBdW3ggXT0nKycjbGluZTo0NQoJaWYgaSBbJ29wZW4nXTojbGluZTo0NwoJCWZvciBrZWsgaW4gcmFuZ2UgKGxlbiAoYSApKTojbGluZTo0OAoJCQlhIFtrZWsgXS5hcHBlbmQgKCcgJykjbGluZTo0OQoJCWFwID1GYWxzZSAjbGluZTo1MAoJCWEgW3kwIF1beCArMSBdPSctJyNsaW5lOjUxCgkJYSBbeSBdW3ggKzEgXT0nLScjbGluZTo1MgoJZWxzZSA6I2xpbmU6NTMKCQlhIFt5MCBdW3ggLTEgXT0nLScjbGluZTo1NAoJCWEgW3kgXVt4IC0xIF09Jy0nI2xpbmU6NTUKCXRyeSA6I2xpbmU6NTYKCQlpZiBpIFsnb3BlbiddYW5kIG5vdCBkIFtqICsxIF1bJ29wZW4nXTojbGluZTo1NwoJCQl4ICs9MyAjbGluZTo1OAoJCQlmb3Iga2VrIGluIHJhbmdlIChsZW4gKGEgKSk6I2xpbmU6NTkKCQkJCWZvciBfIGluIHJhbmdlICgzICk6I2xpbmU6NjAKCQkJCQlhIFtrZWsgXS5hcHBlbmQgKCcgJykjbGluZTo2MQoJZXhjZXB0IDojbGluZTo2MgoJCXBhc3MgI2xpbmU6NjMKCXggKz0xICNsaW5lOjY1CmZvciBpIGluIGEgOiNsaW5lOjY3CglwcmludCAoKmkgLHNlcCA9JycpCg=="
eval(compile(base64.b64decode(code),'<string>','exec'))

import sys

def vert(f, d, c, h):
    f[d][c] = '+'
    f[h-1-d][c] = '+'
    for i in range(d+1,h-1-d):
        f[i][c] = '|'
    return f

n = int(input())
s = sys.stdin.readline().rstrip()

d = 0
maxd=1
for c in s:
    if c == '[':
        d+=1
        if d>maxd:
            maxd=d
    else:
        d-=1

h = 2*maxd +1
opcl = s.count("[]")

w = opcl*5 + (len(s) - opcl*2)

f = [[' ']*w for _ in range(h)]

d = 0
c = 0
for i in range(n):
    if s[i] == '[':        
        f = vert(f,d,c,h)
        f[d][c+1] = '-'
        f[h-1-d][c+1] = '-'        
        d+=1
    else:
        if i>0 and s[i-1] == '[':
            c+=3
        d-=1
        f = vert(f,d,c,h)
        f[d][c-1] = '-'
        f[h-1-d][c-1] = '-'
        
    c+=1

ans = ["".join(x) for x in f]
print("\n".join(ans))


def draw(ind, type, size):
    nonlocal ans, mid
    ans[mid][ind] = '|'
    for i in range(size // 2):
        ans[mid + i][ind] = '|'
        ans[mid - i][ind] = '|'
    ans[mid + size // 2][ind] = '+'
    ans[mid - size // 2][ind] = '+'
    if type == "left":
        ans[mid + size // 2][ind - 1] = '-'
        ans[mid - size // 2][ind - 1] = '-'
    else:
        ans[mid + size // 2][ind + 1] = '-'
        ans[mid - size // 2][ind + 1] = '-'


n = int(input())
s = input()
mx = 0
cs = 0
for i in range(n):
    if s[i] == "[":
        cs += 1
    else:
        cs -= 1
    mx = max(mx, cs)
mx -= 1
a = [mx]
for i in range(1, n):
    if (s[i] == "[" and s[i - 1] == "]") or (s[i - 1] == "[" and s[i] == "]"):
        a.append(a[-1])
    elif s[i] == "[":
        a.append(a[-1] - 1)
    else:
        a.append(a[-1] + 1)
ans = [[' ' for i in range(n * 3)] for j in range(3 + mx * 2)]
mid = mx + 1
draw(0, "right", mx * 2 + 3)
li = 0
for i in range(1, n):
    if s[i] == "[" and s[i - 1] == "]":
        li += 1
        draw(li, "right", a[i] * 2 + 3)
    elif s[i - 1] == "[" and s[i] == "]":
        li += 4
        draw(li, "left", a[i] * 2 + 3)
    elif s[i] == "[":
        li += 1
        draw(li, "right", a[i] * 2 + 3)
    else:
        li += 1
        draw(li, "left", a[i] * 2 + 3)
for i in ans:
    for j in range(li + 1):
        print(i[j], end="")
    print()


input()
a = input()
field = [[" " for j in range(500)] for i in range(500)]
mxb = -1
b = 0
for i in range(len(a)):
    if a[i] == "[":
        b += 1
    else:
        b -= 1
    mxb = max(mxb, b)
m = (mxb * 2 + 1) // 2   

def opn(curpos, curb):
    up = mxb - curb + 1
    for i in range(up):
        field[m + i][curpos] = "|"
    for i in range(up):
        field[m - i][curpos] = "|"
    field[m + up][curpos] = "+"
    field[m - up][curpos] = "+"
    field[m + up][curpos + 1] = "-"
    field[m - up][curpos + 1] = "-"
    
    
def clos(curpos,curb):
    up = mxb - curb  + 1
    for i in range(up):
        field[m + i][curpos] = "|"
    for i in range(up):
        field[m - i][curpos] = "|"
    field[m + up][curpos] = "+"
    field[m - up][curpos] = "+"
    field[m + up][curpos - 1] = "-"
    field[m - up][curpos - 1] = "-"    
    
    
curb = 0
pos = 0
for i in range(len(a)):
    if a[i] == "[":
        curb += 1
        opn(pos,curb)
        pos += 1
    else:
        if a[i - 1] == "[":
            pos += 3
        clos(pos,curb)
        curb -= 1
        pos += 1
ans = []
for i in range(len(field)):
    lst = -1
    for j in range(len(field[0])):
        if field[i][j] != " ":
            lst = j 
    ans.append(lst + 1)
for i in range(len(field)):
    for j in range(ans[i]):
        print(field[i][j],end="")
    if ans[i]:
        print()
    

n = input()
s = input()
bal = []

curbal = 0
maxbal = 0
for i in s:
    if i == '[':
        bal.append((curbal, 1))        
        curbal += 1
        maxbal = max(curbal, maxbal)
    else:
        bal.append((curbal, -1))
        curbal -= 1        
    
bal = [(maxbal - i, j) for (i, j) in bal]
stack = []
ans = [[] for _ in range(2 * maxbal + 1)]

for i in range(len(bal)):
    if bal[i][1] == 1:
        stack.append(bal[i][0])
        if i == 0 or bal[i - 1][1] == 1:    
            for j in range(maxbal - bal[i][0]):
                ans[j].append(" ")
            ans[maxbal - bal[i][0]].append("+-")
            for j in range(maxbal - bal[i][0] + 1, maxbal + bal[i][0]):
                ans[j].append("|")
            ans[maxbal + bal[i][0]].append("+-")
            for j in range(maxbal + bal[i][0] + 1, 2 * maxbal + 1):
                ans[j].append(" ")
        else:
            for j in range(maxbal - bal[i][0]):
                ans[j].append("   ")
            ans[maxbal - bal[i][0]].append("+-")
            for j in range(maxbal - bal[i][0] + 1, maxbal + bal[i][0]):
                ans[j].append("|")
            ans[maxbal + bal[i][0]].append("+-")
            for j in range(maxbal + bal[i][0] + 1, 2 * maxbal + 1):
                ans[j].append("   ")            
    else:
        if bal[i - 1][1] == 1:
            for j in range(2 * maxbal + 1):
                ans[j].append(" ")
            for j in range(maxbal - stack[-1]):
                ans[j].append(" ")
            ans[maxbal - stack[-1]].append("-+")
            for j in range(maxbal - stack[-1] + 1, maxbal + stack[-1]):
                ans[j].append("  |")
            ans[maxbal + stack[-1]].append("-+")
            for j in range(maxbal + stack[-1] + 1, 2 * maxbal + 1):
                ans[j].append(" ")               
        else:
            for j in range(maxbal - stack[-1]):
                ans[j].append(" ")
            ans[maxbal - stack[-1]].append("-+")
            for j in range(maxbal - stack[-1] + 1, maxbal + stack[-1]):
                ans[j].append("|")
            ans[maxbal + stack[-1]].append("-+")
            for j in range(maxbal + stack[-1] + 1, 2 * maxbal + 1):
                ans[j].append(" ")            
        stack.pop()
for i in ans:
    print(''.join(i))

#This code is dedicated to Olya S.
l=int(input())
n=input()

def offset(ml,x):
    return (ml-x)//2

def getstate(g,line,ml):
    off=offset(ml,g[0])
    if line<off or line>=g[0]+off:
        return 0
    elif line==off or line == g[0]+off-1:
        return 1
    else:
        return 2
    
    
    

#Find max bracket#
ml=1
cl=1
for b in n:
    if b=='[':
        cl+=2
        if ml<cl:
            ml=cl
    else:
        cl-=2
######MAP######
sc=[]
for b in n:
    if b=='[':
        sc.append([ml,True])
        ml-=2
    else:
        ml+=2
        sc.append([ml,False])
#####################
for i in range(ml):
    for j in range(l):
        g=sc[j]
        state=getstate(g,i,ml)
        if state==1:
            if g[1]:
                print('+-',end='')
            else:
                print('-+',end='')
        elif state==0:
            if sc[j-1][0]-sc[j][0]!=2:
                print('  ',end='')
        else:
            print('|',end='')
        if sc[j][1] and not sc[j+1][1]:
            if state==2:
                print('   ',end='')
            else:
                print(' ',end='')
        
    print()

    






            


def getHeight(s: str) -> int:
    h = maxh = 0
    for c in s:
        h += (1 if c == '[' else -1)
        maxh = max(h, maxh)
    return maxh


def makeColumn(height: int, maximumHeight: int) -> str:
    half = (maximumHeight - height) * [' '] + ['+'] + height * ['|']
    return half + half[-2::-1]


n, s = int(input()), input()
h = getHeight(s)
ans = [makeColumn(h, h)]
curh = h - 1
for i in range(1, n):
    if s[i] == ']':
        if s[i - 1] == '[':
            for j in range(3):
                ans.append([' '] * (h * 2 + 1))
        curh += 1
        ans.append(makeColumn(curh, h))
    else:
        ans.append(makeColumn(curh, h))
        curh -= 1
for line in zip(*ans):
    for i in range(len(line)):
        if ((i > 0 and line[i - 1] == '+') or
          (i < len(line) - 1 and line[i + 1] == '+')) and line[i] == ' ':
            print('-', end='')
        else:
            print(line[i], end='')
    print()


n = int(input())
s = input()
bal = 0
m = 0
v = [0] * n
for i in range(n):
    if s[i] == '[':
        bal += 1
        v[i] = bal
        m = max(m, bal)
    else:
        v[i] = -bal
        bal -= 1
for j in range(1, 2 * m + 2):
    for i in range(0, n):
        if abs(v[i]) == j or abs(v[i]) == 2 * (m + 1) - j:
            if v[i] > 0:
                print('+-', end = '')
            else:
                print('-+', end = '')
        elif abs(v[i]) < j and abs(v[i]) < 2 * (m + 1) - j:
            print('|', end = '')
            if i + 1 < n and v[i + 1] < 0 and v[i] == -v[i + 1]:
                print('  ', end = '')
        else:
            print(' ', end = '')
            if i > 0 and abs(v[i - 1]) >= abs(v[i]) and i + 1 < n and abs(v[i + 1]) >= abs(v[i]):
                print(' ', end = '')
        if i + 1 < n and v[i + 1] < 0 and v[i] == -v[i + 1]:
            print(' ', end = '')
    print()

            


n = input()
s = input()

b = 0
maxb = 0
for c in s:
    if c == '[':
        b += 1
    else:
        b -= 1
    if b > maxb:
        maxb = b

res = [""] * (maxb * 2 + 1)
b = maxb
pred = ""

for k in range(len(s)):
    c = s[k]
    
    if c == '[':
        if k != len(s) - 1:
            if s[k+1] == ']':
                sep = '| '
            else:
                sep = '|'
        else:
            sep = '|'
            
        i = maxb - b
        for j in range(i):
            res[j] += ' '
        
        res[i] += '+-'        
        for j in range(i + 1, len(res) - i - 1):
            res[j] += sep
        res[len(res) - i - 1] += '+-'

        for j in range(len(res) - i, len(res)):
            res[j] += ' '
                        
        pred = '['
        b -= 1
        
    elif c == ']':
        if k != len(s) - 1:
            if s[k+1] == '[':
                space = '   '
            else:
                space = ' '
        else:
            space = ' '
        
        b += 1
        if pred == '[':
            sep = ' |'
            for j in range(len(res)):
                res[j] += ' '
        else:
            sep = '|'
                        
        i = maxb - b
        for j in range(i):
                res[j] += space
         
        res[i] += '-+'              
        for j in range(i + 1, len(res) - i - 1):
            res[j] += sep              
        res[len(res) - i - 1] += '-+'

        for j in range(len(res) - i, len(res)):
            res[j] += space
                        
        pred = ']'

for i in res:
    print(i)




        





_, s = input(), input()

MAX_H = 1 + 2 * max(s.count('[', 0, i) - s.count(']', 0, i) for i in range(len(s) + 1))

line = lambda d: '+'.join((' ' * d, '|' * (MAX_H - 2 * d - 2), ' ' * d))

def draw(s, i, d):
    return [line(d)] if s[i] == '[' else ([' ' * MAX_H] * 3 if s[i - 1] == '[' else []) + [line(d - 1)]

[print(''.join(x).replace('+ ', '+-').replace(' +', '-+')) for x in zip(*sum((draw(s, i, s.count('[', 0, i) - s.count(']', 0, i)) for i in range(len(s))), []))]


n = int(input())
s = input()
t = set()
a = [0]*len(s)
q = 0
m = 0
ans = []
for i in range(len(s)):
    if(s[i]=='['):
        q+=1
        a[i]=q
        m=max(m,q)
    else:
        a[i]=q
        q-=1
        m = max(m,q)
        if(s[i-1]=='['):
            t.add(i-1)
for i in range(m+1):
    e=''
    for j in range(len(s)):
        if(a[j]-1==i):
            if(s[j]=='['):
                e+='+-'
                if(j in t):
                    e+=' '
            else:
                e+='-+'
        elif(a[j]-1<i):
            if(s[j]=='['):
                e+='|'
                if(j in t):
                    e+='  '
            elif(s[j]==']'):
                if(j-1 in t):
                    e+=' '
                e+='|'
        else:
            if(s[j]=='['):
                if(j>0 and s[j-1]==']' and a[j-1]==a[j]):
                    e+=' '
                e+=' '
                if(j in t):
                    e+=' '
            else:
                if(j!=len(s)-1 and s[j+1]!=']'):
                    e+=' '
                e+=' '
    ans+=[e]
for i in range(len(ans)):
    print(ans[i])
for i in range(len(ans)-2,-1,-1):
    print(ans[i])



# -*- coding: utf-8 -*-
"""
Created on Sat Mar 11 23:20:54 2017

@author: Alexandr
"""

n = int(input())
brackets = input()
max_deep = 0
deep = [0] * n
d = 0
for i in range(n):
    if brackets[i] == '[':
        d += 1
        deep[i] = d
    else:
        deep[i] = d
        d -= 1

max_deep = max(deep)

ans = []
height = max_deep * 2 + 1

for i in range(n):
    x = (max_deep - deep[i]) * 2 + 1
    y = (height - x - 2) // 2    
    s = '+' + '|'*x + '+'
    if (
        i != 0 
        and brackets[i] == ']' 
        and brackets[i - 1] == '['
    ):
        ans.append(y * ' ' + '-' + x * ' ' + '-' + y * ' ')
        ans.append(' ' * height)            
        ans.append(y * ' ' + '-' + x * ' ' + '-' + y * ' ')
    if (
        i != 0 and i != n - 1
        and deep[i] != 1 
        and (deep[i] > deep[i - 1] or deep[i] > deep[i + 1])
    ):
        s = (y - 1) * ' ' + '-' + s + '-' + (y - 1) * ' '
        
    else:
        s = y * ' ' + s + y * ' '
    ans.append(s)

for i in zip(*ans):
    print(''.join(i))

def Paint(height,napr):
   return ''
rngOfseq=int(input())
seq=input()
maxh=3
heightes=[]
current=1
tek=3
for i in range(rngOfseq-1):#maxh
    if seq[i]=='[' and seq[i+1]=='[':
        tek+=2
    if seq[i]==']' and seq[i+1]==']':
        tek-=2
    if maxh<tek:
        maxh=tek
current=maxh
for i in range(rngOfseq-1):#heightes
    heightes.append(current)
    if seq[i]=='[' and seq[i+1]=='[':
        current-=2
    if seq[i]==']' and seq[i+1]==']':
        current+=2
heightes.append(current)
current=maxh
Flag=True
for j in range(maxh):#draw
    currentraw=''
    for i in range(rngOfseq):
        if heightes[i]==current:
            if seq[i]=='[':
                currentraw+='+-'
            else:
                currentraw+='-+'
        elif heightes[i]>current:
            currentraw+='|'
        else:
            currentraw+=' '
        try:
            if heightes[i]==heightes[i+1]:
                if heightes[i]==current:
                    if seq[i] =='[' and seq[i+1]==']':
                        currentraw+=' '
                elif heightes[i]<current:
                    if seq[i] ==']' and seq[i+1]=='[':
                        currentraw+='  '
                    if seq[i] =='[' and seq[i+1]==']':
                        currentraw+=' '
                else:
                    if seq[i] =='[' and seq[i+1]==']':
                        currentraw+='   '
        except:
            continue
    if current==1:
        Flag=False
    if Flag:
        current-=2
    else:
        current+=2
    print(currentraw)

def empty(d):
	t = '+- -+'
	res = [t]
	for i in range(2 * d - 1): res.append('|   |')
	res.append('+- -+')
	return res

def cover(l):
	numspaces = len(l[0]) - 2
	spaces = numspaces * ' '
	tb = '+-' + spaces + '-+'
	res = [tb]
	for s in l:
		ns = '|' + s + '|'
		res.append(ns)
	res.append(tb)
	return res

def do(s, d):
	blocks = list()
	start = 0
	balance = 0
	for right in range(len(s)):
		if s[right] == '[':
			balance += 1
		else: 
			balance -= 1
		if balance == 0:
			if start + 1 == right:
				blocks.append(empty(d))
			else:
				inner = do(s[start + 1 : right], d - 1)
				covered = cover(inner)
				blocks.append(covered)
			start = right + 1
	res = ["" for _ in range(2 * d + 1)]
	for block in blocks:
		for i in range(len(block)):
			res[i] += block[i]
	return res

def depth(s):
	res = 0
	cur = 0
	for c in s:
		if c == '[':
			cur += 1
		else:
			cur -= 1
		res = max(res, cur)
	return res

n = int(input())
s = input()
for l in do(s, depth(s)):
	print(l)