Let $G$ be a 4-free graph, and such that the number of its vertices is a multiple of three. What is the maximum number of triangles in $G$?
For any edge $e$, we denote $d(e)$ as the number of triangles having the edge $e$ as a side, in other words, the number of vertices connected to both ends of $e$. We will adopt the method of counting triangles mentioned above using this notion of the degree of an edge instead of the degree of a vertex.

Let $3k$ be the number of vertices in $G$. We will start by showing that if $e, f, g$ are three edges forming a triangle,

$$
d(e) + d(f) + d(g) \leq 3k
$$

Indeed, otherwise, by the pigeonhole principle, there must necessarily be a vertex of the graph, different from the endpoints of $e, f, g$, which is counted twice on the left side, thus being a vertex of two triangles having two of these edges as sides. This would imply the existence of a $K_4$, a contradiction.

By denoting $t$ as the number of triangles and summing the inequality above over all triangles, we obtain

$$
\sum_{\text{triangles}} (d(e) + d(f) + d(g)) \leq 3kt
$$

In the sum on the left side, each $d(e)$ is counted as many times as there are triangles containing $e$, so $d(e)$ times. Thus, the left side is $\sum_{\text{edges}} d(e)^2$. We then apply the Cauchy-Schwarz inequality to get:

$$
3kt \geq \sum_{\text{edges}} d(e)^2 \geq \frac{\left(\sum_{\text{edges}} d(e)\right)^2}{m}
$$

where we denote $m$ as the number of edges in the graph. In the sum $\sum_{\text{edges}} d(e)$, each triangle is counted three times (once for each of its sides), so it is $3t$.

We thus have $mk \geq 3t$. On the other hand, according to Turán's theorem, $m \leq \frac{(3k^2)}{3} = 3k^2$. Therefore, we have $t \leq k^3$.

Conversely, to show that this result is optimal, the fact that we used Turán's theorem to prove it suggests considering the Turán graph $K_{k, k, k}$, which is $4$-free and tripartite. The number of triangles is clearly $k^3$.