import java.util.;
class xy{
int x;
int y;
}
class help implements Comparator{
public int compare(xy o1,xy o2){
int a=o1.x;
int b=o1.y;
int c=o2.x;
int d=o2.y;
if(((aa)+(bb))<((cc)+(dd)))
return -1;
else if((((aa)+(bb))>((cc)+(dd))))
return 1;
return 0;
}
}
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int q=s.nextInt();
int k=s.nextInt();
PriorityQueue pq=new PriorityQueue(new help());
Stack stack=new Stack<>();
while(q–>0){
int query=s.nextInt();
if(query==1){
int x=s.nextInt();
int y=s.nextInt();
xy input=new xy();
input.x=x;
input.y=y;
pq.add(input);
}else{
for(int i=0;i<k-1;i++){
xy temp=pq.poll();
stack.add(temp);
}
if(!pq.isEmpty()){
xy output=pq.poll();
int a=output.x;
int b=output.y;
int ans=(aa)+(b*b);
System.out.println(ans);
}
while(!stack.isEmpty()){
xy elements=stack.pop();
pq.add(elements);
}
}
}
}
}