{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv\u003e\u003cp\u003eBessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find her way to a safe location (one that is never destroyed by a meteor) . She is currently grazing at the origin in the coordinate plane and wants to move to a new, safer location while avoiding being destroyed by meteors along her way.\u003c/p\u003e\u003cp\u003eThe reports say that \u003ci\u003eM\u003c/i\u003e meteors (1 ≤ \u003ci\u003eM\u003c/i\u003e ≤ 50,000) will strike, with meteor \u003ci\u003ei\u003c/i\u003e will striking point (\u003ci\u003eX\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e, \u003ci\u003eY\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e) (0 ≤ \u003ci\u003eX\u003csub\u003ei \u003c/sub\u003e\u003c/i\u003e≤ 300; 0 ≤ \u003ci\u003eY\u003csub\u003ei \u003c/sub\u003e\u003c/i\u003e≤ 300) at time \u003ci\u003eT\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e (0 ≤ \u003ci\u003eT\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e\u0026nbsp; ≤ 1,000). Each meteor destroys the point that it strikes and also the four rectilinearly adjacent lattice points.\u003c/p\u003e\u003cp\u003eBessie leaves the origin at time 0 and can travel in the first quadrant and parallel to the axes at the rate of one distance unit per second to any of the (often 4) adjacent rectilinear points that are not yet destroyed by a meteor. She cannot be located on a point at any time greater than or equal to the time it is destroyed).\u003c/p\u003e\u003cp\u003eDetermine the minimum time it takes Bessie to get to a safe place.\u003c/p\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e* Line 1: A single integer: \u003ci\u003eM\u003c/i\u003e\u003cbr\u003e* Lines 2..\u003ci\u003eM\u003c/i\u003e+1: Line \u003ci\u003ei\u003c/i\u003e+1 contains three space-separated integers: \u003ci\u003eX\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e, \u003ci\u003eY\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e, and \u003ci\u003eT\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e \u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e* Line 1: The minimum time it takes Bessie to get to a safe place or -1 if it is impossible.\u003c/p\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4\r\n0 0 2\r\n2 1 2\r\n1 1 2\r\n0 3 5\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}