#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;


// typedef SplayNode SN;
struct SplayNode {
    SplayNode *parent, *right, *left;
    ll size, value;

    SplayNode(){
        parent = nullptr;
        right = nullptr;
        left = nullptr;
        size = 1;
    }

    void rotate(){
        SplayNode *pp, *p, *c;
        p = this->parent;
        pp = p->parent;

        if(pp && pp->left == p)pp->left = this;
        if(pp && pp->right == p) pp->right = this;
        this->parent = pp;

        if(p->left == this) {
            c = this->right;
            this->right = p;
            p->left = c;
        }
        else {
            c = this->left;
            this->left = p;
            p->right = c;
        }
        
        p->parent = this;
        if(c) c->parent = p;

        p->update();
        this->update();
    };

    int state(){
        if(!this->parent)return 0;
        if(this->parent->left == this)return 1;
        if(this->parent->right == this)return 2;
        return 0;
    }
    void splay(){
        while(this->state()){
            if(this->parent->state() == 0){
                this->rotate();
            }
            else if(this->state() == this->parent->state()){
                this->parent->rotate();
                this->rotate();
            }
            else{
                this->rotate();
                this->rotate();
            }
        }
    };
    void update(){
        this->size = 1;
        if(this->left)this->size += this->left->size;
        if(this->right)this->size += this->right->size;
    };
    
    friend SplayNode* get(int ind, SplayNode *root){
        SplayNode *now = root;
        while(true){
            int lsize = now->left ? now->left->size : 0;
            if(ind < lsize){
                now = now->left;
            }
            if(ind == lsize){
                now->splay();
                return now;
            }
            if(ind > lsize){
                now = now->right;
                ind -= lsize + 1;
            }
        }
    };

    // friend pair<SN, SN> split(int ind, SN *&root){};
    // friend SN merge(SN &lroot, SN &rroot){};

};



int main(){
    ll q; cin >> q;
    vector<SplayNode> vec(q+1);
    // debug("test");
    rep(i,q){
        vec[i+1].left = &vec[i];
        vec[i].parent = &vec[i+1];
        vec[i+1].update();
        // debug(i);
    }

    ll vecsize = 0;
    SplayNode *root = &vec[q];
    rep(i,q){
        ll ord; cin >> ord;
        if(ord == 0){
            ll x; cin >> x;
            root = get(vecsize++,root);
            root->value = x;
            // if(root->left)debug(root->left->value);
        }
        if(ord == 1){
            ll p; cin >> p;
            root = get(p, root);
            cout << root->value << "\n";
        }
        if(ord == 2){
            root = get(--vecsize, root);
        }
    }
}


Measured memory_bytes: 10720