## Task A-2.5.

Frog Žana is at the origin of the number line, and in each step, she jumps one to the left, one to the right, or stays in place. Lina and Dina have chosen relatively simple numbers $m$ and $n$, where $m > n$. After every $n$ steps, Lina commands: "Left!", and after every $m$ steps, Dina commands: "Right!" Žana remains still until she hears the first command, and then she starts (or continues) jumping in the direction of the command. She stops in the first step where she hears both commands. Determine the distance from the origin where Žana stops, depending on the numbers $m$ and $n$.
## First Solution.

Zhana stops at a distance of $(m-n) n$ from the starting point.

Since $m$ and $n$ are relatively prime, Zhana will hear both commands for the first time after $m n$ steps.

Let's call the period of Zhana's steps between the $i$-th and $(i+1)$-th Lina's command (for some natural number $i$). Since $m > n$, in each period, there will be at most one Dina's command issued.

For some $k$, consider the periods in which Dina issued the $k$-th and $(n-k)$-th command.

By the time Dina issued her $k$-th command, $m k$ steps had passed from the start, while her $(n-k)$-th command was issued $m k$ steps before the end of Zhana's journey. Thus, these two commands were issued symmetrically with respect to Zhana's journey.

Similarly, if Dina's $k$-th command was issued after the $i$-th Lina's command, Dina's $(n-k)$-th command was issued before the $(m-i)$-th Lina's command. We conclude that the steps Zhana took in the periods in which the $k$-th and $(n-k)$-th Dina's commands were issued are symmetric, and thus cancel each other out: in these two periods, Zhana took a total of $n$ steps to the left and $n$ steps to the right.

Therefore, Zhana's distance from the starting point is determined solely by the periods in which there were no Dina's commands.

Before stopping, $(m-1)$ periods will pass in which Dina will issue $(n-1)$ commands (not counting the commands in the $(m n)$-th step). In each period, Dina issued at most one command. We conclude that in $n-1$ periods, she issued one command, and in $m-n$ periods, she issued no commands.

In each of these $m-n$ periods without Dina's command, Zhana took $n$ steps to the left, so her final distance from the starting point is $(m-n) n$.