Task 4. In a sequence of numbers $a_{1}, a_{2}, \ldots, a_{1000}$ consisting of 1000 different numbers, a pair $\left(a_{i}, a_{j}\right)$ with $i < j$ is called increasing if $a_{i} < a_{j}$ and decreasing if $a_{i} > a_{j}$. Determine the largest positive integer $k$ with the property that in any sequence of 1000 different numbers, there are at least $k$ non-overlapping increasing pairs or at least $k$ non-overlapping decreasing pairs.
Solution. We will prove that the largest $k$ is equal to 333. First, consider the sequence $1000, 999, 998, \ldots, 669, 668, 1, 2, 3, \ldots, 666, 667$. The first 333 numbers in the sequence are not usable in an increasing pair, because for each of these numbers, only larger numbers are to the left and only smaller numbers are to the right. Therefore, only the last 667 numbers are available for increasing pairs, and this yields at most 333 non-overlapping increasing pairs. For a decreasing pair $\left(a_{i}, a_{j}\right)$ with $i < j$, the same logic applies, and thus $k > 333$ cannot be satisfied.

Now we prove that for all $t \geq 1$, in a sequence of $3t-1$ different numbers, there are always at least $t$ non-overlapping increasing pairs or $t$ non-overlapping decreasing pairs. We prove this by induction on $t$. For $t=1$, the sequence has length 2, and this pair of numbers is either increasing or decreasing, so it holds. Now let $r \geq 1$ and assume the statement is true for $t=r$. We now consider $t=r+1$ and take an arbitrary sequence $a_{1}, a_{2}, \ldots, a_{3r+2}$ with $3r+2$ different numbers. If the sequence is completely increasing, then we can divide the sequence into adjacent pairs, all of which are increasing. There are $\left\lfloor\frac{3r+2}{2}\right\rfloor \geq \frac{2r+2}{2}=r+1$ such pairs. If the sequence is completely decreasing, there are analogously at least $r+1$ decreasing pairs. If the sequence is neither completely increasing nor completely decreasing, then there is a point in the sequence where it first increases and then decreases, or vice versa, i.e., there are numbers $a_{i}, a_{i+1}, a_{i+2}$ in the sequence with $a_{i} < a_{i+1} > a_{i+2}$ or $a_{i} > a_{i+1} < a_{i+2}$. In both cases, among these three numbers, there is both an increasing pair and a decreasing pair. Now apply the induction hypothesis to the sequence $a_{1}, a_{2}, \ldots, a_{i-1}, a_{i+3}, a_{i+4}, \ldots, a_{3r+2}$. This is a sequence with $3r+2-3=3r-1$ different numbers, so there are $r$ non-overlapping increasing pairs or $r$ non-overlapping decreasing pairs. In the first case, we add the increasing pair from $a_{i}, a_{i+1}, a_{i+2}$ to these, and in the second case, we add the decreasing pair. Thus, we have found $r+1$ non-overlapping increasing pairs or $r+1$ non-overlapping decreasing pairs. This completes the induction.

Now substitute $t=333$ into this result: in a sequence of 998 different numbers, there are always at least 333 non-overlapping increasing pairs or at least 333 non-overlapping decreasing pairs. This also holds for a sequence of 1000 numbers (ignore the last two numbers in the sequence). Therefore, $k=333$ satisfies the condition and is thus the largest $k$ that satisfies it.