import Data.List

collect :: Int -> IO [(Int,(Int,Int))]
collect n = zip [1..n] <$> geniof (\(x:y:ls) -> (x,y)) n

cdigit :: Int -> Int
cdigit n | (n`div`10 == 0) = 1
         | otherwise       = 1+(n`div`10)

rewrite :: Int -> [(Int,(Int,Int))] -> [(Int,String)]
rewrite _ [] = []
rewrite c ((a,(p,y)):ls) = let
   id6 = take (6-(cdigit p)) (repeat '0')  ++ (show p) ++ take (6-(cdigit c)) (repeat '0') ++  (show c)
   in if ls == [] || (fst.snd.head $ ls) == p
         then (a,id6) : rewrite (c+1) ls
         else (a,id6) : rewrite 1 ls

writedownf :: (a -> String) -> [a] -> IO ()
writedownf _ [] = return ()
writedownf f (x:xs) = putStrLn (f x) >> writedownf f xs

writedown ::  [String] -> IO ()
writedown = writedownf id