Question 144
Let $p \neq q$ be coprime positive integers. Determine all infinite sequences $a_{1}, a_{2}, \ldots$ of positive integers such that the following conditions hold for all $n \geqslant 1$:
$$
\begin{aligned}
& \max \left(a_{n}, a_{n+1}, \ldots, a_{n+p}\right)-\min \left(a_{n}, a_{n+1}, \ldots, a_{n+p}\right)=p \quad \text{ and } \\
& \max \left(a_{n}, a_{n+1}, \ldots, a_{n+q}\right)-\min \left(a_{n}, a_{n+1}, \ldots, a_{n+q}\right)=q .
\end{aligned}
$$
$$
\begin{aligned}
& \max \left(a_{n}, a_{n+1}, \ldots, a_{n+p}\right)-\min \left(a_{n}, a_{n+1}, \ldots, a_{n+p}\right)=p \quad \text{ and } \\
& \max \left(a_{n}, a_{n+1}, \ldots, a_{n+q}\right)-\min \left(a_{n}, a_{n+1}, \ldots, a_{n+q}\right)=q .
\end{aligned}
$$