TITLE: $x(p − x)y(p − y)$ is square implies $x = y$
QUESTION [11 upvotes]: Given a prime $p > 2$ and positive integers $x,y \le \frac{p − 1}{2}$, prove that if $x(p − x)y(p − y)$ is a perfect square, then $x = y$.

This question was previously asked without context , and so was closed, but I did start towards a solution.
The primary insight is that the result depends on the unique representation of a prime as a sum of squares. 
Obviously if that were not true we could have $m_0^2+n_0^2=m_1^2+n_1^2=p$. Then we could choose $x=m_0^2$ and $y=m_1^2$ as the lesser parts of those two different representations and with all contributing values being square, get a square that disproves the claim.
The other strand of proof that I did not succeed in completing was to eliminate the possibility that the various components might multiply together to give a square. Here are my thoughts on this so far:

Since $p$ prime, $x$ is coprime to $v:=(p-x)$ and $y$ is coprime to $w:=(p-y)$.
Find $g :=\gcd(x,y)$ and $h:=\gcd(v,w)$, and set $(a,b,c,d):=(x/g,y/g,v/h,w/h)$. If one of these terms is $1$ then all are, and $x=y$.
Assume that we have $a,b,c,d>1$. Then the expression of interest is $abcdg^2h^2$, which is square iff $abcd$ is square. The only possible common factors are in the pairs $(a,d)$ and $(b,c)$ so we would need $ad$ square and $bc$ square. 

Can anyone either complete my proof or find a better way to demonstrate the truth of the opening claim?

REPLY [3 votes]: This is the problem from the second stage of last year's Polish Mathematical Olympiad, see here. Below I present the official problem solution, from here.
Suppose the expression is a square, say $k^2$. Applying AM-GM inequality we quickly find $k<p^2/4$. On the other hand, from $x,y<p/2$, we find $k>xy$. Now we rewrite
$$0=k^2-xy(p-x)(p-y)=(k-xy)(k+xy)-pxy(p-x-y),$$
from where $p\mid k-xy$ or $p\mid k+xy$.
Suppose first $k-xy=lp>0$. Then
$$lp(lp+2xy)=lp(k+xy)=pxy(p-x-y),\\
p(xy-l^2)=xy(2l+x+y).$$
Since $x,y<p$, $p\mid 2l+x+y$. From $lp=k-xy<k<p^2/4$ we get $l<p/4$, and then $2l+x+y<2p/4+p/2+p/2=2p$, hence $2l+x+y=p$. However, then $p(xy-l^2)=pxy$, impossible given $l>0$.
Hence $k+xy=lp$ for some $l$. Like above, we get $p(xy-l^2)=xy(x+y-2l)$. From $lp=k+xy<p^2/4+(p/2)^2=p^2/2$ we get $l<p/2$. Hence
$$p>x+y>x+y-2l>-2\cdot p/2=-p,$$
thus $x+y-2l=0$ (since it's divisible by $p$). Thus $p(xy-l^2)=0$, i.e. $xy=l^2$. Hence finally
$$(x-y)^2=(x+y)^2-4xy=(2l)^2-4l^2=0$$
giving $x=y$.