fork download
  1. import qualified Data.Map as M
  2. main = do
  3. let m = M.fromListWith (+) $ zip xs (repeat 1)
  4. (a,b) = M.partitionWithKey (\k _ -> reverse k == k) m
  5. (c,d) = M.partitionWithKey (\k _ -> reverse k > k) b
  6. s = concatMap (\(k,x) -> concat $ replicate x k) $ M.toAscList
  7. $ M.union (M.map (`div`2) a) (M.intersectionWith min c (M.mapKeys reverse d))
  8. putStrLn $ s ++ concat (take 1 [k | (k,x) <- M.toAscList a, odd x]) ++ reverse s
Success #stdin #stdout 0s 8388607KB
stdin
6
fdk
jnv
vnj
kdf
qaq
bhh
stdout
fdkjnvqaqvnjkdf