#include "bits/stdc++.h"

using namespace std;

using i64 = long long;


// merge/split ベースの赤黒木(葉木)
struct RedBlackTree{
    struct Node{
        /*
        uint64_t x;
        short cnt;
        int siz, cnt_sum;
        bool red;
        Node* c[2];
        Node(Node* nil = nullptr) : x(0), cnt(0), siz(0), cnt_sum(0), red(false){
            c[0] = nil;
            c[1] = nil;
        }
         */
        int sum, siz, rank;
        bool red;
        Node* l;
        Node* r;
        Node(int val, bool red, bool leaf, Node* l = nullptr, Node* r = nullptr) : sum(val), siz(leaf), rank(0), red(red), l(l), r(r){}
    };

    Node* nil;
    RedBlackTree(){
        nil = new Node(0, false, false);
        nil->l = nil;
        nil->r = nil;
    }

    void update(Node* p){
        if(p == nil)
            return;
        p->siz = p->l->siz + p->r->siz;
        p->sum = p->l->sum + p->r->sum;
        p->rank = p->l->rank + !p->l->red;
        assert(p->rank == p->r->rank + !p->r->red);
        // p->cnt_sum = p->c[0]->cnt_sum + p->c[1]->cnt_sum + p->cnt;
    }

    Node* make(int val){
        Node* node = new Node(val, false, true, nil, nil);
        node->rank = 1;
        return node;
    }

    Node* mergeSub(Node* a, Node* b){
        if(a->rank < b->rank){
            Node* c = mergeSub(a, b->l);
            if(!b->red && c->red && c->l->red){
                if(!b->r->red){
                    b->l = c->l;
                    c->l = c->r;
                    c->r = b->r;
                    b->r = c;
                    update(c);
                    update(b);
                    return b;
                }
                else{
                    b->l = c;
                    b->red ^= 1;
                    b->l->red ^= 1;
                    b->r->red ^= 1;
                    update(b);
                    return b;
                }
            }
            b->l = c;
            update(b);
            return b;
        }
        else if(a->rank > b->rank){
            Node* c = mergeSub(a->r, b);
            if(!a->red && c->red && c->r->red){
                if(!a->l->red){
                    a->r = c->r;
                    c->r = c->l;
                    c->l = a->l;
                    a->l = c;
                    update(c);
                    update(a);
                    return a;
                }
                else{
                    a->r = c;
                    a->red ^= 1;
                    a->l->red ^= 1;
                    a->r->red ^= 1;
                    update(a);
                    return a;
                }
            }
            a->r = c;
            update(a);
            return a;
        }
        else{
            assert(!(a->red || b->red));
            Node* node = new Node(0, true, false, a, b);
            update(node);
            return node;
        }
    }

    Node* merge(Node* a, Node* b){
        if(a == nil)
            return b;
        if(b == nil)
            return a;
        Node* c = mergeSub(a, b);
        c->red = false;
        return c;
    }

    Node* access(Node* p, int k){
        int t = 0;
        while(p->l != nil || p->r != nil){
            ++t;
            assert(p->l != nil && p->r != nil);
            if(p->l->siz <= k){
                k -= p->l->siz;
                p = p->r;
            }
            else{
                p = p->l;
            }
        }
        return p;
    }

};


signed main(){
    int q;
    cin >> q;
    RedBlackTree rb;
    auto root = rb.nil;
    for(int i = 0; i < q; ++i){
        root = rb.merge(root, rb.make(0));
    }
    int cnt = 0;
    for(int i = 0; i < q; ++i){
        int type;
        cin >> type;
        if(type == 0){
            int x;
            cin >> x;
            auto ptr = rb.access(root, cnt);
            ptr->sum = x;
            ++cnt;
        }
        else if(type == 1){
            int idx;
            cin >> idx;
            auto ptr = rb.access(root, idx);
            cout << ptr->sum << endl;
        }
        else{
            --cnt;
        }
    }
}




Measured memory_bytes: 21860