[proofplan]
We first use that $\Gamma_0(N)$ has finite index in $SL_2(\mathbb{Z})$, so a finite union of translates of the standard modular fundamental domain controls the quotient. Away from the rational boundary points this gives the usual orbifold quotient of $\mathcal{H}$, whose elliptic stabilisers are finite and hence give legitimate Riemann-surface charts after quotienting by finite rotation groups. The only noncompact parts are finitely many cuspidal ends, and each cusp has a finite width $w$ so that the local parameter $\exp(2\pi i z/w)$ identifies a punctured cusp neighbourhood with a punctured disc. Filling in these finitely many punctures gives compactness, while connectedness follows from the connectedness of $\mathcal{H}$ and the fact that adjoining cusp points preserves connectedness.
[/proofplan]
custom_env
admin
[step:Reduce the quotient to finitely many translates of the standard fundamental domain]Let
\begin{align*}
\mathcal{F} := \left\{z \in \mathcal{H} : |\operatorname{Re}(z)| \leq \frac{1}{2},\ |z| \geq 1\right\}
\end{align*}
denote the closed standard fundamental domain for the action of $SL_2(\mathbb{Z})$ on $\mathcal{H}$. Let $r \in \mathbb{N}$ be the finite index
\begin{align*}
r := [SL_2(\mathbb{Z}) : \Gamma_0(N)].
\end{align*}
Choose matrices $\gamma_1,\dots,\gamma_r \in SL_2(\mathbb{Z})$ whose images are representatives for the left cosets $\Gamma_0(N)\backslash SL_2(\mathbb{Z})$.
Since $\Gamma_0(N)$ has finite index in $SL_2(\mathbb{Z})$ and $\mathcal{F}$ is a fundamental domain for $SL_2(\mathbb{Z})$, every point of $\mathcal{H}$ is $\Gamma_0(N)$-equivalent to a point of the finite union
\begin{align*}
\mathcal{D} := \bigcup_{j=1}^{r} \gamma_j \mathcal{F}.
\end{align*}
Indeed, for $z \in \mathcal{H}$, choose $A \in SL_2(\mathbb{Z})$ and $u \in \mathcal{F}$ such that $z = A u$. Since the $\gamma_j$ are left-coset representatives, there are $\Gamma \in \Gamma_0(N)$ and $j \in \{1,\dots,r\}$ such that $A = \Gamma \gamma_j$. Hence $z = \Gamma(\gamma_j u)$, so the image of $\mathcal{D}$ covers $\Gamma_0(N)\backslash \mathcal{H}$.
The finiteness of $r$ follows directly from the reduction map
\begin{align*}
\rho_N: SL_2(\mathbb{Z}) \to SL_2(\mathbb{Z}/N\mathbb{Z}),
\end{align*}
because $\Gamma_0(N)$ contains the inverse image under $\rho_N$ of the finite subgroup of matrices whose lower-left entry is $0$ modulo $N$. Thus $\Gamma_0(N)$ has finite index in $SL_2(\mathbb{Z})$.[/step]
custom_env
admin
[guided]The first point is that although $\Gamma_0(N)$ is smaller than $SL_2(\mathbb{Z})$, it is only smaller by finitely many cosets. We make this finite reduction explicit. Define
\begin{align*}
\mathcal{F} := \left\{z \in \mathcal{H} : |\operatorname{Re}(z)| \leq \frac{1}{2},\ |z| \geq 1\right\},
\end{align*}
the usual closed fundamental domain for $SL_2(\mathbb{Z})$ acting on $\mathcal{H}$.
We need $\Gamma_0(N)$ to have finite index in $SL_2(\mathbb{Z})$. Define the reduction map
\begin{align*}
\rho_N: SL_2(\mathbb{Z}) \to SL_2(\mathbb{Z}/N\mathbb{Z})
\end{align*}
by reducing each matrix entry modulo $N$. The group $SL_2(\mathbb{Z}/N\mathbb{Z})$ is finite. The subgroup $\Gamma_0(N)$ contains the inverse image of the finite subgroup consisting of matrices whose lower-left entry is $0$ modulo $N$, so $\Gamma_0(N)$ has finite index. Let
\begin{align*}
r := [SL_2(\mathbb{Z}) : \Gamma_0(N)]
\end{align*}
and choose representatives $\gamma_1,\dots,\gamma_r \in SL_2(\mathbb{Z})$ for the left cosets $\Gamma_0(N)\backslash SL_2(\mathbb{Z})$.
Now define the finite union
\begin{align*}
\mathcal{D} := \bigcup_{j=1}^{r} \gamma_j \mathcal{F}.
\end{align*}
We verify that its image covers $\Gamma_0(N)\backslash \mathcal{H}$. Given $z \in \mathcal{H}$, the standard fundamental-domain property for $SL_2(\mathbb{Z})$ gives $A \in SL_2(\mathbb{Z})$ and $u \in \mathcal{F}$ with $z = A u$. Since the $\gamma_j$ represent the left cosets, there are $\Gamma \in \Gamma_0(N)$ and $j \in \{1,\dots,r\}$ such that $A = \Gamma \gamma_j$. Therefore
\begin{align*}
z = \Gamma(\gamma_j u),
\end{align*}
so $z$ and $\gamma_j u \in \mathcal{D}$ define the same point of $\Gamma_0(N)\backslash \mathcal{H}$. Thus a finite union of standard translates controls the entire quotient.[/guided]
custom_env
admin
[step:Give the interior quotient its Riemann-surface structure]Let
\begin{align*}
Y_0(N) := \Gamma_0(N)\backslash \mathcal{H}
\end{align*}
be the noncompact modular curve. We verify the hypotheses of the quotient-surface theorem. The group $\Gamma_0(N)$ is a subgroup of $SL_2(\mathbb{Z})$, hence its image in $PSL_2(\mathbb{R})$ is a discrete Fuchsian group. By the [proper discontinuity of Fuchsian group actions](/page/Fuchsian%20Group), a discrete subgroup of $PSL_2(\mathbb{R})$ acts properly discontinuously on $\mathcal{H}$ by Möbius transformations. For each $z \in \mathcal{H}$, define the stabiliser subgroup
\begin{align*}
\Gamma_{0}(N)_z := \{\Gamma \in \Gamma_0(N) : \Gamma z = z\}.
\end{align*}
The image of $\Gamma_{0}(N)_z$ in $PSL_2(\mathbb{R})$ is a discrete subgroup of the compact rotation group fixing $z$; a discrete subset of a compact group is finite. The kernel of $SL_2(\mathbb{R}) \to PSL_2(\mathbb{R})$ is $\{I,-I\}$, so $\Gamma_{0}(N)_z$ itself is finite.
The action is by holomorphic automorphisms because each matrix
\begin{align*}
\Gamma = \begin{pmatrix} a & b \\ c & d \end{pmatrix} \in \Gamma_0(N)
\end{align*}
acts by $z \mapsto (az+b)/(cz+d)$, whose denominator is nonzero on $\mathcal{H}$. Therefore the [quotient-surface theorem for properly discontinuous holomorphic actions with finite stabilisers](/page/Riemann%20Surface%20Quotient) applies and gives $Y_0(N)$ the structure of a Riemann surface, with the quotient map
\begin{align*}
\pi: \mathcal{H} \to Y_0(N)
\end{align*}
holomorphic.
Connectedness follows at this stage because $\mathcal{H}$ is connected, $\pi$ is continuous for the [quotient topology](/page/Quotient%20Topology), and $\pi$ is surjective; the image of a connected topological space under a continuous map is connected.[/step]
custom_env
admin
[guided]We now put the complex structure on the interior quotient
\begin{align*}
Y_0(N) := \Gamma_0(N)\backslash \mathcal{H}.
\end{align*}
Each element
\begin{align*}
\Gamma =
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
\in \Gamma_0(N)
\end{align*}
acts by the holomorphic automorphism
\begin{align*}
z \mapsto \frac{az+b}{cz+d}
\end{align*}
of $\mathcal{H}$. The action is properly discontinuous because $\Gamma_0(N)$ is a discrete subgroup of $SL_2(\mathbb{R})$ acting on $\mathcal{H}$ by Möbius transformations. For each $z \in \mathcal{H}$, the stabiliser
\begin{align*}
\Gamma_{0}(N)_z := \{\Gamma \in \Gamma_0(N) : \Gamma z = z\}
\end{align*}
is finite; geometrically these are the elliptic stabilisers, and algebraically they are finite cyclic subgroups after passing to $PSL_2(\mathbb{R})$.
We now verify the hypotheses of the [quotient-surface theorem for properly discontinuous holomorphic actions with finite stabilisers](/page/Riemann%20Surface%20Quotient). First, $\Gamma_0(N)$ maps to a discrete subgroup of $PSL_2(\mathbb{R})$ because it is contained in $SL_2(\mathbb{Z})$, whose entries form a discrete subset of $\mathbb{R}^4$. The [proper discontinuity of Fuchsian group actions](/page/Fuchsian%20Group) then gives proper discontinuity of the action on $\mathcal{H}$. Second, the action is holomorphic because every group element acts by a Möbius transformation. Third, stabilisers are finite: the stabiliser of a point $z \in \mathcal{H}$ in $PSL_2(\mathbb{R})$ is conjugate to $SO(2)$, hence compact, and its intersection with the discrete image of $\Gamma_0(N)$ is finite. Lifting back from $PSL_2(\mathbb{R})$ to $SL_2(\mathbb{R})$ adds at most the two central matrices $I$ and $-I$, so $\Gamma_0(N)_z$ is finite.
All hypotheses of the quotient theorem are therefore satisfied. Applying it gives a Riemann-surface structure on
\begin{align*}
Y_0(N) = \Gamma_0(N)\backslash \mathcal{H}
\end{align*}
and makes the quotient map
\begin{align*}
\pi: \mathcal{H} \to Y_0(N)
\end{align*}
holomorphic.
Finally, $Y_0(N)$ is connected. The upper half-plane $\mathcal{H}$ is connected, the quotient map $\pi$ is continuous by the quotient topology, and $\pi$ is surjective by definition. Hence $Y_0(N)$ is the continuous image of a connected space, so it is connected.[/guided]
custom_env
admin
[step:Identify the finitely many cuspidal ends]
Let
\begin{align*}
\mathbb{P}^1(\mathbb{Q}) := \mathbb{Q} \cup \{\infty\}
\end{align*}
be the rational boundary of $\mathcal{H}$. The set of cusps for $\Gamma_0(N)$ is
\begin{align*}
C_0(N) := \Gamma_0(N)\backslash \mathbb{P}^1(\mathbb{Q}).
\end{align*}
This set is finite. Indeed, $SL_2(\mathbb{Z})$ acts transitively on $\mathbb{P}^1(\mathbb{Q})$, and $\Gamma_0(N)$ has finite index in $SL_2(\mathbb{Z})$, so the number of $\Gamma_0(N)$-orbits in $\mathbb{P}^1(\mathbb{Q})$ is at most $[SL_2(\mathbb{Z}) : \Gamma_0(N)]$.
Choose representatives
\begin{align*}
\alpha_1,\dots,\alpha_m \in \mathbb{P}^1(\mathbb{Q})
\end{align*}
for the finitely many cusps, where
\begin{align*}
m := |C_0(N)|.
\end{align*}
For each $k \in \{1,\dots,m\}$, choose a scaling matrix $\sigma_k \in SL_2(\mathbb{Z})$ satisfying
\begin{align*}
\sigma_k(\infty) = \alpha_k.
\end{align*}
The cusp width $w_k \in \mathbb{N}$ at $\alpha_k$ is the positive generator of the subgroup
\begin{align*}
\{n \in \mathbb{Z} : \sigma_k
\begin{pmatrix}
1 & n \\
0 & 1
\end{pmatrix}
\sigma_k^{-1} \in \Gamma_0(N)\}
\subset \mathbb{Z}.
\end{align*}
This subgroup is nonzero because $\Gamma_0(N)$ has finite index in $SL_2(\mathbb{Z})$, and hence $w_k$ is finite.
[/step]
custom_env
admin
[step:Use the cusp parameter to fill each punctured end]Fix $k \in \{1,\dots,m\}$. Let $w_k$ be the cusp width at $\alpha_k$, and define the holomorphic map
\begin{align*}
q_k: \{z \in \mathcal{H} : \operatorname{Im}(z) > R\} &\to \{q \in \mathbb{C} : 0 < |q| < e^{-2\pi R/w_k}\} \\
z &\mapsto \exp\left(\frac{2\pi i z}{w_k}\right),
\end{align*}
where $R > 0$ is chosen sufficiently large that the corresponding horoball neighbourhoods for the finitely many cusps are disjoint modulo $\Gamma_0(N)$.
The definition of $w_k$ gives invariance under the translation $z \mapsto z+w_k$. We also need injectivity modulo the full group, not only invariance under this one translation. By the [standard cusp-neighbourhood theorem for finite-index subgroups of $SL_2(\mathbb{Z})$](/page/Modular%20Curve%20Cusp), after increasing $R$ if necessary, the only elements of $\Gamma_0(N)$ identifying two points of
\begin{align*}
\sigma_k\{z \in \mathcal{H} : \operatorname{Im}(z) > R\}
\end{align*}
are the elements of the cusp stabiliser
\begin{align*}
\Gamma_0(N)_{\alpha_k} := \{\Gamma \in \Gamma_0(N) : \Gamma \alpha_k = \alpha_k\}.
\end{align*}
Conjugating by $\sigma_k$ identifies this stabiliser, modulo the central sign, with the translation subgroup generated by $z \mapsto z+w_k$. Hence two points in the chosen horoball have the same image in $\Gamma_0(N)\backslash\mathcal{H}$ exactly when their $q_k$-values agree. Therefore $q_k$ descends to a biholomorphic coordinate from the punctured cusp neighbourhood
\begin{align*}
\Gamma_0(N)\backslash \sigma_k\{z \in \mathcal{H} : \operatorname{Im}(z) > R\}
\end{align*}
onto the punctured disc
\begin{align*}
\{q \in \mathbb{C} : 0 < |q| < e^{-2\pi R/w_k}\}.
\end{align*}
Adjoin one point $c_k$ corresponding to $q=0$. This turns the punctured cusp neighbourhood into the full disc
\begin{align*}
\{q \in \mathbb{C} : |q| < e^{-2\pi R/w_k}\}.
\end{align*}
Doing this for all $k \in \{1,\dots,m\}$ defines
\begin{align*}
X_0(N) := Y_0(N) \cup \{c_1,\dots,c_m\}.
\end{align*}
The topology on $X_0(N)$ is generated by the open sets of $Y_0(N)$ together with the full cusp discs in the $q_k$-coordinates. These $q_k$-coordinates are complex charts at the added cusp points. On any overlap with an interior quotient chart $\varphi: U \to V \subset \mathbb{C}$, the transition function has the form $\varphi \circ \pi \circ \sigma_k \circ q_k^{-1}$ on a punctured disc or punctured annulus. It is holomorphic because it is a composition of the inverse exponential branch, a Möbius transformation, the quotient map, and the interior chart. After shrinking the cusp disc, its image lies in the bounded coordinate disc $V$. Hence the [removable singularity theorem](/page/Removable%20Singularity%20Theorem) extends the transition holomorphically across $q=0$ whenever the overlap accumulates at the cusp; on annular overlaps away from $q=0$ no extension is needed. Thus the cusp charts are compatible with the interior quotient atlas.[/step]
custom_env
admin
[guided]Fix a cusp representative $\alpha_k$ and a scaling matrix $\sigma_k \in SL_2(\mathbb{Z})$ satisfying
\begin{align*}
\sigma_k(\infty) = \alpha_k.
\end{align*}
The role of $\sigma_k$ is to move the chosen cusp to $\infty$, where the stabiliser is described by translations. The cusp width $w_k \in \mathbb{N}$ was defined by
\begin{align*}
\{n \in \mathbb{Z} : \sigma_k
\begin{pmatrix}
1 & n \\
0 & 1
\end{pmatrix}
\sigma_k^{-1} \in \Gamma_0(N)\}
= w_k\mathbb{Z}.
\end{align*}
Thus the translation $z \mapsto z+w_k$ is exactly the primitive parabolic identification at the cusp.
Choose $R > 0$ sufficiently large so that the horoball neighbourhoods
\begin{align*}
\sigma_k\{z \in \mathcal{H} : \operatorname{Im}(z) > R\}
\end{align*}
for the finitely many cusp representatives are pairwise disjoint after passing to the quotient by $\Gamma_0(N)$. This is possible because there are only finitely many cusp classes and the action is properly discontinuous away from the boundary.
Define the cusp parameter
\begin{align*}
q_k: \{z \in \mathcal{H} : \operatorname{Im}(z) > R\} &\to \{q \in \mathbb{C} : 0 < |q| < e^{-2\pi R/w_k}\} \\
z &\mapsto \exp\left(\frac{2\pi i z}{w_k}\right).
\end{align*}
This map is invariant under $z \mapsto z+w_k$, because
\begin{align*}
\exp\left(\frac{2\pi i (z+w_k)}{w_k}\right)
=
\exp\left(\frac{2\pi i z}{w_k}\right)\exp(2\pi i)
=
\exp\left(\frac{2\pi i z}{w_k}\right).
\end{align*}
It is also the standard universal covering map from the upper half-strip modulo $w_k\mathbb{Z}$ to a punctured disc. However, to get a coordinate on the quotient by all of $\Gamma_0(N)$, we must know that no additional group elements identify points inside this small horoball. The [standard cusp-neighbourhood theorem for finite-index subgroups of $SL_2(\mathbb{Z})$](/page/Modular%20Curve%20Cusp) gives exactly this after increasing $R$: if two points of
\begin{align*}
\sigma_k\{z \in \mathcal{H} : \operatorname{Im}(z) > R\}
\end{align*}
are equivalent under $\Gamma_0(N)$, then the identifying element lies in the cusp stabiliser
\begin{align*}
\Gamma_0(N)_{\alpha_k} := \{\Gamma \in \Gamma_0(N) : \Gamma \alpha_k = \alpha_k\}.
\end{align*}
Conjugating this stabiliser by $\sigma_k^{-1}$ gives, up to the central sign, the translation group generated by
\begin{align*}
z \mapsto z+w_k.
\end{align*}
Thus $q_k$ is not merely invariant: it separates the equivalence classes in the punctured cusp neighbourhood. Hence it descends to a biholomorphic coordinate from
\begin{align*}
\Gamma_0(N)\backslash \sigma_k\{z \in \mathcal{H} : \operatorname{Im}(z) > R\}
\end{align*}
onto
\begin{align*}
\{q \in \mathbb{C} : 0 < |q| < e^{-2\pi R/w_k}\}.
\end{align*}
We now add one point $c_k$ corresponding to $q=0$. In the $q_k$-coordinate, the punctured disc becomes the full disc
\begin{align*}
\{q \in \mathbb{C} : |q| < e^{-2\pi R/w_k}\}.
\end{align*}
Repeating this construction for all cusp representatives defines
\begin{align*}
X_0(N) := Y_0(N) \cup \{c_1,\dots,c_m\}.
\end{align*}
The topology on $X_0(N)$ is the topology generated by the original open sets of $Y_0(N)$ and these full cusp discs. The charts at the newly added points are the $q_k$-charts.
It remains to justify compatibility with the existing complex structure. Let $\varphi: U \to V \subset \mathbb{C}$ be an interior quotient chart with $U \subset Y_0(N)$ and $V$ chosen to be a bounded coordinate disc. On a punctured overlap with the cusp chart, the transition map is
\begin{align*}
\varphi \circ \pi \circ \sigma_k \circ q_k^{-1}.
\end{align*}
Here $q_k^{-1}$ denotes a local branch of the logarithm inverse to $q_k$, $\sigma_k$ acts by a Möbius transformation, $\pi$ is holomorphic on the interior quotient, and $\varphi$ is holomorphic by definition of the interior atlas. Therefore the transition map is holomorphic on the punctured overlap. If the overlap accumulates at $q=0$, then after shrinking the cusp disc its image lies in the bounded coordinate disc $V$, so the [removable singularity theorem](/page/Removable%20Singularity%20Theorem) extends the transition holomorphically across $q=0$. If the overlap is an annulus bounded away from $q=0$, the transition is already holomorphic on its whole domain. Thus the cusp charts are compatible with the interior atlas, and the filled cusp is a genuine point of a Riemann surface.[/guided]
custom_env
admin
[step:Show the filled quotient is compact]Let
\begin{align*}
\mathcal{F}_R := \mathcal{F} \cap \{z \in \mathcal{H} : \operatorname{Im}(z) \leq R\}
\end{align*}
be the truncated standard fundamental domain, and define
\begin{align*}
\mathcal{K}_R := \bigcup_{j=1}^{r} \gamma_j \mathcal{F}_R.
\end{align*}
The set $\mathcal{F}_R$ is closed and bounded in $\mathbb{C}$, so $\mathcal{K}_R$ is compact because it is a finite union of continuous images of the compact set $\mathcal{F}_R$ under Möbius transformations whose denominators do not vanish on $\mathcal{H}$.
It remains to check that the omitted parts of $\mathcal{D}$ are contained in the cusp neighbourhoods already filled in the previous step. For each $j \in \{1,\dots,r\}$, the point $\gamma_j(\infty) \in \mathbb{P}^1(\mathbb{Q})$ is equivalent under $\Gamma_0(N)$ to exactly one chosen cusp representative $\alpha_{k(j)}$. Choose $\Delta_j \in \Gamma_0(N)$ with
\begin{align*}
\Delta_j \gamma_j(\infty) = \alpha_{k(j)}.
\end{align*}
Then
\begin{align*}
\tau_j := \sigma_{k(j)}^{-1}\Delta_j\gamma_j \in SL_2(\mathbb{Z})
\end{align*}
fixes $\infty$, hence $\tau_j = \pm\begin{pmatrix}1 & n_j \\ 0 & 1\end{pmatrix}$ for some $n_j \in \mathbb{Z}$. Therefore, for the standard tail $\mathcal{F} \cap \{\operatorname{Im}(z)>R\}$,
\begin{align*}
\gamma_j\bigl(\mathcal{F} \cap \{\operatorname{Im}(z)>R\}\bigr)
= \Delta_j^{-1}\sigma_{k(j)}\tau_j\bigl(\mathcal{F} \cap \{\operatorname{Im}(z)>R\}\bigr)
\subset \Delta_j^{-1}\sigma_{k(j)}\{z \in \mathcal{H}: \operatorname{Im}(z)>R\}.
\end{align*}
Since $\Delta_j \in \Gamma_0(N)$, the image of this set in $\Gamma_0(N)\backslash\mathcal{H}$ is contained in the cusp neighbourhood associated to $\alpha_{k(j)}$. Thus the image of $\mathcal{K}_R$ covers the complement of the finitely many open cusp discs
\begin{align*}
\{q \in \mathbb{C} : |q| < e^{-2\pi R/w_k}\},
\qquad
k=1,\dots,m.
\end{align*}
The image of $\mathcal{K}_R$ in $X_0(N)$ is compact because it is the continuous image of a compact set. Each closed cusp disc
\begin{align*}
\{q \in \mathbb{C} : |q| \leq e^{-2\pi R/w_k}\}
\end{align*}
is compact in $\mathbb{C}$. Therefore $X_0(N)$ is covered by finitely many compact sets: the compact image of $\mathcal{K}_R$ together with the finitely many closed cusp discs. Hence $X_0(N)$ is compact.[/step]
custom_env
admin
[guided]The point requiring care is that the unbounded part of the finite union
\begin{align*}
\mathcal{D}=\bigcup_{j=1}^r \gamma_j\mathcal{F}
\end{align*}
does not necessarily lie inside the particular geometric horoballs $\sigma_k\{\operatorname{Im}(z)>R\}$ before passing to the quotient. We therefore truncate the standard fundamental domain first and then identify each omitted tail with one of the chosen cusp neighbourhoods modulo $\Gamma_0(N)$.
Define
\begin{align*}
\mathcal{F}_R := \mathcal{F} \cap \{z \in \mathcal{H} : \operatorname{Im}(z) \leq R\},
\qquad
\mathcal{K}_R := \bigcup_{j=1}^{r} \gamma_j \mathcal{F}_R.
\end{align*}
The set $\mathcal{F}_R$ is closed and bounded in $\mathbb{C}$, hence compact by the [Heine-Borel theorem](/theorems/315). Each matrix $\gamma_j$ acts on $\mathcal{H}$ by a Möbius transformation, and its denominator cannot vanish at a point of $\mathcal{H}$ because such a zero would be real. Hence $\gamma_j$ is continuous on $\mathcal{F}_R$, so $\gamma_j\mathcal{F}_R$ is compact. Since $\mathcal{K}_R$ is a finite union of these compact sets, $\mathcal{K}_R$ is compact.
Now consider one omitted tail
\begin{align*}
\gamma_j\bigl(\mathcal{F} \cap \{\operatorname{Im}(z)>R\}\bigr).
\end{align*}
The endpoint of this tail on the rational boundary is $\gamma_j(\infty)$. By construction of the cusp representatives, there is a unique index $k(j) \in \{1,\dots,m\}$ and an element $\Delta_j \in \Gamma_0(N)$ such that
\begin{align*}
\Delta_j\gamma_j(\infty)=\alpha_{k(j)}.
\end{align*}
Set
\begin{align*}
\tau_j := \sigma_{k(j)}^{-1}\Delta_j\gamma_j.
\end{align*}
Then $\tau_j \in SL_2(\mathbb{Z})$ and $\tau_j(\infty)=\infty$. The stabiliser of $\infty$ in $SL_2(\mathbb{Z})$ consists exactly of the matrices $\pm\begin{pmatrix}1 & n \\ 0 & 1\end{pmatrix}$ with $n \in \mathbb{Z}$, so
\begin{align*}
\tau_j = \pm\begin{pmatrix}1 & n_j \\ 0 & 1\end{pmatrix}
\end{align*}
for some $n_j \in \mathbb{Z}$. Such a matrix preserves imaginary parts. Therefore
\begin{align*}
\gamma_j\bigl(\mathcal{F} \cap \{\operatorname{Im}(z)>R\}\bigr)
= \Delta_j^{-1}\sigma_{k(j)}\tau_j\bigl(\mathcal{F} \cap \{\operatorname{Im}(z)>R\}\bigr)
\subset \Delta_j^{-1}\sigma_{k(j)}\{z \in \mathcal{H}: \operatorname{Im}(z)>R\}.
\end{align*}
Because $\Delta_j \in \Gamma_0(N)$ represents the identity operation after passing to the quotient $\Gamma_0(N)\backslash\mathcal{H}$, this tail maps into the cusp neighbourhood associated to $\alpha_{k(j)}$. Thus every unbounded part removed from $\mathcal{D}$ is accounted for by one of the finitely many filled cusp discs.
The quotient image of $\mathcal{K}_R$ is compact because continuous images of compact spaces are compact. The filled cusp neighbourhood for $\alpha_k$ is represented by the closed disc
\begin{align*}
\{q \in \mathbb{C} : |q| \leq e^{-2\pi R/w_k}\},
\end{align*}
which is compact in $\mathbb{C}$. We have covered $X_0(N)$ by the compact image of $\mathcal{K}_R$ and the finitely many compact closed cusp discs. A finite union of compact subsets is compact, so $X_0(N)$ is compact.[/guided]
custom_env
admin
[step:Conclude connectedness after adjoining the cusp points]
The space $Y_0(N)=\Gamma_0(N)\backslash\mathcal{H}$ is connected by the earlier quotient argument. The compactification $X_0(N)$ is obtained from $Y_0(N)$ by adjoining finitely many cusp points, each of which lies in the closure of a punctured cusp neighbourhood contained in $Y_0(N)$. Thus $Y_0(N)$ is dense in $X_0(N)$.
Since the closure of a connected subset is connected, $X_0(N)=\overline{Y_0(N)}$ is connected. Combining this connectedness with the Riemann-surface structure constructed by the interior quotient charts and the cusp $q$-charts, and with compactness from the previous step, proves that $X_0(N)$ is a compact connected Riemann surface.
[/step]