-- $Id: lists.ghc,v 1.1 2001/06/12 04:47:12 doug Exp $
-- http://www.bagley.org/~doug/shootout/
-- from Michal Gajda

module Main(main) where

import Prelude

copy [] = []
copy (x:xs) = x:copy xs
-- to be honest, in pure functional language the RIGHT
-- thing is copy list = list, because it's not mutable anyway
-- (and the price is paid when doing reverse or (++) anyway)

-- `seq`s below force evaluation of isok1 and isok2
test :: Int -> Int
test size = isok1 `seq` length l3
  where single x = [x]
        l1 = [1..size] 
        l2 = copy l1 -- Should be just: "l1"
        l3 = foldl (++) [] (map single l2)
        l2' = foldr (++) [] (map single l3)
        l1' = reverse l1
        isok1 = head l1' == size
        isok2 = l1' == l2'
  
main = do s <- getLine
          putStrLn . show . test . read $ s