Prove that $a_i\leq 0$ for $i=1,2,...,N-1$? Let $a_0,a_1,...,a_N$ be real number satisfying $a_0=a_N=0$ and 
$$a_{i+1}-2a_i +a_{i-1}=a_{i}^{2}$$
for all $i=1,2,...,N-1$.

Prove that $a_i\leq 0$ for $i=1,2,...,N-1$.

I saw the problem in "Baltic Way 2014" and tried to solve it. I've obtained that
$\sum_{i=1}^{N-1} a_{i}^{2}=a_1+a_{N-1}$. Any hint appreciated.
 A: This is an interesting example of a potentially difficult problem that becomes exceptionally easy when appropriately generalized.
The relation $a_{i+1} - 2a_i + a_{i-1} \ge 0$ states that each interior value $a_i$ ($i=1, 2, \ldots, N-1$) does not exceed the mean of its neighbors.  A trivial induction on $N$ (starting at $N=2$, which is immediate) shows this implies the maximum of the $\{a_i\}$ must occur at one of the endpoints $i=0$ or $i=N$--and you're done.

This is a one-dimensional discrete version of the Maximum Principle for subharmonic functions..  In one dimension, a "subharmonic function" merely is one that is convex.  The second difference $a_{i+1} - 2a_i + a_{i-1} \ge 0$ is the analog of the second derivative at $a_i$.
The continuous analog of the defining equation  $a_{i+1} - 2a_i + a_{i-1}  = a_i^2$ is $a^{\prime\prime}(z) = a(z)^2$.  This differential equation has, as solution, any linear function plus a certain Weierstrass $\wp$ function.  This illustrates the sense in which relaxing the equality "$= a_i^2$" to an inequality "$\ge 0$" is a genuine simplification.
