Let $ S = \{ \mathbf{p}_1, \mathbf{p}_2, \dots, \mathbf{p}_n \} \subset \mathbb{R}^2 $ be a set of $ n $ distinct points in the plane, with $ \mathbf{p}_i = (x_i, y_i) $.
For a line $ \ell $ passing through the origin, let $ \pi_\ell : \mathbb{R}^2 \to \ell $ denote the orthogonal projection onto $ \ell $. Define the projected multiset:
$$
P_\ell = \{ \pi_\ell(\mathbf{p}_i) \mid \mathbf{p}_i \in S \}.
$$
A line $ \ell $ is **good** if $ P_\ell $ is **centrally symmetric** about some point $ \mathbf{P} \in \ell $, i.e., for every point $ \mathbf{q} \in P_\ell $, the point $ 2\mathbf{P} - \mathbf{q} $ is also in $ P_\ell $ with the same multiplicity.
Let $ \theta \in [0, \pi) $ parametrize the direction of $ \ell $, so that $ \ell = \{ t (\cos\theta, \sin\theta) \mid t \in \mathbb{R} \} $.
We are to compute the number of distinct directions $ \theta \in [0, \pi) $ for which $ P_\ell $ is centrally symmetric.
**Key observations:**
1. The projection $ \pi_\ell(\mathbf{p}_i) $ is the scalar projection along the unit vector $ \mathbf{u}_\theta = (\cos\theta, \sin\theta) $:
$$
\pi_\ell(\mathbf{p}_i) = (\mathbf{p}_i \cdot \mathbf{u}_\theta) \cdot \mathbf{u}_\theta.
$$
The **scalar coordinate** of the projection along $ \ell $ is $ s_i = \mathbf{p}_i \cdot \mathbf{u}_\theta = x_i \cos\theta + y_i \sin\theta $.
2. The multiset $ P_\ell $ is centrally symmetric about some point $ \mathbf{P} \in \ell $ **if and only if** the multiset of scalar projections $ \{ s_1, s_2, \dots, s_n \} $ is centrally symmetric about some $ c \in \mathbb{R} $, i.e., for every $ s_i $, $ 2c - s_i $ is also in the multiset with the same multiplicity.
3. A multiset of real numbers is centrally symmetric about $ c $ if and only if:
$$
\{ s_1, \dots, s_n \} = \{ 2c - s_1, \dots, 2c - s_n \}.
$$
This implies that the multiset is symmetric about its **mean** (if $ n $ is odd, the center must be the median, which must equal the mean). Thus, the only possible center is $ c = \frac{1}{n} \sum_{i=1}^n s_i $, and the condition becomes:
$$
\forall i, \exists j \text{ such that } s_j = 2c - s_i.
$$
4. Since $ c = \frac{1}{n} \sum_{i=1}^n \mathbf{p}_i \cdot \mathbf{u}_\theta = \left( \frac{1}{n} \sum_{i=1}^n \mathbf{p}_i \right) \cdot \mathbf{u}_\theta = \bar{\mathbf{p}} \cdot \mathbf{u}_\theta $, where $ \bar{\mathbf{p}} = \frac{1}{n} \sum \mathbf{p}_i $, the condition becomes:
$$
\forall i, \exists j \text{ such that } \mathbf{p}_i \cdot \mathbf{u}_\theta + \mathbf{p}_j \cdot \mathbf{u}_\theta = 2 \bar{\mathbf{p}} \cdot \mathbf{u}_\theta,
$$
or equivalently,
$$
(\mathbf{p}_i + \mathbf{p}_j - 2\bar{\mathbf{p}}) \cdot \mathbf{u}_\theta = 0.
$$
5. Define the **centered points**: $ \mathbf{q}_i = \mathbf{p}_i - \bar{\mathbf{p}} $. Then the condition becomes:
$$
\forall i, \exists j \text{ such that } (\mathbf{q}_i + \mathbf{q}_j) \cdot \mathbf{u}_\theta = 0.
$$
That is, $ \mathbf{q}_i + \mathbf{q}_j \perp \mathbf{u}_\theta $.
6. For the multiset of projections to be symmetric, the set $ \{ \mathbf{q}_1, \dots, \mathbf{q}_n \} $ must be **centrally symmetric about the origin** in the plane — **but only along the direction $ \mathbf{u}_\theta $**. That is, for the projection to be symmetric, the set $ \{ \mathbf{q}_i \} $ must be symmetric under reflection through the origin **in the direction of $ \ell $**.
However, a necessary and sufficient condition is:
> The multiset $ \{ \mathbf{p}_i \} $ is such that the set of vectors $ \{ \mathbf{p}_i - \bar{\mathbf{p}} \} $ is centrally symmetric **as a whole** — then **every** line through the origin is good. Otherwise, only lines $ \ell $ for which the projection of the centered set is symmetric (i.e., the direction $ \mathbf{u}_\theta $ is orthogonal to some $ \mathbf{q}_i + \mathbf{q}_j $) are candidates.
7. **Critical insight**: The set of projections $ \{ s_i \} $ is centrally symmetric **if and only if** the multiset $ \{ \mathbf{q}_i \} $ is centrally symmetric **in the direction of $ \ell $**. That is, for every $ \mathbf{q}_i $, there exists $ \mathbf{q}_j $ such that $ \mathbf{q}_i + \mathbf{q}_j \perp \mathbf{u}_\theta $.
But this must hold for **all** $ i $. So, the set $ \{ \mathbf{q}_i \} $ must be centrally symmetric **as a whole** (i.e., $ \{ \mathbf{q}_i \} = \{ -\mathbf{q}_i \} $), or else only specific directions $ \mathbf{u}_\theta $ satisfy the condition.
8. **Final characterization**:
- If the entire set $ S $ is centrally symmetric about $ \bar{\mathbf{p}} $, i.e., $ \{ \mathbf{p}_i \} = \{ 2\bar{\mathbf{p}} - \mathbf{p}_i \} $, then **every** line through the origin is good → output $ -1 $.
- Otherwise, the good lines correspond to directions $ \mathbf{u}_\theta $ such that $ \mathbf{u}_\theta \perp (\mathbf{q}_i + \mathbf{q}_j) $ for some pair $ (i,j) $, and the multiset of projections is symmetric. But since the set is not centrally symmetric globally, the only possible good lines are those perpendicular to $ \mathbf{q}_i + \mathbf{q}_j $ for some pair $ i < j $, **and** for which the projection symmetry condition holds.
However, a simpler and known approach from competitive programming problems (e.g., CodeForces) is:
> The number of good lines equals the number of distinct directions $ \theta \in [0, \pi) $ such that the multiset $ \{ \mathbf{p}_i \cdot \mathbf{u}_\theta \} $ is symmetric about its mean.
This happens if and only if the multiset $ \{ \mathbf{q}_i \} $ is symmetric under reflection through the origin **along $ \ell $**, i.e., the set of vectors $ \{ \mathbf{q}_i \} $ is symmetric under the operation of negating components **along $ \ell $**.
The only directions $ \ell $ that can work are those for which the set $ \{ \mathbf{q}_i \} $ is symmetric with respect to the line perpendicular to $ \ell $ — i.e., $ \ell $ is an axis of symmetry of the multiset $ \{ \mathbf{q}_i \} $ **through the origin**.
But since we are projecting onto $ \ell $, and requiring the **projection** to be centrally symmetric, the correct known solution is:
> Good lines correspond to directions $ \mathbf{u} $ such that the multiset $ \{ \mathbf{q}_i \} $ is symmetric under the transformation $ \mathbf{v} \mapsto -\mathbf{v} $ **when projected onto $ \mathbf{u}^\perp $** — i.e., $ \mathbf{u} $ is perpendicular to a vector $ \mathbf{q}_i + \mathbf{q}_j $ for some pair $ i, j $, and the pairing covers all points.
Actually, the known solution (from CodeForces problems like "Good Line") is:
- Compute $ \bar{\mathbf{p}} = \frac{1}{n} \sum \mathbf{p}_i $.
- Compute $ \mathbf{q}_i = \mathbf{p}_i - \bar{\mathbf{p}} $.
- If all $ \mathbf{q}_i = \mathbf{0} $, then all points coincide — contradiction (guaranteed distinct), so skip.
- If $ \{ \mathbf{q}_i \} = \{ -\mathbf{q}_i \} $ as multisets → then every line is good → output $ -1 $.
- Otherwise, for each unordered pair $ (i, j) $ with $ i < j $, compute $ \mathbf{v}_{ij} = \mathbf{q}_i + \mathbf{q}_j $. If $ \mathbf{v}_{ij} \ne \mathbf{0} $, then the direction $ \ell $ perpendicular to $ \mathbf{v}_{ij} $ is a candidate.
- For each such candidate direction (i.e., normalized vector $ \mathbf{u} \perp \mathbf{v}_{ij} $), check whether the projection of $ \{ \mathbf{q}_i \} $ onto $ \ell $ is centrally symmetric (i.e., the multiset of dot products $ \{ \mathbf{q}_i \cdot \mathbf{u} \} $ is symmetric about 0).
- Count distinct such directions $ \mathbf{u} \in [0, \pi) $.
But note: since $ \mathbf{u} \perp \mathbf{v}_{ij} $, then $ \mathbf{u} \cdot (\mathbf{q}_i + \mathbf{q}_j) = 0 \Rightarrow \mathbf{q}_i \cdot \mathbf{u} = - \mathbf{q}_j \cdot \mathbf{u} $, so at least this pair is symmetric. But we need **all** points to pair up.
So the algorithm:
- If the multiset $ \{ \mathbf{q}_i \} $ is centrally symmetric about origin → output $ -1 $.
- Else:
- Initialize a set $ D $ of directions.
- For each pair $ (i, j) $, $ i < j $:
- Let $ \mathbf{v} = \mathbf{q}_i + \mathbf{q}_j $.
- If $ \mathbf{v} \ne \mathbf{0} $, compute a unit vector $ \mathbf{u} $ perpendicular to $ \mathbf{v} $, normalized to direction in $ [0, \pi) $.
- Check if the multiset $ \{ \mathbf{q}_k \cdot \mathbf{u} \} $ is symmetric about 0.
- If yes, add $ \mathbf{u} $ to $ D $ (as a normalized direction, avoiding duplicates).
- Output $ |D| $.
However, note that if $ \mathbf{v} = \mathbf{0} $, then $ \mathbf{q}_j = -\mathbf{q}_i $, so this pair is already symmetric — but we still need to check global symmetry.
So the **formal statement** is:
---
**Definitions:**
- Let $ \mathbf{p}_1, \dots, \mathbf{p}_n \in \mathbb{R}^2 $ be distinct points.
- Let $ \bar{\mathbf{p}} = \frac{1}{n} \sum_{i=1}^n \mathbf{p}_i $.
- Let $ \mathbf{q}_i = \mathbf{p}_i - \bar{\mathbf{p}} $ for $ i = 1, \dots, n $.
**Given:**
- $ \mathbf{q}_i \ne \mathbf{0} $ for at least one $ i $ (since points are distinct).
- The multiset $ \{ \mathbf{q}_1, \dots, \mathbf{q}_n \} $ is **not necessarily** centrally symmetric about $ \mathbf{0} $.
**Objective:**
Find the number of distinct unit vectors $ \mathbf{u} \in \mathbb{R}^2 $ with $ \|\mathbf{u}\| = 1 $, and $ \mathbf{u} $ representing a direction in $ [0, \pi) $, such that the multiset $ \{ \mathbf{q}_i \cdot \mathbf{u} \mid i = 1, \dots, n \} $ is symmetric about 0.
That is:
$$
\{ \mathbf{q}_1 \cdot \mathbf{u}, \dots, \mathbf{q}_n \cdot \mathbf{u} \} = \{ -(\mathbf{q}_1 \cdot \mathbf{u}), \dots, -(\mathbf{q}_n \cdot \mathbf{u}) \}
$$
as multisets.
**Equivalently:**
The multiset $ \{ \mathbf{q}_i \cdot \mathbf{u} \} $ is symmetric about 0 if and only if for every $ i $, there exists $ j $ such that $ \mathbf{q}_i \cdot \mathbf{u} = - \mathbf{q}_j \cdot \mathbf{u} $, and multiplicities match.
**Constraint:**
If $ \{ \mathbf{q}_i \} = \{ -\mathbf{q}_i \} $ as multisets, then **every** $ \mathbf{u} $ satisfies the condition → output $ -1 $.
Otherwise, count the number of distinct directions $ \mathbf{u} \in S^1 / \sim $ (where $ \mathbf{u} \sim -\mathbf{u} $) for which $ \{ \mathbf{q}_i \cdot \mathbf{u} \} $ is symmetric about 0.
---
**Final Formal Statement:**
Let $ \mathbf{q}_i = \mathbf{p}_i - \frac{1}{n} \sum_{j=1}^n \mathbf{p}_j $ for $ i = 1, \dots, n $.
- If $ \{ \mathbf{q}_1, \dots, \mathbf{q}_n \} = \{ -\mathbf{q}_1, \dots, -\mathbf{q}_n \} $ as multisets, output $ -1 $.
- Else, let $ \mathcal{U} = \left\{ \mathbf{u} \in \mathbb{R}^2 \mid \|\mathbf{u}\| = 1, \{ \mathbf{q}_i \cdot \mathbf{u} \}_{i=1}^n \text{ is symmetric about } 0 \right\} $.
- Output $ \left| \left\{ \mathbf{u} \in \mathcal{U} \mid \mathbf{u} \in [0, \pi) \text{ direction} \right\} \right| $.
Where "direction in $ [0, \pi) $" means we identify $ \mathbf{u} $ and $ -\mathbf{u} $, and represent each line by its unique unit vector with angle $ \theta \in [0, \pi) $.
---