4. (22 points) Suppose a set of planar points $S$ has the following properties:
(1) No three points are collinear;
(2) The distance between any two points is unique.

For two points $A$ and $B$ in $S$, if there exists a point $C \in S$ such that $|A C|<|A B|<|B C|$, then $A B$ is called a "middle edge" of $S$. For three points $A$, $B$, and $C$ in $S$, if $A B$, $A C$, and $B C$ are all middle edges of $S$, then $\triangle A B C$ is called a "middle edge triangle" of $S$. Find the smallest $n$ such that any $n$-element planar point set $S$ with properties (1) and (2) must contain a middle edge triangle.
4. Color all middle edges of $S$ red, and color other edges blue.

When $n \geqslant 6$, according to Ramsey's theorem, there must exist a monochromatic triangle, which must have a middle edge, and it must be a middle edge triangle.

The following set of five points with properties (1) and (2) does not have a middle edge triangle:

Assume five points $P_{1}, P_{2}, P_{3}, P_{4}, P_{5}$ are arranged in a counterclockwise order on the circumference of a circle, and
$$
\begin{array}{c}
{\overparen{P_{1} P_{2}}}_{2}^{\circ}=\frac{\pi}{10},{\overparen{P_{2} P_{3}}}^{0}=\frac{3 \pi}{5},{\overparen{P_{3} P_{4}}}^{0}=\frac{3 \pi}{10}, \\
\overparen{P}_{4} P_{5}^{0}=\frac{3 \pi}{4},{\overparen{P_{5} P_{1}}}^{0}=\frac{\pi}{4} .
\end{array}
$$

Then the distances between points $P_{1}, P_{2}, P_{3}, P_{4}, P_{5}$ are all different, and $P_{2} P_{3}, P_{3} P_{1}, P_{1} P_{5}, P_{5} P_{4}, P_{4} P_{2}$ are middle edges, but there is no middle edge triangle.
For cases with fewer than five points, simply remove some points from the previous example, and there will still be no middle edge triangle.
(Provided by An Sai)