import Data.List ( foldl' , indexElem , nub )