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

Solutions:
n = int(input())
brackets = input()
levels = [None] * n
i = 0
while i < n:
	if brackets[i] == '[':
		level = 0
		levels[i] = level
		for j in range(i + 1, n):
			if brackets[j] == '[':
				level += 1
				levels[j] = level
			else:
				levels[j] = level
				if level == 0:
					i = j + 1
					break
				level -= 1
max_level = max(levels)
len_rotate = n + brackets.count('[]') * 3
len_rotate_ele = max_level * 2 + 1 + 2
rotate = [None] * len_rotate
offset = 0
for i in range(n):
	cur_level = levels[i]
	cur_index = i + offset
	body_len = (max_level - cur_level) * 2 + 1
	body = ''.join(['+', '|' * body_len, '+'])
	if cur_level == 0:
		rotate[cur_index] = body
	elif cur_level > levels[i - 1] or cur_level > levels[i + 1]:
		space = ' ' * (cur_level - 1)
		rotate[cur_index] = '-'.join([space, body, space])
	else:
		space = ' ' * cur_level
		rotate[cur_index] = ''.join([space, body, space])
	if brackets[i] == '[' and brackets[i + 1] == ']':
		space = ' ' * cur_level
		rotate[cur_index + 1] = rotate[cur_index + 3] = '-'.join([space, ' ' * body_len, space])
		rotate[cur_index + 2] = ' ' * len_rotate_ele
		offset += 3
rotate_back = [None] * len_rotate_ele
for i in range(len_rotate_ele):
	line = ''
	for j in range(len_rotate):
		line += rotate[j][i]
	rotate_back[i] = line
print('\n'.join(rotate_back))


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


n = int(input())
S = input()
maxi = 0
lala = 0
for i in range(len(S)):
	s = S[i]
	if s == '[':
		lala += 1
	else:
		lala -= 1
	maxi = max(maxi, lala)
mass = maxi * 2 + 1
dlin = n + S.count('[]')
S = S.replace('[]', '[ ]')
SS = list()
for i in range(len(S)):
	s = S[i]
	if s == ' ':
		SS.append(-1)
	elif s == '[':
		SS.append(maxi - lala)
		lala += 1
	else:
		lala -= 1
		SS.append(maxi - lala)
	maxi = max(maxi, lala)
SSS = list(S)
ans = [[] for i in range(mass)]
a = maxi
for i in range(len(SS)):
	if SS[i] == -1:
		ans[a] += '   '
	else:
		ans[a] += '|'
for i in range(1, maxi + 1):
	a1 = a + i
	a2 = a - i
	for j in range(len(SS)):
		elem = SSS[j]
		code = SS[j]
		if code > i and code != -1:
			ans[a1] += '|'
			ans[a2] += '|'
		elif code == i and elem == '[':
			ans[a1] += '+-'
			ans[a2] += '+-'
		elif code == i and elem == ']':
			ans[a1] += '-+'
			ans[a2] += '-+'
		elif code == -1 and SS[j - 1] == i:
			ans[a1] += ' '
			ans[a2] += ' '
		elif code == -1:
			ans[a1] += '   '
			ans[a2] += '   '
		elif code < i and SS[j - 1] == i:
			pass
		elif code < i and SS[j + 1] == i:
			pass
		elif code < i:
			ans[a1] += ' '
			ans[a2] += ' '
for elem in ans:
	print(*elem, sep='')


n = int(input())
s = input()
high = 1
max_high = 1
for i in range(1, n):
	if s[i] == '[':
		high += 1
	else:
		if high > max_high:
			max_high = high
		high -= 1
high = max_high
lenght = 1
for i in range(1, n):
	if s[i] == s[i - 1]:
		lenght += 1
	elif s[i] == ']' and s[i - 1] == '[':
		lenght += 4
	else:
		lenght += 1
Map = []
high = high * 2 + 1
for i in range(high):
	Map.append(dict())
	for j in range(lenght):
		Map[i][j] = ' '
highs = [high]
xs = [0]
h = high
x = 0
for i in range(1, n):
	if s[i] == s[i - 1]:
		if s[i] == ']':
			h += 2
		else:
			h -= 2
		x += 1
	elif s[i] == ']' and s[i - 1] == '[':
		x += 4
	else:
		x += 1
	highs.append(h)
	xs.append(x)

