Language: C++

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

static const int MAXN = 1e3 + 10;
deque<char> ans;
stack<char> s;
char data[MAXN];
int n;

int main()
{
    scanf("%d" , &n);
    scanf(" %s" , data + 1);
    for(int i = 1 ; i <= n ; ++i)
    {
        char a = data[i];
        if(a == '(')
        {
            if(data[i + 1] == ')')
            {
                ++i;
                ans.push_back('(');
                ans.push_back(')');
            }
            else
                s.push('(');
        }
        else
        {
            if(s.empty())
                ans.push_front('(');
            while(!s.empty())
            {
                s.pop();
                ans.push_front('(');
            }
            ans.push_back(')');
        }
    }

    while(!s.empty())
    {
        ans.push_front('(');
        ans.push_back(')');
        ans.pop();
    }

    for(auto i: ans)
        printf("%c" , i);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:19: error: reference to 'data' is ambiguous
   13 |     scanf(" %s" , data + 1);
      |                   ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:6: note:                 'char data [1010]'
    7 | char data[MAXN];
      |      ^~~~
a.cc:16:18: error: reference to 'data' is ambiguous
   16 |         char a = data[i];
      |                  ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:6: note:                 'char data [1010]'
    7 | char data[MAXN];
      |      ^~~~
a.cc:19:16: error: reference to 'data' is ambiguous
   19 |             if(data[i + 1] == ')')
      |                ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:6: note:                 'char data [1010]'
    7 | char data[MAXN];
      |      ^~~~
a.cc:45:13: error: 'class std::deque<char>' has no member named 'pop'
   45 |         ans.pop();
      |             ^~~