Language: C++

#include <iostream>
using namespace std;

#define MAX 10000000001

#define rep(i, x) for(int i=0;i<(x);i++)
char S[MAX];
int Q;
int first, last;
// lastは-1する必要あり
int main() {
    first = 0;
    last = 0;
    cin >> S;
    //cout << S1.size() << endl;
    rep(i, MAX){
        if(S[i] == '\0') {
            break;
        }
        last++;
    }

    cin >> Q;
    
    rep(i, Q) {
        int T, F;
        char C;
        cin >> T;
        // T=1 文字列Sの前後を反転する。
        // T=2 整数Fと英小文字Cが与えられる
        //  F=1 Sの先頭にCiを追加
        //  F=2 Sの末尾にCiを追加
        if(T == 1) {
            char tmp = S[last-1];
            S[last-1] = S[first];
            S[first] = tmp;
        } else if(T == 2) {
            cin >> F >> C;
            if(F == 1) {
                if(first == 0) {
                    first = MAX;
                }
                first--;
                S[first] = C;
            } else if(F == 2) {
                S[last] = C;
                last++;
                if(last == MAX) {
                    last = 0;
                }
            }
        }
    }

    //cout << first << ":" << last << endl;

    if(first > last){
        for(int i =first;i < MAX;i++){
            //cout << i << endl;
            cout << S[i];
        }
        for(int i=0;i < last; i++){
            //cout << i << endl;
            cout << S[i];
        }
    } else {
        for(int i=first;i< last;i++){
            //cout << i << endl;
            cout << S[i];
        }
    }
    cout << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:4:13: warning: overflow in conversion from 'long int' to 'int' changes value from '10000000001' to '1410065409' [-Woverflow]
    4 | #define MAX 10000000001
      |             ^~~~~~~~~~~
a.cc:41:29: note: in expansion of macro 'MAX'
   41 |                     first = MAX;
      |                             ^~~
/tmp/ccDzdMsc.o: in function `main':
a.cc:(.text+0xa): relocation truncated to fit: R_X86_64_PC32 against symbol `first' defined in .bss section in /tmp/ccDzdMsc.o
a.cc:(.text+0x14): relocation truncated to fit: R_X86_64_PC32 against symbol `last' defined in .bss section in /tmp/ccDzdMsc.o
a.cc:(.text+0x52): relocation truncated to fit: R_X86_64_PC32 against symbol `last' defined in .bss section in /tmp/ccDzdMsc.o
a.cc:(.text+0x5b): relocation truncated to fit: R_X86_64_PC32 against symbol `last' defined in .bss section in /tmp/ccDzdMsc.o
a.cc:(.text+0x69): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/ccDzdMsc.o
a.cc:(.text+0xab): relocation truncated to fit: R_X86_64_PC32 against symbol `last' defined in .bss section in /tmp/ccDzdMsc.o
a.cc:(.text+0xc4): relocation truncated to fit: R_X86_64_PC32 against symbol `first' defined in .bss section in /tmp/ccDzdMsc.o
a.cc:(.text+0xca): relocation truncated to fit: R_X86_64_PC32 against symbol `last' defined in .bss section in /tmp/ccDzdMsc.o
a.cc:(.text+0xed): relocation truncated to fit: R_X86_64_PC32 against symbol `first' defined in .bss section in /tmp/ccDzdMsc.o
a.cc:(.text+0x144): relocation truncated to fit: R_X86_64_PC32 against symbol `first' defined in .bss section in /tmp/ccDzdMsc.o
a.cc:(.text+0x14e): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status