Language: C++

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <climits>
#include <utility>
#include <map>
#include <set>
#include <complex>
#include <numeric>

#include <time.h>
#include <float.h>

#define loop(i, n) for(i = 0; i < n; i++)
#define loop1(i, n) for(i = 1; i <= n; i++)
#define loop2(i, n, start) for(i = start; i <= n; i++)
#define loopIterators(it, vec) for(it = (vec).begin(); it != (vec).end(); it++)
#define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
#define loopRev(i, n) for(i = (n - 1); i >= 0; i--)
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCases(t) cin >> t; while(t--)
#define PN(n) cout << (n)
#define PN1(n) cout << (n) << " "
#define PN2(a, b) cout << (a) << " " << (b) << " "
#define PNN1(n) cout << (n) << endl
#define PNN2(a, b) cout << (a) << " " << (b) << endl
#define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define PrintArray(ar, n) for(i = 0; i < n; i++) cout << ar[i] << " "; cout << endl
#define PrintSet(ar, it) for(it = ar.begin(); it != ar.end(); it++) cout << *it << " "; cout << endl
#define PrintMap(map, it) for(it = map.begin(); it != map.end(); it++) PNN2(it -> first, it -> second)
#define sz(a) sizeof(a)
#define IN1(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define ALL(s) s.begin(), s.end()
#define SWAP(a, b, c) c = a; a = b; b = c
#define STRSP(s) scanf("%[^\n]%*c", s)
#define ENTER PNN1("");
#define MOD7 1000000007
#define MOD9 10000009
#define MAX 100005
#define llPair std::pair<lli, lli>
#define iiPair std::pair<int , int>
#define ONLINE_JUDGE

typedef long long int lli;
typedef long int li;
typedef unsigned long long int ulli;
typedef long double ld;

using namespace std;

int main(void){
	FLASH

	#ifndef ONLINE_JUDGE
		freopen("input-stream.txt", "r", stdin);
    freopen("output-stream.txt", "w", stdout);
	#endif

	std::string str;
	std::string::iterator it;
	deque<char> queue;
	deque<char>::iterator itDeque;
	int q, i, reverse = 0;

	IN2(str, q);
	loopIterators(it, str) queue.emplace_back(*it);

	while (q--) {
		int t;
		IN1(t);
		switch (t) {
			case 1:
				reverse = (reverse + 1) % 2;
				break;
			case 2:
				int f;
				char c;
				IN2(f, c);
				--f;
				f = (f + reverse) % 2;
				f == 0? queue.emplace_front(c): queue.emplace_back(c);
				break;
		}
	}

	reverse == 0?
	loopIterators(itDeque, queue) PN(*itDeque):
	loopIteratorsRev(itDeque, queue) PN(*itDeque);

	#ifndef ONLINE_JUDGE
		fclose(stdin);
    fclose(stdout);
	#endif

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:32: error: expected primary-expression before 'for'
   25 | #define loopIterators(it, vec) for(it = (vec).begin(); it != (vec).end(); it++)
      |                                ^~~
a.cc:97:9: note: in expansion of macro 'loopIterators'
   97 |         loopIterators(itDeque, queue) PN(*itDeque):
      |         ^~~~~~~~~~~~~
a.cc:96:22: error: expected ':' before 'for'
   96 |         reverse == 0?
      |                      ^
      |                      :
a.cc:25:32: error: expected primary-expression before 'for'
   25 | #define loopIterators(it, vec) for(it = (vec).begin(); it != (vec).end(); it++)
      |                                ^~~
a.cc:97:9: note: in expansion of macro 'loopIterators'
   97 |         loopIterators(itDeque, queue) PN(*itDeque):
      |         ^~~~~~~~~~~~~
a.cc:25:59: warning: ignoring return value of 'bool std::operator!=(const _Deque_iterator<char, char&, char*>::_Self&, const _Deque_iterator<char, char&, char*>::_Self&)', declared with attribute 'nodiscard' [-Wunused-result]
   25 | #define loopIterators(it, vec) for(it = (vec).begin(); it != (vec).end(); it++)
      |                                                           ^
a.cc:97:9: note: in expansion of macro 'loopIterators'
   97 |         loopIterators(itDeque, queue) PN(*itDeque):
      |         ^~~~~~~~~~~~~
In file included from /usr/include/c++/14/deque:66,
                 from /usr/include/c++/14/stack:62,
                 from a.cc:9:
/usr/include/c++/14/bits/stl_deque.h:298:7: note: declared here
  298 |       operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
a.cc:25:79: error: expected ';' before ')' token
   25 | #define loopIterators(it, vec) for(it = (vec).begin(); it != (vec).end(); it++)
      |                                                                               ^
a.cc:97:9: note: in expansion of macro 'loopIterators'
   97 |         loopIterators(itDeque, queue) PN(*itDeque):
      |         ^~~~~~~~~~~~~
a.cc:26:63: error: no match for 'operator!=' (operand types are 'std::deque<char>::iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::iterator'} and 'std::deque<char>::reverse_iterator' {aka 'std::reverse_iterator<std::_Deque_iterator<char, char&, char*> >'})
   26 | #define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
      |                                                               ^~ ~~~~~~~~~~~~
      |                                                                            |
      |                                                                            std::deque<char>::reverse_iterator {aka std::reverse_iterator<std::_Deque_iterator<char, char&, char*> >}
