result :: Int
result = IS.findMin $ head sortedLoopGroups
  where
    -- sort by descending group size to find the maximum
    sortedLoopGroups = sortOn (Down . IS.size) loopGroups
    loopGroups :: [IS.IntSet]
    loopGroups = unfoldr go loopMapInit
    go loopMap =
      if IS.null grp
        then Nothing
        else Just (grp, loopMap')
      where
        (grp, loopMap') = extractLoop loopMap
result :: Int
result = IS.findMin $ head sortedLoopGroups
  where
    -- sort by descending group size to find the maximum
    sortedLoopGroups = sortOn (Down . IS.size) loopGroups
    loopGroups :: [IS.IntSet]
    loopGroups = unfoldr go loopMapInit
    go loopMap =
      if IS.null grp
        then Nothing
        else Just (grp, loopMap')
      where
        (grp, loopMap') = extractLoop loopMap
result = IS.findMin $ head sortedLoopGroups
  where
    -- sort by descending group size to find the maximum
    sortedLoopGroups = sortOn (Down . IS.size) loopGroups
    loopGroups :: [IS.IntSet]
    loopGroups = unfoldr go loopMapInit
    go loopMap =
      if IS.null grp
        then Nothing
        else Just (grp, loopMap')
      where
        (grp, loopMap') = extractLoop loopMap