Language: C++

class user_input{
private:
    static constexpr unsigned int sizeOfAscii = 128;
    bool isBlankChar[sizeOfAscii];
    // 符号なし整数を getchar で読み込んで構成する (もし, 符号付きだとバグる)
    template <typename Tp>
    inline void charToUnsignedInteger(Tp& val) const {
        val = 0; int c; while(true){
            c = getchar_unlocked();
            if(c == EOF) return;
            if(not isBlankChar[c]) break;
        }
        if(c < '0' or c > '9') return;
        do{
            val = 10 * val + c - '0';
            c = getchar_unlocked();
        } while(not (c == EOF or isBlankChar[c]));
    }
public:
    constexpr user_input(void) : isBlankChar(){
        for(unsigned int i = 0; i < sizeOfAscii; ++i) isBlankChar[i] = false;
        isBlankChar[int('\n')] = true; isBlankChar[int('\t')] = true; 
        isBlankChar[int(' ')]  = true; isBlankChar[int('\v')] = true;
    }
    inline const user_input& operator >> (unsigned int& uint_arg) const {
        charToUnsignedInteger<unsigned int>(uint_arg); return *this;
    }
    inline const user_input& operator >> (char& char_arg) const {
        do{
            if((char_arg = getchar_unlocked()) == EOF) return *this;
        } while(isBlankChar[int(char_arg)]);
        return *this;
    }
    inline const user_input& operator >> (std::string& str_arg) const {
        str_arg.erase();
        int c; while(true){ 
            c = getchar_unlocked();
            if(c == EOF) return *this;
            if(not isBlankChar[c]) break;
        }
        constexpr unsigned int buffer_size = 128; 
        char buffer_input[buffer_size]; unsigned int buffer_length = 0;
        do{
            buffer_input[buffer_length++] = c;
            if(buffer_length == buffer_size){
                buffer_length = 0; str_arg.append(buffer_input, buffer_size);
            }
            c = getchar_unlocked();
        } while(c != EOF and (not isBlankChar[c]) );
        str_arg.append(buffer_input, buffer_length);
        return *this;
    }
}; constexpr user_input cin;

template <typename element_t, const unsigned int N>
class dequeic{
    static_assert(N);
    
    element_t data[2 * N];
    const element_t* left_end = data;
    const element_t* right_end = data + 2 * N;
    element_t *begin_ptr = data + N;
    element_t *end_ptr   = data + N;
public:
    dequeic(void){}
    inline void push_front(const element_t& val){
        assert(left_end != begin_ptr); *(--begin_ptr) = val;
    }
    inline void push_back(const element_t& val){ 
        assert(right_end != end_ptr); *(end_ptr++) = val; 
    }
    inline void pop_front(void){ assert(begin_ptr != end_ptr); begin_ptr++; }
    inline void pop_back(void){ assert(begin_ptr != end_ptr); --end_ptr; }
    
    inline element_t& operator [](int index){
        return *(begin_ptr + index);
    }
    inline element_t& at(int index){
        assert(0 <= index and index < size());
        return *(begin_ptr + index);
    }
    
    inline bool empty(void){ return begin_ptr == end_ptr; }
    unsigned int size(void) const{
        return end_ptr - begin_ptr;
    }
    element_t* const begin(void) const {return begin_ptr;}
    element_t* const end(void) const {return end_ptr;}
};

const unsigned int N = 3e5 + 1;

int main(void){
    std::string s; cin >> s;
    const unsigned int n = s.size();
    dequeic<char, N> dq; for(int i = 0; i < n; ++i) dq.push_back(s[i]);
    bool flag = true;
    unsigned int q; cin >> q;
    while(q--){
        char c; cin >> c;
        if(c == '1') flag = not flag;
        else{
            char k, t; cin >> k >> t;
            if(flag){
                if(k == '1') dq.push_front(t);
                else dq.push_back(t);
            }
            else{
                if(k == '1') dq.push_back(t);
                else dq.push_front(t);
            }
        }
    }
    if(not flag) std::reverse(dq.begin(), dq.end());
    for(auto itr = dq.begin(); itr != dq.end(); ++itr) putchar_unlocked(*itr); putchar_unlocked('\n');
    return 0;
}

