TITLE: Mantel's Theorem proof verification
QUESTION [14 upvotes]: I found the following proof for Mantel's theorem in Lecture 1 of David Conlon's "Extremal graph theory" course. I cannot understand the equality that I have highlighted in the image was arrived at. I would appreciate some assistance.

Theorem 1 (Mantel's theorem) *If a graph $G$ on $n$ vertices contains no triangle then it contains at most $\frac {n^2}{4}$ edges. 
First proof Suppose that $G$ has $m$ edges. Let $x$ and $y$ be two vertices in $G$ which are joined by an edge. If $d(v)$ is the degree of a vertex $v$, we see that $d(x)+d(y)\leq n$. This is because every vertex in the graph $G$ is connected to at most one of $x$ and $y$. Note now that 
  $$\bbox[5px,border:2px solid red]{
   \sum_x d^2(x)=\sum_{x,y\in E} \big( d(x)+d(y)\big)
   }
   \leq mn.$$
  On the other hand, since $\sum_x d(x)=2m$, the Cauchy-Schwarz inequality implies that 
  $$\sum_x d^2(x)\geq\frac{\big(\sum_x d(x)\big)^2}{n} \geq \frac{4m^2}{n}.$$
  Therfore
  $$\frac{4m^2}{n} \leq mn,$$
  and the result follows. $\tag*{$\square$}$

For people with visulal limitations, the highlighted part is: $$\sum_x d^2(x)=\sum_{x,y\in E} \big( d(x)+d(y)\big) \leq mn.$$

REPLY [6 votes]: In the sum $S:=\sum_{xy\in E}\bigl(d(x)+d(y)\bigr)$ the ends $x$ and $y$ of each edge $e=xy$  get  $d(x)$, resp. $d(y)$,  points each. This means that every vertex $x\in V$ gets $d(x)$ points for each edge having an end at $x$. It follows that $S=\sum_{x\in V}d^2(x)$.