Problem:
Priority Queue

Priority queue is a container of elements which the element with the highest priority should be extracted first.

For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations.

insert($t$, $x$): Insert $x$ to $Q_t$.

getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing.

deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing.

In the initial state, all queues are empty.

Input

The input is given in the following format.

$n \; q$
$query_1$
$query_2$
:
$query_q$

Each query $query_i$ is given by

0 $t$ $x$

or

1 $t$

or

2 $t$

where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively.

Output

For each getMax operation, print an integer in a line.

Constraints

$1 \leq n \leq 1,000$

$1 \leq q \leq 200,000$

$-1,000,000,000 \leq x \leq 1,000,000,000$

Sample Input 1

2 10
0 0 3
0 0 9
0 0 1
1 0
2 0
1 0
0 0 4
1 0
0 1 8
1 1

Sample Output 1

9
3
4
8

Solution in C++14 (judge verdict: Accepted)

//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑

int main() {
	ll a, b;
	cin >> a >> b;
	vector<priority_queue<ll>>pq(a);

	for (int i = 0; i < b; ++i) {
		ll x, y, z;
		cin >> x >> y;
		if (x == 0) {
			cin >> z;
			pq[y].emplace(z);
		}
		else if (x == 1 && pq[y].size() != 0) {
			cout << pq[y].top() << endl;
		}
		else if (x == 2 && pq[y].size() != 0) {
			pq[y].pop();
		}
	}
}