#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <tuple>

using namespace std;

using lint = long long;
using ldouble = long double;

tuple<string, int, string> parse(string S) {
    string L;
    int itr, depth = 1;
    for (itr = 1; depth > 0; ++itr) {
        L.push_back(S[itr]);
        if (S[itr] == '(') {
            ++depth;
        } else if (S[itr] == ')') {
            --depth;
        }
    }
    L.pop_back();

    string V;
    for (++itr; S[itr] != ']'; ++itr) {
        V.push_back(S[itr]);
    }

    string R;
    depth = 1;
    for (itr += 2; depth > 0; ++itr) {
        R.push_back(S[itr]);
        if (S[itr] == '(') {
            ++depth;
        } else if (S[itr] == ')') {
            --depth;
        }
    }
    R.pop_back();
    return make_tuple(L, stoi(V), R);
}

string compose(string L, int v, string R) {
    return "(" + L + ")[" + to_string(v) + "](" + R + ")";
}

string merge(string S, string T) {
    if (S.empty() || T.empty()) return "";

    string sl, sr, tl, tr;
    int sv, tv;
    tie(sl, sv, sr) = parse(S);
    tie(tl, tv, tr) = parse(T);

    return compose(merge(sl, tl), sv + tv, merge(sr, tr));
}

int main() {
    string S, T;
    cin >> S >> T;
    cout << merge(S, T) << endl;
    return 0;
}

