Official algorithmic problem description and constraints.
Let's imagine the surface of Mars as an infinite coordinate plane. Initially, the rover Perseverance-2 and the helicopter Ingenuity-2 are located at the point with coordinates (0,0). A set of instructions π consisting of π instructions of the following types was specially developed for them:
Each instruction must be executed either by the rover or by the helicopter. Moreover, each device must execute at least one instruction. Your task is to distribute the instructions in such a way that after executing all π instructions, the helicopter and the rover end up at the same point, or determine that this is impossible.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.