PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000077. Đường chân trời của thành phố (The Skyline Problem)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đường chân trời của thành phố (The Skyline Problem)

The Skyline Problem

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Each building is a rectangle with left boundary LiL_i, right boundary RiR_i, and height HiH_i, standing on the ground. Output the skyline as key points [x,h][x,h] from left to right, including the final point of height 00. Never output adjacent horizontal pieces at the same height.

Input

The first line contains nn, followed by nn lines Li,Ri,HiL_i,R_i,H_i sorted by nondecreasing LiL_i. This is the stdin/stdout adaptation.

Output

Print the number of key points kk, then kk lines of x,hx,h in increasing x order.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 0≤Li<Ri≤231−10\le L_i<R_i\le2^{31}-1; 1≤Hi≤231−11\le H_i\le2^{31}-1; buildings are sorted by nondecreasing LiL_i.
  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; 0≤Li<Ri≤231−10\le L_i<R_i\le2^{31}-1; 1≤Hi≤231−11\le H_i\le2^{31}-1; buildings are sorted by nondecreasing LiL_i.
  • Subtask 3 (50 points): 1≤n≤100001\le n\le 10000; 0≤Li<Ri≤231−10\le L_i<R_i\le2^{31}-1; 1≤Hi≤231−11\le H_i\le2^{31}-1; buildings are sorted by nondecreasing LiL_i.

Examples

Input

2
0 2 3
2 5 3

Output

2
0 3
5 0

Explanation

Both buildings have height 33 and meet at x-coordinate 22, so there is no height change there. The only key points are (0,3)(0,3) and (5,0)(5,0).