human
C --Misawa's rooted tree

Problem Statement

You noticed that your best friend Misawa's birthday was near, and decided to give him a rooted binary tree as a gift. Here, the rooted binary tree has the following graph structure. (Figure 1)

* Each vertex has exactly one vertex called the parent of that vertex, which is connected to the parent by an edge. However, only one vertex, called the root, has no parent as an exception.
* Each vertex has or does not have exactly one vertex called the left child. If you have a left child, it is connected to the left child by an edge, and the parent of the left child is its apex.
* Each vertex has or does not have exactly one vertex called the right child. If you have a right child, it is connected to the right child by an edge, and the parent of the right child is its apex.



Figure 1. An example of two rooted binary trees and their composition

You wanted to give a handmade item, so I decided to buy two commercially available rooted binary trees and combine them on top of each other to make one better rooted binary tree. Each vertex of the two trees you bought has a non-negative integer written on it. Mr. Misawa likes a tree with good cost performance, such as a small number of vertices and large numbers, so I decided to create a new binary tree according to the following procedure.

1. Let the sum of the integers written at the roots of each of the two binary trees be the integers written at the roots of the new binary tree.
2. If both binary trees have a left child, create a binary tree by synthesizing each of the binary trees rooted at them, and use it as the left child of the new binary tree root. Otherwise, the root of the new bifurcation has no left child.
3. If the roots of both binaries have the right child, create a binary tree by synthesizing each of the binary trees rooted at them, and use it as the right child of the root of the new binary tree. Otherwise, the root of the new bifurcation has no right child.


You decide to see what the resulting...
Using python3 can you solve the prior task?
 Here the resulting?
assistant
#Here the resulting.

from sys import setrecursionlimit
setrecursionlimit(10 ** 8)

A = input()
B = input()

A_root = [[-1] * 3 for i in range(1000)]
B_root = [[-1] * 3 for i in range(1000)]

class Source():
  def __init__(self, S):
    self.S = S
    self.pos = 0
   
  
def peek(S):
  return S.S[S.pos] if S.pos < len(S.S) else -1

def next(S):
  S.pos += 1

def tree(S, A, i):
  next(S)
  if peek(S) == ')':
    next(S)
    return -1
  c = i[0]
  i[0] += 1
  l = i[0] 
  left = tree(S, A, i)
  center = root(S, A)
  i[0] += 1
  r = i[0]
  right = tree(S, A, i)
  
  A[c] = [center, l, r]
  next(S)
  
def root(S, A):
  res = 0
  next(S)
  while peek(S) != ']':
    res = res * 10 + int(peek(S))
    next(S)
  next(S)
  
  return res
  
tree(Source('(' + A + ')'), A_root, [0])
tree(Source('(' + B + ')'), B_root, [0])

def f(i, j):
  if A_root[i][0] == -1 or B_root[j][0] == -1:
    return '()'
  center = '[' + str(A_root[i][0] + B_root[j][0]) + ']'
  return '(' + f(A_root[i][1], B_root[j][1]) + center + f(A_root[i][2], B_root[j][2]) + ')'

print(f(0, 0)[1:-1])