#include <cstdio>
#include<cstring>
#include <algorithm>
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const int MAXN = 8010;
int n, col[MAXN << 2], vis[MAXN << 2], ans[MAXN << 2];
void PushDown(int rt, int m) {
if (col[rt]!=-1) {
col[rt << 1] = col[rt << 1 | 1] = col[rt];
col[rt] = -1;
}
}
//[L,R]
void update(int L, int R, int c, int l, int r, int rt) {
if (L <= l && r <= R) {
col[rt] = c;
return;
}
if (col[rt] == c)return;
PushDown(rt, r - l + 1);
int m = (l + r) >> 1;
if (L <= m) update(L, R, c, lson);
if (R > m) update(L, R, c, rson);
}
void query(int l, int r, int rt) {
if (col[rt] != -1) {
for (int i = l; i <= r; i++)
vis[i] = col[rt];//每个叶子节点的颜色
return;
}
if (l == r) return;
int m = (l + r) >> 1;
query(lson);
query(rson);
}
int main()
{
int x1, x2, c;
while (scanf("%d", &n) != EOF)
{
memset(col, -1, sizeof(col));
memset(vis, -1, sizeof(vis));
memset(ans, 0, sizeof(ans));
for (int i = 0; i < n; i++)
{
scanf("%d%d%d", &x1, &x2, &c);
update(x1+1 , x2 , c, 1, 8001, 1);//[x1+1,x2+1-1]
}
query(1, 8001, 1);
int i = 1;
while (i < MAXN) {
int color,j;
color = vis[i];
j = i + 1;
if (color == -1) { i++; continue; }//没颜色
while (vis[j] != -1 && vis[j] == color && j < MAXN) j++;//连续颜色相同
ans[color]++;
i = j;
}
for (int i = 0; i < MAXN;i++)if (ans[i])
printf("%d %d\n", i, ans[i]);
puts("");
}
return 0;
}