n,b=gets.split.map &:to_i a=(0...n).map{gets.split.map &:to_i} x=a.map{|c|c[0]}.sort.uniq a.map{|c|c[0]=x.index(c[0])} p a z=0 n.times{|i|n.times{|j| f=[0]*n g=[0]*n n.times{|k|a[i][1]<=a[k][1]&&a[k][1]<=a[j][1]&&(f[a[k][0]]+=1;g[a[k][0]]+=a[k][2])} s=t=0 l=0 n.times{|k| s+=f[k] t+=g[k] while t>b do s-=f[l];t-=g[l];l+=1 end z