\setcounter{AlgoLine}{0}
\DontPrintSemicolon
	\KwIn{Set $E$ of items with a dissimilarity function $d(i,j)$ between items $i$ and $j$; $k$ medoids $c_1, \dots, c_k \in E$}
	\KwResult{Clusters $G_1, \dots, G_k \subset E$}
	
	\Repeat{no strict improvement is found\nllabel{pam_repetition}}
	{
		\ForAll{item $i \in E$} 
		{Assign $i$ to the closest medoid, creating clusters $G_1, \dots, G_k \subset E$\nllabel{pam_assign}}
		\ForAll{medoid $c_j$}
		{\ForAll{item $i \in E$}
			{Compute the improvement (or the loss) of a solution where $c_j$ is moved on item $i$\nllabel{pam_exchange}\\
			}
		}
		\If{A strictly positive improvement is found}
		{Move the medoid on the item inducing the largest improvement\nllabel{pam_retain}}
	}

