Language: C++

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int idxa = 0, idxb = 0;

int calc(string &A, string &B)
{
    string tmpa, tmpb;
    idxa++;
    idxb++;
    while (A[idxa] != ']')
    {
        tmpa.push_back(A[idxa++]);
    }
    while (B[idxb] != ']')
    {
        tmpb.push_back(B[idxb++]);
    }
    //cout << tmpa << " " << tmpb << endl;
    return stoi(tmpa) + stoi(tmpb);
}
int proceed(int idx, string &C)
{
    int cnt = 1;
    while (1)
    {
        idx++;
        if (C[idx] == ')')
            cnt--;
        if (C[idx] == '(')
            cnt++;
        if (cnt < 0)
            break;
    }
    return idx;
}

int main()
{
    string A, B;
    cin >> A >> B;
    string ans;
    while (idxa < A.size())
    {
        if (A[idxa] == B[idxb])
        {
            if (A[idxa] == '[')
            {
                ans.push_back('[');
                int tmp = calc(A, B);
                ans += to_string(tmp);
                ans.push_back(']');
            }
            else
                ans.push_back(A[idxa]);
        }
        else
        {
            if (A[idxa] == '(')
                idxa = proceed(idxa, A);
            else
            {
                idxb = proceed(idxb, B);
            }
            ans.push_back(A[idxa]);
        }
        idxa++;
        idxb++;
        //cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int idxa = 0, idxb = 0;

int calc(string &A, string &B)
{
    string tmpa, tmpb;
    idxa++;
    idxb++;
    while (A[idxa] != ']')
    {
        tmpa.push_back(A[idxa++]);
    }
    while (B[idxb] != ']')
    {
        tmpb.push_back(B[idxb++]);
    }
    //cout << tmpa << " " << tmpb << endl;
    return stoi(tmpa) + stoi(tmpb);
}
int proceed(int idx, string &C)
{
    int cnt = 1;
    while (1)
    {
        idx++;
        if (C[idx] == ')')
            cnt--;
        if (C[idx] == '(')
            cnt++;
        if (cnt < 0)
            break;
    }
    return idx;
}

int main()
{
    string A, B;
    cin >> A >> B;
    string ans;
    while (idxa < A.size())
    {
        if (A[idxa] == B[idxb])
        {
            if (A[idxa] == '[')
            {
                ans.push_back('[');
                int tmp = calc(A, B);
                ans += to_string(tmp);
                ans.push_back(']');
            }
            else
                ans.push_back(A[idxa]);
        }
        else
        {
            if (A[idxa] == '(')
                idxa = proceed(idxa, A);
            else
            {
                idxb = proceed(idxb, B);
            }
            ans.push_back(A[idxa]);
        }
        idxa++;
        idxb++;
        //cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}



Compiler output:
a.cc:88:10: error: redefinition of 'const ll mod'
   88 | const ll mod = ll(1e9) + 7;
      |          ^~~
a.cc:8:10: note: 'const ll mod' previously defined here
    8 | const ll mod = ll(1e9) + 7;
      |          ^~~
a.cc:89:11: error: redefinition of 'const int INF'
   89 | const int INF = int(1e9);
      |           ^~~
a.cc:9:11: note: 'const int INF' previously defined here
    9 | const int INF = int(1e9);
      |           ^~~
a.cc:91:5: error: redefinition of 'int idxa'
   91 | int idxa = 0, idxb = 0;
      |     ^~~~
a.cc:11:5: note: 'int idxa' previously defined here
   11 | int idxa = 0, idxb = 0;
      |     ^~~~
a.cc:91:15: error: redefinition of 'int idxb'
   91 | int idxa = 0, idxb = 0;
      |               ^~~~
a.cc:11:15: note: 'int idxb' previously defined here
   11 | int idxa = 0, idxb = 0;
      |               ^~~~
a.cc:93:5: error: redefinition of 'int calc(std::string&, std::string&)'
   93 | int calc(string &A, string &B)
      |     ^~~~
a.cc:13:5: note: 'int calc(std::string&, std::string&)' previously defined here
   13 | int calc(string &A, string &B)
      |     ^~~~
a.cc:109:5: error: redefinition of 'int proceed(int, std::string&)'
  109 | int proceed(int idx, string &C)
      |     ^~~~~~~
a.cc:29:5: note: 'int proceed(int, std::string&)' previously defined here
   29 | int proceed(int idx, string &C)
      |     ^~~~~~~
a.cc:125:5: error: redefinition of 'int main()'
  125 | int main()
      |     ^~~~
a.cc:45:5: note: 'int main()' previously defined here
   45 | int main()
      |     ^~~~