Problem:
C - みさわさんの根付き木
Problem Statement
あなたは親友であるみさわさんの誕生日が近いことに気づき，根付きの二分木をプレゼントすることにした．
ここで，根付きの二分木とは，以下のようなグラフ構造である．(図 1)
各頂点には，その頂点の親と呼ばれる頂点がちょうど 1 つだけ存在し，親と辺で結ばれている．ただし，根と呼ばれる 1 つの頂点のみ，例外的に親を持たない．
各頂点は，左の子と呼ばれる頂点をちょうど1つ持つか，あるいは持たない．左の子を持つ場合，左の子とは辺で結ばれており，左の子の親はその頂点である．
各頂点は，右の子と呼ばれる頂点をちょうど1つ持つか，あるいは持たない．右の子を持つ場合，右の子とは辺で結ばれており，右の子の親はその頂点である．
図 1. 2 つの根付きの二分木とその合成の例
あなたは手作りの品を贈りたいと考えたので，市販の根付きの二分木を 2 つ買ってきて重ね合わせて合成することで，さらによい根付きの二分木を 1 つ作ることにした．
あなたが買ってきた 2 つの木の各頂点には非負の整数が書かれている．
みさわさんは少ない頂点数で各数値が大きいような，コストパフォーマンスがよい木が好みなので，以下の手順に沿って新しい二分木を作ることにする．
2 つの二分木それぞれの根に書かれた整数の和を，新しい二分木の根に書く整数とする．
どちらの二分木の根も左の子を持っている場合，それらを根とする二分木それぞれを合成した二分木を作り，新しい二分木の根の左の子とする．そうでない場合，新しい二分木の根は左の子を持たない．
どちらの二分木の根も右の子を持っている場合，それらを根とする二分木それぞれを合成した二分木を作り，新しい二分木の根の右の子とする．そうでない場合，新しい二分木の根は右の子を持たない．
あなたは実際に合成する作業を行う前に，できあがる根付きの二分木がどのようになるのか確かめることにした．
買ってきた 2 つの根付きの二分木の情報が与えられるので，上記の手順に従って合成される新しい根付きの二分木を求めるプログラムを作成せよ．
ここで，根付きの二分木の情報は以下のような形式で文字列として表現するものとする．
(左の子を表す文字列)[根に書かれた整数](右の子を表す文字列)
節点が存在しない木は空文字列とする．例えば図 1 の合成されてできた新しい根付きの二分木は
(()[6]())[8](((()[4]())[7]())[9]())
のように書く．
Input
入力は次の形式で表される．
$A$
$B$
$A$，$B$ はそれぞれ買ってきた根付きの二分木の情報を表す文字列であり，長さは $7$ 以上 $1000$ 以下である．
与えられる情報は前述の形式に従っており，余計な空白文字等を含まない．
また，節点が存在しない根付き木が入力されることはない．
各節点に書かれた整数は $0$ 以上 $1000$ 以下であると仮定してよい．
ただし，出力の各節点に書かれる整数はこの範囲に収まらない場合もあることに注意せよ．
Output
2 つの根付きの二分木を合成してできあがる新しい根付きの二分木の情報を 1 行で出力せよ．特に，行末の改行を除く余計な空白文字等を含まないよう注意せよ．
Sample Input 1
((()[8]())[2]())[5](((()[2]())[6](()[3]()))[1]())
(()[4]())[3](((()[2]())[1]())[8](()[3]()))
Output for the Sample Input 1
(()[6]())[8](((()[4]())[7]())[9]())
Sample Input 2
(()[1]())[2](()[3]())
(()[1](()[2]()))[3]()
Output for the Sample Input 2
(()[2]())[5]()
Sample Input 3
(()[1]())[111]()
()[999](()[9]())
Output for the Sample Input 3
()[1110]()
Sample Input 4
(()[2](()[4]()))[8]((()[16]())[32](()[64]()))
((()[1]())[3]())[9](()[27](()[81]()))
Output for the Sample Input 4
(()[5]())[17](()[59](()[145]()))
Sample Input 5
()[0]()
()[1000]()
Output for the Sample Input 5
()[1000]()

Submitted solutions:

code_snippet: #include <string>
#include <iostream>
#include <vector>

using namespace std;
#define vec vector<int>

const int SIZE=10000000;

vec Aar(SIZE,-1);
vec Bar(SIZE,-1);
vec Xar(SIZE,-1);


void input(vec & ar,const string & str,int & i,int k)
{
    if(str[i]=='(')
    {
        ++i;
        input(ar,str,i,2*k+1);
    }
    if(str[i]==')')
    {
        ++i;
        input(ar,str,i,(k-1)/2);
        return;
    }
    if(str[i]=='[')
    {
        ++i;
        int n=0;
        while(str[i]!=']')
        {
            n*=10;
            n+=(int)(str[i]-'0');
            ++i;
        }
        ++i;
        ar[k] = n;
    }
    if(str[i]=='(')
    {
        ++i;
        input(ar,str,i,2*k+2);
    }
    if(str[i]==')')
    {
        ++i;
        input(ar,str,i,(k-1)/2);
        return;
    }
}

void output(int k)
{
    if(Xar[k]==-1)return;

    cout << "(";
    output(2*k+1);
    cout << ")";

    cout << "[" << Xar[k] << "]";

    cout << "(";
    output(2*k+2);
    cout << ")";
}

