import java.util.*;
import java.util.ArrayList;
class Heap1 {
ArrayList<Integer> list = new ArrayList<Integer>();
public void add(int item)
{
list.add(item);
upheapify(size()-1);
}
public void upheapify(int c)
{
int p=(c-1)/2;
if(list.get(p)<list.get(c))
{swap(p,c);
upheapify(p);
}}
public void swap(int c1,int c2)
{
int a=list.get(c1);
int b=list.get(c2);
list.set(c1, b);
list.set(c2, a);
}
public int size()
{
return list.size();
}
public void display()
{
System.out.println(list);
}
public int remove()
{
swap(0,this.list.size()-1);
int rv=list.remove(list.size()-1);
downheapify(0);
return rv;
}
public void downheapify(int p)
{
int lc=2*p+1;
int rc=2*p+2;
int min=p;
if(lc<size() && list.get(lc)>list.get(min))
{
min=lc;
}
if(rc<size() && list.get(rc)>list.get(min))
{
min = rc;
}
if(min!=p)
{
swap(p,min);
downheapify(min);
}
}
public int get(){
return this.list.get(0);
}
}
class Heap3 {
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int q = scan.nextInt();
int k = scan.nextInt();
int flag;
int z=k;
Heap1 h = new Heap1();
while(q-->0)
{
flag=scan.nextInt();
int v=0;
if(flag==1)
{
int x = scan.nextInt();
int y = scan.nextInt();
int dis = (x)*x+(y)*y;
h.add(dis);
v++;
if(v>3)
{
h.remove();
v--;
}
}
if(flag==2)
{
System.out.println(h.remove()+" ");
v--;
}
}
}
}