#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
#define pb push_back
#define sz(a) (int)a.size()
#define zero(a) memset (a, 0, sizeof(a))
#define mp make_pair
#define taskname ""
//.clear()
//.begin()
//
class cartesian_tree
{
public:
int key, y;
int count;
cartesian_tree *l, *r;
cartesian_tree (int _key)
{
count = 1;
key = _key;
y = ((rand()<<15) + rand());
l = NULL;
r = NULL;
}
cartesian_tree (void)
{
count = 1;
key = 0;
y = 0;
l = NULL;
r = NULL;
}
};
cartesian_tree* merge (cartesian_tree *u, cartesian_tree *v)
{
if (u == NULL)
return v;
if (v == NULL)
return u;
if (u->y >= v->y)
{
u->r = merge (u->r, v);
u->count = (u->l != NULL ? u->l->count : 0) + (u->r != NULL ? u->r->count : 0) + 1;
return u;
}
else
{
v->l = merge (u, v->l);
v->count = (v->l != NULL ? v->l->count : 0) + (v->r != NULL ? v->r->count : 0) + 1;
return v;
}
}
cartesian_tree split (cartesian_tree *u, int key)
{
cartesian_tree res, tmp;
res.l = res.r = NULL;
if (u == NULL)
return res;
if (u->key >= key)
{
tmp = split (u->l, key);
u->l = tmp.r;
u->count = (u->l != NULL ? u->l->count : 0) + (u->r != NULL ? u->r->count : 0) + 1;
res.l = tmp.l, res.r = u;
// res.l->sum = tmp.l->sum, res.r->sum = u->sum;
}
else
{
tmp = split (u->r, key);
u->r = tmp.l;
u->count = (u->l != NULL ? u->l->count : 0) + (u->r != NULL ? u->r->count : 0) + 1;
res.r = tmp.r, res.l = u;
// res.r->sum = tmp.r->sum, res.l->sum = u->sum;
}
return res;
}
cartesian_tree* del (cartesian_tree *u, cartesian_tree *p, cartesian_tree *node, int key)
{
if (u == NULL)
return node;
if (u->key == key)
{
cartesian_tree *d;
if (p == NULL)
d = node, node = merge (node->l, node->r);
else
{
if (p->r == u)
d = p->r, p->r = merge(u->l, u->r);
else
d = p->l, p->l = merge(u->l, u->r);
}
free(d);
return node;
}
if (u->key > key)
return del(u->l, u, node, key);
else
return del(u->r, u, node, key);
u->count = (u->l != NULL ? u->l->count : 0) + (u->r != NULL ? u->r->count : 0) + 1;
}
cartesian_tree* add (cartesian_tree *u, cartesian_tree *v)
{
if (u == NULL)
return v;
if (u->y > v->y)
{
if (u->key < v->key)
{
u->r = add(u->r, v);
u->count = (u->l != NULL ? u->l->count : 0ll) + (u->r != NULL ? u->r->count : 0) + 1;
}
else
{
u->l = add(u->l, v);
u->count = (u->l != NULL ? u->l->count : 0ll) + (u->r != NULL ? u->r->count : 0) + 1;
}
return u;
}
else
{
cartesian_tree tmp;
tmp = split (u, v->key);
v->l = tmp.l, v->r = tmp.r;
v->count = (v->l != NULL ? v->l->count : 0) + (v->r != NULL ? v->r->count : 0) + v->key;
return v;
}
return NULL;
}
uint greater_count (cartesian_tree* u, int key)
{
if (u == NULL)
return 0;
uint res = 0;
if (u->key >= key)
{
if (u->r != NULL)
res += u->r->count;
return res + 1 + greater_count(u->l, key);
}
else
return greater_count(u->r, key);
}
void clear (cartesian_tree *u)
{
if (u == NULL)
return;
clear(u->l), clear(u->r);
free(u);
}
class myset
{
public:
cartesian_tree *node;
myset()
{
node = NULL;
}
void insert (int k)
{
cartesian_tree *v = new cartesian_tree(k);
node = add (node, v);
}
void erase (int k)
{
node = del (node, NULL, node, k);
}
uint greater_count (int k)
{
return ::greater_count (node, k);
}
};
int main (void)
{
freopen (taskname".in", "r", stdin);
freopen (taskname".out", "w", stdout);
return 0;
}