def s_create(x, h, side):
	if side == ']':
		Map[(high - h) // 2][x - 1] = '-'
		Map[(high - h) // 2][x] = '+'
		Map[high - (high - h) // 2 - 1][x - 1] = '-'
		Map[high - (high - h) // 2 - 1][x] = '+'
	else:
		Map[(high - h) // 2][x + 1] = '-'
		Map[(high - h) // 2][x] = '+'
		Map[high - (high - h) // 2 - 1][x + 1] = '-'
		Map[high - (high - h) // 2 - 1][x] = '+'
	for i in range(h - 2):
		Map[(high - h) // 2 + i + 1][x] = '|'
last_h = high
s_create(0, high, '[')
for i in range(1, n):
	s_create(xs[i], highs[i], s[i])
for i in range(high):
	for j in range(lenght):
		print(Map[i][j], end='')
	print()


def maxvlozh(stroka):
	stack = 0
	maxvl = 0
	for i in range(len(stroka)):
		if stroka[i] == '[':
			stack += 1
		else:
			stack -= 1
		if maxvl < stack:
			maxvl = stack
	return maxvl

def kol_vlozh(stroka, i):
	stack = 0
	kol = -1
	for i in range(i, len(s)):
		if stroka[i] == '[':
			stack += 1
			kol += 1
		else:
			stack -= 1
		if stack == 0:
			break
	return kol

def kol_bezvlozh(stroka, i):
	p = 0
	stack = 0
	kol = 0
	for i in range(i, len(s)):
		if stroka[i] == '[':
			stack += 1
			t = 1
		else:
			stack -= 1
			t = -1
		if p == 0:
			p = t
		if p > 0 and t < 0:
			kol += 1
		p = t
		if stack == 0:
			break
	return kol

def mass_vlozh(stroka, maxur):
	mass = []
	stack = 0
	p = 0
	for i in range(len(stroka)):
		if stroka[i] == '[':
			stack += 1
			mass.append(maxur - stack + 1)
		else:
			stack -= 1
			mass.append(maxur - stack)
	return mass
input()
s = input()
maxur = maxvlozh(s)
mass = mass_vlozh(s, maxur)
stack_ris = []
stack_ur = maxur
for i in range(2 * maxur + 1):
	ris = ''
	p = 0
	for j in range(len(mass)):
		if mass[j] == stack_ur:
			p = 1
			if s[j] == '[':
				ris += '+-'
				kol_vl = kol_vlozh(s, j)
				kol_bv = kol_bezvlozh(s, j)
				shir = kol_vl * 2 + kol_bv * 3 - 2
				ris += ' ' * shir
			elif s[j] == ']':
				ris += '-+'
		elif mass[j] > stack_ur:
			ris += '|'
			kol_vl = kol_vlozh(s, j)
			if s[j] == '[' and kol_vl == 0:
				ris += ' ' * 3
	stack_ris.append(ris)
	stack_ur -= 1
	if stack_ur == -1:
		for j in range(len(stack_ris)):
			print(stack_ris[len(stack_ris) - j - 1])
		break
	else:
		print(ris)


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
ml = 1
cl = 1
for b in n:
	if b == '[':
		cl += 2
		if ml < cl:
			ml = cl
	else:
		cl -= 2
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()


import sys

class Bracket:

	def __init__(self, t, size):
		self.deep = size
		self.type = t
n = int(input())
s = input()
deep = 0
brackets = []
max_deep = 0
for i in s:
	if i == '[':
		brackets.append(Bracket(0, deep))
		deep += 1
		max_deep = max(max_deep, deep)
	else:
		deep -= 1
		brackets.append(Bracket(1, deep))
lenght = 0
for i in range(brackets.__len__()):
	lenght += 1
	if i > 0:
		if brackets[i].type == 1 and brackets[i - 1].type == 0:
			lenght += 3
(w, h) = (lenght, max_deep * 2 + 1)
mas = [[' ' for x in range(w)] for y in range(h)]

def print_bracket(deep: int, type, j):
	global mas
	if type == 0:
		mas[deep][j] = '+'
		mas[deep][j + 1] = '-'
		mas[len(mas) - deep - 1][j] = '+'
		mas[len(mas) - deep - 1][j + 1] = '-'
	else:
		mas[deep][j] = '+'
		mas[deep][j - 1] = '-'
		mas[len(mas) - deep - 1][j] = '+'
		mas[len(mas) - deep - 1][j - 1] = '-'
delta = 0
for i in range(brackets.__len__()):
	temp = 0
	if i > 0:
		if brackets[i].type == 1 and brackets[i - 1].type == 0:
			temp = brackets[i]
			delta += 3
		else:
			temp = brackets[i]
	else:
		temp = brackets[i]
	print_bracket(temp.deep, temp.type, i + delta)

def check_bottom(i, j):
	global mas
	for z in range(i, h):
		if mas[z][j] == '+':
			return True
	return False
for i in range(1, h):
	for j in range(w):
		if mas[i][j] == ' ' and (mas[i - 1][j] == '+' or mas[i - 1][j] == '|'):
			if check_bottom(i, j):
				mas[i][j] = '|'
for i in range(h):
	for j in range(w):
		sys.stdout.write(mas[i][j])
	if i < h - 1:
		print()


from sys import stdout
input()
s = input()
hs = []
i = 0
m = 0
for c in s:
	if c == '[':
		i += 1
		if i > m:
			m = i
		hs.append(i)
	else:
		if hs[-1] == i:
			hs.append(0)
			hs.append(0)
			hs.append(0)
		hs.append(i)
		i -= 1
for (i, h) in enumerate(hs):
	hs[i] = m - h + 1 if h != 0 else 0
for i in range(m):
	for (j, h) in enumerate(hs):
		if m - h == i:
			stdout.write('+')
		elif m - h < i:
			stdout.write('|')
		elif m - hs[j - 1] == i:
			stdout.write('-')
		elif m - hs[j + 1] == i:
			stdout.write('-')
		else:
			stdout.write(' ')
	stdout.write('\n')
for h in hs:
	if h == 0:
		stdout.write(' ')
	else:
		stdout.write('|')
stdout.write('\n')
for i in range(1, m + 1):
	for (j, h) in enumerate(hs):
		if h == i:
			stdout.write('+')
		elif h > i:
			stdout.write('|')
		elif hs[j - 1] == i:
			stdout.write('-')
		elif hs[j + 1] == i:
			stdout.write('-')
		else:
			stdout.write(' ')
	stdout.write('\n')


d = dict()
d['['] = 1
d[']'] = -1
n = int(input())
s = input()
bal = 0
best = -1
for elem in s:
	bal += d[elem]
	best = max(best, bal)
size = 2 * best + 1
ans = [[' '] * (3 * n) for i in range(size)]
last_type = 'close'
last_size = size
curr_state = 0
for elem in s:
	if last_type == 'close' and elem == '[':
		curr_state += 1
		up = best - last_size // 2
		down = best + last_size // 2
		ans[up][curr_state] = '+'
		ans[down][curr_state] = '+'
		for i in range(up + 1, down):
			ans[i][curr_state] = '|'
		ans[up][curr_state + 1] = '-'
		ans[down][curr_state + 1] = '-'
		last_type = 'open'
	elif last_type == 'close' and elem == ']':
		curr_state += 1
		up = best - last_size // 2 - 1
		down = best + last_size // 2 + 1
		ans[up][curr_state] = '+'
		ans[down][curr_state] = '+'
		for i in range(up + 1, down):
			ans[i][curr_state] = '|'
		ans[up][curr_state - 1] = '-'
		ans[down][curr_state - 1] = '-'
		last_size += 2
	elif last_type == 'open' and elem == '[':
		curr_state += 1
		up = best - last_size // 2 + 1
		down = best + last_size // 2 - 1
		ans[up][curr_state] = '+'
		ans[down][curr_state] = '+'
		for i in range(up + 1, down):
			ans[i][curr_state] = '|'
		ans[up][curr_state + 1] = '-'
		ans[down][curr_state + 1] = '-'
		last_size -= 2
	else:
		curr_state += 4
		up = best - last_size // 2
		down = best + last_size // 2
		ans[up][curr_state] = '+'
		ans[down][curr_state] = '+'
		for i in range(up + 1, down):
			ans[i][curr_state] = '|'
		ans[up][curr_state - 1] = '-'
		ans[down][curr_state - 1] = '-'
		last_type = 'close'
for i in range(size):
	for j in range(1, curr_state + 1):
		print(ans[i][j], end='')
	print()


s = input()
s = input()
level = 0
max_level = 0
skob = []
for i in s:
	if i == '[':
		level += 1
		skob.append(('o', level))
	else:
		if level > max_level:
			max_level = level
		skob.append(('c', level))
		level -= 1
h = max_level * 2 + 1
place = 0
mapp = [[' '] * h]
for i in range(len(skob)):
	level = skob[i][1]
	mapp.append([' '] * h)
	if skob[i][0] == 'o':
		mapp[place][level - 1] = '+'
		mapp[place + 1][level - 1] = '-'
		for j in range(level, h - level):
			mapp[place][j] = '|'
		mapp[place][h - level] = '+'
		mapp[place + 1][h - level] = '-'
	if skob[i][0] == 'c':
		if skob[i - 1][0] == 'o':
			place += 3
			mapp.append([' '] * h)
			mapp.append([' '] * h)
			mapp.append([' '] * h)
		for j in range(level, h - level):
			mapp[place][j] = '|'
		mapp[place - 1][level - 1] = '-'
		mapp[place][level - 1] = '+'
		mapp[place - 1][h - level] = '-'
		mapp[place][h - level] = '+'
	place += 1
s = [''] * h
for i in mapp:
	for j in range(len(i)):
		s[j] += i[j]
for i in s:
	print(i[:len(i) - 1])


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

def parse(s, i=0):
	ss = i
	start = i
	h = 0
	while i < len(s) and s[i] == '[':
		(i, nh) = parse(s, i + 1)
		h = max(h, nh + 2)
		start = i
	if i == ss:
		h = 1
	return (i + 1, h)
(_, h) = parse(s)
l = 4 * n
mid = (h - 1) // 2
buf = [[' ' for i in range(l)] for i in range(h)]

def draw(s, h, i=0, p=0):
	if i >= len(s):
		return
	if s[i] == '[':
		r = (h - 1) // 2
		for j in range(r):
			buf[mid + j][p] = '|'
			buf[mid - j][p] = '|'
		buf[mid + r][p] = '+'
		buf[mid - r][p] = '+'
		buf[mid + r][p + 1] = '-'
		buf[mid - r][p + 1] = '-'
		draw(s, h - 2, i + 1, p + 1)
	else:
		h += 2
		if s[i - 1] == '[':
			p += 3
		r = (h - 1) // 2
		for j in range(r):
			buf[mid + j][p] = '|'
			buf[mid - j][p] = '|'
		buf[mid + r][p] = '+'
		buf[mid - r][p] = '+'
		buf[mid + r][p - 1] = '-'
		buf[mid - r][p - 1] = '-'
		draw(s, h, i + 1, p + 1)
draw(s, h)
for i in range(h):
	l = -1
	for j in range(len(buf[i])):
		if buf[i][j] != ' ':
			l = j + 1
	buf[i] = buf[i][:l]
for i in buf:
	print(''.join(i))


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


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 += '|'
		elif 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])


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


def skobka(l, x, y, h, sk, ind):
	l[x][y] = '+'
	x1 = x
	for i in range(h):
		x1 += 1
		l[x1][y] = '|'
	x1 += 1
	l[x1][y] = '+'
	if sk[ind] == '[':
		l[x][y + 1] = '-'
		l[x1][y + 1] = '-'
	else:
		l[x][y - 1] = '-'
		l[x1][y - 1] = '-'
	return l
n = int(input())
sk = input()
dps = []
(deep, curd) = (0, 0)
for i in range(n):
	if sk[i] == '[':
		curd += 1
	elif sk[i] == ']':
		curd -= 1
	deep = max(deep, curd)
h = deep * 2 + 1
w = int(n * 2.5)
r = [[' '] * w for i in range(h)]
(x, y) = (0, 0)
i = 0
v = h - 2
while i < n:
	s = sk[i]
	j = i
	if s == '[':
		while j < n and s == sk[j]:
			r = skobka(r, x, y, v, sk, j)
			v -= 2
			j += 1
			x += 1
			y += 1
		v += 2
		i += j - i
		y += 3
		x -= 1
	else:
		while j < n and s == sk[j]:
			r = skobka(r, x, y, v, sk, j)
			v += 2
			j += 1
			x -= 1
			y += 1
		i += j - i
		x += 1
		v -= 2
a = r[0][:]
a.reverse()
ind = a.index('+')
for i in r:
	for j in range(len(i) - ind):
		print(i[j], end='')
	print()


input()
s = input()
(h, y) = ([], 0)
for q in s:
	h.append(y)
	y += 2 * (q == '[') - 1
m = 1 + 2 * max(h)
f = lambda y: '+'.join((' ' * y, '|' * (m - 2 * y - 2), ' ' * y))
g = lambda i, y: [f(y)] if s[i] == '[' else ([' ' * m] * 3 if s[i - 1] == '[' else []) + [f(y - 1)]
for t in zip(*sum((g(i, y) for (i, y) in enumerate(h)), [])):
	print(''.join(t).replace('+ ', '+-').replace(' +', '-+'))


import sys
N = int(input())
S = input()
d = [0] * N
k = -1
m = 0
for i in range(N):
	if S[i] == '[':
		k += 1
		d[i] = k
	else:
		d[i] = k
		k -= 1
	m = max(m, k)
H = 2 * m + 3
W = N
for k in range(N - 1):
	if S[k] == '[' and S[k + 1] == ']':
		W += 3
field = [['.'] * W for i in range(H)]
j = 0

def pr(file):
	for line in field:
		for c in line:
			print(c, end='')
		print()
for k in range(N):
	h = H - 2 * d[k]
	pad = (H - h) // 2
	for i in range(H):
		if i < pad or i > H - pad - 1:
			field[i][j] = ' '
		elif i == pad or i == H - pad - 1:
			field[i][j] = '+'
		else:
			field[i][j] = '|'
	j += 1
	if k < N - 1 and S[k] == '[' and (S[k + 1] == ']'):
		for _ in range(3):
			for i in range(H):
				field[i][j] = ' '
			j += 1
for i in range(H):
	for j in range(W):
		if field[i][j] != '+':
			continue
		if j < W - 1 and field[i][j + 1] == ' ':
			field[i][j + 1] = '-'
		if j > 0 and field[i][j - 1] == ' ':
			field[i][j - 1] = '-'
pr(sys.stdout)


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())
s = input()
b = []
p = 0
m = 0
for i in range(n):
	if s[i] == '[':
		p += 1
		b.append(p)
		m = max(p, m)
	else:
		b.append(p)
		p -= 1
a = [[' '] * (3 * n) for i in range(2 * m + 1)]
i = 0
c = []
l = True
while b != []:
	k = b.pop(0)
	if c != [] and c[-1] == k:
		c.pop()
		if l:
			i += 3
		a[k - 1][i - 1] = '-'
		a[k + 2 * (m - k + 1) - 1][i - 1] = '-'
		a[k - 1][i] = '+'
		a[k + 2 * (m - k + 1) - 1][i] = '+'
		for j in range(2 * (m - k) + 1):
			a[j + k][i] = '|'
		l = False
	else:
		c.append(k)
		a[k - 1][i + 1] = '-'
		a[k + 2 * (m - k + 1) - 1][i + 1] = '-'
		a[k - 1][i] = '+'
		a[k + 2 * (m - k + 1) - 1][i] = '+'
		for j in range(2 * (m - k) + 1):
			a[j + k][i] = '|'
		l = True
	i += 1
for j in range(2 * m + 1):
	for g in range(i):
		print(a[j][g], end='')
	print()


from itertools import groupby
n = int(input())
seq = list(input())
answer = []
stack = []
depth = -1
for i in range(len(seq)):
	if seq[i] == '[':
		stack.append('[')
		depth += 2
		answer.append(depth)
	else:
		stack.pop()
		answer.append(depth)
		depth -= 2
		if len(stack) == 0:
			answer.append('*')
answer = [list(group) for (k, group) in groupby(answer, lambda x: x != '*') if k]
max_depth = 0
for i in range(len(answer)):
	if max_depth < max(answer[i]):
		max_depth = max(answer[i])
for i in range(len(answer)):
	answer[i] = [max_depth + 1 - a for a in answer[i]]
answer = [s for sub in answer for s in sub]
out = ''
stack = []
for i in range(len(answer)):
	line = ''
	if seq[i] == '[' and len(stack) == 0:
		line += ' ' * ((max_depth - answer[i]) // 2)
		line += '+'
		line += '|' * answer[i]
		line += '+'
		line += ' ' * ((max_depth - answer[i]) // 2)
		if seq[i + 1] == ']':
			line += ' ' * ((max_depth - answer[i]) // 2)
			line += '-'
			line += ' ' * answer[i]
			line += '-'
			line += ' ' * ((max_depth - answer[i]) // 2)
		stack.append(answer[i])
	elif seq[i] == '[' and len(stack) > 0:
		if seq[i - 1] == '[':
			line += ' ' * ((max_depth - answer[i] - 2) // 2)
			line += '-'
		else:
			line += ' ' * ((max_depth - answer[i]) // 2)
		line += '+'
		line += '|' * answer[i]
		line += '+'
		if seq[i - 1] == '[':
			line += '-'
			line += ' ' * ((max_depth - answer[i] - 2) // 2)
		else:
			line += ' ' * ((max_depth - answer[i]) // 2)
		if seq[i + 1] == ']':
			line += ' ' * ((max_depth - answer[i]) // 2)
			line += '-'
			line += ' ' * answer[i]
			line += '-'
			line += ' ' * ((max_depth - answer[i]) // 2)
		stack.append(answer[i])
	elif seq[i] == ']':
		if seq[i - 1] == '[':
			line += ' ' * ((max_depth - answer[i]) // 2)
			line += '-'
			line += ' ' * answer[i]
			line += '-'
			line += ' ' * ((max_depth - answer[i]) // 2)
		if i < len(answer) - 1 and seq[i + 1] == ']':
			line += ' ' * ((max_depth - answer[i] - 2) // 2)
			line += '-'
			line += '+'
			line += '|' * answer[i]
			line += '+'
			line += '-'
			line += ' ' * ((max_depth - answer[i] - 2) // 2)
		else:
			line += ' ' * ((max_depth - answer[i]) // 2)
			line += '+'
			line += '|' * answer[i]
			line += '+'
			line += ' ' * ((max_depth - answer[i]) // 2)
		stack.pop()
	out += line
out = [out[i:i + max_depth + 2] for i in range(0, len(out), max_depth + 2)]
i = 0
while i < len(out):
	if out[i].replace(' ', '') == '--' and out[i + 1].replace(' ', '') == '--':
		out.insert(i + 1, ' ' * len(out[i]))
	i += 1
vertical = [list(r) for r in out]
final = ''
for i in range(len(vertical[0])):
	for j in range(len(vertical)):
		final += vertical[j][i]
	final += '\n'
final = final[:-1]
print(final)


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='')


n = int(input())
max_depth = 0
depth = 0
depth_array = []
string = input()
for elem in string:
	if elem == '[':
		depth += 1
	elif elem == ']':
		depth -= 1
	else:
		print('Error')
	depth_array.append(depth)
	if max_depth < depth:
		max_depth = depth
res_str_array = ['+' + (2 * max_depth - 1) * '|' + '+']
prev_depth = 1
for (i, depth) in enumerate(depth_array[1:]):
	if prev_depth == depth:
		print('Error')
	elif prev_depth < depth:
		if string[i] == '[':
			res_str_array.append(' ' * (depth - 2) + '-+' + (2 * (max_depth - depth + 1) - 1) * '|' + '+-' + ' ' * (depth - 2))
		else:
			res_str_array.append(' ' * (depth - 1) + '+' + (2 * (max_depth - depth + 1) - 1) * '|' + '+' + ' ' * (depth - 1))
	else:
		if string[i] == '[':
			res_str_array.append(' ' * depth + '-' + (2 * (max_depth - depth) - 1) * ' ' + '-' + ' ' * depth)
			res_str_array.append(' ' * (2 * max_depth + 1))
			res_str_array.append(' ' * depth + '-' + (2 * (max_depth - depth) - 1) * ' ' + '-' + ' ' * depth)
		if i == n - 2 or string[i + 2] == '[':
			res_str_array.append(' ' * depth + '+' + (2 * (max_depth - depth) - 1) * '|' + '+' + ' ' * depth)
		else:
			res_str_array.append(' ' * (depth - 1) + '-+' + (2 * (max_depth - depth) - 1) * '|' + '+-' + ' ' * (depth - 1))
	prev_depth = depth
res_print_array = []
for i in range(2 * max_depth + 1):
	res_print_array.append('')
	for elem in res_str_array:
		res_print_array[-1] += elem[i]
for elem in res_print_array:
	print(elem)


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)


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='')
		elif 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='')
		elif 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()


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)


def draw(height, currentHeight, needAddition):
	column = drawSpace(height)
	diff = int((height - currentHeight) / 2)
	for i in range(currentHeight):
		column[diff + i] = '|'
	column[diff] = '+'
	column[-(diff + 1)] = '+'
	if needAddition:
		column[diff - 1] = '-'
		column[-diff] = '-'
	return column

def drawCloser(height, currentHeight):
	column = drawSpace(height)
	diff = int((height - currentHeight) / 2)
	column[diff] = '-'
	column[-(diff + 1)] = '-'
	return column

def drawSpace(height):
	return [' ' for i in range(height)]
n = int(input())
brakets = input()
maximum = 0
current = 0
for s in brakets:
	if s == '[':
		current += 1
	else:
		current -= 1
	if current > maximum:
		maximum = current
height = maximum * 2 + 1
previousHeight = 0
needAddition = False
columns = []
for (i, s) in enumerate(brakets):
	needAddition = False
	if i == 0:
		previousHeight = height
	elif s == '[':
		if brakets[i - 1] == '[':
			previousHeight -= 2
			needAddition = True
	elif s == ']':
		if i != len(brakets) - 1 and brakets[i + 1] == ']':
			needAddition = True
		if brakets[i - 1] == '[':
			columns.append(drawCloser(height, previousHeight))
			columns.append(drawSpace(height))
			columns.append(drawCloser(height, previousHeight))
		else:
			previousHeight += 2
	columns.append(draw(height, previousHeight, needAddition))
for y in range(height):
	for x in range(len(columns)):
		print(columns[x][y], end='')
	print()


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


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()
max_depth = 0
depth = 0
sizes = []
for i in s:
	if i == '[':
		depth += 1
	else:
		depth -= 1
	max_depth = max(depth, max_depth)
change = []
for i in s:
	if i == '[':
		sizes.append(max_depth - depth)
		depth += 1
	else:
		depth -= 1
		sizes.append(max_depth - depth)
change = [0] * len(s)
for i in range(len(s)):
	if i != len(s) - 1:
		if s[i] == '[' and s[i + 1] == ']':
			change[i] = 1
for i in range(max_depth, 0, -1):
	res = []
	a = 0
	for j in range(len(s)):
		if s[j] == '[':
			if sizes[j] > i:
				res.append('|')
				if change[j]:
					res.append(' ')
					res.append(' ')
					res.append(' ')
				a = 0
			elif sizes[j] == i:
				res.append('+')
				if change[j]:
					res.append('-')
					res.append(' ')
					res.append('-')
				a = 1
			else:
				if a:
					res.append('-')
				else:
					res.append(' ')
				if change[j]:
					res.append(' ')
					res.append(' ')
					res.append(' ')
				a = 0
		elif sizes[j] > i:
			res.append('|')
		elif sizes[j] == i:
			res.append('+')
		elif j != len(s) - 1:
			if s[j + 1] == ']' and sizes[j + 1] == i:
				res.append('-')
			else:
				res.append(' ')
		else:
			res.append(' ')
	print(''.join(res))
res = []
a = 0
for j in range(len(s)):
	res.append('|')
	if change[j]:
		res.append(' ')
		res.append(' ')
		res.append(' ')
print(''.join(res))
for i in range(1, max_depth + 1):
	res = []
	a = 0
	for j in range(len(s)):
		if s[j] == '[':
			if sizes[j] > i:
				res.append('|')
				if change[j]:
					res.append(' ')
					res.append(' ')
					res.append(' ')
				a = 0
			elif sizes[j] == i:
				res.append('+')
				if change[j]:
					res.append('-')
					res.append(' ')
					res.append('-')
				a = 1
			else:
				if a:
					res.append('-')
				else:
					res.append(' ')
				if change[j]:
					res.append(' ')
					res.append(' ')
					res.append(' ')
				a = 0
		elif sizes[j] > i:
			res.append('|')
		elif sizes[j] == i:
			res.append('+')
		elif j != len(s) - 1:
			if s[j + 1] == ']' and sizes[j + 1] == i:
				res.append('-')
			else:
				res.append(' ')
		else:
			res.append(' ')
	print(''.join(res))


class t4:

	def run(self, tr, az):
		if self._Q >= len(tr):
			return az
		if tr[self._Q] == '[':
			self._Y += 1
			az[self._Q] = -self._Y
			self._Q += 1
		else:
			az[self._Q] = self._Y
			self._Y -= 1
			self._Q += 1
		return self.run(tr, az)

	def trans_func(self, data):
		tr_matrix = []
		for row in data:
			tr_matrix.append(row[::-1])
		return tr_matrix

	def qu(self, az, w):
		if az[w] == 0:
			return
		q = w
		c = int(len(az) / 2)
		if len(az) % 2 != 0:
			c += 1
		self.bz[c][q] = '.'
		t = self._M - abs(az[w])
		for i in range(0, t):
			self.bz[c - i][q] = '|'
			self.bz[c + i][q] = '|'
		self.bz[c - t][q] = '+'
		self.bz[c + t][q] = '+'
		if az[w] > 0:
			i = -1
		else:
			i = 1
		if self.bz[c - t][q + i] != ' ':
			self._Q += 1
			q += 1
		self.bz[c - t][q + i] = '-'
		self.bz[c + t][q + i] = '-'

	def draw(self, az):
		i = 1
		while i < len(az):
			if abs(az[i]) == abs(az[i - 1]) and az[i] != 0 and (az[i - 1] < 0):
				az = az[:i] + [0, 0, 0] + az[i:]
				i += 1
			i += 1
		self._M = max(az) + 1
		self.bz = []
		WW = max(len(az) + 1, self._M * 2 + 1)
		for i in range(0, WW):
			cz = []
			for j in range(0, WW):
				cz.append(' ')
			self.bz.append(cz)
		self._Q = 0
		for i in range(0, len(az)):
			self.qu(az, i)

	def print_norm(self, az):
		az = self.trans_func(az)
		for i in range(0, len(az)):
			st = ''
			for j in range(0, len(az[i])):
				st += az[i][-j]
			if not st.isspace():
				print(st.lstrip(' ').rstrip(' '))

	def __init__(self):
		self._Q = 0
		self._Y = 0
		x = int(input())
		y = input()
		tr = []
		tr.extend(y)
		az = []
		for i in range(0, x):
			az.append(0)
		az = self.run(tr, az)
		self.draw(az)
		self.print_norm(self.bz)
t4()


n = input()
s = input()
depth = 0
maxdepth = 0
delta = 0
for i in s:
	if i == '[':
		depth += 1
	else:
		depth -= 1
	maxdepth = max(depth, maxdepth)
for i in range(len(s) - 1):
	if s[i] == '[' and s[i + 1] == ']':
		delta += 1
h = 2 * maxdepth + 1
l = 2 * len(s) + delta
res = [[' ' for i in range(l)] for j in range(h)]

def printbkt(index, depth, c):
	if c == '[':
		res[depth][index] = '+'
		res[depth][index + 1] = '-'
		res[h - 1 - depth][index] = '+'
		res[h - 1 - depth][index + 1] = '-'
		for i in range(depth + 1, h - depth - 1):
			res[i][index] = '|'
	else:
		res[depth][index] = '-'
		res[depth][index + 1] = '+'
		res[h - 1 - depth][index] = '-'
		res[h - 1 - depth][index + 1] = '+'
		for i in range(depth + 1, h - depth - 1):
			res[i][index + 1] = '|'
printbkt(0, 0, '[')
s = s + '$'
index = 0
depth = 1
for i in range(1, int(n)):
	if s[i] == '[':
		depth += 1
	else:
		depth -= 1
	if s[i - 1] == '[' and s[i] == ']':
		index += 3
		printbkt(index, depth, ']')
	elif s[i] == '[':
		if s[i] != s[i - 1]:
			index += 1
		index += 1
		printbkt(index, depth - 1, '[')
	else:
		if s[i] != s[i - 1]:
			index += 1
		index += 1
		printbkt(index, depth, ']')
for i in res:
	print(''.join(i).strip())


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


length = int(input())
brackets = input()
OPEN = '['
CLOSE = ']'
PLUS = '+'
PIPE = '|'
MINUS = '-'
width = 0
height = 0
depth = 0
previous_open = False
for bracket in brackets:
	if bracket == OPEN:
		depth += 1
		width += 2
		height = max(height, depth)
		previous_open = True
	elif bracket == CLOSE:
		depth -= 1
		if previous_open:
			width += 3
		previous_open = False
height = height * 2 + 1
result = [[' '] * width for i in range(height)]

def draw(d, pos, s):
	h1 = d
	h2 = height - d - 1
	result[h1][pos] = PLUS
	result[h2][pos] = PLUS
	for i in range(h1 + 1, h2):
		result[i][x] = PIPE
	result[h1][pos + s] = MINUS
	result[h2][pos + s] = MINUS
x = 0
depth = 0
for bracket in brackets:
	if bracket == OPEN:
		draw(depth, x, 1)
		depth += 1
		previous_open = True
	elif bracket == CLOSE:
		if previous_open:
			x += 3
		depth -= 1
		draw(depth, x, -1)
		previous_open = False
	x += 1
for row in result:
	print(''.join(row))


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
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())
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]))


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


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()
s = input().strip()
d = 0
cd = 0
for c in s:
	if c == '[':
		cd += 1
	else:
		cd -= 1
	d = max(d, cd)
r = [[' '] * (len(s) + 3 * s.count('[]')) for _ in range(2 * d + 1)]
cd = 0
cp = 0
prev = ']'
for c in s:
	if c == ']':
		cd -= 1
	if prev == '[' and c == ']':
		cp += 3
	for i in range(cd + 1, len(r) - cd - 1):
		r[i][cp] = '|'
	r[cd][cp] = r[-cd - 1][cp] = '+'
	tcp = cp + (1 if c == '[' else -1)
	r[cd][tcp] = r[-cd - 1][tcp] = '-'
	if c == '[':
		cd += 1
	cp += 1
	prev = c
for t in r:
	print(''.join(t))


import collections as col
import itertools as its
import sys
import operator
from copy import copy, deepcopy

class Solver:

	def __init__(self):
		pass

	def solve(self):
		n = int(input())
		psp = input()
		m = 0
		st = []
		pair = [0] * n
		for i in range(n):
			if psp[i] == '[':
				st.append(i)
				m = max(m, len(st))
			else:
				p = st.pop()
				pair[p] = i
				pair[i] = p
		tres = [''] * (m * 2 + 1)
		now = m
		for i in range(n):
			if psp[i] == '[':
				tres[m] += '|'
				for j in range(1, now):
					tres[m + j] += '|'
					tres[m - j] += '|'
				tres[m + now] += '+-'
				tres[m - now] += '+-'
				l = len(tres[m + now])
				for j in range(2 * m + 1):
					while len(tres[j]) < l:
						tres[j] += ' '
				now -= 1
			else:
				now += 1
				tres[m] += ' |'
				for j in range(1, now):
					tres[m + j] += ' |'
					tres[m - j] += ' |'
				tres[m + now] += '-+'
				tres[m - now] += '-+'
				l = len(tres[m + now])
				for j in range(2 * m + 1):
					while len(tres[j]) < l:
						tres[j] += ' '
		res = [[' '] for _ in range(2 * m + 1)]
		for i in range(len(tres[0])):
			inter = False
			skip = False
			for j in range(2 * m + 1):
				if tres[j][i] != ' ' and res[j][-1] != ' ':
					inter = True
					if tres[j][i] == '-' and res[j][-1] == '-':
						skip = True
			if inter:
				for j in range(2 * m + 1):
					res[j].append(' ')
			if skip:
				for j in range(2 * m + 1):
					res[j].append(' ')
			for j in range(2 * m + 1):
				if tres[j][i] != ' ':
					res[j][-1] = tres[j][i]
		for i in range(2 * m + 1):
			print(''.join(res[i]))
s = Solver()
s.solve()


n = int(input())
sb = input()
ms = 0
o = 0
k = sb.count('[]') * 3 + n
for s in range(n):
	if sb[s] == '[':
		o += 1
	else:
		o -= 1
	if o >= ms:
		ms = o
ms = ms * 2 + 1
m = [[' ' for x in range(k)] for y in range(ms)]
c = 0
cr = ms
o = 0
for x in range(n):
	if sb[x] == '[':
		for i in range(o, o + cr):
			char = '|'
			if i == o or i == o + cr - 1:
				char = '+'
			m[i][c] = char
		m[o][c + 1] = '-'
		m[o + cr - 1][c + 1] = '-'
		if x + 1 < n:
			if sb[x + 1] == ']':
				c += 3
			else:
				o += 1
				cr -= 2
	else:
		for i in range(o, o + cr):
			char = '|'
			if i == o or i == o + cr - 1:
				char = '+'
			m[i][c] = char
		m[o][c - 1] = '-'
		m[o + cr - 1][c - 1] = '-'
		if x + 1 < n:
			if sb[x + 1] == ']':
				o -= 1
				cr += 2
	c += 1
t = ''
for i in range(len(m)):
	for j in m[i]:
		if j != None:
			t += j
	t += '\n'
print(t[:-1])


n = int(input())
s = input().strip()
depth = [0] * n
bal = 0
for i in range(n):
	if s[i] == '[':
		depth[i] = bal
		bal += 1
	else:
		bal -= 1
		depth[i] = bal
scheme_length = n
for i in range(n - 1):
	if s[i] + s[i + 1] == '[]':
		scheme_length += 3
height = 2 * (max(depth) + 1) + 1
scheme = [[' '] * scheme_length for i in range(height)]
i = 0
p = 0
prev = ' '
while p < scheme_length:
	if s[i] == '[':
		scheme[depth[i]][p] = scheme[height - depth[i] - 1][p] = '+'
		scheme[depth[i]][p + 1] = scheme[height - depth[i] - 1][p + 1] = '-'
		for j in range(depth[i] + 1, height - depth[i] - 1):
			scheme[j][p] = '|'
		prev = '['
		i += 1
		p += 1
	else:
		if prev == '[':
			prev = ' '
			p += 3
			continue
		scheme[depth[i]][p] = scheme[height - depth[i] - 1][p] = '+'
		scheme[depth[i]][p - 1] = scheme[height - depth[i] - 1][p - 1] = '-'
		for j in range(depth[i] + 1, height - depth[i] - 1):
			scheme[j][p] = '|'
		prev = ']'
		i += 1
		p += 1
for row in scheme:
	print(''.join(row))


def printMatrix(a):
	text = ''
	for i in range(len(a)):
		for j in a[i]:
			if j != None:
				text += j
		text += '\n'
	print(text[:-1])
n = int(input())
skb = input()
max_size = 0
opened = 0
krit_size = skb.count('[]') * 3 + n
for s in range(n):
	if skb[s] == '[':
		opened += 1
	else:
		opened -= 1
	if opened >= max_size:
		max_size = opened
max_size = max_size * 2 + 1
matrix = [[' ' for x in range(krit_size)] for y in range(max_size)]
counter = 0
curr_size = max_size
opened = 0
for s in range(n):
	if skb[s] == '[':
		for i in range(opened, opened + curr_size):
			char = '|'
			if i == opened or i == opened + curr_size - 1:
				char = '+'
			matrix[i][counter] = char
		matrix[opened][counter + 1] = '-'
		matrix[opened + curr_size - 1][counter + 1] = '-'
		if s + 1 < n:
			if skb[s + 1] == ']':
				counter += 3
			else:
				opened += 1
				curr_size -= 2
	else:
		for i in range(opened, opened + curr_size):
			char = '|'
			if i == opened or i == opened + curr_size - 1:
				char = '+'
			matrix[i][counter] = char
		matrix[opened][counter - 1] = '-'
		matrix[opened + curr_size - 1][counter - 1] = '-'
		if s + 1 < n:
			if skb[s + 1] == ']':
				opened -= 1
				curr_size += 2
	counter += 1
printMatrix(matrix)


n = int(input())
seq = input()
opened = 0
stack = '['
ds = []
for i in seq:
	ds.append(opened)
	if i == '[':
		opened += 1
	else:
		opened -= 1
		ds[-1] -= 1
h = max(ds) * 2 + 3
w = (n + 5) * 3
arr = [[' ' for _ in range(h)] for _ in range(w)]
pos = 0

def draw(symbol, margin):
	global pos
	global h

	def drawa():
		for i in range(margin, h - margin):
			if i == margin or i == h - margin - 1:
				arr[pos][i] = '+'
			else:
				arr[pos][i] = '|'

	def drawb():
		arr[pos][margin] = '-'
		arr[pos][h - margin - 1] = '-'
	if symbol == '[':
		drawa()
		pos += 1
		drawb()
	else:
		drawb()
		pos += 1
		drawa()
for i in range(n):
	margin = ds[i]
	if i == 0 or seq[i - 1] == seq[i]:
		draw(seq[i], margin)
	elif seq[i - 1] == '[' and seq[i] == ']':
		pos += 2
		draw(seq[i], margin)
	elif seq[i - 1] == ']' and seq[i] == '[':
		pos += 1
		draw(seq[i], margin)
for j in range(h):
	for i in range(pos + 1):
		print(arr[i][j], end='')
	print()


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


n = int(input())
s = input()
cur = 0
m = -1
for c in s:
	if c == '[':
		cur += 1
	else:
		cur -= 1
	m = max(m, 2 * cur + 1)
double = s.count('[]')
grid = [[' '] * (n + 3 * double) for _ in range(m)]
level = 0
prev = ''
END = 0
for c in s:
	if c == ']':
		level -= 1
	if c == ']' and prev == '[':
		END += 3
	grid[level][END] = '+'
	grid[m - level - 1][END] = '+'
	for j in range(level + 1, m - level - 1):
		grid[j][END] = '|'
	rtmp = END
	if c == '[':
		rtmp += 1
	else:
		rtmp -= 1
	grid[level][rtmp] = '-'
	grid[m - level - 1][rtmp] = '-'
	if c == '[':
		level += 1
	prev = c
	END += 1
for u in grid:
	print(*u, sep='')


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


n = int(input())
brackets = input()
level = 0
lines = []
flag = []
max_level = 0
for i in brackets:
	if i == '[':
		lines.append([0, level])
		level += 1
		if level > max_level:
			max_level = level
	else:
		lines.append([1, level - 1])
		level -= 1
max_height = (max_level - 1) * 2 + 1 + 2
step = [int(i) for i in range(max_level)]
for_print = []
for i in range(n):
	ll = step[-lines[i][1] - 1] * 2 + 1 + 2
	if i > 0:
		if (lines[i - 1][0] + 1 == lines[i][0]) & (lines[i - 1][1] == lines[i][1]):
			side = ' ' * ((max_height - ll) // 2) + '-' + ' ' * (ll - 2) + '-' + ' ' * ((max_height - ll) // 2)
			for_print.append(side)
			for_print.append(' ' * max_height)
			for_print.append(side)
			if i == flag[0]:
				flag.pop(0)
		elif lines[i][0] == 0:
			flag.append(i + 1)
		else:
			ll1 = step[-lines[i - 1][1] - 1] * 2 + 1 + 2
			new_string = for_print[len(for_print) - 1][0:(max_height - ll1) // 2 - 1] + '-'
			new_string += for_print[len(for_print) - 1][(max_height - ll1) // 2:(max_height - ll1) // 2 + step[-lines[i - 1][1] - 1] * 2 + 3]
			new_string += '-' + for_print[len(for_print) - 1][(max_height - ll1) // 2 + step[-lines[i - 1][1] - 1] * 2 + 3 + 1:len(for_print[len(for_print) - 1])]
			for_print[len(for_print) - 1] = new_string
	else:
		flag = [i + 1]
	s = ''
	if len(flag) > 0:
		if i == flag[0]:
			s += ' ' * ((max_height - ll) // 2 - 1)
			s += '-'
			s += '+'
			s += '|' * (ll - 2)
			s += '+'
			s += '-'
			s += ' ' * ((max_height - ll) // 2 - 1)
			flag.pop(0)
		else:
			s += ' ' * ((max_height - ll) // 2)
			s += '+'
			s += '|' * (ll - 2)
			s += '+'
			s += ' ' * ((max_height - ll) // 2)
	else:
		s += ' ' * ((max_height - ll) // 2)
		s += '+'
		s += '|' * (ll - 2)
		s += '+'
		s += ' ' * ((max_height - ll) // 2)
	for_print.append(s)
for i in range(max_height):
	for j in range(len(for_print)):
		print(for_print[j][i], end='')
	if i != max_height - 1:
		print('')


(_, 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()
d = 0
md = 0
for i in s:
	if i == '[':
		d += 1
	else:
		d -= 1
	md = max(md, d)
nv = md * 2 - 1
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 = ''
	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()


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


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 = int(input())
strr = input()
maxx = 0
curr = 0
l = 0
for i in range(n):
	if strr[i] == '[':
		curr += 1
		l += 1
	if strr[i] == ']':
		curr -= 1
		l += 1
		if strr[i - 1] == '[':
			l += 3
	if curr > maxx:
		maxx = curr
ans = []
for i in range(2 * maxx + 1):
	ans.append([' '] * l)

def draw(level, ind, ch):
	for i in range(maxx - level + 1, maxx + level):
		ans[i][ind] = '|'
	ans[maxx - level][ind] = '+'
	ans[maxx + level][ind] = '+'
	if ch == '[':
		ans[maxx - level][ind + 1] = '-'
		ans[maxx + level][ind + 1] = '-'
	if ch == ']':
		ans[maxx - level][ind - 1] = '-'
		ans[maxx + level][ind - 1] = '-'
curr = maxx + 1
l = 0
for i in range(n):
	if strr[i] == '[':
		curr -= 1
		l += 1
		draw(curr, l - 1, '[')
	if strr[i] == ']':
		l += 1
		if strr[i - 1] == '[':
			l += 3
		draw(curr, l - 1, ']')
		curr += 1
for a in ans:
	print(''.join(a))


n = int(input())
s = input()
(counter, max_counter) = (0, 0)
(x, string_list) = ([], [])
for i in s:
	if i == '[':
		counter += 1
		max_counter = max(max_counter, counter)
		x.append(counter)
	elif i == ']':
		x.append(counter)
		counter -= 1
for i in range(n):
	x[i] = max_counter - x[i]

def make_string(x, ear=False):
	if not ear:
		return ' ' * (max_counter - x - 1) + '+' + 2 * x * '|' + '|+' + ' ' * (max_counter - x - 1)
	else:
		return ' ' * (max_counter - x - 2) + '-+' + 2 * x * '|' + '|+-' + ' ' * (max_counter - x - 2)

def use_ear(i):
	if x[i] == max_counter - 1:
		return False
	if x[i - 1] > x[i] or x[i + 1] > x[i]:
		return True
for i in range(n):
	if s[i] == '[':
		s1 = make_string(x[i], use_ear(i))
		string_list.append(s1)
		if s[i + 1] == ']':
			string_list.append(' ' * (max_counter - 1 - x[i]) + '-' + ' ' * (2 * x[i] + 1) + '-' + ' ' * (max_counter - 1 - x[i]))
	elif s[i] == ']':
		s1 = make_string(x[i], use_ear(i))
		if s[i - 1] == '[':
			string_list.append(' ' * (max_counter * 2 + 1))
			string_list.append(' ' * (max_counter - 1 - x[i]) + '-' + ' ' * (2 * x[i] + 1) + '-' + ' ' * (max_counter - 1 - x[i]))
		string_list.append(s1)

def draw(string_list):
	a = len(string_list[0])
	b = len(string_list)
	for i in range(a):
		for j in range(b):
			print(string_list[j][i], end='')
		print()
draw(string_list)