Compiler output:
a.cc:34:43: error: 'std::string' has not been declared
   34 |     inline const user_input& operator >> (std::string& str_arg) const {
      |                                           ^~~
a.cc: In member function 'void user_input::charToUnsignedInteger(Tp&) const':
a.cc:9:17: error: there are no arguments to 'getchar_unlocked' that depend on a template parameter, so a declaration of 'getchar_unlocked' must be available [-fpermissive]
    9 |             c = getchar_unlocked();
      |                 ^~~~~~~~~~~~~~~~
a.cc:9:17: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:10:21: error: 'EOF' was not declared in this scope
   10 |             if(c == EOF) return;
      |                     ^~~
a.cc:1:1: note: 'EOF' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | class user_input{
a.cc:16:17: error: there are no arguments to 'getchar_unlocked' that depend on a template parameter, so a declaration of 'getchar_unlocked' must be available [-fpermissive]
   16 |             c = getchar_unlocked();
      |                 ^~~~~~~~~~~~~~~~
a.cc:17:27: error: 'EOF' was not declared in this scope
   17 |         } while(not (c == EOF or isBlankChar[c]));
      |                           ^~~
a.cc:17:27: note: 'EOF' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc: In member function 'const user_input& user_input::operator>>(char&) const':
a.cc:30:28: error: 'getchar_unlocked' was not declared in this scope
   30 |             if((char_arg = getchar_unlocked()) == EOF) return *this;
      |                            ^~~~~~~~~~~~~~~~
a.cc:30:51: error: 'EOF' was not declared in this scope
   30 |             if((char_arg = getchar_unlocked()) == EOF) return *this;
      |                                                   ^~~
a.cc:30:51: note: 'EOF' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc: In member function 'const user_input& user_input::operator>>(int&) const':
a.cc:35:17: error: request for member 'erase' in 'str_arg', which is of non-class type 'int'
   35 |         str_arg.erase();
      |                 ^~~~~
a.cc:37:17: error: 'getchar_unlocked' was not declared in this scope
   37 |             c = getchar_unlocked();
      |                 ^~~~~~~~~~~~~~~~
a.cc:38:21: error: 'EOF' was not declared in this scope
   38 |             if(c == EOF) return *this;
      |                     ^~~
a.cc:38:21: note: 'EOF' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc:46:44: error: request for member 'append' in 'str_arg', which is of non-class type 'int'
   46 |                 buffer_length = 0; str_arg.append(buffer_input, buffer_size);
      |                                            ^~~~~~
a.cc:48:17: error: 'getchar_unlocked' was not declared in this scope
   48 |             c = getchar_unlocked();
      |                 ^~~~~~~~~~~~~~~~
a.cc:49:22: error: 'EOF' was not declared in this scope
   49 |         } while(c != EOF and (not isBlankChar[c]) );
      |                      ^~~
a.cc:49:22: note: 'EOF' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc:50:17: error: request for member 'append' in 'str_arg', which is of non-class type 'int'
   50 |         str_arg.append(buffer_input, buffer_length);
      |                 ^~~~~~
a.cc: In function 'int main()':
a.cc:94:10: error: 'string' is not a member of 'std'
   94 |     std::string s; cin >> s;
      |          ^~~~~~
a.cc:1:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
  +++ |+#include <string>
    1 | class user_input{
a.cc:94:27: error: 's' was not declared in this scope
   94 |     std::string s; cin >> s;
      |                           ^
a.cc:114:23: error: 'reverse' is not a member of 'std'
  114 |     if(not flag) std::reverse(dq.begin(), dq.end());
      |                       ^~~~~~~
a.cc:115:56: error: 'putchar_unlocked' was not declared in this scope
  115 |     for(auto itr = dq.begin(); itr != dq.end(); ++itr) putchar_unlocked(*itr); putchar_unlocked('\n');
      |                                                        ^~~~~~~~~~~~~~~~
a.cc:115:80: error: 'putchar_unlocked' was not declared in this scope
  115 |     for(auto itr = dq.begin(); itr != dq.end(); ++itr) putchar_unlocked(*itr); putchar_unlocked('\n');
      |                                                                                ^~~~~~~~~~~~~~~~
a.cc: In instantiation of 'void user_input::charToUnsignedInteger(Tp&) const [with Tp = unsigned int]':
a.cc:26:44:   required from here
   26 |         charToUnsignedInteger<unsigned int>(uint_arg); return *this;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
a.cc:9:33: error: 'getchar_unlocked' was not declared in this scope
    9 |             c = getchar_unlocked();
      |                 ~~~~~~~~~~~~~~~~^~
a.cc:16:33: error: 'getchar_unlocked' was not declared in this scope
   16 |             c = getchar_unlocked();
      |                 ~~~~~~~~~~~~~~~~^~
a.cc: In instantiation of 'void dequeic<element_t, N>::push_front(const element_t&) [with element_t = char; unsigned int N = 300001]':
a.cc:105:43:   required from here
  105 |                 if(k == '1') dq.push_front(t);
      |                              ~~~~~~~~~~~~~^~~
a.cc:67:15: error: 'assert' was not declared in this scope
   67 |         assert(left_end != begin_ptr); *(--begin_ptr) = val;
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:1:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
  +++ |+#include <cassert>
    1 | class user_input{
a.cc: In instantiation of 'void dequeic<element_t, N>::push_back(const element_t&) [with element_t = char; unsigned int N = 300001]':
a.cc:106:34:   required from here
  106 |                 else dq.push_back(t);
      |                      ~~~~~~~~~~~~^~~
a.cc:70:15: error: 'assert' was not declared in this scope
   70 |         assert(right_end != end_ptr); *(end_ptr++) = val;
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:70:15: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'