
import Data.Char (toLower)

rotations [] = []
rotations xs = map (take $ length xs) $ rot (length xs) (cycle xs)
    where rot 1 xs = []
          rot n (x:xs) = xs : rot (n - 1) xs

lyndon s = all (> s) (rotations s)

main = interact $ unlines . filter (lyndon . map toLower) . lines

