Your spaceship starts at the origin (0,0) of a two-dimensional plane. The galaxy holds N stars, and star i is at (Xi,Yi).
Each minute you do exactly one of two things: pick a star and rotate the ship 90 degrees clockwise around that star, or stay where you are. You may pick the same star again later. Rotating a point (p,q) by 90 degrees clockwise around (a,b) moves it to (a+q−b, b−p+a).
You have M minutes, and you want to finish as far from the origin as possible. A rotation sends integer coordinates to integer coordinates, so the squared distance between the origin and the final position is always an integer. Report that integer.

The picture shows the first three rotations of one possible path. The yellow dots are stars and the purple dots are positions of the ship. This path is not necessarily part of an optimal solution.