Sum of squares and linear sum 
For which positive integer $n$ can we write $n=a_1+a_2+\dots+a_k$ (for some unfixed $k$ and positive integers $a_1,a_2,\ldots,a_k$) such that $\sum_{i=1}^k a_i^2 = \sum_{i=1}^k a_i + 2\sum_{i<j}a_ia_j$?

When $k=1$, the equation is $a_1^2=a_1$, so $a_1=1$ and $n=1$ is the only possibility.
When $k=2$, we get $a_1^2+a_2^2 = a_1+a_2+2a_1a_2$, or $(a_1-a_2)^2 = a_1+a_2$, hence $n$ must be a perfect square. For perfect square $n=r^2$, we can solve $a_1+a_2=r^2$ and $a_1-a_2=r$, which must have a solution because $r^2\equiv r\pmod 2$. So all perfect squares work.

Here we prove an auxiliary claim for WhatsUp’s answer.
Let $S$ be the set of all pairs $(a,b)$ of natural numbers such that a system
$$\cases{
c_1 + 2c_2 + 3c_3 + 4c_4 + 5c_5 + 6c_6=x\\ 
c_1 + 4c_2 + 9c_3 + 16c_4 + 25c_5 + 36c_6=y}$$
has a solution in non-negative integers.
The set $S$ can be constructed recursively as follows. Put $(0,0)\in S$ and if $(x,y)\in S$ then put to $S$ pairs $(x+1,y+1)$, $(x+2,y+4)$, $(x+3,y+9)$, $(x+4,y+16)$, $(x+5,y+25)$, and $(x+6,y+36)$. If $(x,y)\in S$ then $x\le y \le 6x$. Moreover, $y-x=4c_2 + 6c_3 + 12c_4 + 20c_5 + 30c_6$, so $x$ and $y$ have the same parity.
Black points are pairs $(x,y)\in S$ for $0\le x, y\le 255$. Red points are pairs $(x,y)\not\in S$ for $x\le y \le 6x$ and $x,y$ of the same parity.

We claim that if $16\le x\le y\le 5x$ and $x$ and $y$ have the same parity then $(x,y)\in S$. We shall prove the claim by indution with respect to $x$. For $16\le x\le 20$ the claim can be checked directly, see the graph below. Assume that the claim is already proved for $x\ge 20$ and  $x+1\le y\le 5(x+1)$. If $x+1\le y-20$ then $(x-4,y-25)\in S$ by the induction hypoteses and so $(x+1,y)=(x-4,y-25)+(5,25)\in S$ by the construction of $S$. If $x+1>y-20$ then $(x,y-1)\in S$ by the induction hypoteses and so $(x+1,y)=(x,y-1)+(1,1)\in S$ by the construction of $S$.
