Problem

Source: Rioplatense Olympiad 2016 level 3 P1

Tags: game strategy, combinatorics, Sum of Squares, game



Ana and Beto play against each other. Initially, Ana chooses a non-negative integer $N$ and announces it to Beto. Next Beto writes a succession of $2016$ numbers, $1008$ of them equal to $1$ and $1008$ of them equal to $-1$. Once this is done, Ana must split the succession into several blocks of consecutive terms (each term belonging to exactly one block), and calculate the sum of the numbers of each block. Finally, add the squares of the calculated numbers. If this sum is equal to $N$, Ana wins. If not, Beto wins. Determine all values of $N$ for which Ana can ensure victory, no matter how Beto plays.