Let $G = \left\langle {V,E} \right\rangle$, a simple and complete graph with the size of $n$.
Each edge in the graph can be colored with blue or red.
A "bad" triangle defined to be a triangle (circle with three edges) such that it contains two colors (two blue edges and one red and vice-verca).
Also, $d_i$ is the number for blue edges for the vertex $i$.
It appears that the number of bad triangles defined by the following formula which I'm trying to understand:
$$\sum\limits_{i = 1}^n {\frac{{({d_i} \cdot (n - 1 - {d_i}))}}{2}} $$
Trying to interpret it:
for each vertex, the number of bad triangles is the number of blue edges multiplied by the number of red edges divided by $2$.
But what is standing behind this?