\begin{equation}
\def\arraystretch{1.3}
\begin{array}{@{}lll@{}}
\toprule
& \multicolumn{2}{c@{}}{\text{Algorithm 2 (Pseudo-code for IRS allocation and alternating beamforming)}} \\
\cmidrule(l){2-3}
1 & Initialization: Random\, \boldsymbol{\Phi},{\textbf{\textit{W}}}, \mathcal{N}_0 = \{ 1,2,...,N \}, \mathcal{N}_k = \phi, 1 \leq k \leq K\\
2 & \textbf{repeat} \\
3 & With\; \alpha_k=\frac{1}{\abs{\textbf{\textit{h}}^H_{d,k}{\textbf{\textit{w}}}_{k}}}, set\; \ell_k=[N\frac{\alpha_k}{\sum_{i=1}^{K}\alpha_i}] \;with\; remainders\; as\; (6)\\
4 & Order\; UEs\; as\; \alpha_{m_1}\geq\alpha_{m_2}\geq...\geq\alpha_{m_K} \\
5 & \textbf{for}\; i=1\; \textbf{to}\; K\; \textbf{do} \\
6 & \textbf{repeat}\\
7 & n_0=argmax_n\abs{{f}_{n,m_i}^{*}\textbf{\textit{g}}_n^{H}\textbf{\textit{w}}_{m_i}},n \in \mathcal{N}_0\\
8 & \mathcal{N}_{m_i} = \mathcal{N}_{m_i}+\{n_0\},\; \mathcal{N}_0 = \mathcal{N}_0-\{n_0\}\\
9 & \textbf{until}\; Iteration\; is\; repeated\; \ell_{m_i}\; number\; of\; times\; \\
10 & \textbf{for}\; k=1\; \textbf{to}\; K\; \textbf{do}\\
11 & \textbf{repeat}\\
12 & \angle{\theta_{n_k}}=-\angle{(\textbf{\textit{h}}^H_{d,k}{\textbf{\textit{w}}}_{k})}-\angle{{f}_{n_k,k}}+\angle{(\textbf{\textit{g}}^H_{n,k}{\textbf{\textit{w}}}_{k})}\\
13 & \mathcal{N}_{k} = \mathcal{N}_{k}-\{n_k\},\; \mathcal{N}_0 = \mathcal{N}_0+\{n_k\}\\
14 & \textbf{until}\; \mathcal{N}_{k} = \phi \\
15 & Update\; transmit\; beamformer\; {\textbf{\textit{W}}}\; using\; effective\; channel\; formed\; by\; \boldsymbol{\Phi}\\
16 & \textbf{until}\; Iteration\; is\; repeated\; V>0\; number\; of\; times\; \\
\bottomrule
\end{array}
\end{equation}