TITLE: Prove that $n$ is a power of 2 in the following sets of sums
QUESTION [6 upvotes]: Let $\{a_1,...,a_n\}$ and $\{b_1,...,b_n\}$ be two distinct sets of positive integers such that the sets of sums $\{a_i+a_j | 1 \leq i < j \leq n \}$ and $\{b_i+b_j | 1 \leq i < j \leq n \}$ are the same, with the same number of repetitions, eventually. Prove that $n$ is a power of $2$.
This problem came from the polynomials unit in a summer course for the IMO. I've been looking around but haven't been able to find any insights. I tried to force polynomials such as $P(x) = (x-a_2)...(x-a_n)$, hoping to find anything that would be helpful but had no luck with these attempts.
Looking at it again, I would think that the part of the question talking about repetitions would relate to the multiplicities of a polynomial. But then I hit a wall and don't know what to do with that information.

REPLY [4 votes]: I will just post the solution which I've found on AoPS.
Define polynomials $A(x)$ and $B(x)$ as follows
$$
A(x)=\sum_{i=1}^{n}x^{a_i},~B(x)=\sum_{i=1}^{n}x^{b_i}.
$$
Then, conditions of the problem imply
$$
(A(x))^2-A(x^2)=(B(x))^2-B(x^2),
$$
or
$$
(A(x))^2-(B(x))^2=A(x^2)-B(x^2).
$$
Thus, for $P(x)=A(x)-B(x)$ we have
$$
A(x)+B(x)=\frac{A(x^2)-B(x^2)}{A(x)-B(x)}=\frac{P(x^2)}{P(x)}.
$$
Finally, let $k$ be the multiplicity of the root $x_0=1$ in $P(x)$ (note that $k\geq 1$ since $P(1)=0$). Then, $P(x)=(x-1)^k Q(x)$ for some polynomial $Q(x)$ with $Q(1)\neq 0$. The previous equality can be rewritten as
$$
A(x)+B(x)=\frac{(x^2-1)^kQ(x^2)}{(x-1)^kQ(x)}=(x+1)^k\cdot\frac{Q(x^2)}{Q(x)}.
$$
Plugging $x=1$ gives
$$
2n=A(1)+B(1)=2^k,
$$
so $n=2^{k-1}$ is a power of two, as desired.