\begin{algo}{DuvalFactorization}{w,n}
  \IN{$w$ a word of length $n$}
  \OUT{starting positions of the factors in the \CUT
       Chen-Fox-Lyndon factorization of $w$}
  \SET{k}{-1}
  \DOWHILE{k < n-1}
    \SET{i}{k+1}
    \SET{j}{k+2}
    \DOWHILE{j < n \AND w_i \leq w_j}
      \IF{w_i < w_j}
        \SET{i}{k+1}
      \ELSE
        \INC{i}
      \FI
      \INC{j}
    \OD
    \DOWHILE{k < i}
      \CALL{output}{k+1}
      \SET{k}{k+j-i}
    \OD
  \OD
\end{algo}
