#include<bits/stdc++.h>
using namespace std;
int main() {
int q,k;
cin>>q;
cin>>k;
priority_queue<int,vector,greater>pq;
vectorv;
while (q>0){
int p,x2,y2,z;
cin>>p;
cin>>x2;
cin>>y2;
if (p==1){
z=pow(x2,2)+pow(y2,2);
pq.push(z);
}
else{
int o,m;
o=k;
while(o>1){
m=pq.top();
v.push_back(m);
pq.pop();
o=o-1;
}
cout<<pq.top();
int h;
while(!v.empty())
{
h=v.back();
v.pop_back();
pq.push(h);
}
}
}
return 0;
}