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

#FT0000218. Đếm quan hệ thứ tự ba chiều (3D Partial Order)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm quan hệ thứ tự ba chiều (3D Partial Order)

3D Partial Order

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn elements; element ii has three positive integer attributes (ai,bi,ci)(a_i,b_i,c_i). Elements are distinguished by their indices, even when all three attributes are equal.

For each index ii, let f(i)f(i) be the number of other elements j≠ij\ne i satisfying all three inequalities:

aj≤ai,bj≤bi,cj≤ci.a_j\le a_i,\qquad b_j\le b_i,\qquad c_j\le c_i.

For every integer dd from 00 to n−1n-1, count how many indices ii satisfy f(i)=df(i)=d.

Input

  • The first line contains two integers n,kn,k: the number of elements and the maximum allowed coordinate.
  • Each of the following nn lines contains three integers ai,bi,cia_i,b_i,c_i describing element ii.

Output

Print nn lines. Line d+1d+1, for 0≤d<n0\le d<n, contains the number of indices ii satisfying f(i)=df(i)=d.

Subtasks

  • Subtask 1 (20 points): 1≤n≤101\le n\le10; 1≤ai,bi,ci≤k≤201\le a_i,b_i,c_i\le k\le20 for all ii.

  • Subtask 2 (30 points): 1≤n≤20001\le n\le2000; 1≤ai,bi,ci≤k≤1041\le a_i,b_i,c_i\le k\le10^4 for all ii.

  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤ai,bi,ci≤k≤2⋅1051\le a_i,b_i,c_i\le k\le2\cdot10^5 for all ii.

Examples

Input

5 4
1 1 1
2 2 2
1 2 2
2 2 2
3 1 1

Output

1
2
0
2
0

Explanation

Element 1=(1,1,1)1=(1,1,1) dominates no other indexed element, so f(1)=0f(1)=0. Elements 3=(1,2,2)3=(1,2,2) and 5=(3,1,1)5=(3,1,1) each dominate only element 11, so both have f=1f=1. Elements 22 and 44 share coordinates (2,2,2)(2,2,2); each dominates element 11, element 33, and the other identical-coordinate element, giving f=3f=3. Thus the histogram for d=0,1,2,3,4d=0,1,2,3,4 is 1,2,0,2,01,2,0,2,0.