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.

Partial answer.
If we write $m = \sum_i a_i^2$, then the identity $$\left(\sum_i a_i\right)^2 = \sum_i a_i^2 + 2\sum_{i < j} a_i a_j$$ allows us to translate our condition to $$ 2m = n^2 + n.$$ We know that $m \equiv n^2\mod 2$, hence a necessary condition is $4\mid n^2 - n$, which means $n\equiv 0, 1\mod 4$.
Now we can try the first several possibilities, as below ("-" means there is no solution):
1: 1
4: 3, 1
5: -
8: -
9: 6, 3
12: -
13: 9, 3, 1
16: 10, 6
17: 12, 2, 2, 1
20: 14, 3, 2, 1
21: 15, 1, 1, 1, 1, 1, 1
24: 17, 2, 2, 1, 1, 1
25: 15, 10

I did these calculations manually, so there are possibly errors.
My feeling is that for sufficiently large $n\equiv 0, 1\mod 4$, it is always possible to find a solution. However it seems hard to prove.

EDIT:
With a simple computer program, I verified that for all $n < 200$ with $n \equiv 0, 1\mod 4$, only $5, 8, 12$ cannot be obtained. I also corrected some errors in the calculations above.
Here is a brief idea of a proof. Firstly, we find the maximum integer $x$ such that $x^2 < \frac{n^2 + n}2$. For large $n$, this $x$ is about $\frac 1{\sqrt 2}n \sim 0.7 n$.
We take either $x$ or $x - 1$ (in case $x^2$ is too close to $\frac{n^2 + n}2$) as our first term $a_1$. This leaves us with a remaining sum of about $0.3n$ and a remaining sum of squares of about $1.4n$, which is the size of the difference between $x^2$ and $(x + 1)^2$.
Thus the problem becomes to find integers who sum up to $0.3n$ while their squares sum up to $1.4n$. It suffices to search for small values of $a_i$, say with $a_i\in [1, 6]$.
If we denote by $c_i$ the number of $a_i$ that are equal to $i$, then it becomes a group of two linear equations in $6$ variables:
\begin{eqnarray}
c_1 + 2c_2 + 3c_3 + 4c_4 + 5c_5 + 6c_6 &=& n - a_1 (\sim 0.3n)\\
c_1 + 4c_2 + 9c_3 + 16c_4 + 25c_5 + 36c_6 &=& \frac{n^2 + n}2 - a_1^2 (\sim 1.4n)\\
\end{eqnarray}
It should be possible to show that this system has non-negative integer solutions for sufficiently large $n$.
