Nikees has a set $S$ of $n$ points on a plane and decides to colour them. All $\dbinom{n}{2}$ line segments are drawn and they have distinct lengths. Find the maximum number of colours that are used at least once, given that:

(a) For each point $P$, the two endpoints of the longest line segment connecting $P$ must be of the same colour. 

(b) For each point $P$, the two endpoints of the shortest line segment connecting $P$ must be of the same colour.
To solve this problem, we need to determine the maximum number of colors that can be used to color a set \( S \) of \( n \) points on a plane, such that the conditions (a) and (b) are satisfied. Let's break down the solution step by step.

1. **Understanding the Problem:**
   - We have \( n \) points on a plane.
   - All \( \binom{n}{2} \) line segments connecting these points have distinct lengths.
   - For each point \( P \), the endpoints of the longest and shortest line segments connecting \( P \) must be of the same color.

2. **Claim:**
   - The maximum number of colors that can be used is \( \left\lfloor \frac{n+1}{4} \right\rfloor \) for \( n \geq 3 \).
   - For \( n \leq 3 \), the maximum number of colors is trivially 1.

3. **Lower Bound Construction:**
   - Consider three points \( A \), \( B \), and \( C \) on a line such that \( AB = 1 \) and \( BC = 2 \).
   - Mark two positions \( X \) and \( Y \) such that \( X, B, Y \) are collinear, \( XY \perp AC \), and \( XB = BY = 1 \).
   - Draw an arc of a circle centered at \( B \) with a radius slightly greater than 1 and mark positions \( x_1, x_2, \ldots, x_i \) on this arc, where \( i = \left\lfloor \frac{n+1}{4} \right\rfloor - 1 \).
   - Reflect these positions across \( B \) to get \( y_1, y_2, \ldots, y_i \).
   - Place pairs of points near these positions such that they are very close to the marked positions.

4. **Color Assignment:**
   - The closest and furthest points to \( A \) are \( B \) and \( C \) respectively, and similarly for \( B \) and \( C \).
   - Assign a unique color to \( A \), \( B \), and \( C \).
   - For the points near the marked positions, the closest point will be near the same position, and the furthest point will be near the diametrically opposite position.
   - Hence, each pair of positions can be assigned a unique color, resulting in \( \left\lfloor \frac{n+1}{4} \right\rfloor \) colors in total.

5. **Upper Bound Argument:**
   - For any point, the furthest and nearest points must be of the same color, so each color must have at least 3 points.
   - Suppose there are two colors with at least 3 points each, say points \( A, B, C \) and \( A', B', C' \) are of the same color.
   - Without loss of generality, assume \( AC > AB > BC \) and \( A'C' > A'B' > B'C' \).
   - Note that \( AB' > AB \) since \( B \) is the closest point to \( A \), and \( A'B' > AB' \) since \( A' \) is the furthest point from \( B' \).
   - This implies \( A'B' > AB \), but also \( A'B < AB \) and \( A'B' < A'B \), leading to a contradiction.

Thus, the maximum number of colors that can be used is \( \left\lfloor \frac{n+1}{4} \right\rfloor \).

The final answer is \( \boxed{ \left\lfloor \frac{n+1}{4} \right\rfloor } \).