Language: C++

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

string forward, backward;
int q, t, f;
char c;
int main(){
  bool back = false;
  cin >> forward >> q;
  while (q--) {
    cin >> t;
    if (t==1) {
      back = !back;
      swap(forward, backward);
    } else {
      cin >> f >> c;
      (f==1 ? backward : forward) += c;
    }
  }
  reverse(backward.begin(), backward.end());
  cout << backward << forward << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:10: error: reference to 'forward' is ambiguous
    9 |   cin >> forward >> q;
      |          ^~~~~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:61,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/move.h:84:5: note: candidates are: 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&&)'
   84 |     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
      |     ^~~~~~~
/usr/include/c++/14/bits/move.h:71:5: note:                 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&)'
   71 |     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
      |     ^~~~~~~
a.cc:4:8: note:                 'std::string forward'
    4 | string forward, backward;
      |        ^~~~~~~
a.cc:14:12: error: reference to 'forward' is ambiguous
   14 |       swap(forward, backward);
      |            ^~~~~~~
/usr/include/c++/14/bits/move.h:84:5: note: candidates are: 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&&)'
   84 |     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
      |     ^~~~~~~
/usr/include/c++/14/bits/move.h:71:5: note:                 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&)'
   71 |     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
      |     ^~~~~~~
a.cc:4:8: note:                 'std::string forward'
    4 | string forward, backward;
      |        ^~~~~~~
a.cc:17:26: error: reference to 'forward' is ambiguous
   17 |       (f==1 ? backward : forward) += c;
      |                          ^~~~~~~
/usr/include/c++/14/bits/move.h:84:5: note: candidates are: 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&&)'
   84 |     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
      |     ^~~~~~~
/usr/include/c++/14/bits/move.h:71:5: note:                 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&)'
   71 |     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
      |     ^~~~~~~
a.cc:4:8: note:                 'std::string forward'
    4 | string forward, backward;
      |        ^~~~~~~
a.cc:21:23: error: reference to 'forward' is ambiguous
   21 |   cout << backward << forward << endl;
      |                       ^~~~~~~
/usr/include/c++/14/bits/move.h:84:5: note: candidates are: 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&&)'
   84 |     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
      |     ^~~~~~~
/usr/include/c++/14/bits/move.h:71:5: note:                 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&)'
   71 |     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
      |     ^~~~~~~
a.cc:4:8: note:                 'std::string forward'
    4 | string forward, backward;
      |        ^~~~~~~