($n,$k)=glob<>; for(<>){ ($s,$p,$u)=glob<>; push@{$a[$s]{$u}//=[]},$p*1e5+$i; ++$i; } for(reverse@a){ for$u(keys%$_){ @{$_->{$u}}=sort{$a-$b}@{$_->{$u}}; } while(1){ for$u(keys%$_){ push@b,shift@{$_->{$u}} if @{$_->{$u}}; } last if !@b; @b=sort{$a-$b}@b; while(@b){ print pop(@b)%1e5,$/; exit if !--$k; } } }