#include <cstdio>
#include <cassert>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp> // не стандарт, а gnu-расширение

using namespace std;
using namespace __gnu_pbds;

int main() {
	tree<pair<int, int>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> s;
	// greater<>
	// splay_tree_tag

	int cc = 0;
	s.insert({1, cc++});
	s.insert({2, cc++});
	s.insert({4, cc++});
	s.insert({1, cc++});
	s.insert({1, cc++});
	printf("set = ");
	for (auto [a,i] : s)
		printf("<%d,i=%d> ", a, i);
	puts("");

	printf("ord(4) = %d\n", (int)s.order_of_key({4, INT_MAX}));
	printf("ord(3) = %d\n", (int)s.order_of_key({3, INT_MAX}));
	printf("ord(2) = %d\n", (int)s.order_of_key({2, INT_MAX}));

	auto [a,i] = *s.lower_bound({3, -1});
	printf("lower_bound(3) = %d (i=%d)\n", a, i);
}