import std.stdio;
import std.ascii;
import std.string;
import std.conv;

class T {
    int value;
    T left, right;
    this(int value, T left, T right) {
        this.value = value;
        this.left = left;
        this.right = right;
    }
    override string toString() const {
        string l = (left ? left.toString : "");
        string r = (right ? right.toString : "");
        return "(" ~ l ~ ")" ~ "[" ~ value.to!string ~ "]" ~ "(" ~ r ~ ")";
    }
}

int size(string s) {
    return cast(int)(s.length);
}

int parse_int(string s, ref int n) {
    assert(isDigit(s[n]));
    int r = 0;
    while (n < s.size && isDigit(s[n])) {
        r = r * 10 + cast(int)(s[n] - '0');
        n++;
    }
    return r;
}

T parse(string s, ref int n) {
    assert(s[n] == '(');
    n++;
    if (s[n] == ')') {
        return null;
    }
    T l = parse(s, n);
    //stderr.writeln(s, " ", n, " ", s[n]);
    assert(s[n] == ')');
    n++;
    assert(s[n] == '[');
    n++;
    int value = parse_int(s, n);
    assert(s[n] == ']');
    n++;
    T r = parse(s, n);
    assert(s[n] == ')');
    n++;
    return new T(value, l, r);
}

void main() {
    auto A = "(" ~ stdin.readln.chomp ~ ")";
    auto B = "(" ~ stdin.readln.chomp ~ ")";

    T dfs(T a, T b) {
        if (a is null || b is null) return null;
        return new T(a.value + b.value, dfs(a.left, b.left), dfs(a.right, b.right));
    }

    int n = 0, m = 0;
    writeln(dfs(parse(A, n), parse(B, m)));
}