The first two elements of the sequence $x_{n}$ are $x_{1}=1001, x_{2}=1003$ and if $n \geq 1$, then $x_{n+2}=\frac{x_{n+1}-2004}{x_{n}}$. What is the sum of the first 2004 elements of the sequence?
Solution. Let's use the fact that $x_{1}+x_{2}=2004$, so the recursion can be written in the following form:

$$
x_{n+2}=\frac{x_{n+1}-x_{1}-x_{2}}{x_{n}}
$$

Let's write out the first few terms of the sequence:

$1001 ; \quad 1003 ; \quad x_{3}=\frac{x_{2}-x_{1}-x_{2}}{x_{1}}=-1 ; \quad x_{4}=\frac{x_{3}-x_{1}-x_{2}}{x_{2}}=\frac{-1-x_{1}-x_{2}}{x_{2}} ;$

$$
\begin{aligned}
& x_{5}=\frac{x_{4}-x_{1}-x_{2}}{x_{3}}=-x_{4}+x_{1}+x_{2} \\
& x_{6}=\frac{x_{5}-x_{1}-x_{2}}{x_{4}}=\frac{-x_{4}+x_{1}+x_{2}-x_{1}-x_{2}}{x_{4}}=-1 ; \quad \ldots
\end{aligned}
$$

Notice that $x_{4}+x_{5}=x_{1}+x_{2}=2004$ and $x_{6}=x_{3}=-1$.

We will prove by complete induction that for any $n \in \mathbb{N}$, $x_{3 n+1}+x_{3 n+2}=2004$ and $x_{3 n+3}=-1$. We have seen that this is true for $n=1$ and 2.

Assume that the statement is true up to $(k-1)$: $x_{3 k-2}+x_{3 k-1}=2004$ and $x_{3 k}=-1$. We will prove it for $k$.

Based on the recursion and the induction hypothesis,

$$
\begin{aligned}
& x_{3 k+1}=\frac{x_{3 k}-x_{3 k-1}-x_{3 k-2}}{x_{3 k-1}}=\frac{-1-x_{3 k-1}-x_{3 k-2}}{x_{3 k-1}} \\
& x_{3 k+2}=\frac{x_{3 k+1}-x_{3 k-1}-x_{3 k-2}}{x_{3 k}}=-x_{3 k+1}+x_{3 k-1}+x_{3 k-2}
\end{aligned}
$$

From this, $x_{3 k+1}+x_{3 k+2}=x_{3 k+1}-x_{3 k+1}+x_{3 k-1}+x_{3 k-2}=2004$ by the induction hypothesis. Furthermore (using this),

$$
x_{3 k+3}=\frac{x_{3 k+2}-x_{3 k+2}-x_{3 k+1}}{x_{3 k+1}}=-1
$$

This implies that the sum of the numbers in each group of three in the first 2004 terms of the sequence is 2003.

Since $2004=3 \cdot 668$, the first 2004 terms consist of 668 such triplets, so the desired sum is $2003 \cdot 668=1338004$.