static int ptToIndex(Pt p, int w) { ret p.y*w+p.x; }