Given the convex pentagon $A B C D E$, each of its sides and diagonals must be drawn in either red or blue so that for any triangle formed by three of its vertices, both colors appear on its perimeter. In how many ways can this be done?
In the triangle $ABC$, two of the sides are of the same color, and the third is of the opposite color. Let's assume that $AB$ and $BC$ are red, and $AC$ is blue. In the triangle $ACD$, at least one of the sides $AD$ and $CD$ is red. If $CD$ is red, then in the triangle $BCD$, $BD$ is blue. In the triangle $BCE$, at least one of the sides $BE$ and $CE$ is blue. If $BE$ is blue, then in the triangle $BDE$, $BE$ is red, in the triangle $CDE$, $CE$ is blue, in the triangle $ACE$, $AE$ is red, and finally, in the triangle $ADE$, $AD$ is blue. In the thus obtained coloring, the sides of the pentagon are red, and the diagonals are blue. This satisfies the problem's requirements because no matter which 3 vertices we choose, there is a pair of adjacent and a pair of non-adjacent vertices among them.

We get all colorings if, on the one hand, in the triangle $ABC$, we choose the blue edge in all possible ways, i.e., in 3 ways, and on the other hand, we connect one of the endpoints of this edge to the vertex $D$ with a red segment and the other with a blue segment, and finally, in each coloring, we swap the red and blue colors. The coloring of the segment $BE$ to blue already led to $CE$ also being blue, so swapping the roles of the two segments does not lead to a new coloring. The number of all valid colorings is therefore $3 \cdot 2 \cdot 2 = 12$.