/**
* Author: Sergey Kopeliovich (Burunduk30@gmail.com)
* Date: 2014.08.05
* OK, 3.633 sec, 5 mb
* O(n*sqrtn*logn)
*/
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
const int maxN = 1e5;
const int maxn = 2 * maxN;
const int K = 500;
const int M = 2200;
int pn, n, mem[2][maxn], *a = mem[0], *b = mem[1];
struct Part {
int i, n, *b;
Part() { b = new int[K]; }
void init( int _i, int _n ) { i = _i, n = _n, calc(); }
void calc() {
memcpy(b, a + i, sizeof(a[0]) * n);
sort(b, b + n);
}
int get( int r ) {
return upper_bound(b, b + n, r) - b;
}
} p[M];
void init() {
pn = 0;
for (int i = 0; i < n; i += K)
p[pn++].init(i, min(K, n - i));
}
void build() {
n = 0;
forn(i, pn)
memcpy(b + n, a + p[i].i, p[i].n * sizeof(a[0])), n += p[i].n;
swap(a, b);
init();
}
void shift_r( int j ) {
int *b = p[pn].b;
memmove(p + j + 1, p + j, sizeof(p[0]) * (pn++ - j));
p[j].b = b;
}
void shift_l( int j ) {
int *b = p[j].b;
memmove(p + j, p + j + 1, sizeof(p[0]) * (--pn - j));
p[pn].b = b;
}
int split( int i ) {
int j = 0;
while (j < pn && i >= p[j].n)
i -= p[j++].n;
if (i) {
shift_r(j);
p[j + 1].init(p[j].i + i, p[j].n - i);
p[j].init(p[j].i, i);
j++;
}
return j;
}
void Add( int i, int x ) {
shift_r(i = split(i));
a[n] = x, p[i].init(n++, 1);
}
void Del( int i ) {
split(i + 1);
shift_l(split(i));
}
int Get( int L, int R, int x ) {
int res = 0;
for (L = split(L), R = split(R + 1); L < R; L++)
res += p[L].get(x);
return res;
}
void Start( int _n, int *_a ) {
n = _n, memcpy(a, _a, sizeof(a[0]) * n);
init();
}
int main() {
static int n, a[maxn];
double start = clock();
int i;
assert(freopen("kthstat.in", "r", stdin));
assert(freopen("kthstat.out", "w", stdout));
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
Start(n, a);
char type;
int x, y, z, tn = 0;
while (scanf(" %c", &type) == 1) {
if (type == '+')
scanf("%d%d", &x, &y), Add(x, y);
else if (type == '-')
scanf("%d", &x), Del(x);
else if (type == '?')
scanf("%d%d%d", &x, &y, &z), printf("%d\n", Get(x, y, z));
else {
fprintf(stderr, "Unknown option: %c\n", type);
exit(3128);
}
if (pn >= M - 2)
build();
tn++;
}
fprintf(stderr, "OK, %d tests, time = %.2f\n", tn, (clock() - start) / CLOCKS_PER_SEC);
}