[step:Prime case 2: form two-element sets and a singleton, then apply iterated Cauchy-Davenport]Assume no value appears $p$ or more times. Since the sequence is sorted and has $2p - 1$ terms, define the sets
\begin{align*}
A_i &= \{a_i, \, a_{i+p-1}\} \quad \text{for } i = 1, 2, \ldots, p-1, \\
A_p &= \{a_{2p-1}\}.
\end{align*}
Each $A_i$ for $i \leq p - 1$ draws one element from the "first half" ($a_1, \ldots, a_{p-1}$) and one from the "second half" ($a_p, \ldots, a_{2p-2}$) of the sorted sequence (with indices offset by $p - 1$). Since no value appears $p$ times, the elements $a_i$ and $a_{i+p-1}$ cannot all be equal for any run of $p$ consecutive terms, so in particular $a_i \neq a_{i+p-1}$ for each $i = 1, \ldots, p-1$. Therefore $|A_i| = 2$ for $i = 1, \ldots, p-1$, and $|A_p| = 1$.
We verify the size condition for the [Iterated Cauchy-Davenport](/theorems/2605) theorem with $k = p$ sets in $\mathbb{Z}_p$:
\begin{align*}
\sum_{i=1}^{p} |A_i| = 2(p - 1) + 1 = 2p - 1 \leq p + p - 1 = 2p - 1.
\end{align*}
The condition $\sum |A_i| \leq p + k - 1 = 2p - 1$ holds with equality. By the [Iterated Cauchy-Davenport](/theorems/2605) theorem:
\begin{align*}
|A_1 + A_2 + \cdots + A_p| \geq \sum_{i=1}^{p} |A_i| - p + 1 = (2p - 1) - p + 1 = p.
\end{align*}
Since $A_1 + \cdots + A_p \subseteq \mathbb{Z}_p$ and $|\mathbb{Z}_p| = p$, we conclude $A_1 + A_2 + \cdots + A_p = \mathbb{Z}_p$.
In particular, $0 \in A_1 + A_2 + \cdots + A_p$. This means there exist choices $s_i \in A_i$ for each $i = 1, \ldots, p$ such that $s_1 + s_2 + \cdots + s_p = 0$ in $\mathbb{Z}_p$. Each $s_i$ is one of the two elements of $A_i$ (or the single element if $i = p$), so the chosen $s_1, \ldots, s_p$ correspond to exactly $p$ terms from the original sequence $a_1, \ldots, a_{2p-1}$. These $p$ terms form the required subset $I$ with $|I| = p$ and $\sum_{i \in I} a_i \equiv 0 \pmod{p}$.[/step]