链接
#include<bits/stdc++.h>
using namespace std;
short m,x,y,t;
struct Pp{
int x,y,t;
Pp(){};
Pp(int xx,int yy,int tt){x = xx;y = yy;t = tt;};
};
short mp[310][310];
int dx[5] = {0,1,0,-1,0},dy[5] = {0,0,1,0,-1};
queue<Pp> q;
signed main() {
cin>>m;
q.push(Pp(0,0,0));
for(int i = 0; i <= 310; i++)
for(int j = 0; j <= 310; j++)
mp[i][j] = -1;
for(int i = 1; i <= m; i++) {
cin>>x>>y>>t;
for(int j = 0; j <= 4; j++)
if(x + dx[j] >= 0 and y + dy[j] >= 0)
mp[x + dx[j]][y + dy[j]] = mp[x + dx[j]][y + dy[j]] == -1?t:min(t,mp[x + dx[j]][y + dy[j]]);
}cout<<1<<q.size()<<'\n';
while(!q.empty()) {
Pp point = q.front();
q.pop();
x = point.x,y = point.y,t = point.t + 1;
for(int i = 1; i <= 4; i++) {
if(x + dx[i] >= 0 and y + dy[i] >= 0)
if(mp[x + dx[i]][y + dy[i]] == -1) {
cout<<t;
return 0;
} else if(mp[x + dx[i]][y + dy[i]] > t)
q.push(Pp(x + dx[i],y + dy[i],t));
}
}
cout<<-1;
}