Rating:
```python
from pwn import *
def depth(s):
cnt=0
while(len(s)!=0):
s=s.replace('()','')
cnt+=1
return cnt
def calc(s1,s2):
d1=depth(s1)
d2=depth(s2)
if d1==d2:
return s1+s2
if d1<d2:
return "(%s%s)"%(s1,s2[1:-1])
if d1>d2:
return "(%s%s)"%(s1[1:-1],s2)
solve = lambda x:reduce(calc,x.replace(" ",'').split('+'))
host = '2018shell2.picoctf.com'
port = 61344
r=remote(host,port)
while True:
try:
lines=r.recvuntil('\n>').split('\n')
print '\n'.join(lines)
din=lines[-3].split('=')[0]
r.sendline(solve(din))
except:
print r.recv()
break
r.close()
```