N * (y - 1) + x - 1; Can you explain how this works for 0,0 and a 5by5 grid. Won't it be something like -6.