import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(reader.readLine());
int N=Integer.parseInt(st.nextToken());//N个函数
int M=Integer.parseInt(st.nextToken());//结果要求输出M个数字
int a[]=new int[N];
int b[]=new int[N];
int c[]=new int[N];
for (int i = 0; i <N ; i++) {
st=new StringTokenizer(reader.readLine());
a[i]=Integer.parseInt(st.nextToken());
b[i]=Integer.parseInt(st.nextToken());
c[i]=Integer.parseInt(st.nextToken());
}
PriorityQueue<Node2085> pq=new PriorityQueue();//小顶堆
List<Node2085> list=new ArrayList<>();
for (int j = 0; j <N ; j++) {//N个函数,把第一列先加入进来
int x=1;
Integer v=a[j]*x*x +b[j]*x +c[j];
Node2085 node=new Node2085(j,x,v);
pq.add(node);
}
int len=M-1;
while(len>=0){
Node2085 node=pq.poll();
int n=node.n;//函数的号码
int index=node.index+1;//x的数值
int v=a[n]*index*index+b[n]*index+c[n];
list.add(node);
pq.add(new Node2085(n,index,v));
len--;
}
StringBuilder sb=new StringBuilder();
for (Node2085 node:list
) {
sb.append(" "+node.v);
}
System.out.println(sb.toString().trim());
reader.close();
}
}
class Node2085 implements Comparable<Node2085>{
public Node2085(int n,int index,int v) {
this.n=n;
this.index=index;
this.v = v;
}
int v;
int n;
int index;
@Override
public int compareTo(Node2085 node) {
return this.v-node.v;
}
}