a.cc:98:9: note: in expansion of macro 'loopIteratorsRev'
   98 |         loopIteratorsRev(itDeque, queue) PN(*itDeque);
      |         ^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/iosfwd:42,
                 from /usr/include/c++/14/ios:40,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/postypes.h:197:5: note: candidate: 'template<class _StateT> bool std::operator!=(const fpos<_StateT>&, const fpos<_StateT>&)'
  197 |     operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/postypes.h:197:5: note:   template argument deduction/substitution failed:
a.cc:26:77: note:   'std::deque<char>::iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::iterator'} is not derived from 'const std::fpos<_StateT>'
   26 | #define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
      |                                                                             ^
a.cc:98:9: note: in expansion of macro 'loopIteratorsRev'
   98 |         loopIteratorsRev(itDeque, queue) PN(*itDeque);
      |         ^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44:
/usr/include/c++/14/bits/allocator.h:243:5: note: candidate: 'template<class _T1, class _T2> bool std::operator!=(const allocator<_CharT>&, const allocator<_T2>&)'
  243 |     operator!=(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/include/c++/14/bits/allocator.h:243:5: note:   template argument deduction/substitution failed:
a.cc:26:77: note:   'std::deque<char>::iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::iterator'} is not derived from 'const std::allocator<_CharT>'
   26 | #define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
      |                                                                             ^
a.cc:98:9: note: in expansion of macro 'loopIteratorsRev'
   98 |         loopIteratorsRev(itDeque, queue) PN(*itDeque);
      |         ^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:455:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  455 |     operator!=(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:455:5: note:   template argument deduction/substitution failed:
a.cc:26:77: note:   'std::deque<char>::iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::iterator'} is not derived from 'const std::reverse_iterator<_Iterator>'
   26 | #define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
      |                                                                             ^
a.cc:98:9: note: in expansion of macro 'loopIteratorsRev'
   98 |         loopIteratorsRev(itDeque, queue) PN(*itDeque);
      |         ^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:500:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  500 |     operator!=(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:500:5: note:   template argument deduction/substitution failed:
a.cc:26:77: note:   'std::deque<char>::iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::iterator'} is not derived from 'const std::reverse_iterator<_Iterator>'
   26 | #define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
      |                                                                             ^
a.cc:98:9: note: in expansion of macro 'loopIteratorsRev'
   98 |         loopIteratorsRev(itDeque, queue) PN(*itDeque);
      |         ^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1686:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1686 |     operator!=(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1686:5: note:   template argument deduction/substitution failed:
a.cc:26:77: note:   'std::deque<char>::iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::iterator'} is not derived from 'const std::move_iterator<_IteratorL>'
   26 | #define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
      |                                                                             ^
a.cc:98:9: note: in expansion of macro 'loopIteratorsRev'
   98 |         loopIteratorsRev(itDeque, queue) PN(*itDeque);
      |         ^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1753:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1753 |     operator!=(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1753:5: note:   template argument deduction/substitution failed:
a.cc:26:77: note:   'std::deque<char>::iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::iterator'} is not derived from 'const std::move_iterator<_IteratorL>'
   26 | #define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
      |                                                                             ^
a.cc:98:9: note: in expansion of macro 'loopIteratorsRev'
   98 |         loopIteratorsRev(itDeque, queue) PN(*itDeque);
      |         ^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/stl_pair.h:1052:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1052 |     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1052:5: note:   template argument deduction/substitution failed:
a.cc:26:77: note:   'std::deque<char>::iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::iterator'} is not derived from 'const std::pair<_T1, _T2>'
   26 | #define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
      |                                                                             ^
a.cc:98:9: note: in expansion of macro 'loopIteratorsRev'
   98 |         loopIteratorsRev(itDeque, queue) PN(*itDeque);
      |         ^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54:
/usr/include/c++/14/string_view:651:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator!=(basic_string_view<_CharT, _Traits>, basic_string_view<_CharT, _Traits>)'
  651 |     operator!=(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:651:5: note:   template argument deduction/substitution failed:
a.cc:26:77: note:   'std::_Deque