Let $a_{1}, a_{2}, \ldots, a_{2013}$ be real numbers satisfying the following conditions:

- $a_{1}=a_{2013}=0$
- $\left|a_{i}-a_{i+1}\right|<1$, for $1 \leq i \leq 2012$.
- $\sum_{i=1}^{2013} a_{i}=0$.

Find the greatest possible value of the sum $\sum_{i=1}^{m} a_{i}$, where $m(1 \leq m \leq 2013)$ is allowed to vary, in addition to the sequence $\left\{a_{i}\right\}$.
The answer is that the sum can come arbitrarily close to $503^{2}=253009$, but (due to an unfortunate oversight in the problem statement) cannot equal it.

Suppose that the sequence $\left\{a_{i}\right\}$ is fixed, and consider the $m$ that yields the largest value of the sum $\sum_{i=1}^{m} a_{i}$. Clearly, we can assume $1 \leq m \leq 2012$. If $m \geq 1007$, consider the alternative sequence $\left\{a_{i}^{\prime}\right\}$ defined by

$$
a_{i}^{\prime}=-a_{2014-i} .
$$

The partial sums of this sequence and the original one are related by

$$
\sum_{i=1}^{m} a_{i}=\sum_{i=1}^{2013-m} a_{i}^{\prime}
$$

so by passing from one sequence to the other we can assume that the greatest sum occurs for $m \leq 1006$.

The conditions obviously imply

$$
a_{2}<1, a_{3}<2, \ldots, a_{i}<a_{i-1} .
$$

On the other hand, note that $a_{m+1} \leq 0$, since otherwise a better value of $m$ would be $m+1$. So

$$
a_{m}<1, a_{m-1}<2, \ldots, a_{i}<a_{m+1-i}
$$

If $m \leq 504$, we use (1) to write $a_{1}+\cdots+a_{m}<0+1+\cdots+503$. Otherwise, we use (11) on $a_{1}, \ldots, a_{504}$ and (2) on the remaining terms (one can make the cut at $1+\lfloor m / 2\rfloor$ instead, but the expressions become needlessly uglier) to write

$$
\begin{aligned}
a_{1}+\cdots+a_{m} & <0+1+\cdots+502+503+(m-504)+(m-505)+\cdots+1 \\
& \leq 0+1+\cdots+502+503+502+\cdots+1 \\
& =\frac{503 \cdot 504}{2}+\frac{502 \cdot 503}{2}=503^{2}
\end{aligned}
$$

One can indeed achieve this bound to arbitrary precision by taking

$$
\begin{gathered}
a_{1}=0, a_{2}=x, a_{3}=2 x, \ldots, a_{503}=502 x, a_{504}=503 x, a_{505}=502 x, \ldots, a_{1006}=x, a_{1007}=0 \\
a_{1008}=-x, \ldots, a_{1509}=-502 x, a_{1510}=-503 x, a_{1511}=-502 x, \ldots, a_{2012}=-x, a_{2013}=0
\end{gathered}
$$

where $x$ is a real number that may be brought arbitrarily close to 1 .