Problem: Let $n \ge 3$ be an integer and let $K_n$ be the complete graph on $n$ vertices.
Each edge of $K_n$ is colored either red, green, or blue.
Let $A$ denote the number of triangles in $K_n$ with all edges of the same color, and
let $B$ denote the number of triangles in $K_n$ with all edges of different colors.
Prove that \[ B \le 2A + \frac{n(n-1)}3. \]

Solution: Consider all unordered pairs of different edges which share exactly one vertex
(call these \emph{vees} for convenience).
Assign each vee a \emph{charge} of $+2$ if its edge colors are the same,
and a charge of $-1$ otherwise.

We compute the total charge in two ways.

\paragraph{Total charge by summing over triangles.}
Note that
\begin{itemize}
  \ii each monochromatic triangle has a charge of $+6$,
  \ii each bichromatic triangle has a charge of $0$, and
  \ii each trichromatic triangle has a charge of $-3$.
\end{itemize}
Since each vee contributes to exactly one triangle,
we obtain that the total charge is $6A - 3B$.

\paragraph{Total charge by summing over vertices.}
We can also calculate the total charge by examining the centers of the vees.
If a vertex has $a$ red edges, $b$ green edges, and $c$ blue edges,
the vees centered at that vertex contribute a total charge of
\begin{align*}
  & \phantom{=}\;\; 2\left[ \binom a2 + \binom b2 + \binom c2\right] - (ab + ac + bc)\\
  & = (a^2 - a + b^2 - b + c^2 - c) - (ab + ac + bc)\\
  & = (a^2 + b^2 + c^2 - ab - ac - bc) - (a + b + c)\\
  & = (a^2 + b^2 + c^2 - ab - ac - bc) - (n-1)\\
  & \ge -(n-1).
\end{align*}
In particular, the total charge is at least $-n(n-1)$.

\paragraph{Conclusion.}
Thus, we obtain
\[
  6A - 3B \ge -n(n-1)
  \iff B \le 2A + \frac{n(n-1)}3
\]
as desired.