int main()
{
    string A,B;
    cin >> A >> B;
    int si=0;
    input(Aar,A,si,0);
    si = 0;
    input(Bar,B,si,0); 

    for(int i=0;i<SIZE;++i)
    {
        if(Aar[i]>=0 && Bar[i]>=0)
        {
            Xar[i]=Aar[i]+Bar[i];
        }
    }

    output(0);

    cout << endl;
}
accuracy: 0.8490566037735849
time_ms: 30
memory_kb: 119872
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, a, b) for (int i = (int)(a - 1); i >= b; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define dbgv(i, a, v) \
  rep(i, a) { cout << v[i] << ((i < a - 1) ? ' ' : '\n'); }
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX / 3

int rp, rq, rans;
int p[1010][1010][2], q[1010][1010][2], ans[2020][1010][2];

int toArray(string s, int h, bool f) {
  if (s.size() == 0) return -1;
  int l = 1, i = 1;
  while (l > 0 && i < s.size()) {
    if (s[i] == '(')
      l++;
    else if (s[i] == ')')
      l--;
    i++;
  }
  int j = i + 1, r = 0;
  while ('0' <= s[j] && s[j] <= '9') {
    r = r * 10 + (s[j] - '0');
    j++;
  }
  if (f) {
    p[h][r][0] = toArray(s.substr(1, i - 2), h + 1, true);
    p[h][r][1] = toArray(s.substr(j + 2, s.size() - j - 3), h + 1, true);
  } else {
    q[h][r][0] = toArray(s.substr(1, i - 2), h + 1, false);
    q[h][r][1] = toArray(s.substr(j + 2, s.size() - j - 3), h + 1, false);
  }
  return r;
}

int combine(int a, int b, int h) {
  if (a != -1 && b != -1) {
    int r = a + b;
    ans[h][r][0] = combine(p[h][a][0], q[h][b][0], h + 1);
    ans[h][r][1] = combine(p[h][a][1], q[h][b][1], h + 1);
    return r;
  } else {
    return -1;
  }
}

string toString(int r, int h) {
  if (r == -1) return "";
  string ret = "(";
  ret += toString(ans[h][r][0], h + 1);
  ret += ")[" + to_string(r) + "](";
  ret += toString(ans[h][r][1], h + 1);
  return ret + ")";
}

int main() {
  cin.sync_with_stdio(false);
  memset(p, -1, sizeof(p));
  memset(q, -1, sizeof(q));
  memset(ans, -1, sizeof(ans));
  string a, b;
  cin >> a >> b;
  rp = toArray(a, 0, true), rq = toArray(b, 0, false);
  rans = combine(rp, rq, 0);
  cout << toString(rans, 0) << endl;
  return 0;
}
accuracy: 0.09433962264150944
time_ms: 10
memory_kb: 35148
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, a, b) for (int i = (int)(a - 1); i >= b; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define dbgv(i, a, v) \
  rep(i, a) { cout << v[i] << ((i < a - 1) ? ' ' : '\n'); }
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX / 3

int p[1010000], q[1010000], ans[1010000];

void toArray(string s, int *array, int rnum) {
  if (s.size() == 0) return;
  int l = 1, i = 1;
  while (l > 0 && i < s.size()) {
    if (s[i] == '(')
      l++;
    else if (s[i] == ')')
      l--;
    i++;
  }
  int j = i + 1, r = 0;
  while ('0' <= s[j] && s[j] <= '9') {
    r = r * 10 + (s[j] - '0');
    j++;
  }
  array[rnum] = r;
  toArray(s.substr(1, i - 2), array, rnum * 2 + 1);
  toArray(s.substr(j + 2, s.size() - j - 3), array, rnum * 2 + 2);
}

string toString(int *array, int rnum) {
  if (array[rnum] == -1) return "";
  string ret = "(";
  ret += toString(array, rnum * 2 + 1);
  ret += ")[" + to_string(array[rnum]) + "](";
  ret += toString(array, rnum * 2 + 2);
  return ret + ")";
}

int main() {
  cin.sync_with_stdio(false);
  memset(p, -1, sizeof(p));
  memset(q, -1, sizeof(q));
  memset(ans, -1, sizeof(ans));
  string a, b;
  cin >> a >> b;
  toArray(a, p, 0), toArray(b, q, 0);
  rep(i, 1010) {
    if (p[i] > -1 && q[i] > -1) ans[i] = p[i] + q[i];
  }
  cout << toString(ans, 0) << endl;
  return 0;
}
accuracy: 0.8490566037735849
time_ms: 10
memory_kb: 15128
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int const MAX=10000000;

int T[2][MAX];
int A[MAX];

void decode(string s,int num,int ab){
  int i=0;
  int l=0,r=0;
  for(;;i++){
    if(s[i]=='(') l++;
    else if(s[i]==')') r++;
    if(l==r){
      if(i>1) decode(s.substr(1,i-1),num*2+1,ab);
      break;
    }
  }
  int tmp=i;
  for(;;i++){
    if(s[i]==']'){
      T[ab][num]=stoi(s.substr(tmp+2,i-1));
      break;
    }
  }
  if(i<s.length()-3) decode(s.substr(i+2,s.length()-4-i),num*2+2,ab);
  return;
}

string encode(int num){
  if(A[num]>=0){
    return "("+encode(num*2+1)+")["+to_string(A[num])+"]("+encode(num*2+2)+")";
  }else{
    return "";
  }
}

void merge(int num){
  A[num]=T[0][num]+T[1][num];
  if(T[0][num*2+1]>=0&&T[1][num*2+1]>=0) merge(num*2+1);
  if(T[0][num*2+2]>=0&&T[1][num*2+2]>=0) merge(num*2+2);
  return;
}

int main(){
  string a,b;
  cin >> a >> b;
  for(int i=0;i<MAX;i++){
    T[0][i]=T[1][i]=A[i]=-1;
  }
  decode(a,0,0);
  decode(b,0,1);
  merge(0);
  // for(int i=0;i<50;i++){
  //   cout << A[i] << " ";
  // }
  // cout << endl;
  cout << encode(0) << endl;
  return 0;
}
accuracy: 0.09433962264150944
time_ms: 40
memory_kb: 120460
final_rank: 17

code_snippet: #include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
string s1,s2;ll kasai[2000000],isao[2000000],jcreation[2000000];
bool visited[2000000],visited2[2000000];

void dfs(int now,int cnt){
  visited[cnt]=true;
  if(now==s1.size()){
    return;
  }
  if(s1[now]=='('){
    if(visited[cnt*2+1])
      dfs(now+1,(cnt*2)+2);
    else
      dfs(now+1,(cnt*2)+1);
  }else if(s1[now]==')'){
    dfs(now+1,(cnt-1)/2);
  }else{
    now++;
    ll num=0;
    while(s1[now]>='0'&&s1[now]<='9'){
      num*=10;
      num+=s1[now]-'0';
      now++;
    }
    kasai[cnt]=num;
    dfs(now+1,cnt);
  }
}
void dfs2(int now,int cnt){
  visited2[cnt]=true;
  if(now==s2.size()){
    return;
  }
  if(s2[now]=='('){
    if(visited2[cnt*2+1])
      dfs2(now+1,(cnt*2)+2);
    else
      dfs2(now+1,(cnt*2)+1);
  }else if(s2[now]==')'){
    dfs2(now+1,(cnt-1)/2);
  }else{
    now++;
    ll num=0;
    while(s2[now]>='0'&&s2[now]<='9'){
      num*=10;
      num+=s2[now]-'0';
      now++;
    }
    isao[cnt]=num;
    dfs2(now+1,cnt);
  }
}
string Stoi(int num){
  string s="";
  while(num>0){
    s+=(char)((num%10)+'0');
    num/=10;
  }
  reverse(s.begin(),s.end());
  return s;
}
string dfs3(int now){
  string ret="";
  if(jcreation[now]==-1)return ret;
  ret="("+dfs3(2*now+1)+")["+Stoi(jcreation[now])+"]("+dfs3(2*now+2)+")";
  return ret;
}
int main(){
  for(int i=0;i<2000000;i++){
    kasai[i]=-1;
    isao[i]=-1;
    jcreation[i]=-1;
  }
  cin>>s1>>s2;
  dfs(0,0);
  dfs2(0,0);
  for(int i=0;i<2000000;i++){
    // cout<<i<<" "<<kasai[i]<<" "<<isao[i]<<endl;
    if(isao[i]>=0&&kasai[i]>=0){
      (jcreation[i]=isao[i]+kasai[i]);
    }
  }
  cout<<dfs3(0)<<endl;
  return 0;
}
accuracy: 0.8490566037735849
time_ms: 20
memory_kb: 50100
final_rank: 6

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s[2];
ll t[3][10000000];
bool f[10000000];

string solve(int k) {
	if (t[2][k] == -1)return "";
	string res = "(" + solve(2 * k + 1) + ")";
	res += ("[" + to_string(t[2][k]) + "]");
	return res + "(" + solve(2 * k + 2) + ")";
}

int main() {
	rep(i, 3)fill(t[i], t[i] + 10000000, -1);
	cin >> s[0] >> s[1];
	rep(i, 2) {
		ll k = 0;
		ll num = 0;
		fill(f, f + 10000000, 0);
		rep(j, s[i].size()) {
			if (s[i][j] == '(')k = 2 * k + 1 + f[k];
			else if (s[i][j] == ')')k = (k - 1) / 2;
			else if (s[i][j] == ']') {
				f[k] = 1;
				t[i][k] = num;
				num = 0;
			}
			else if (s[i][j] >= '0'&&s[i][j] <= '9') {
				num *= 10;
				num += s[i][j] - '0';
			}
		}
	}
	rep(i, 2) {
		rep(j, 10000000) {
			if (t[0][j] != -1 && t[1][j] != -1) {
				t[2][j] = t[0][j] + t[1][j];
			}
		}
	}
	//rep(i, 20) {
	//	cout << t[2][i] << " ";
	//}
	cout << solve(0) << endl;
}
accuracy: 0.8490566037735849
time_ms: 90
memory_kb: 247452
final_rank: 8

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s[2];
ll t[3][1000000];
bool f[1000000];

string solve(int k) {
	if (t[2][k] == -1)return "";
	string res = "(" + solve(2 * k + 1) + ")";
	res += ("[" + to_string(t[2][k]) + "]");
	return res + "(" + solve(2 * k + 2) + ")";
}

int main() {
	rep(i, 3)fill(t[i], t[i] + 1000000, -1);
	cin >> s[0] >> s[1];
	rep(i, 2) {
		ll k = 0;
		ll num = 0;
		fill(f, f + 1000000, 0);
		rep(j, s[i].size()) {
			if (s[i][j] == '(')k = 2 * k + 1 + f[k];
			else if (s[i][j] == ')')k = (k - 1) / 2;
			else if (s[i][j] == ']') {
				f[k] = 1;
				t[i][k] = num;
				num = 0;
			}
			else if (s[i][j] >= '0'&&s[i][j] <= '9') {
				num *= 10;
				num += s[i][j] - '0';
			}
		}
	}
	rep(i, 2) {
		rep(j, 1000000) {
			if (t[0][j] != -1 && t[1][j] != -1) {
				t[2][j] = t[0][j] + t[1][j];
			}
		}
	}
	//rep(i, 20) {
	//	cout << t[2][i] << " ";
	//}
	cout << solve(0) << endl;
}
accuracy: 0.8490566037735849
time_ms: 10
memory_kb: 27724
final_rank: 4

code_snippet: #include "bits/stdc++.h"
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2740&lang=jp
typedef long long ll;
#define INF 1<<30
using namespace std;

void check(int& i,int k, vector<int>& str,string& S) {
	/* "(" ~ )[x]( ~ ) */
	if (S[i] == '(') i++;

	/* ( "~" )[x]( ~ ) */
	if (S[i] == '(') {
		check(i, 2 * k + 1, str, S);
	}

	/* ( ~ ")"[x]( ~ )  */
	if (S[i] == ')') i++;

	/* ( ~ )"[x]"( ~ ) */
	i++; // "["
	str[k] = 0;
	while (S[i] != ']') {
		str[k] = str[k] * 10 + (S[i] - '0');
		i++;
	}
	i++; // "]"

	/* ( ~ )[x]"(" ~ ) */
	if (S[i] == '(') i++;

	/* ( ~ )[x]( "~" )*/
	if (S[i] == '(') {
		check(i, 2 * k + 2, str, S);
	}

	/* ( ~ )[x]( ~ ")"*/
	if (S[i] == ')') i++;
}

/* print answer method */
void out(int k,vector<int>& Sum){
	cout << "(";
	if (Sum[2 * k + 1] != -1) {
		out(2 * k + 1, Sum);
	}
	cout << ")[" << Sum[k] << "](";
	if (Sum[2 * k + 2] != -1) {
		out(2 * k + 2, Sum);
	}
	cout << ")";
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	/* input */
	string A, B; cin >> A >> B;

	/* initialize */
	int k = max(A.length(), B.length());
	vector<int> A_tree(k*k, -1), B_tree(k*k, -1),Sum_tree(k*k,-1);

	/* calc */
	int x = 0;
	check(x, 0, A_tree, A);
	x = 0;
	check(x, 0, B_tree, B);

	for (int i = 0; i < (int)A_tree.size();i++) {
		if (A_tree[i] == -1 || B_tree[i] == -1) continue;
		Sum_tree[i] = A_tree[i] + B_tree[i];
	}

	/*for (auto v : Sum_tree) {
		cout << v << " ";
	}
	cout << endl;*/

	/* solve */
	out(0, Sum_tree);
	cout << endl;

	return 0;
}
accuracy: 0.8490566037735849
time_ms: 10
memory_kb: 14780
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

void solve(string s, long long par, map<long long,int>& m) {
	int cnt = 0;
	int l = 1, r = 0;
	for (int i = 1; i < s.size() - 1; i++) {
		if (s[i] == '(')cnt++;
		else if (s[i] == ')')cnt--;

		if (cnt == 0) {
			r = i;
			string next = s.substr(l, r - l + 1);

			if (l == 1) {
				solve(next, par * 2 + 1, m);

				i += 2;

				int l2 = i;
				while (1) {
					i++;
					if (s[i] == ']') {
						m[par] = stoi(s.substr(l2, i - l2).data());
						i++;
						break;
					}
				}

				l = r = i;
				i--;
			}
			else {
				solve(next, par * 2 + 2,m);
			}
		}
	}
}

string solve2(map<long long, int>& m , long long par) {
	string s1, s2, s3;

	if (m.find(par) != m.end()) {
		s2 = to_string(m[par]);
	}
	else return "";

	s1 = solve2(m, par * 2 + 1);
	s3 = solve2(m, par * 2 + 2);

	return "(" + s1 + ")" + "[" + s2 + "]" + "(" + s3 + ")";
}

int main()
{
	string s1, s2;
	cin >> s1 >> s2;

	s1.insert(s1.begin(), '(');
	s1.push_back(')');
	s2.insert(s2.begin(), '(');
	s2.push_back(')');

	map<long long, int>a, b;


	solve(s1, 0, a);
	solve(s2, 0, b);
	
	map<long long, int>c;

	for (auto itr = a.begin(); itr != a.end(); itr++) {
		long long p = itr->first;
		auto itr2 = b.find(p);
		if (itr2 != b.end()) {
			c[p] = itr->second + itr2->second;
		}
	}

	cout << solve2(c, 0) << endl;

    return 0;
}
accuracy: 0.8490566037735849
time_ms: 10
memory_kb: 22852
final_rank: 3

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

void solve(string s, int par, map<int,int>& m) {
	int cnt = 0;
	int l = 1, r = 0;
	for (int i = 1; i < s.size() - 1; i++) {
		if (s[i] == '(')cnt++;
		else if (s[i] == ')')cnt--;

		if (cnt == 0) {
			r = i;
			string next = s.substr(l, r - l + 1);

			if (l == 1) {
				solve(next, par * 2 + 1, m);

				i += 2;

				int l2 = i;
				while (1) {
					i++;
					if (s[i] == ']') {
						m[par] = stoi(s.substr(l2, i - l2).data());
						i++;
						break;
					}
				}

				l = r = i;
				i--;
			}
			else {
				solve(next, par * 2 + 2,m);
			}
		}
	}
}

string solve2(map<int, int>& m ,int par) {
	string s1, s2, s3;

	if (m.find(par) != m.end()) {
		s2 = to_string(m[par]);
	}
	else return "";

	s1 = solve2(m, par * 2 + 1);
	s3 = solve2(m, par * 2 + 2);

	return "(" + s1 + ")" + "[" + s2 + "]" + "(" + s3 + ")";
}

int main()
{
	string s1, s2;
	cin >> s1 >> s2;

	s1.insert(s1.begin(), '(');
	s1.push_back(')');
	s2.insert(s2.begin(), '(');
	s2.push_back(')');

	map<int, int>a, b;


	solve(s1, 0, a);
	solve(s2, 0, b);
	
	map<int, int>c;

	for (auto itr = a.begin(); itr != a.end(); itr++) {
		int p = itr->first;
		auto itr2 = b.find(p);
		if (itr2 != b.end()) {
			c[p] = itr->second + itr2->second;
		}
	}

	cout << solve2(c, 0) << endl;

    return 0;
}
accuracy: 0.8490566037735849
time_ms: 20
memory_kb: 22972
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
struct no{
  long int key;
  no *left,*right;
  no(){left=right=NULL;}
};
typedef no* node;
int n,p3,p4;
string s1[2];
vector<long int>v[2];
void v_make(int t){
  v[t].push_back('(');
  for(int i=0;i<s1[t].size();i++){
    if(!isdigit(s1[t][i]))v[t].push_back(s1[t][i]);
    else{
      int p=s1[t][i]-'0';
      while(isdigit(s1[t][i+1]))p*=10,p+=s1[t][++i]-'0';
      v[t].push_back(p+100);
    }
  }
  v[t].push_back(')');
}
node con(int l,int r){if(r<=l+1)return NULL;
  node po=new no();
  int p=0,c=-1;
  for(int i=l+1;i<r;i++)
    if((char)v[n][i]=='(')p++;
    else if((char)v[n][i]==')')p--;
    else if(v[n][i]>=100&&!p){
      c=i;
      po->key=v[n][i]-100;
      break;
    }
  if(l+1!=c)po->left=con(l+1,c-1);
  if(r-1!=c)po->right=con(c+1,r-1);
  return po;
}
string make_num(long int p){
  string t;
  while(p){
    t+=p%10+'0';
    p/=10;
  }
  reverse(t.begin(),t.end());
  return t;
}
string init(node a,node b){
  string l,r,x=make_num(a->key+b->key);
  if(a->left!=NULL&&b->left!=NULL)
    l=init(a->left,b->left);
  if(a->right!=NULL&&b->right!=NULL)
    r=init(a->right,b->right);
  return "("+l+")["+x+"]("+r+")";
}
int main(){
  cin>>s1[0]>>s1[1];
  for(int j=0;j<2;j++)
    for(int i=0;i<(int)s1[j].size();i++)
      if(s1[j][i]=='('&&s1[j][i+1]==')')s1[j].erase(s1[j].begin()+i),s1[j].erase(s1[j].begin()+i);
  for(int j=0;j<2;j++)
    for(int i=0;i<(int)s1[j].size();i++)
      if(s1[j][i]=='['||s1[j][i]==']')s1[j].erase(s1[j].begin()+i);
  v_make(0);v_make(1);

  n=0;node a=con(0,v[n].size()-1);
  n=1;node b=con(0,v[n].size()-1);
  cout<<init(a,b)<<endl;
}
accuracy: 0.09433962264150944
time_ms: 20
memory_kb: 12888
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
struct no{
  long int key;
  no *left,*right;
  no(){left=right=NULL;}
};
typedef no* node;
int n;
string s1[2];
vector<long int>v[2];
void v_make(int t){
  v[t].push_back('(');
  for(int i=0;i<s1[t].size();i++){
    if(!isdigit(s1[t][i]))v[t].push_back(s1[t][i]);
    else{
      int p=s1[t][i]-'0';
      while(isdigit(s1[t][i+1]))p*=10,p+=s1[t][++i]-'0';
      v[t].push_back(p+100);
    }
  }
  v[t].push_back(')');
}
node con(int l,int r){
  node po=new no();
  int p=0,c=-1;
  for(int i=l+1;i<r;i++)
    if((char)v[n][i]=='(')p++;
    else if((char)v[n][i]==')')p--;
    else if(v[n][i]>=100&&!p){
      c=i;
      po->key=v[n][i]-100;
      break;
    }
  if(l+1!=c)po->left=con(l+1,c-1);
  if(r-1!=c)po->right=con(c+1,r-1);
  return po;
}
string make_num(long int p){
  string t;
  while(p){
    t+=p%10+'0';
    p/=10;
  }
  reverse(t.begin(),t.end());
  return t;
}
string init(node a,node b){
  string l,r,x=make_num(a->key+b->key);
  if(a->left!=NULL&&b->left!=NULL)
    l=init(a->left,b->left);
  if(a->right!=NULL&&b->right!=NULL)
    r=init(a->right,b->right);
  return "("+l+")["+x+"]("+r+")";
}
int main(){
  cin>>s1[0]>>s1[1];
  for(int j=0;j<2;j++)
    for(int i=0;i<(int)s1[j].size()-1;i++)
      if(s1[j][i]=='('&&s1[j][i+1]==')')s1[j].erase(s1[j].begin()+i),s1[j].erase(s1[j].begin()+i);
  for(int j=0;j<2;j++)
    for(int i=0;i<(int)s1[j].size();i++)
      if(s1[j][i]=='['||s1[j][i]==']')s1[j].erase(s1[j].begin()+i);

  v_make(0);v_make(1);
  n=0;node a=con(0,v[n].size()-1);
  n=1;node b=con(0,v[n].size()-1);
  cout<<init(a,b)<<endl;
}
accuracy: 0.09433962264150944
time_ms: 20
memory_kb: 35600
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
struct no{
  long int key;
  no *left,*right;
  no(){left=right=NULL;}
};
typedef no* node;
int n;
string s1[2];
vector<long int>v[2];
void v_make(int t){
  v[t].push_back('(');
  for(int i=0;i<s1[t].size();i++){
    if(!isdigit(s1[t][i]))v[t].push_back(s1[t][i]);
    else{
      int p=s1[t][i]-'0';
      while(isdigit(s1[t][i+1]))p*=10,p+=s1[t][++i]-'0';
      v[t].push_back(p+100);
    }
  }
  v[t].push_back(')');
}
node con(int l,int r){
  node po=new no();
  int p=0,c=-1;
  for(int i=l+1;i<r;i++)
    if((char)v[n][i]=='(')p++;
    else if((char)v[n][i]==')')p--;
    else if(v[n][i]>=100&&!p){
      c=i;
      po->key=v[n][i]-100;
      break;
    }
  if(l+1!=c)po->left=con(l+1,c-1);
  if(r-1!=c)po->right=con(c+1,r-1);
  return po;
}
string make_num(long int p){
  string t;
  while(p){
    t+=p%10+'0';
    p/=10;
  }
  reverse(t.begin(),t.end());
  return t;
}
string init(node a,node b){
  string l,r,x=make_num(a->key+b->key);
  if(a->left!=NULL&&b->left!=NULL)
    l=init(a->left,b->left);
  if(a->right!=NULL&&b->right!=NULL)
    r=init(a->right,b->right);
  return "("+l+")["+x+"]("+r+")";
}
int main(){
  cin>>s1[0]>>s1[1];
  for(int j=0;j<2;j++)
    for(int i=0;i<(int)s1[j].size()-1;i++)
      if(s1[j][i]=='('&&s1[j][i+1]==')')s1[j].erase(s1[j].begin()+i),s1[j].erase(s1[j].begin()+i);
  for(int j=0;j<2;j++)
    for(int i=0;i<(int)s1[j].size()-1;i++)
      if(s1[j][i]=='['||s1[j][i]==']')s1[j].erase(s1[j].begin()+i);
  v_make(0);v_make(1);
  n=0;node a=con(0,v[n].size()-1);
  n=1;node b=con(0,v[n].size()-1);
  cout<<init(a,b)<<endl;
}
accuracy: 0.018867924528301886
time_ms: 30
memory_kb: 35756
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
struct no{
  int key;
  no *left,*right;
  no(){left=right=NULL;}
};
typedef no* node;
string s,t;
int n,x;
vector<int>a[2];
void mae(string q){
  a[n].push_back('(');
  for(int i=0;i<(int)q.size();i++)
    if(q[i]=='('&&q[i+1]==')')
      q.erase(q.begin()+i,q.begin()+i+2);
  for(int i=0;i<q.size();i++){
    if(q[i]=='['){
      int p=0;i++;
      while(isdigit(q[i]))p*=10,p+=q[i++]-'0';
      a[n].push_back(p+100);
    }
    else a[n].push_back(q[i]);
  }
  a[n].push_back(')');
}
node con(int l,int r){
  node po=new no();
  int p=0,c=-1,o;
  for(int i=l+1;i<r;i++){
    if((char)a[n][i]=='(')p++;
    else if((char)a[n][i]==')')p--;
    else if(a[n][i]>=100&&!p){
      o=a[n][i]-100;
      c=i;
      break;
    }
  }//if(p){cout<<1;exit(0);}
  po->key=o;
  if(l+1!=c){
    //if(c-1>l+1)
    po->left=con(l+1,c-1);
  }
  if(r-1!=c){
   // if(r-1>c+1)
    po->right=con(c+1,r-1);
  }
  return po;
}
string df(int q){
  if(!q)return "0";
  string y;
  while(q){
    y+=q%10+'0';
    q/=10;
  }
  reverse(y.begin(),y.end());
  return y;
}
string init(node aa,node b){
  int t1=0,t2=0;
  string l,r,xx=df(aa->key+b->key);
  if(aa->left!=NULL&&b->left!=NULL)
    l=init(aa->left,b->left),t1++;
  if(aa->right!=NULL&&b->right!=NULL)
    r=init(aa->right,b->right),t2++;
  if(!t1&&!t2)return "()["+xx+"]()";
  else if(t2&&!t1)return "()["+xx+"]("+r+")";
  else if(t1&&!t2)return "("+l+")["+xx+"]()";
  else return "("+l+")["+xx+"]("+r+")";
}
main(){
  string s1;
  cin>>s>>t;
  n=0;mae(s);
  n=1;mae(t);
  n=0;node p1=con(0,a[0].size()-1);
  n=1;node p2=con(0,a[1].size()-1);
  cout<<init(p1,p2)<<endl;
}
accuracy: 0.09433962264150944
time_ms: 20
memory_kb: 30156
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
struct no{
  int key;
  no *left,*right;
  no(){left=right=NULL;}
};
typedef no* node;
string s,t;
int n,x;
vector<int>a[2];
void mae(string q){
  a[n].push_back('(');
  for(int i=0;i<(int)q.size();i++)
    if(q[i]=='('&&q[i+1]==')')
      q.erase(q.begin()+i,q.begin()+i+2);
  for(int i=0;i<q.size();i++){
    if(q[i]=='['){
      int p=0;i++;
      while(isdigit(q[i]))p*=10,p+=q[i++]-'0';
      a[n].push_back(p+100);
    }
    else a[n].push_back(q[i]);
  }
  a[n].push_back(')');
}
node con(int l,int r){
  node po=new no();
  int p=0,c=-1,o;
  for(int i=l+1;i<r;i++){
    if((char)a[n][i]=='(')p++;
    else if((char)a[n][i]==')')p--;
    else if(a[n][i]>=100&&!p){
      o=a[n][i]-100;
      c=i;
      break;
    }
  }
  po->key=o;
  if(l+1!=c){
    if(c-1>l+1)
    po->left=con(l+1,c-1);
  }
  if(r-1!=c){
    if(r-1>c+1)
    po->right=con(c+1,r-1);
  }
  return po;
}
string df(int q){
  if(!q)return "0";
  string y;
  while(q){
    y+=q%10+'0';
    q/=10;
  }
  reverse(y.begin(),y.end());
  return y;
}
string init(node aa,node b){
  int t1=0,t2=0;
  string l,r,xx=df(aa->key+b->key);
  if(aa->left!=NULL&&b->left!=NULL)
    l=init(aa->left,b->left),t1++;
  if(aa->right!=NULL&&b->right!=NULL)
    r=init(aa->right,b->right),t2++;
  if(!t1&&!t2)return "()["+xx+"]()";
  else if(t2&&!t1)return "()["+xx+"]("+r+")";
  else if(t1&&!t2)return "("+l+")["+xx+"]()";
  else return "("+l+")["+xx+"]("+r+")";
}
main(){
  string s1;
  cin>>s>>t;
  n=0;mae(s);
  n=1;mae(t);
  n=0;node p1=con(0,a[0].size()-1);
  n=1;node p2=con(0,a[1].size()-1);
  cout<<init(p1,p2)<<endl;
}
accuracy: 0.09433962264150944
time_ms: 80
memory_kb: 43460
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
struct no{
  int key;
  no *left,*right;
  no(){left=right=NULL;}
};
typedef no* node;
string s,t;
int n,x;
vector<int>a[2];
void mae(string q){
  a[n].push_back('(');
  for(int i=0;i<(int)q.size();i++)
    if(q[i]=='('&&q[i+1]==')')
      q.erase(q.begin()+i,q.begin()+i+2),i--;
  for(int i=0;i<q.size();i++){
    if(q[i]=='['){
      int p=0;i++;
      while(isdigit(q[i]))p*=10,p+=q[i++]-'0';
      a[n].push_back(p+100);
    }
    else a[n].push_back(q[i]);
  }
  a[n].push_back(')');
}
node con(int l,int r){
  node po=new no();
  int p=0,c=-1,o;
  for(int i=l+1;i<r;i++){
    if((char)a[n][i]=='(')p++;
    else if((char)a[n][i]==')')p--;
    else if(a[n][i]>=100&&!p){
      o=a[n][i]-100;
      c=i;
      break;
    }
  }
  po->key=o;
  if(l+1!=c){
    if(c-1>l+1)
    po->left=con(l+1,c-1);
  }
  if(r-1!=c){
    if(r-1>c+1)
    po->right=con(c+1,r-1);
  }
  return po;
}
string df(int q){
  if(!q)return "0";
  string y;
  while(q){
    y+=q%10+'0';
    q/=10;
  }
  reverse(y.begin(),y.end());
  return y;
}
string init(node aa,node b){
  int t1=0,t2=0;
  string l,r,xx=df(aa->key+b->key);
  if(aa->left!=NULL&&b->left!=NULL)
    l=init(aa->left,b->left),t1++;
  if(aa->right!=NULL&&b->right!=NULL)
    r=init(aa->right,b->right),t2++;
  if(!t1&&!t2)return "()["+xx+"]()";
  else if(t2&&!t1)return "()["+xx+"]("+r+")";
  else if(t1&&!t2)return "("+l+")["+xx+"]()";
  else return "("+l+")["+xx+"]("+r+")";
}
main(){
  string s1;
  cin>>s>>t;
  n=0;mae(s);
  n=1;mae(t);
  n=0;node p1=con(0,a[0].size()-1);
  n=1;node p2=con(0,a[1].size()-1);
  cout<<init(p1,p2)<<endl;
}
accuracy: 0.09433962264150944
time_ms: 90
memory_kb: 43472
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
struct no{
  int key;
  no *left,*right;
  no(){left=right=NULL;}
};
typedef no* node;
string s,t;
int n,x;
vector<int>a[2];
void mae(string q){
  a[n].push_back('(');
  for(int i=0;i<(int)q.size();i++)
    if(q[i]=='('&&q[i+1]==')')
      q.erase(q.begin()+i,q.begin()+i+2),i--;
  for(int i=0;i<q.size();i++){
    if(q[i]=='['){
      int p=0;i++;
      while(isdigit(q[i]))p*=10,p+=q[i++]-'0';
      a[n].push_back(p+100);
    }
    else a[n].push_back(q[i]);
  }
  a[n].push_back(')');
}
node con(int l,int r){
  node po=new no();
  int p=0,c=-1,o;if(r-l-1==0)exit(0);
  for(int i=l+1;i<r;i++){
    if((char)a[n][i]=='(')p++;
    else if((char)a[n][i]==')')p--;
    else if(a[n][i]>=100&&!p){
      o=a[n][i]-100;
      c=i;
      break;
    }
  }
  po->key=o;
  if(l+1!=c)po->left=con(l+1,c-1);
  if(r-1!=c)po->right=con(c+1,r-1);
  return po;
}
string df(int q){
  if(!q)return "0";
  string y;
  while(q){
    y+=q%10+'0';
    q/=10;
  }
  reverse(y.begin(),y.end());
  return y;
}
string init(node aa,node b){
  int t1=0,t2=0;
  string l,r,xx=df(aa->key+b->key);
  if(aa->left!=NULL&&b->left!=NULL)
    l=init(aa->left,b->left),t1++;
  if(aa->right!=NULL&&b->right!=NULL)
    r=init(aa->right,b->right),t2++;
  if(!t1&&!t2)return "()["+xx+"]()";
  else if(t2&&!t1)return "()["+xx+"]("+r+")";
  else if(t1&&!t2)return "("+l+")["+xx+"]()";
  else return "("+l+")["+xx+"]("+r+")";
}
main(){
  string s1;
  cin>>s>>t;
  n=0;mae(s);
  n=1;mae(t);
  n=0;node p1=con(0,a[0].size()-1);
  n=1;node p2=con(0,a[1].size()-1);
  cout<<init(p1,p2)<<endl;
}
accuracy: 0.09433962264150944
time_ms: 30
memory_kb: 30264
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
struct no{
  int key;
  no *left,*right;
  no(){left=right=NULL;}
};
typedef no* node;
string s,t;
int n,x;
vector<int>a[2];
void mae(string q){
  a[n].push_back('(');
  for(int i=0;i<(int)q.size();i++)
    if(q[i]=='('&&q[i+1]==')')
      q.erase(q.begin()+i,q.begin()+i+2),i--;
  for(int i=0;i<q.size();i++){
    if(q[i]=='['){
      int p=0;i++;
      while(isdigit(q[i]))p*=10,p+=q[i++]-'0';
      a[n].push_back(p+100);
    }
    else a[n].push_back(q[i]);
  }
  a[n].push_back(')');
}
node con(int l,int r){
  node po=new no();
  int p=0,c=-1,o;
  for(int i=l+1;i<r;i++){
    if((char)a[n][i]=='(')p++;
    else if((char)a[n][i]==')')p--;
    else if(a[n][i]>=100&&!p){
      o=a[n][i]-100;
      c=i;
      break;
    }
  }
  po->key=o;
  if(l+1!=c)po->left=con(l+1,c-1);
  if(r-1!=c)po->right=con(c+1,r-1);
  return po;
}
string df(int q){
  if(!q)return "0";
  string y;
  while(q){
    y+=q%10+'0';
    q/=10;
  }
  reverse(y.begin(),y.end());
  return y;
}
string init(node aa,node b){
  int t1=0,t2=0;
  string l,r,xx=df(aa->key+b->key);
  if(aa->left!=NULL&&b->left!=NULL)
    l=init(aa->left,b->left),t1++;
  if(aa->right!=NULL&&b->right!=NULL)
    r=init(aa->right,b->right),t2++;
  if(!t1&&!t2)return "()["+xx+"]()";
  else if(t2&&!t1)return "()["+xx+"]("+r+")";
  else if(t1&&!t2)return "("+l+")["+xx+"]()";
  else return "("+l+")["+xx+"]("+r+")";
}
main(){
  string s1;
  cin>>s>>t;
  n=0;mae(s);
  n=1;mae(t);
  n=0;node p1=con(0,a[0].size()-1);
  n=1;node p2=con(0,a[1].size()-1);
  cout<<init(p1,p2)<<endl;
}
accuracy: 0.09433962264150944
time_ms: 20
memory_kb: 30164
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
struct no{
  int key;
  no *left,*right;
  no(){left=right=NULL;}
};
typedef no* node;
string s,t;
int n,x;
vector<int>a[2];
void mae(string q){
  a[n].push_back('(');
  for(int i=0;i<(int)q.size();i++)
    if(q[i]=='('&&q[i+1]==')')
      q.erase(q.begin()+i,q.begin()+i+2),i--;
  for(int i=0;i<q.size();i++){
    if(q[i]=='['){
      int p=0;i++;
      while(isdigit(q[i]))p*=10,p+=q[i++]-'0';
      a[n].push_back(p+100);
    }
    else a[n].push_back(q[i]);
  }
  a[n].push_back(')');
}
node con(int l,int r){
  node po=new no();
  int p=0,c=-1,o;//if(l+1>=r+1){return NULL;}
  for(int i=l+1;i<r-1;i++){
    if((char)a[n][i]=='(')p++;
    else if((char)a[n][i]==')')p--;
    else if(a[n][i]>=100&&!p){
      o=a[n][i]-100;
      c=i;
      break;
    }
  }
  po->key=o;
  if(l+1!=c)po->left=con(l+1,c);
  if(r-1!=c+1)po->right=con(c+1,r-1);
  return po;
}
string df(int q){
  if(!q)return "0";
  string y;
  while(q){
    y+=q%10+'0';
    q/=10;
  }
  reverse(y.begin(),y.end());
  return y;
}
string init(node aa,node b){
  int t1=0,t2=0;
  string l,r,xx=df(aa->key+b->key);
  if(aa->left!=NULL&&b->left!=NULL)
    l=init(aa->left,b->left),t1++;
  if(aa->right!=NULL&&b->right!=NULL)
    r=init(aa->right,b->right),t2++;
  if(!t1&&!t2)return "()["+xx+"]()";
  else if(t2&&!t1)return "()["+xx+"]("+r+")";
  else if(t1&&!t2)return "("+l+")["+xx+"]()";
  else return "("+l+")["+xx+"]("+r+")";
}
main(){
  string s1;
  cin>>s>>t;
  n=0;mae(s);
  n=1;mae(t);
  n=0;node p1=con(0,a[0].size());
  n=1;node p2=con(0,a[1].size());
  cout<<init(p1,p2)<<endl;
}
accuracy: 0.09433962264150944
time_ms: 20
memory_kb: 30244
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
struct no{
  int key;
  no *left,*right;
  no(){left=right=NULL;}
};
typedef no* node;
string s,t;
int n,x;
vector<int>a[2];
void mae(string q){
  a[n].push_back('(');
  for(int i=0;i<(int)q.size();i++)
    if(q[i]=='('&&q[i+1]==')')
      q.erase(q.begin()+i,q.begin()+i+2),i--;
  for(int i=0;i<q.size();i++){
    if(q[i]=='['){
      int p=0;i++;
      while(isdigit(q[i]))p*=10,p+=q[i++]-'0';
      a[n].push_back(p+100);
    }
    else a[n].push_back(q[i]);
  }
  a[n].push_back(')');
}
node con(int l,int r){
  node po=new no();
  int p=0,c=-1,o;//if(l+1>=r+1){cout<<1<<endl;exit(0);}
  for(int i=l+1;i<=r-1;i++){
    if((char)a[n][i]=='(')p++;
    else if((char)a[n][i]==')')p--;
    else if(a[n][i]>=100&&!p){
      o=a[n][i]-100;
      c=i;
      break;
    }
  }
  po->key=o;
  if(l+1!=c)po->left=con(l+1,c);
  if(r-1!=c+1)po->right=con(c+1,r-1);
  return po;
}
string df(int q){
  if(!q)return "0";
  string y;
  while(q){
    y+=q%10+'0';
    q/=10;
  }
  reverse(y.begin(),y.end());
  return y;
}
string init(node aa,node b){
  int t1=0,t2=0;
  string l,r,xx=df(aa->key+b->key);
  if(aa->left!=NULL&&b->left!=NULL)
    l=init(aa->left,b->left),t1++;
  if(aa->right!=NULL&&b->right!=NULL)
    r=init(aa->right,b->right),t2++;
  if(!t1&&!t2)return "()["+xx+"]()";
  else if(t2&&!t1)return "()["+xx+"]("+r+")";
  else if(t1&&!t2)return "("+l+")["+xx+"]()";
  else return "("+l+")["+xx+"]("+r+")";
}
main(){
  string s1;
  cin>>s>>t;
  n=0;mae(s);
  n=1;mae(t);
  n=0;node p1=con(0,a[0].size());
  n=1;node p2=con(0,a[1].size());
  cout<<init(p1,p2)<<endl;
}
accuracy: 0.09433962264150944
time_ms: 10
memory_kb: 30148
final_rank: 9