{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns #-}

import           Control.Applicative
import qualified Data.ByteString.Char8 as B
import           Data.Char

main :: IO ()
main = do
    [_, t] <- map read.words <$> getLine :: IO [Int]
    (xs, ys) <- B.span (/= '.') . B.filter (not.isSpace) <$> B.getLine
    putStr $ solve t xs . tail $ B.unpack ys

solve :: Int -> B.ByteString -> String -> String
solve _ xs (y:ys) | '4' < y = plusOne xs
solve t xs ('4':ys)
    | null rs || head rs < '4' || t <= lf = B.unpack xs ++ '.':solve' t 1 'x' ys
    | otherwise = plusOne xs
  where
    (fs, rs) = span ('4'==) ys
    lf = length fs + 1
    flg = case takeWhile ('4'<=) ys of
        [] -> False
        zs -> any ('4'<) zs
solve t xs (y:ys) = B.unpack xs ++ '.':solve' t 0 y ys

solve' = go
  where
    go 0 0 z zs = z:zs
    go 0 f p zs = [p | p/='x'] ++ replicate f '4' ++ zs
    go !t 0 p (z:zs)
      | '4' < z = [succ p]
      | z == '4' = go t 1 p zs
      | otherwise = p : go t 0 z zs
    go !t !f p (z:zs)
      | '4' < z, t >= f + 1 , p /= 'x' = [succ p]
      | '4' < z = [p | p/='x'] ++ replicate (max 0 $ f-t) '4' ++ "5"
      | z == '4' = go t (f + 1) p zs
      | otherwise = [p | p/='x'] ++ replicate f '4' ++ go t 0 z zs
    go _ f p "" | f > 0 = p : replicate f '4'
    go _ _ p "" = [p]
    go _ _ _ "" = ""

plusOne :: B.ByteString -> String
plusOne bs
  | Just (x, _) <- B.readInteger bs = show $ x + 1
  | otherwise = error "readInteger"

import Data.List
import Control.Monad (liftM)

solve :: Int -> String -> String
solve n q = case findIndex (>= '5') s of
    Nothing -> q
    Just ix -> unparse p . reverse . carry n . reverse $ take (succ ix) s
    where (p, v) = break (=='.') q
          s = tail v

carry :: Int -> String -> String
carry 0  s  = s
carry _ [x] = [x | x < '5']
carry n ('9' : s) = case dropWhile (=='9') s of
    (x:xs) -> carry (pred n) (succ x : xs)
    []     -> []
carry n s@(x:y:r) = if x >= '5' then carry (pred n) (succ y : r) else s

unparse :: String -> String -> String
unparse p s = case s of
    [] -> increment p
    xs -> p ++ "." ++ s

increment :: String -> String
increment s = case fx of
    []     -> '1' : zeros
    (x:xs) -> reverse xs ++ [succ x] ++ zeros
    where (px, fx) = span (== '9') $ reverse s
          zeros = replicate (length px) '0'

main = liftM words getLine >>= \[_, n] -> getLine >>= putStrLn . solve (read n)

{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns #-}

import           Control.Applicative

main :: IO ()
main = do
    [_, t] <- map read.words <$> getLine :: IO [Int]
    (xs, _:ys) <- span (/= '.') <$> getLine
    putStr $ solve t xs ys

solve :: Int -> String -> String -> String
solve _ xs (y:ys) | '4' < y = show $ (read xs :: Integer) + 1
solve t xs ('4':ys)
    | null rs || head rs < '4' || t <= lf = xs ++ "." ++ solve' t 1 'x' ys
    | otherwise = show $ (read xs :: Integer) + 1
  where
    (fs, rs) = span ('4'==) ys
    lf = length fs + 1
    flg = case takeWhile ('4'<=) ys of
        [] -> False
        zs -> any ('4'<) zs
solve t xs (y:ys) = xs ++ "." ++ solve' t 0 y ys

solve' t f x xs = go t f x xs
  where
    go 0 0 z zs = z:zs
    go 0 f 'x' zs = replicate f '4' ++ zs
    go 0 f p zs = p:replicate f '4' ++ zs
    go !t 0 p (z:zs)
      | '4' < z = [succ p]
      | z == '4' = go t 1 p zs
      | otherwise = go t 0 z zs
    go !t !f p (z:zs)
      | '4' < z, t >= f + 1 , p /= 'x' = [succ p]
      | '4' < z = [p | p/='x'] ++ replicate (max 0 $ f-t) '4' ++ "5"
      | z == '4' = go t (f + 1) p zs
      | otherwise = replicate f '4' ++ go t 0 z zs
    go _ f p "" | f > 0 = p:replicate f '4'
    go _ _ p "" = [p]
    go _ _ _ zs = zs

{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns #-}

import           Control.Applicative

main :: IO ()
main = do
    [_, t] <- map read.words <$> getLine :: IO [Int]
    (xs, _:ys) <- span (/= '.') <$> getLine
    putStr $ solve t xs ys

solve :: Int -> String -> String -> String
solve _ xs (y:ys) | '4' < y = show $ (read xs :: Integer) + 1
solve t xs ('4':ys)
    | null rs || head rs < '4' || t <= lf = xs ++ "." ++ solve' t 1 'x' ys
    | otherwise = show $ (read xs :: Integer) + 1
  where
    (fs, rs) = span ('4'==) ys
    lf = length fs + 1
    flg = case takeWhile ('4'<=) ys of
        [] -> False
        zs -> any ('4'<) zs
solve t xs (y:ys) = xs ++ "." ++ solve' t 0 y ys

solve' t f x xs = go t f x xs
  where
    go 0 0 z zs = z:zs
    go 0 f 'x' zs = replicate f '4' ++ zs
    go 0 f p zs = p:replicate f '4' ++ zs
    go !t 0 p (z:zs)
      | '4' < z = [succ p]
      | z == '4' = go t 1 p zs
      | otherwise = p:go t 0 z zs
    go !t !f p (z:zs)
      | '4' < z, t >= f + 1 , p /= 'x' = [succ p]
      | '4' < z = [p | p/='x'] ++ replicate (max 0 $ f-t) '4' ++ "5"
      | z == '4' = go t (f + 1) p zs
      | otherwise = replicate f '4' ++ go t 0 z zs
    go _ f p "" | f > 0 = p:replicate f '4'
    go _ _ p "" = [p]
    go _ _ _ zs = zs

import Data.List
import Control.Monad (liftM)

solve :: Int -> String -> String
solve n q = case findIndex (>= '5') (tail s) of
    Nothing -> unparse t s
    Just ix -> let s' = reverse . carry n . reverse $ take (ix + 2) s
                in unparse (t + fromEnum (head s' == '1' && head s == '9')) s'
    where s = delete '.' q
          Just t = elemIndex '.' q

carry :: Int -> String -> String
carry 0  s  =  s
carry _ [ ] = [ ]
carry _ [x] = [x]
carry n ('9' : s) = case dropWhile (=='9') s of
    []     -> ['1']
    (x:xs) -> carry (pred n) (succ x : xs)
carry n s@(x:y:r) = if x >= '5' then carry (pred n) (succ y : r) else s

unparse :: Int -> String -> String
unparse n s = if d >= 0
                then s ++ replicate d '0'
                else let (u, v) = splitAt n s in u ++ ['.'] ++ v
    where d = n - length s

main = liftM words getLine >>= \[_, n] -> getLine >>= putStrLn . solve (read n)

import Data.List
import Control.Monad (liftM)

solve :: Int -> String -> String
solve n q = case findIndex (>= '5') s of
    Nothing -> q
    Just ix -> unparse p . reverse . carry n . reverse $ take (succ ix) s
    where (p, v) = break (=='.') q
          s = tail v

carry :: Int -> String -> String
carry 0  s  = s
carry _ [x] = [x | x < '5']
carry n ('9' : s) = case dropWhile (=='9') s of
    (x:xs) -> carry (pred n) (succ x : xs)
    []     -> []
carry n s@(x:y:r) = if x >= '5' then carry (pred n) (succ y : r) else s

unparse :: String -> String -> String
unparse p s = case s of
    [] -> increment p
    xs -> p ++ "." ++ s

increment :: String -> String
increment s = case fx of
    []     -> '1' : zeros
    (x:xs) -> xs ++ [succ x] ++ zeros
    where (px, fx) = span (== '9') $ reverse s
          zeros = replicate (length px) '0'

main = liftM words getLine >>= \[_, n] -> getLine >>= putStrLn . solve (read n)


main = do
  (n:as) <- map read . words <$> getContents
  print $ maximum as - minimum as - n + 1

maxMinFold :: Ord a => [a] -> (a, a)
maxMinFold (x:xs) =
  foldr (\x (tailMin, tailMax) -> (min x tailMin, max x tailMax)) (x,x) xs

main = do
       input1 <- getLine
       input2 <- getLine
       let num = (read input1 :: Int)
       let l = map (read :: String -> Int) . words $ input2
       let (a,b) = maxMinFold l
       let res = b - a - num + 1
       putStr (show res)

import Control.Applicative
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readIntBS = fst . fromJust . BS.readInt

main = do
  n <- readLn :: IO Int
  xs <- map read . words <$> getLine :: IO [Int]

  print $ maximum xs - minimum xs + 1 - n

-- Codeforces 1041A

main :: IO ()
main = do
    n <- getLine >>= return.read :: IO Int
    as <- getLine >>= return.(map read).words :: IO [Int]
    putStrLn $ show (maximum as - minimum as - n + 1)

import Data.List
import Control.Monad

main = do
    let solution = sum . (\x-> zipWith (\x y->x-y-1) (tail x) x ) . sort
        int x =  read x ::Int
    l <-  getLine >>= return . int
    as <- getLine >>=  return . map int . words
    print $ solution as

import Data.List

main=do
     e1<-getLine
     es<-getLine
     let xs=map read (words es)::[Int]
         a=read e1::Int
     print $ (maximum xs)-(minimum xs)-a+1

import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
second xs = map fst $ filter (even . snd) $ zip xs [1..]

solve :: [Int] -> Int
solve xs = (l - f + 1) - n
    where ys = sort xs
          f  = head ys
          l  = last ys
          n  = length xs

main :: IO ()
main = do
    _ <- getLine
    v <- readInts
    print $ solve v

main = getContents >>= print . solve . map read . words

solve (n:as) = maximum as - minimum as + 1 - n

import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe
import Data.Array

main= do
		getLine
		a<- map read <$> words <$> getLine ::IO [Int]
		let mi = minimum a
		let ma = maximum a
		print $ (ma-mi)+1-(length a)

main :: IO ()
main = interact (solve . lines)

solve :: [String] -> String
solve s = show $ solve' $  last s

solve' line =
 let nums = map (read :: String -> Integer) (words line)
     nmax = maximum nums
     nmin = minimum nums in
     nmax - nmin + 1 - (toInteger (length nums))

process :: [Int] -> Int
process xs = (maximum xs - minimum xs + 1) - length xs

readInt :: String -> Int
readInt = read

main = do
    n <- fmap readInt getLine
    xs <- fmap (map readInt.words) getLine
    print $ process xs


import Data.List

hail :: Integer -> String -> Integer
hail n [] = 0
hail n ('h':'e':'a':'v':'y':xs) = hail (n `seq` n+1) xs
hail n ('m':'e':'t':'a':'l':xs) = n + hail n xs
hail n s = hail n (tail s)

main = interact $ show . hail 0

{-# LANGUAGE PatternGuards #-}

import Control.Concurrent
import Control.Monad
import System.IO
import Text.Printf
import System.Environment

main = subMain

handler:: String -> [Int] -> Integer -> Integer -> Integer
handler ('h':str) result heavyCount metallCount = findHeavy str result heavyCount metallCount
handler ('m':str) result heavyCount metallCount = findMetal str result heavyCount metallCount
handler (_:str) result heavyCount metallCount = handler str result heavyCount metallCount
handler [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0

findHeavy:: String -> [Int] -> Integer -> Integer -> Integer
findHeavy ('e':('a':('v':('y':str))))result heavyCount metallCount = handler str (0:result)(heavyCount + 1) metallCount
findHeavy [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0
findHeavy str result heavyCount metallCount = handler str result heavyCount metallCount

findMetal:: String -> [Int] -> Integer -> Integer -> Integer
findMetal ('e':('t':('a':('l':str))))result heavyCount metallCount = handler str (1:result) heavyCount (metallCount + 1)
findMetal [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0
findMetal str result heavyCount metallCount = handler str result heavyCount metallCount

checkResult:: [Int] -> Integer -> Integer -> Integer ->Integer
--checkResult x heavyCount metallCount count = (x, heavyCount, metallCount)
checkResult (0:xs) heavyCount metallCount count = checkResult xs (heavyCount-1) metallCount (count+metallCount)
checkResult (1:xs) heavyCount metallCount count = checkResult xs heavyCount (metallCount-1) (count)
checkResult _ _ 0 count = count
checkResult _ 0 _ count = count
checkResult [] _ _ count = count

subMain = do
  text <- getLine
  print $ handler text [] 0 0

---------------
-----------------------------------------------------------------------------

---------------
-----------------------------------------------------------------------------

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8 as C
import Control.Applicative ((<$>))

calc' :: Integer -> Int -> C.ByteString -> Integer
--calc' r _ ss | C.length ss < 5 = r
--calc' r h ss = let (p,q) = C.splitAt 5 ss in
--  if p == "heavy"
--    then calc' r (h+1) q
--    else if p == "metal"
--           then calc' (r+h) h q
--           else if C.length q < 5 then r else calc' r h $ C.dropWhile f ss
--           where f x = and $ map (/= x) ['h','m']

calc' r _ ss | C.length ss < 5        = r
calc' r h ss | C.take 5 ss == "heavy" = calc' r (h+1) $ C.drop 5 ss
             | C.take 5 ss == "metal" = calc' (r+(toInteger h)) h $ C.drop 5 ss
             | otherwise              = calc' r h $ C.dropWhile f (C.tail ss)
                 where f x = and $ map (/= x) ['h','m']

--calc' r h ('h':'e':'a':'v':'y':ss) = calc' r (h+1) ss
--calc' r h ('m':'e':'t':'a':'l':ss) = calc' (r+h) h ss
--calc' r h (_:ss)                   = calc' r h (dropWhile f ss)
--          where f x = and $ map (/= x) ['h','m']

calc :: C.ByteString -> Integer
calc = calc' 0 0

main = print =<< calc <$> C.getLine

energy :: String -> Integer
energy str = energy' 0 str
  where energy' _ "" = 0
        energy' heavys ('h':'e':'a':'v':'y':rest) = energy' (succ heavys) rest
        energy' heavys ('m':'e':'t':'a':'l':rest) = heavys + energy' heavys rest
        energy' heavys (_:rest) = energy' heavys rest

main = do
  str <- getLine
  putStrLn $ show (energy str)

{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns, ViewPatterns, TupleSections, OverloadedStrings #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Array.Base
import Data.Array.ST (runSTUArray)

main :: IO ()
main = B.getLine>>=print.solve.head.B.words

solve :: B.ByteString -> Integer
solve bs = go 0 0 bs
   where
     !n = B.length bs
     !ms = metal n bs
     go !i !res xs
       | B.null xs = res
       | B.isPrefixOf "heavy" xs = go (i+5) (res+fromIntegral(unsafeAt ms (i+5))) $ B.drop 5 xs
       | otherwise = go (i+1) res $ B.tail xs

metal :: Int -> B.ByteString -> UArray Int Int
metal n bs = runSTUArray $ do
  a <- newArray (0,n+100) 0 :: ST s (STUArray s Int Int)
  let go !i xs
        | B.isPrefixOf"metal"xs = do
             unsafeWrite a i 1
             go (i+5) $ B.drop 5 xs
        | B.null xs = return ()
        | otherwise = go (i+1) $ B.tail xs
  go 0 bs
  forM_ [n-1,n-2..1] $ \i-> do
    ai <- unsafeRead a i
    unsafeRead a(i-1)>>=unsafeWrite a (i-1).(ai+)
  return a

import Data.List

pre str i = isPrefixOf "heavy" (drop (i-1) str)
suf str i = isSuffixOf "metal" (take i str)

{--
solve str = pair 0 ss tt
    where len = length str
          ss = filter (pre str) [1..len]
          tt = filter (suf str) [1..len]
          pair sum s@(x:xs) t@(y:ys)
            | x + 4 <= y = pair ( sum + (length t) ) xs t
            | otherwise = pair sum s ys
          pair sum _ _ = sum
--}

solve str = solve' 0 str
    where solve' sum ('h':'e':'a':'v':'y':xs) = solve' (sum+1) xs
          solve' sum ('m':'e':'t':'a':'l':xs) = sum + solve' sum xs
          solve' sum (x:xs) = solve' sum xs
          solve' _ _ = 0
main = do
    interact $ show . solve

import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set

main :: IO ()
main = do
  s <- BS.getLine
  print $ rush s

rush :: BS.ByteString -> Integer
rush s = let heads = BS.findSubstrings (BS.pack "heavy") s
             tails = BS.findSubstrings (BS.pack "metal") s
             headSet = Set.fromAscList heads
             f t acc = acc + fromIntegral (Set.size (fst (Set.split t headSet)))
         in
             foldr f 0 tails

import Data.Int
import qualified Data.ByteString.Char8 as C

main :: IO()
main = do
	str <- C.getLine
	let pre = C.findSubstrings (C.pack "heavy") str
	    suf = C.findSubstrings (C.pack "metal") str
	print $ solve pre suf (length suf) (0::Int64)
	where
		solve [] _ _ s = s
		solve _ [] _ s = s
		solve a@(ah:at) b@(bh:bt) c s
			| ah < bh = solve at b c (s + fromIntegral c)
			| otherwise = solve a bt (c-1) s

import Data.Int
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  str <- C.getLine
  let pre = C.findSubstrings (C.pack "heavy") str
      suf = C.findSubstrings (C.pack "metal") str
  print $ gao pre suf (length suf) (0::Int64)
  where
    gao [] _ _ s = s
    gao _ [] _ s = s
    gao a@(ah:at) b@(bh:bt) c s
      | ah < bh   = gao at b c (s + fromIntegral c)
      | otherwise = gao a bt (c - 1) s

import Data.List

main = do
    line <- getLine
    let heavyBits = getOccuranceBits line "heavy"
    let metalBits = getOccuranceBits line "metal"
    let heavyScan = scanl1 (+) (heavyBits)
    let answerScan = zipWith (\x y -> if (y == 0) then 0 else x) heavyScan metalBits
    print (sum answerScan)

getOccuranceBits :: [Char] -> [Char] -> [Integer]
getOccuranceBits [] _ = []
getOccuranceBits (c:cs) (pattern) = now : (getOccuranceBits cs pattern) where
    now = if (isPrefixOf (pattern) (c:cs)) then 1 else 0

import Data.List

main = do
    line <- getLine
    let heavyBits = getOccuranceBits line "heavy"
    let metalBits = getOccuranceBits line "metal"
    let heavyScan = scanl1 (+) (heavyBits)
    let answerScan = zipWith (*) heavyScan metalBits
    print (sum answerScan)

getOccuranceBits :: [Char] -> [Char] -> [Integer]
getOccuranceBits [] _ = []
getOccuranceBits (c:cs) (pattern) = now : (getOccuranceBits cs pattern) where
    now = if (isPrefixOf (pattern) (c:cs)) then 1 else 0

import qualified Data.ByteString as B

main :: IO ()
main = print . solve 0 0 =<< B.getLine

solve :: Integer -> Integer -> B.ByteString -> Integer
solve s h xs
  | heavy `B.isPrefixOf` xs = seq hh $ solve s hh (B.drop 5 xs)
  | metal `B.isPrefixOf` xs = seq ss $ solve ss h (B.drop 5 xs)
  | B.null xs = s
  | otherwise = solve s h (B.tail xs)
  where
  hh = h + 1
  ss = s + h

heavy :: B.ByteString
heavy = B.pack [104,101,97,118,121]

metal :: B.ByteString
metal = B.pack [109,101,116,97,108]

import Control.Monad (liftM)
import Data.Array ((!), listArray)
import Prelude hiding (reads)

reads :: Read a => IO [a]
reads  =  liftM (map read . words) getLine

solve :: String -> Integer
solve s  =  sum [d ! i | i <- [1..n], d ! i == d ! (i-1)]
  where
    n  =  length $ solve' s
    d  =  listArray (0, n) $ scanl (+) 0 $ solve' s
    solve' ""  =  []
    solve' ('h':'e':'a':'v':'y':s)  =  1 : solve' s
    solve' ('m':'e':'t':'a':'l':s)  =  0 : solve' s
    solve' s  =  solve' $ tail s

main :: IO ()
main  =  getLine >>= print . solve

import Data.List

main = do
    line <- getLine
    let heavyBits = getOccuranceBits line "heavy"
    let metalBits = getOccuranceBits line "metal"
    let heavyScan = scanl1 (+) (heavyBits)
    let answerScan = zipWith (\x y -> if (y == 0) then 0 else x) heavyScan metalBits
    print (sum answerScan)

getOccuranceBits :: [Char] -> [Char] -> [Int]
getOccuranceBits [] _ = []
getOccuranceBits (c:cs) (pattern) = now : (getOccuranceBits cs pattern) where
    now = if (isPrefixOf (pattern) (c:cs)) then 1 else 0

import qualified Data.ByteString as B

main :: IO ()
main = print . solve 0 =<< B.getLine

solve :: Int -> B.ByteString -> Int
solve h xs
  | heavy `B.isPrefixOf` xs = solve (h + 1) (B.drop 5 xs)
  | metal `B.isPrefixOf` xs = h + solve h (B.drop 5 xs)
  | B.null xs = 0
  | otherwise = solve h (B.tail xs)

heavy :: B.ByteString
heavy = B.pack [104,101,97,118,121]

metal :: B.ByteString
metal = B.pack [109,101,116,97,108]

{-# LANGUAGE PatternGuards #-}

import Control.Concurrent
import Control.Monad
import System.IO
import Text.Printf
import System.Environment

main = subMain

handler:: String -> [Int] -> Integer -> Integer -> Integer
handler ('h':str) result heavyCount metallCount = findHeavy str result heavyCount metallCount
handler ('m':str) result heavyCount metallCount = findMetal str result heavyCount metallCount
handler (_:str) result heavyCount metallCount = handler str result heavyCount metallCount
handler [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0

findHeavy:: String -> [Int] -> Integer -> Integer -> Integer
findHeavy ('e':('a':('v':('y':str))))result heavyCount metallCount = handler str (0:result)(heavyCount + 1) metallCount
findHeavy (_:str) result heavyCount metallCount = handler str result heavyCount metallCount
findHeavy [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0

findMetal:: String -> [Int] -> Integer -> Integer -> Integer
findMetal ('e':('t':('a':('l':str))))result heavyCount metallCount = handler str (1:result) heavyCount (metallCount + 1)
findMetal (_:str) result heavyCount metallCount = handler str result heavyCount metallCount
findMetal [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0

checkResult:: [Int] -> Integer -> Integer -> Integer ->Integer
checkResult (0:xs) heavyCount metallCount count = checkResult xs (heavyCount-1) metallCount (count+metallCount)
checkResult (1:xs) heavyCount metallCount count = checkResult xs heavyCount (metallCount-1) (count)
checkResult _ _ 0 count = count
checkResult _ 0 _ count = count
checkResult [] _ _ count = count

subMain = do
  text <- getLine
  print $ handler text [] 0 0

---------------
-----------------------------------------------------------------------------

---------------
-----------------------------------------------------------------------------

{-# LANGUAGE PatternGuards #-}

import Control.Concurrent
import Control.Monad
import System.IO
import Text.Printf
import System.Environment

main = subMain

handler ('h':str) result heavyCount metallCount = findHeavy str result heavyCount metallCount
handler ('m':str) result heavyCount metallCount = findMetal str result heavyCount metallCount
handler (_:str) result heavyCount metallCount = handler str result heavyCount metallCount
handler [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0

findHeavy ('e':('a':('v':('y':str))))result heavyCount metallCount = handler str (0:result)(heavyCount + 1) metallCount
findHeavy (_:str) result heavyCount metallCount = handler str result heavyCount metallCount
findHeavy [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0

findMetal ('e':('t':('a':('l':str))))result heavyCount metallCount = handler str (1:result)heavyCount(metallCount + 1)
findMetal (_:str) result heavyCount metallCount = handler str result heavyCount metallCount
findMetal [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0

checkResult (0:xs) heavyCount metallCount count = checkResult xs (heavyCount-1) metallCount (count+metallCount)
checkResult (1:xs) heavyCount metallCount count = checkResult xs heavyCount (metallCount-1) (count)
--checkResult _ _ 0 count = count
--checkResult _ 0 _ count = count
checkResult [] _ _ count = count

subMain = do
  text <- getLine
  print $ handler text [] 0 0

---------------
-----------------------------------------------------------------------------

{-# LANGUAGE PatternGuards #-}

import Control.Concurrent
import Control.Monad
import System.IO
import Text.Printf
import System.Environment

main = subMain

handler ('h':str) result heavyCount metallCount = findHeavy str result heavyCount metallCount
handler ('m':str) result heavyCount metallCount = findMetal str result heavyCount metallCount
handler (_:str) result heavyCount metallCount = handler str result heavyCount metallCount
handler [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0

findHeavy ('e':('a':('v':('y':str))))result heavyCount metallCount = handler str (0:result)(heavyCount + 1) metallCount
findHeavy (_:str) result heavyCount metallCount = handler str result heavyCount metallCount
findHeavy [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0

findMetal ('e':('t':('a':('l':str))))result heavyCount metallCount = handler str (1:result)heavyCount(metallCount + 1)
findMetal (_:str) result heavyCount metallCount = handler str result heavyCount metallCount
findMetal [] result heavyCount metallCount = checkResult (reverse result) heavyCount metallCount 0

checkResult (0:xs) heavyCount metallCount count = checkResult xs (heavyCount-1) metallCount (count+metallCount)
checkResult (1:xs) heavyCount metallCount count = checkResult xs heavyCount (metallCount-1) (count)
checkResult _ _ 0 count = count
checkResult _ 0 _ count = count
checkResult [] _ _ count = count

subMain = do
  text <- getLine
  print $ handler text [] 0 0

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8 as C
import Control.Applicative ((<$>))

calc' :: Int -> Int -> C.ByteString -> Int
--calc' r _ ss | C.length ss < 5 = r
--calc' r h ss = let (p,q) = C.splitAt 5 ss in
--  if p == "heavy"
--    then calc' r (h+1) q
--    else if p == "metal"
--           then calc' (r+h) h q
--           else if C.length q < 5 then r else calc' r h $ C.dropWhile f ss
--           where f x = and $ map (/= x) ['h','m']

calc' r _ ss | C.length ss < 5        = r
calc' r h ss | C.take 5 ss == "heavy" = calc' r (h+1) $ C.drop 5 ss
             | C.take 5 ss == "metal" = calc' (r+h) h $ C.drop 5 ss
             | otherwise              = calc' r h $ C.dropWhile f (C.tail ss)
                 where f x = and $ map (/= x) ['h','m']

--calc' r h ('h':'e':'a':'v':'y':ss) = calc' r (h+1) ss
--calc' r h ('m':'e':'t':'a':'l':ss) = calc' (r+h) h ss
--calc' r h (_:ss)                   = calc' r h (dropWhile f ss)
--          where f x = and $ map (/= x) ['h','m']

calc :: C.ByteString -> Int
calc = calc' 0 0

main = print =<< calc <$> C.getLine


import Control.Arrow
import Data.List

main = interact $ words >>> drop 1 >>> map (read >>> solve >>> show) >>> unlines

ordinary :: [Integer]
ordinary = [d*(10^l - 1) `div` 9 | d <- [1..9], l <- [1..9]]

solve :: Integer -> Int
solve n = length $ filter (<= n) ordinary

import Control.Monad

main = do
    t <- read <$> getLine
    replicateM_ t $ getLine >>= print . solve

solve :: [Char] -> Int
solve x = length x * 9 + read [head x] - 10 + fromEnum (x >= t)
    where t = replicate (length x) (head x)

import Control.Monad

printResult = do
    s <- getLine
    let
        l = length s
        n = read s :: Int
        b = read $ replicate l '1' :: Int
        r = (l-1) * 9 + div n b
    print r

main = do
    t <- readLn :: IO Int
    replicateM_ t printResult

import qualified Data.Set as Set
import Data.List
import Control.Monad

readInts = fmap (map read.words) getLine :: IO [Int]

createString 0 = ""
createString n = "1" ++ createString (n-1)

printS = do
    n<-getLine
    let s = createString (length n)
        x = read s :: Int
        y = read n :: Int
    print $ (length n - 1) * 9 + (div y x)

main = do
    t<-readLn
    replicateM_ t printS

import Control.Monad

main = do
    t <- read <$> getLine
    replicateM_ t $
        getLine >>=
        print . \x ->
            length x * 9 + read [head x] - 10 + fromEnum (head x == minimum x)


import Control.Monad

main :: IO ()
main = do
    t <- readLn
    replicateM_ t process

process :: IO ()
process = do
    n <- (readLn :: IO Int)
    line <- getLine
    let a = map read (words line)
    line <- getLine
    let b = map read (words line)
    let c = maximum (zipWith min a b)
    let d = maximum (zipWith max a b)
    print (c * d)

import Control.Monad

main :: IO ()
main = do
    t <- readLn
    replicateM_ t process

process :: IO ()
process = do
    nLine <- getLine  -- ignore n
    aLine <- getLine
    bLine <- getLine
    print (minMaxProd (parse aLine) (parse bLine))
    where
        parse line = map read (words line)
        minMaxProd a b = c * d
            where
                c = maximum (zipWith max a b)
                d = maximum (zipWith min a b)

import Control.Arrow ((>>>))

main :: IO ()
main =
  interact $
    lines
      >>> drop 1
      >>> map (words >>> map read)
      >>> chunksOf 3
      >>> map (solve >>> show)
      >>> unlines

solve :: [[Int]] -> Int
solve [_, as, bs] = maximum (zipWith min as bs) * maximum (zipWith max as bs)

-- helpers
chunksOf :: Int -> [a] -> [[a]]
chunksOf _ [] = []
chunksOf k xs = let (hs, ts) = splitAt k xs in hs : chunksOf k ts

module Main where

(|>) = flip ($)

chunksOf :: Int -> [a] -> [[a]]
chunksOf n [] = []
chunksOf n xs = take n xs : chunksOf n (drop n xs)

swapfix :: Ord a => (a, a) -> (a, a)
swapfix (x, y) = (min x y, max x y)

parse :: [String] -> [[Int]]
parse = map (map read . words) . tail

solve :: [[Int]] -> Int
solve [a, b] =
    let fixed = swapfix <$> zip a b in
    let acost = foldl1 max (fst <$> fixed) in
    let bcost = foldl1 max (snd <$> fixed) in
    acost * bcost

main :: IO ()
main = interact $
    unlines
    . map (show . solve . parse)
    . chunksOf 3
    . tail
    . lines


import qualified Data.Set as Set

findHead :: Integer -> [Integer] -> Integer -> Set.Set Integer
findHead _ [] _ = Set.empty
findHead psum (a:as) b = Set.insert (b - a - psum) $ findHead (psum + a) as b

solve :: [Integer] -> [Integer] -> Set.Set Integer
solve as bs = foldr (Set.intersection . findHead 0 as) lll bs
    where lll = findHead 0 as (head bs)
-- solve as (b:bs)
--     | bs == []  = findHead 0 as b
--     | otherwise = Set.intersection (findHead 0 as b) $ solve as bs
--     -- | otherwise = Trace.traceShow (bs) $ solve as bs

main = do
    nk <- getLine
    a <- getLine
    b <- getLine
    let as = map read $ words a :: [Integer]
        bs = map read $ words b :: [Integer]
    print $ Set.size $ solve as bs

{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-}
module Main where
import qualified Data.ByteString.Char8 as B
import qualified Data.Set as S

main = do
  B.getLine
  as <- fmap readInts B.getLine
  bs <- fmap readInts B.getLine
  print $ S.size $ solve as bs

solve as bs = foldl1 S.intersection $ map (\b -> S.fromList $ map (b-) ss) bs
  where ss = scanl1 (+) as :: [Int]

readInt = maybe undefined fst . B.readInt
readInts = fmap readInt . B.words

import qualified Data.Set as Set

findHead :: Int -> [Int] -> Int -> Set.Set Int
findHead _ [] _ = Set.empty
findHead psum (a:as) b = Set.insert (b - a - psum) $ findHead (psum + a) as b

solve :: [Int] -> [Int] -> Set.Set Int
solve as bs = foldr (Set.intersection . findHead 0 as) lll bs
    where lll = findHead 0 as (head bs)
-- solve as (b:bs)
--     | bs == []  = findHead 0 as b
--     | otherwise = Set.intersection (findHead 0 as b) $ solve as bs
--     -- | otherwise = Trace.traceShow (bs) $ solve as bs

main = do
    nk <- getLine
    a <- getLine
    b <- getLine
    let as = map read $ words a :: [Int]
        bs = map read $ words b :: [Int]
    print $ Set.size $ solve as bs

import qualified Data.Set as Set

findHead :: Int -> [Int] -> Int -> Set.Set Int
findHead _ [] _ = Set.empty
findHead psum (a:as) b = Set.insert (b + a + psum) $ findHead (psum + a) as b

solve :: [Int] -> [Int] -> Set.Set Int
solve as bs = foldr (Set.intersection . findHead 0 as) lll bs
    where lll = findHead 0 as (last bs)

main = do
    nk <- getLine
    a <- getLine
    b <- getLine
    let as = map read $ words a :: [Int]
        bs = map read $ words b :: [Int]
    print $ Set.size $ solve as bs


import qualified Data.ByteString.Lazy.Char8 as C
import IO
import Data.Maybe

readInt = fst . fromJust . C.readInt
readIntList = map readInt . C.words

main = do
	input <- fmap (map (C.takeWhile (/='\r')) . C.lines) $ C.hGetContents stdin
	let [n, m, k] = readIntList $ head input
	let ps = map readIntList . take k $ tail input
	putStrLn $ if elem True [ foldl min (x-1) [n-x, y-1, m-y] < 5 | [x, y] <- ps ] then "YES" else "NO"

readLL :: String -> [Int]
readLL = (map read) . words
main = do
[n, m, k] <- getLine >>= return . readLL
ps <- getContents >>= return . (map readLL) . (take k) . lines
putStrLn $ if any (\[x, y] -> any (<=5) [x, y, (n-x+1), (m-y+1)]) ps then "YES" else "NO"

import Control.Monad (liftM)

(<?>) :: a -> a -> Bool -> a
(<?>) a b p  =  if p then a else b

reads :: Read a => IO [a]
reads  =  liftM (map read . words) getLine

solve :: Int -> Int -> [[Int]] -> Bool
solve n m xs  =  any p xs
  where
    p [x, y]  =  x <= 5 || y <= 5 || (n - x) + 1 <= 5 || (m - y) + 1 <= 5

main :: IO ()
main  =  do
    [n, m, k]  <-  Main.reads
    xs  <-  mapM (const Main.reads) [1..k]
    putStrLn $ "YES" <?> "NO" $ solve n m xs

import Control.Monad

main = do
    [n, m, k] <- liftM (map read . words) getLine
    list <- replicateM k $ do
        [a, b] <- liftM (map read . words) getLine
        return $ a <= 5 || b <= 5 || a >= n - 4 || b >= m - 4

    putStrLn $ if or list then "YES" else "NO"

import qualified Data.ByteString.Lazy.Char8 as C
import IO
import Data.Maybe

readInt = fst . fromJust . C.readInt
readIntList = map readInt . C.words

main = do
	input <- fmap (map (C.takeWhile (/='\r')) . C.lines) $ C.hGetContents stdin
	let [n, m, k] = readIntList $ head input
	let ps = map readIntList . take k $ tail input
	putStrLn $ if elem True [ foldl min (x+1) [n-x, (y+1), m-y] < 5 | [x, y] <- ps ] then "YES" else "NO"

import qualified Data.ByteString.Lazy.Char8 as C
import IO
import Data.Maybe

readInt = fst . fromJust . C.readInt
readIntList = map readInt . C.words

main = do
	input <- fmap (map (C.takeWhile (/='\r')) . C.lines) $ C.hGetContents stdin
	let [n, m, k] = readIntList $ head input
	let ps = map readIntList . take k $ tail input
	putStrLn $ if elem True [ foldl min x [n-1-x, y, m-1-y] < 5 | [x, y] <- ps ] then "YES" else "NO"

------------------------------------------------------------------------
-- 55C. Кекс или смерть
------------------------------------------------------------------------
-- Created: 11.03.2011 18:09:43 Russian Standard Time
-- Copyright 2011 jz <da-eto@ya.ru>

module Main (main) where

readLL :: String -> [Int]
readLL = (map read) . words

-- main function
main = do
    [n, m, k] <- getLine >>= return . readLL
    ps <- getContents >>= return . (map readLL) . (take k) . lines
    putStrLn $ if solve n m ps then "YES" else "NO" where

    solve n m ps = any isWin ps where
        isWin [x, y] = any (<=4) [x, y, (n-x+1), (m-y+1)]

------------------------------------------------------------------------
-- 55C. Кекс или смерть
------------------------------------------------------------------------
-- Created: 11.03.2011 18:09:43 Russian Standard Time
-- Copyright 2011 jz <da-eto@ya.ru>

module Main (main) where

readLL :: String -> [Int]
readLL = (map read) . words

-- main function
main = do
    [n, m, k] <- getLine >>= return . readLL
    ps <- getContents >>= return . (map readLL) . (take k) . lines
    putStrLn $ if solve n m ps then "YES" else "NO" where

    solve n m ps = any isWin ps where
        isWin [x, y] = any (<=3) [x, y, (n-x+1), (m-y+1)]

import Control.Monad

main = do
    [n, m, k] <- liftM (map read . words) getLine
    list <- replicateM k $ do
        [a, b] <- liftM (map read . words) getLine
        return $ a <= 5 || b <= 5 || a >= n - 4 || b >= m - 4

    putStrLn $ if and list then "YES" else "NO"


import Control.Monad

import Data.Char
import Data.List

generateList :: Int -> Int -> [Int]
generateList 0 _ = []
generateList n k = [ele] ++ (generateList (n - 1) (k - ele))
    where ele = min 1000 k

solve :: Int -> [Int] -> [[Int]]
solve 0 _ = []
solve n mList = (drop n mList ++ take n mList) : (solve (n - 1) mList)

main :: IO ()
main = do
    input <- getContents
    let [n, k] = map read . words $ input
    let mList = generateList n k
    putStrLn $ unlines . map (intercalate " " . map show) . solve n $ mList

import Control.Applicative
import Data.List
main :: IO ()
main = do
    inp <- map read <$> words <$> getLine
    let n = inp !! 0 :: Int
        k = inp !! 1
    mapM_ (putStrLn . intercalate " " . map show)
        $ [ [ if x == y then k else 0 | y <- [1..n]] | x <- [1 .. n]]

import Control.Applicative ((<$>))
import Data.List (unfoldr)

main :: IO ()
main = mapM_ (putStrLn . unwords . map show) =<< solve . toTuple . map read . words <$> getLine

solve :: (Int, Int) -> [[Int]]
solve (n, k) = take n $ splitN n $ cycle (k : replicate n 0)

splitN :: Int -> [a] -> [[a]]
splitN n = takeWhile (not . null) . unfoldr (Just . splitAt n)

toTuple :: [a] -> (a, a)
toTuple xs = (head xs, xs !! 1)

import Control.Monad (liftM, forM_)
import Data.Char (ord)
import Data.List (intercalate)

main :: IO ()
main  =  do
    [n, k]  <-  reads
    forM_ [1..n] (\i -> prints [if i == j then k else 0 | j <- [1..n]])

  where

    prints :: Show a => [a] -> IO ()
    prints  =  putStrLn . intercalate " " . map show

    readPair :: Num a => IO (a, a)
    readPair  =  do
        [a, b]  <-  reads
        return (a, b)

    reads :: Num a => IO [a]
    reads  =  liftM (map read . words) getLine
      where
        read ('-':s)  =  (-1) * read s
        read s  =  read' 0 s
        read' a ""  =  a
        read' a (c:s)  =  read' a' s
          where
            a'  =  10 * a + fromIntegral (ord c - ord '0')

f::Int->Int->Int->String
f x y n
   |x==y=show n
   |otherwise=show 0

f2::Int->Int->Int->[String]
f2 y m n
   |y>m=[]
   |otherwise=(unwords [f x y n|x<-[1..m]]):f2 (y+1) m n

main = do
       e<-getLine
       let (n:k:[])= map read (words e)::[Int]
       mapM_ putStrLn $ f2 (1::Int) n k

import Control.Applicative
import Data.List
main :: IO ()
main = do
    inp <- map read <$> words <$> getLine
    let n = inp !! 0 :: Int
        k = inp !! 1
    mapM_ (putStrLn . intercalate " " . map show) $ solve n k n
solve :: Int -> Int -> Int -> [[Int]]
solve _ _ 0 =  []
solve n k left = (replicate (n-left) 0 ++ [k] ++ replicate (left - 1) 0) : solve n k (left - 1)

import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe

process n k i = do
		putStr $ concat $ replicate (i-1) "0 "
		putStr $ (show k)++ " "
		putStrLn $ concat $ replicate (n-i) "0 "

main = do
		[n,k]<- map read <$> words <$> getLine::IO [Int]
		mapM_ (process n k) [1..n]

process :: Int -> Int -> [[Int]]
process n k = [[if i==j then k else 0 | j <- [1..n]] | i <- [1..n]]

readInt :: String -> Int
readInt = read

main :: IO ()
main = do
    [n,k] <- fmap (map readInt.words) getLine
    mapM_ (putStrLn.unwords.map show) $ process n k

import Data.Tuple
import Data.List
cal ls = let n = read $ head $ words $  (ls !! 0)
	     k = read $ last $ words $  (ls !! 0)
	     toN = [0..(n-1)]
	 in map (\a -> concatMap (\b -> show b ++ " ") a) $ map (\i -> make n i k) toN

make n i k = let zeros = [0,0..]
           in (take i zeros) ++ [k] ++ (take (n-i-1) zeros)

main = interact (unlines . cal . lines)


{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns, ViewPatterns, TupleSections, OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Array.Base
import Data.Array.ST (runSTUArray, STArray)
import Data.Bits
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.Function
import Data.Int
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Data.STRef
import GHC.Arr (Array, Ix, unsafeIndex)
bool :: a -> a -> Bool -> a
bool t f b=if b then t else f
readInt :: B.ByteString -> Int
readInt bs = case B.readInt bs of Just (n,_) -> n
rep, rev :: Monad m => Int -> (Int -> m ()) -> m ()
rep !n f=go 0 where go !i=when(i<n)$f i>>go(i+1)
rev !n f=go(n-1)where go !i=when(i>=0)$f i>>go(i-1)
{-# INLINE rep #-}
{-# INLINE rev #-}
modifyArray :: (MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m ()
modifyArray a i f=readArray a i>>=writeArray a i.f
{-# INLINE modifyArray #-}
unsafeModify :: (MArray a e m, Ix i) => a i e -> Int -> (e -> e) -> m ()
unsafeModify a i f=unsafeRead a i>>=unsafeWrite a i.f
{-# INLINE unsafeModify #-}

main :: IO ()
main = do
  [n,a,b] <- map read.words <$> getLine
  xs <- map(fromIntegral.readInt).B.words <$> B.getContents
  putStr.unwords.map show $ solve a b xs

solve :: Integer -> Integer -> [Integer] -> [Integer]
solve a b xs = do
  x <- xs
  let (!q,!r) = (a*x)`quotRem`b
      p w = q*b <= a*w && a*w <= a*x
  [x - lowerBound p 0 x]

lowerBound :: (Integral i) => (i -> Bool) -> i -> i -> i
lowerBound p low high = go low high
   where
     go !low !high
       | high <= low = high
       | p mid       = go low       mid
       | otherwise   = go (mid + 1) high
      where
        mid = (low + high) `quot` 2
{-# INLINE lowerBound #-}

parseInput = map (read :: String -> Integer).words

f :: Integer -> Integer -> [Integer] -> [Integer]
f a b [] = []
f a b (x:xs) = (x * a `mod` b) `div` a : f a b xs

main = do
    s <- getLine
    let [n, a, b] = parseInput s
    xs <- getLine
    putStrLn $ unwords. map show $ f a b $ parseInput xs

parseInput = map (read :: String -> Integer).words

f :: Integer -> Integer -> [Integer] -> [Integer]
f a b [] = []
f a b (x:xs) = (x * a `mod` b) : f a b xs

main = do
    s <- getLine
    let [n, a, b] = parseInput s
    xs <- getLine
    putStrLn $ unwords. map show $ f a b $ parseInput xs

{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns, ViewPatterns, TupleSections, OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Array.Base
import Data.Array.ST (runSTUArray, STArray)
import Data.Bits
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.Function
import Data.Int
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Data.STRef
import GHC.Arr (Array, Ix, unsafeIndex)
bool :: a -> a -> Bool -> a
bool t f b=if b then t else f
readInt :: B.ByteString -> Int
readInt bs = case B.readInt bs of Just (n,_) -> n
rep, rev :: Monad m => Int -> (Int -> m ()) -> m ()
rep !n f=go 0 where go !i=when(i<n)$f i>>go(i+1)
rev !n f=go(n-1)where go !i=when(i>=0)$f i>>go(i-1)
{-# INLINE rep #-}
{-# INLINE rev #-}
modifyArray :: (MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m ()
modifyArray a i f=readArray a i>>=writeArray a i.f
{-# INLINE modifyArray #-}
unsafeModify :: (MArray a e m, Ix i) => a i e -> Int -> (e -> e) -> m ()
unsafeModify a i f=unsafeRead a i>>=unsafeWrite a i.f
{-# INLINE unsafeModify #-}

main :: IO ()
main = do
  [n,a,b] <- map read.words <$> getLine
  xs <- map(fromIntegral.readInt).B.words <$> B.getContents
  putStr.unwords.map show $ solve a b xs

solve :: Integer -> Integer -> [Integer] -> [Integer]
solve a b xs = [(a*x)`rem`b | x<-xs]


{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.Marshal.Alloc
import Debug.Trace
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Unboxed as UB
import Data.Array.ST
import Data.Array
import Data.Char
class IOtyp a where scan' :: String -> a; show' :: a -> String
instance IOtyp Int where scan' = read; show' = show
instance IOtyp Char where scan' (x:_) = x;show' = (:[])
instance IOtyp Float where scan' = read;show' = show
instance IOtyp Double where scan' = read;show' = show
instance IOtyp Integer where scan' = read;show' = show
instance IOtyp String where scan' = id;show' = id
instance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y
instance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z
foreign import ccall "stdio.h puts" c_puts :: CString -> IO ()
scan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'
scans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan
scanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words
scanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist
puts :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}

solve 1 0 0 = [1]
solve n a b | n<=(a+1) = [-1]
solve n a 0 = take n (2:[2..(a+2)]++[1,1..])
solve n a_ b_ = rec a_ (b_+1) 0 0 n
    where
      rec 0 0 _ _ 0 = []
      rec 0 0 max_ sum_ rest = 1 : rec 0 0 max_ sum_ (rest-1)
      rec a 0 max_ sum_ rest = (max_+1) : rec (a-1) 0 (max_+1) sum_ (rest-1)
      rec a b max_ sum_ rest = (sum_+1) : rec a (b-1) (sum_+1) (2*sum_+1) (rest-1)

main = do (n,a,b) <- scan :: IO (Int,Int,Int)
          putStrLn.unwords.map show $ solve n a b

import Control.Monad
import Data.List
next (n, a, b, l, s) = if n == 0 then Nothing
                       else Just (if b > 0 then (s+1, (n-1, a, b-1, s+1, 2*s+1))
                       else if a > 0 then (l+1, (n-1, a-1, b, l+1, s+l+1))
                       else (l, (n-1, a, b, l, l+s)))
main = do
  [n, a, b] <- (liftM ((map read) . words)) getLine
  putStrLn . unwords . map show $ if n == 1 then [1]
                                  else if a == n-1 then [-1]
                                  else if b > 0 then 1 : unfoldr next (n-1, a, b, 1, 1)
                                  else 1 : 1 : unfoldr next (n-2, a, b, 1, 2)

readWords :: IO [String]
readWords = getLine >>= return . words

reads :: Read a => IO [a]
reads = readWords >>= return . (map read)

powersOfTwo :: [Int]
powersOfTwo  =  zipWith (^) (repeat 2) [1..]

solve :: Int -> Int -> Int -> [Int]
solve n 0 0  =  replicate n 1
solve n a 0
  | n > a + 1  =  [1, 1] ++ [2..a+1] ++ (replicate (n-2-a) 1)
  | otherwise  =  []
solve n a b
  =  [1]
  ++ (take b powersOfTwo)
  ++ [2^b+1..2^b+a]
  ++ (replicate (n - 1 - a - b) 1)

printAns :: [Int] -> IO ()
printAns xs  =  printAns_ xs
  where
    printAns_ []      =  print (-1)
    printAns_ [x]     =  print x
    printAns_ (x:xs)  =  putStr (show x ++ " ") >> printAns_ xs

main :: IO ()
main = do
    [n, a, b] <- Main.reads
    printAns (solve n a b)

makeWows 0 = [const 1]
makeWows b = replicate b (*2)

makeOhs a = replicate a (+1)

makeSeq a b n = (makeWows b++makeOhs a++(repeat id))

solve [n,a,b]
	|a>0&&b==0&&n==a+1 = [-1]
	|otherwise = take n $ scanl (flip ($)) 1 (makeSeq a b n)

main=interact$unlines.map show.solve.map read.words

import Data.List
import Control.Monad

rich = 1:[sum [rich !! j | j <- [0..i-2]] + 1
        | i <- [2..]]

solve n a b | b /= 0 = do
    let rich1 = take (b + 1) rich
    let rich2 = [last rich1+1..last rich1 + a]
    let rich3 = replicate (n - a - b - 1) 1

    putStrLn $ intercalate " " $ map show (rich1++rich2++rich3)

solve n a b | a + 2 <= n = do
    let rich1 = [1,1]
    let rich2 = [last rich1+1..last rich1 + a]
    let rich3 = replicate (n - a - b - 2) 1

    putStrLn $ intercalate " " $ map show (rich1++rich2++rich3)

solve n a b | n == 1 = do
    putStrLn "1"

solve n a b = do
    putStrLn "-1"

main = do
    [n, a, b] <- liftM (map read . words) getLine

    solve n a b

s[n,a,b]|length g<n=take n$scanl(flip($))1(g++repeat(\_->1))|1>0=[-1]where q|b>0||a==0=replicate b(*2)|1>0=[id];g=q++replicate a(+1)
main=interact$unwords.map show.s.map read.words

import Control.Monad
import Data.List
next (n, a, b, l, s) = if n == 0 then Nothing
                       else Just (if b > 0 then (s+1, (n-1, a, b-1, s+1, 2*s+1))
                       else if a > 0 then (l+1, (n-1, a-1, b, l+1, s+l+1))
                       else (l, (n-1, a, b, l, l+s)))
main = do
  [n, a, b] <- (liftM ((map read) . words)) getLine
  putStrLn . unwords . map show $ 1 : 1: unfoldr next (n-2, a, b, 1, 2)

import Control.Monad
import Data.List
next (n, a, b, l, s) = if n == 0 then Nothing
                       else Just (if b > 0 then (s+1, (n-1, a, b-1, s+1, 2*s+1))
                       else if a > 0 then (l+1, (n-1, a-1, b, l+1, s+l+1))
                       else (l, (n-1, a, b, l, l+s)))
main = do
  [n, a, b] <- (liftM ((map read) . words)) getLine
  putStrLn . unwords . map show $ 1 : unfoldr next (n-1, a, b, 1, 1)

import Control.Monad
import Data.List
next (n, a, b, l, s) = if n == 0 then Nothing
                       else Just (if b > 0 then (s+1, (n-1, a, b-1, s+1, 2*s+1))
                       else if a > 0 then (l+1, (n-1, a-1, b, l+1, s+l+1))
                       else (l, (n-1, a, b, l, l+s)))
main = do
  [n, a, b] <- (liftM ((map read) . words)) getLine
  putStrLn . unwords . map show $ 1 : unfoldr next (n, a, b, 1, 1)

readWords :: IO [String]
readWords = getLine >>= return . words

reads :: Read a => IO [a]
reads = readWords >>= return . (map read)

powersOfTwo :: [Int]
powersOfTwo  =  zipWith (^) (repeat 2) [1..]

solve :: Int -> Int -> Int -> [Int]
solve n a 0
  | n > a + 1  =  [1, 1] ++ [2..a+1] ++ (replicate (n-2-a) 1)
  | otherwise  =  []
solve n a b
  =  [1]
  ++ (take b powersOfTwo)
  ++ [2^b+1..2^b+a]
  ++ (replicate (n - 1 - a - b) 1)

printAns :: [Int] -> IO ()
printAns xs  =  printAns_ xs
  where
    printAns_ []      =  print (-1)
    printAns_ [x]     =  print x
    printAns_ (x:xs)  =  putStr (show x ++ " ") >> printAns_ xs

main :: IO ()
main = do
    [n, a, b] <- Main.reads
    printAns (solve n a b)

makeSeq a b n = ((replicate b (*2))++(replicate a (+1))++(replicate (n-a-b-1) (const 1)))
solve [n,a,b]
	|b>0 = result 1
	|otherwise = result 2
	where result first = scanl (flip ($)) first (makeSeq a b n)

main=interact$unlines.map show.solve.map read.words

makeWows 0 = [const 1]
makeWows b = replicate b (*2)

makeOhs a = replicate a (+1)

makeSeq a b n = (makeWows b++makeOhs a++(replicate (n-a-b-1) id))

solve [n,a,b]
	|b==0&&n==a+1 = [-1]
	|otherwise = scanl (flip ($)) 1 (makeSeq a b n)

main=interact$unlines.map show.solve.map read.words

makeWows 0 = [const 1]
makeWows b = replicate b (*2)

makeOhs a = replicate a (+1)

makeSeq a b n = (makeWows b++makeOhs a++(repeat id))

solve [n,a,b]
	|b==0&&n==a+1 = [-1]
	|otherwise = take n $ scanl (flip ($)) 1 (makeSeq a b n)

main=interact$unlines.map show.solve.map read.words

import Data.List
import Control.Monad

rich = 1:[sum [rich !! j | j <- [0..i-2]] + 1
        | i <- [2..]]

main = do
    [n, a, b] <- liftM (map read . words) getLine

    let rich1 = take (b + 1) rich
    let rich2 = [last rich1+1..last rich1 + a]
    let rich3 = replicate (n - a - b - 1) 1

    putStrLn $ intercalate " " $ map show (rich1++rich2++rich3)

import Data.List
import Control.Monad

rich = 1:[sum [rich !! j | j <- [0..i-2]] + 1
        | i <- [2..]]

solve n a b | b /= 0 = do
    let rich1 = take (b + 1) rich
    let rich2 = [last rich1+1..last rich1 + a]
    let rich3 = replicate (n - a - b - 1) 1

    putStrLn $ intercalate " " $ map show (rich1++rich2++rich3)

solve n a b | a + 2 <= n = do
    let rich1 = [1,1]
    let rich2 = [last rich1+1..last rich1 + a]
    let rich3 = replicate (n - a - b - 2) 1

    putStrLn $ intercalate " " $ map show (rich1++rich2++rich3)

solve n a b = do
    putStrLn "-1"

main = do
    [n, a, b] <- liftM (map read . words) getLine

    solve n a b

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.Marshal.Alloc
import Debug.Trace
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Unboxed as UB
import Data.Array.ST
import Data.Array
import Data.Char
class IOtyp a where scan' :: String -> a; show' :: a -> String
instance IOtyp Int where scan' = read; show' = show
instance IOtyp Char where scan' (x:_) = x;show' = (:[])
instance IOtyp Float where scan' = read;show' = show
instance IOtyp Double where scan' = read;show' = show
instance IOtyp Integer where scan' = read;show' = show
instance IOtyp String where scan' = id;show' = id
instance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y
instance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z
foreign import ccall "stdio.h puts" c_puts :: CString -> IO ()
scan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'
scans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan
scanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words
scanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist
puts :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}

solve n a_ b_ = rec a_ (b_+1) 0 0 n
    where
      rec 0 0 _ _ 0 = []
      rec 0 0 max_ sum_ rest = 1 : rec 0 0 max_ sum_ (rest-1)
      rec a 0 max_ sum_ rest = (max_+1) : rec (a-1) 0 (max_+1) sum_ (rest-1)
      rec a b max_ sum_ rest = (sum_+1) : rec a (b-1) (sum_+1) (2*sum_+1) (rest-1)

main = do (n,a,b) <- scan :: IO (Int,Int,Int)
          putStrLn.unwords.map show $ solve n a b

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.Marshal.Alloc
import Debug.Trace
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Unboxed as UB
import Data.Array.ST
import Data.Array
import Data.Char
class IOtyp a where scan' :: String -> a; show' :: a -> String
instance IOtyp Int where scan' = read; show' = show
instance IOtyp Char where scan' (x:_) = x;show' = (:[])
instance IOtyp Float where scan' = read;show' = show
instance IOtyp Double where scan' = read;show' = show
instance IOtyp Integer where scan' = read;show' = show
instance IOtyp String where scan' = id;show' = id
instance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y
instance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z
foreign import ccall "stdio.h puts" c_puts :: CString -> IO ()
scan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'
scans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan
scanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words
scanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist
puts :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}

solve n a_ 0 = [-1]

solve n a_ b_ = rec a_ (b_+1) 0 0 n
    where
      rec 0 0 _ _ 0 = []
      rec 0 0 max_ sum_ rest = 1 : rec 0 0 max_ sum_ (rest-1)
      rec a 0 max_ sum_ rest = (max_+1) : rec (a-1) 0 (max_+1) sum_ (rest-1)
      rec a b max_ sum_ rest = (sum_+1) : rec a (b-1) (sum_+1) (2*sum_+1) (rest-1)

main = do (n,a,b) <- scan :: IO (Int,Int,Int)
          putStrLn.unwords.map show $ solve n a b

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.Marshal.Alloc
import Debug.Trace
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Unboxed as UB
import Data.Array.ST
import Data.Array
import Data.Char
class IOtyp a where scan' :: String -> a; show' :: a -> String
instance IOtyp Int where scan' = read; show' = show
instance IOtyp Char where scan' (x:_) = x;show' = (:[])
instance IOtyp Float where scan' = read;show' = show
instance IOtyp Double where scan' = read;show' = show
instance IOtyp Integer where scan' = read;show' = show
instance IOtyp String where scan' = id;show' = id
instance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y
instance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z
foreign import ccall "stdio.h puts" c_puts :: CString -> IO ()
scan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'
scans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan
scanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words
scanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist
puts :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}

solve n 0 0 = take n [1,1..]
solve n 0 b = [-1]
solve n a_ b_ = rec a_ (b_+1) 0 0 n
    where
      rec 0 0 _ _ 0 = []
      rec 0 0 max_ sum_ rest = 1 : rec 0 0 max_ sum_ (rest-1)
      rec a 0 max_ sum_ rest = (max_+1) : rec (a-1) 0 (max_+1) sum_ (rest-1)
      rec a b max_ sum_ rest = (sum_+1) : rec a (b-1) (sum_+1) (2*sum_+1) (rest-1)

main = do (n,a,b) <- scan :: IO (Int,Int,Int)
          putStrLn.unwords.map show $ solve n a b

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.Marshal.Alloc
import Debug.Trace
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Unboxed as UB
import Data.Array.ST
import Data.Array
import Data.Char
class IOtyp a where scan' :: String -> a; show' :: a -> String
instance IOtyp Int where scan' = read; show' = show
instance IOtyp Char where scan' (x:_) = x;show' = (:[])
instance IOtyp Float where scan' = read;show' = show
instance IOtyp Double where scan' = read;show' = show
instance IOtyp Integer where scan' = read;show' = show
instance IOtyp String where scan' = id;show' = id
instance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y
instance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z
foreign import ccall "stdio.h puts" c_puts :: CString -> IO ()
scan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'
scans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan
scanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words
scanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist
puts :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}

solve n a_ b_ = 1 : rec a_ b_ 1 1 n
    where
      rec 0 0 _ _ 0 = []
      rec 0 0 max_ sum_ rest = 1 : rec 0 0 max_ sum_ (rest-1)
      rec a 0 max_ sum_ rest = (max_+1) : rec (a-1) 0 (max_+1) sum_ (rest-1)
      rec a b max_ sum_ rest = (sum_+1) : rec a (b-1) (sum_+1) (2*sum_+1) (rest-1)

main = do (n,a,b) <- scan :: IO (Int,Int,Int)
          putStrLn.unwords.map show $ solve n a b

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.Marshal.Alloc
import Debug.Trace
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Unboxed as UB
import Data.Array.ST
import Data.Array
import Data.Char
class IOtyp a where scan' :: String -> a; show' :: a -> String
instance IOtyp Int where scan' = read; show' = show
instance IOtyp Char where scan' (x:_) = x;show' = (:[])
instance IOtyp Float where scan' = read;show' = show
instance IOtyp Double where scan' = read;show' = show
instance IOtyp Integer where scan' = read;show' = show
instance IOtyp String where scan' = id;show' = id
instance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y
instance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z
foreign import ccall "stdio.h puts" c_puts :: CString -> IO ()
scan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'
scans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan
scanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words
scanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist
puts :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}

solve n a_ b_ = rec (a_+1) (b_+1) 0 0 n
    where
      rec 0 0 _ _ 0 = []
      rec 0 0 max_ sum_ rest = 1 : rec 0 0 max_ sum_ (rest-1)
      rec a 0 max_ sum_ rest = (max_+1) : rec (a-1) 0 (max_+1) sum_ (rest-1)
      rec a b max_ sum_ rest = (sum_+1) : rec a (b-1) (sum_+1) (2*sum_+1) (rest-1)

main = do (n,a,b) <- scan :: IO (Int,Int,Int)
          putStrLn.unwords.map show $ solve n a b

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.Marshal.Alloc
import Debug.Trace
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Unboxed as UB
import Data.Array.ST
import Data.Array
import Data.Char
class IOtyp a where scan' :: String -> a; show' :: a -> String
instance IOtyp Int where scan' = read; show' = show
instance IOtyp Char where scan' (x:_) = x;show' = (:[])
instance IOtyp Float where scan' = read;show' = show
instance IOtyp Double where scan' = read;show' = show
instance IOtyp Integer where scan' = read;show' = show
instance IOtyp String where scan' = id;show' = id
instance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y
instance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z
foreign import ccall "stdio.h puts" c_puts :: CString -> IO ()
scan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'
scans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan
scanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words
scanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist
puts :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}

solve n a b | n<=(a+1) = [-1]
solve n a 0 = take n (2:[2..(a+2)]++[1,1..])
solve n a_ b_ = rec a_ (b_+1) 0 0 n
    where
      rec 0 0 _ _ 0 = []
      rec 0 0 max_ sum_ rest = 1 : rec 0 0 max_ sum_ (rest-1)
      rec a 0 max_ sum_ rest = (max_+1) : rec (a-1) 0 (max_+1) sum_ (rest-1)
      rec a b max_ sum_ rest = (sum_+1) : rec a (b-1) (sum_+1) (2*sum_+1) (rest-1)

main = do (n,a,b) <- scan :: IO (Int,Int,Int)
          putStrLn.unwords.map show $ solve n a b

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.Marshal.Alloc
import Debug.Trace
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Unboxed as UB
import Data.Array.ST
import Data.Array
import Data.Char
class IOtyp a where scan' :: String -> a; show' :: a -> String
instance IOtyp Int where scan' = read; show' = show
instance IOtyp Char where scan' (x:_) = x;show' = (:[])
instance IOtyp Float where scan' = read;show' = show
instance IOtyp Double where scan' = read;show' = show
instance IOtyp Integer where scan' = read;show' = show
instance IOtyp String where scan' = id;show' = id
instance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y
instance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z
foreign import ccall "stdio.h puts" c_puts :: CString -> IO ()
scan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'
scans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan
scanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words
scanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist
puts :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}

solve n a_ 0 = take n ([2..(a_+2)]++[1,1..])

solve n a_ b_ = rec a_ (b_+1) 0 0 n
    where
      rec 0 0 _ _ 0 = []
      rec 0 0 max_ sum_ rest = 1 : rec 0 0 max_ sum_ (rest-1)
      rec a 0 max_ sum_ rest = (max_+1) : rec (a-1) 0 (max_+1) sum_ (rest-1)
      rec a b max_ sum_ rest = (sum_+1) : rec a (b-1) (sum_+1) (2*sum_+1) (rest-1)

main = do (n,a,b) <- scan :: IO (Int,Int,Int)
          putStrLn.unwords.map show $ solve n a b

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.Marshal.Alloc
import Debug.Trace
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Unboxed as UB
import Data.Array.ST
import Data.Array
import Data.Char
class IOtyp a where scan' :: String -> a; show' :: a -> String
instance IOtyp Int where scan' = read; show' = show
instance IOtyp Char where scan' (x:_) = x;show' = (:[])
instance IOtyp Float where scan' = read;show' = show
instance IOtyp Double where scan' = read;show' = show
instance IOtyp Integer where scan' = read;show' = show
instance IOtyp String where scan' = id;show' = id
instance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y
instance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z
foreign import ccall "stdio.h puts" c_puts :: CString -> IO ()
scan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'
scans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan
scanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words
scanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist
puts :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}

solve n a_ b_ = rec a_ b_ 0 0 n
    where
      rec 0 0 _ _ 0 = []
      rec 0 0 max_ sum_ rest = 1 : rec 0 0 max_ sum_ (rest-1)
      rec a 0 max_ sum_ rest = (max_+1) : rec (a-1) 0 (max_+1) sum_ (rest-1)
      rec a b max_ sum_ rest = (sum_+1) : rec a (b-1) (sum_+1) (2*sum_+1) (rest-1)

main = do (n,a,b) <- scan :: IO (Int,Int,Int)
          putStrLn.unwords.map show $ solve n a b

import List
g(_,a)[x,y]=[y,a:x]
p x=[[length x],x]
main=interact$unlines.map(unwords.map show).(>>=p).foldr g[[],[]].sort.(`zip`[1..]).map((+0).read).tail.words

s[n,a,b]|a+b<n=take n$scanl(flip($))1$replicate b(*2)++replicate a(+1)++repeat(\_->1)|1>0=[-1]
main=interact$unwords.map show.s.map read.words

s[n,a,b]|a+b<n=take n$scanl(flip($))1$replicate b(*2)++replicate 2(+1)++repeat(\_->1)|1>0=[-1]
main=interact$unwords.map show.s.map read.words


{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad

solve :: Int -> [Int] -> Int -> Bool
solve x as y = (x + y + sum as) `mod` 2 == 0

main :: IO ()
main = do
  t <- readLn
  replicateM_ t $ do
    [n, x, y] <- map read . words <$> getLine
    as <- map read . words <$> getLine
    putStrLn $ if solve x as y
      then "Alice"
      else "Bob"

import qualified Data.ByteString.Lazy.Char8 as P
import Data.ByteString.Builder
import qualified Data.ByteString.Builder.Prim as Prim
import System.IO
import Control.Monad.Trans.State
import Data.Maybe

--import Data.ByteString.Builder.Extra (flush) -- for interactive problems
import Control.Monad
import Data.List
--import Data.Array.Unboxed

mainFun :: SP Builder
mainFun = do
  t <- getInt
  fmap mconcat $ replicateM t $ do
    n <- getInt
    x <- getInt
    y <- getInt
    a <- replicateM n getInt
    let
      aliceParity = foldl' (+) x a
    pure $ string7 $ if  even (aliceParity  - y)
      then  "Alice\n"
      else  "Bob\n"

type SP = State P.ByteString
type S = StateT P.ByteString

dropSpace :: P.ByteString -> P.ByteString
dropSpace = P.dropWhile (<= ' ') -- not exactly right, but close enough

--getNext :: Monad m => S m P.ByteString
--getNext = state $ P.span (> ' ') . dropSpace

getInt :: Monad m => S m Int
getInt = state $ fromJust . P.readInt . dropSpace

putInts :: [Int] -> Builder
putInts vs = let
  sepPrim = (,) ' ' Prim.>$<
    Prim.liftFixedToBounded Prim.char7 Prim.>*< Prim.intDec
  in  case  vs  of
  [] -> char7 '\n'
  x : xs -> intDec x <> Prim.primMapListBounded sepPrim xs <> char7 '\n'

main :: IO ()
main = do
  hSetBuffering stdout NoBuffering
  inp <- P.getContents
  let  outp = evalState mainFun inp
  P.putStr $ toLazyByteString outp


lastIndexOfPair' :: Int -> Int -> [Int] -> Int
lastIndexOfPair' _ pos [_] = pos
lastIndexOfPair' i pos (x : xs)
 | (x == head xs) = lastIndexOfPair' (i + 1) (i + 1) xs
 | otherwise = lastIndexOfPair' (i + 1) pos xs

lastIndexOfPair :: [Int] -> Int
lastIndexOfPair a = lastIndexOfPair' 0 (-1) a

indexOfPair' :: Int -> [Int] -> Int
indexOfPair' _ [x] = -1
indexOfPair' i (x : xs)
 | (x == head xs) = i
 | otherwise = indexOfPair' (i + 1) xs

indexOfPair :: [Int] -> Int
indexOfPair a = indexOfPair' 0 a

join :: String -> [String] -> String
join _ [x] = x
join delimiter (x : xs) = x ++ delimiter ++ join delimiter xs

ans :: IO String
ans = do
 nInput <- getLine
 aInput <- getLine
 let n = read nInput :: Int
 let a = [read x :: Int | x <- words aInput]
 let pos = indexOfPair a
 let lastPos = lastIndexOfPair a
 let cnt = lastPos - pos + 1
 if (pos == -1 || cnt == 2) then do
  return "0"
 else if (cnt == 3) then do
  return "1"
 else do
  return (show (cnt - 3))

main :: IO ()
main = do
 tInput <- getLine
 let t = read tInput :: Int
 results <- sequence (replicate t ans)
 putStrLn (join "\r\n" results)

lastIndexOfPair' :: Eq t => Int -> Int -> [t] -> Int
lastIndexOfPair' _ pos [_] = pos
lastIndexOfPair' i pos (x : xs)
 | (x == head xs) = lastIndexOfPair' (i + 1) (i + 1) xs
 | otherwise = lastIndexOfPair' (i + 1) pos xs

lastIndexOfPair :: Eq t => [t] -> Int
lastIndexOfPair a = lastIndexOfPair' 0 (-1) a

indexOfPair' :: Eq t => Int -> [t] -> Int
indexOfPair' _ [x] = -1
indexOfPair' i (x : xs)
 | (x == head xs) = i
 | otherwise = indexOfPair' (i + 1) xs

indexOfPair :: Eq t => [t] -> Int
indexOfPair a = indexOfPair' 0 a

join :: String -> [String] -> String
join _ [x] = x
join delimiter (x : xs) = x ++ delimiter ++ join delimiter xs

ans :: IO String
ans = do
 nInput <- getLine
 aInput <- getLine
 let n = read nInput :: Int
 let a = [read x :: Int | x <- words aInput]
 let pos = indexOfPair a
 let lastPos = lastIndexOfPair a
 let cnt = lastPos - pos + 1
 if (pos == -1 || cnt == 2) then do
  return "0"
 else if (cnt == 3) then do
  return "1"
 else do
  return (show (cnt - 3))

main :: IO ()
main = do
 tInput <- getLine
 let t = read tInput :: Int
 results <- sequence (replicate t ans)
 putStrLn (join "\r\n" results)


module Main where
  import Data.List
  import Control.Monad
  import Data.Array
  import qualified Data.Set as S

  toArray :: [a] -> Array Int a
  toArray xs =
    let ls = length xs - 1
        in array (0, ls) $ zip [0..ls] xs

  readInt :: String -> Integer
  readInt s = read s :: Integer

  readMultilineInput :: Int -> (String -> IO a) -> IO [a]
  readMultilineInput n transformer = replicateM n (getLine >>= transformer)

  elemSet :: (Ord a) => a -> S.Set a -> Bool
  elemSet elem sets =
    let found = elem `S.lookupIndex` sets
        in toBool found
        where
          toBool :: Maybe Int -> Bool
          toBool (Just _) = True
          toBool Nothing = False

  location :: String -> (Int, Int) -> (Int, Int)
  location [] a = a
  location ('U':xs) (x, y) = location xs (x, y + 1)
  location ('D':xs) (x, y) = location xs (x, y - 1)
  location ('L':xs) (x, y) = location xs (x - 1, y)
  location ('R':xs) (x, y) = location xs (x + 1, y)

  location2 :: String -> (Int, Int)
  location2 xs = let
    us = length $ (filter (=='U')) xs
    ds = length $ (filter (=='D')) xs
    ls = length $ (filter (=='L')) xs
    rs = length $ (filter (=='R')) xs
    in ((rs - ls), (us - ds))

  minimumChange :: Int -> Int -> Int
  minimumChange x y
    | odd x = minimumChange (x - 1) (y - 1) + 1
    | otherwise = abs (x `div` 2) + abs (y `div` 2)

  solve :: String -> Int
  solve xs
    | length xs `mod` 2 == 1 = -1
    | otherwise =
      let (x, y) = location xs (0, 0)
          in minimumChange (abs x) (abs y)

  sameLoc :: (Int, Int) -> (Int, Int) -> Bool
  sameLoc (x, y) (p, q)
    | x == p && y == q = True

  main :: IO()
  main = do
    xs <- getLine
    putStrLn $ show $ solve xs

main :: IO()
main = do
  str <- getLine
  print $ solve str

solve :: String -> Int
solve str
  | even $ length str = walk str
  | otherwise = -1

walk :: String -> Int
walk str = ((abs x) + (abs y)) `div` 2
  where (x, y) = route str (0, 0)

route :: String -> (Int, Int) -> (Int, Int)
route [] (x1, y1) = (x1, y1)
route (x:xs) (x1, y1)
         | x == 'L' = route xs (x1 - 1, y1)
         | x == 'R' = route xs (x1 + 1, y1)
         | x == 'U' = route xs (x1, y1 + 1)
         | x == 'D' = route xs (x1, y1 - 1)

solve s | (length s) `mod` 2 == 1  = -1
        | otherwise                = ans
        where
            us = length $ filter (\x -> x == 'U') s
            ds = length $ filter (\x -> x == 'D') s
            r1 = (abs (us - ds)) `mod` 2
            ls = length $ filter (\x -> x == 'L') s
            rs = length $ filter (\x -> x == 'R') s
            r2 = (abs (ls - rs)) `mod` 2
            ans = ((abs (us - ds)) `div` 2) + ((abs (ls - rs)) `div` 2) + ((r1 + r2) `div` 2)

main = do
    s <- getLine
    print $ solve s

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	s <- getLine
	let
		( a, b ) = solve 0 0 s
		d = a + b
	print $ which ( d `div` 2 ) ( -1 ) $ d `mod` 2 == 0

solve a b [] = ( abs a, abs b )
solve a b ( 'L' : s ) = solve ( a - 1 ) b s
solve a b ( 'R' : s ) = solve ( a + 1 ) b s
solve a b ( 'U' : s ) = solve a ( b + 1 ) s
solve a b ( 'D' : s ) = solve a ( b - 1 ) s

module Main where
  import Data.List
  import Control.Monad
  import Data.Array
  import qualified Data.Set as S

  toArray :: [a] -> Array Int a
  toArray xs =
    let ls = length xs - 1
        in array (0, ls) $ zip [0..ls] xs

  readInt :: String -> Integer
  readInt s = read s :: Integer

  readMultilineInput :: Int -> (String -> IO a) -> IO [a]
  readMultilineInput n transformer = replicateM n (getLine >>= transformer)

  elemSet :: (Ord a) => a -> S.Set a -> Bool
  elemSet elem sets =
    let found = elem `S.lookupIndex` sets
        in toBool found
        where
          toBool :: Maybe Int -> Bool
          toBool (Just _) = True
          toBool Nothing = False

  location :: String -> (Int, Int) -> (Int, Int)
  location [] a = a
  location ('U':xs) (x, y) = location xs (x, y + 1)
  location ('D':xs) (x, y) = location xs (x, y - 1)
  location ('L':xs) (x, y) = location xs (x - 1, y)
  location ('R':xs) (x, y) = location xs (x + 1, y)

  minimumChange :: Int -> Int -> Int
  minimumChange x y
    | odd x = minimumChange (x - 1) (y - 1) + 1
    | otherwise = (x `div` 2) + (y `div` 2)

  solve :: String -> Int
  solve xs
    | length xs `mod` 2 == 1 = -1
    | otherwise =
      let (x, y) = location xs (0, 0)
          in minimumChange x y

  main :: IO()
  main = do
    xs <- getLine
    putStrLn $ show $ solve xs

module Main where
  import Data.List
  import Control.Monad
  import Data.Array
  import qualified Data.Set as S

  toArray :: [a] -> Array Int a
  toArray xs =
    let ls = length xs - 1
        in array (0, ls) $ zip [0..ls] xs

  readInt :: String -> Integer
  readInt s = read s :: Integer

  readMultilineInput :: Int -> (String -> IO a) -> IO [a]
  readMultilineInput n transformer = replicateM n (getLine >>= transformer)

  elemSet :: (Ord a) => a -> S.Set a -> Bool
  elemSet elem sets =
    let found = elem `S.lookupIndex` sets
        in toBool found
        where
          toBool :: Maybe Int -> Bool
          toBool (Just _) = True
          toBool Nothing = False

  location :: String -> (Int, Int) -> (Int, Int)
  location [] a = a
  location ('U':xs) (x, y) = location xs (x, y + 1)
  location ('D':xs) (x, y) = location xs (x, y - 1)
  location ('L':xs) (x, y) = location xs (x - 1, y)
  location ('R':xs) (x, y) = location xs (x + 1, y)

  location2 :: String -> (Int, Int)
  location2 xs = let
    us = length $ (filter (=='U')) xs
    ds = length $ (filter (=='D')) xs
    ls = length $ (filter (=='L')) xs
    rs = length $ (filter (=='R')) xs
    in ((rs - ls), (us - ds))

  minimumChange :: Int -> Int -> Int
  minimumChange x y
    | odd x = minimumChange (x - 1) (y - 1) + 1
    | otherwise = abs (x `div` 2) + abs (y `div` 2)

  solve :: String -> Int
  solve xs
    | length xs `mod` 2 == 1 = -1
    | otherwise =
      let (x, y) = location xs (0, 0)
          in minimumChange (abs x) (abs y)

  sameLoc :: (Int, Int) -> (Int, Int) -> Bool
  sameLoc (x, y) (p, q)
    | x == p && y == q = True

  main :: IO()
  main = do
    xs <- getLine
    let l1 = location xs (0, 0)
        l2 = location2 xs
        s = sameLoc l1 l2
    putStrLn $ show l1
    putStrLn $ show s
    putStrLn $ show $ solve xs


{-# LANGUAGE TypeFamilies, UndecidableInstances, FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables #-}
import Data.Ord
import Data.Int
import Data.Char
import Data.Foldable
import Data.List
import Data.Maybe
import Data.Either
import Data.Array.ST.Safe
import Data.Array.Unboxed
import Control.Monad
import Control.Monad.ST.Safe
import Control.Monad.Trans.Except
import Control.Monad.Trans.Class
import Text.Read (readEither)

getToken :: IO String
getToken =
    let aux s = do
        x <- getChar
        if x == ' ' || x == '\t' || x == '\n' then
            if s then
                aux s
            else
                return id
        else
            liftM ((.) $ showChar x) $ aux False
    in liftM (flip ($) []) $ aux True

type EIO a = ExceptT String IO a

data HNormal
data HString
data HList

class IOInteract a where
    convertEither :: String -> Either String a
    toShowS :: a -> String -> String
    toShow :: a -> String
    toShow x = toShowS x []

instance (IOType a ~ flag, IOInteractp flag a) => IOInteract a where
    convertEither = convertEitherp (undefined :: flag)
    toShowS = toShowSp (undefined :: flag)

type family IOType x where
    IOType String = HString
    IOType [x] = HList
    IOType x = HNormal

class IOInteractp flag a where
    convertEitherp :: flag -> String -> Either String a
    toShowSp :: flag -> a -> String -> String

instance (Show a, Read a) => IOInteractp HNormal a where
    convertEitherp _ x = readEither x
    toShowSp _ x = shows x

instance IOInteractp HString String where
    convertEitherp _ x = Right x
    toShowSp _ x = showString x

instance (IOInteract a) => IOInteractp HList [a] where
    convertEitherp _ x = mapM convertEither $ words x
    toShowSp _ [] = id
    toShowSp _ (x : []) = toShowS x
    toShowSp dum (x : xs) = toShowS x . showChar ' ' . toShowSp dum xs

get :: IOInteract a => EIO a
get = ExceptT $ liftM convertEither getToken
put :: IOInteract a => a -> EIO ()
put = lift . putStr . toShow
putln :: IOInteract a => a -> EIO ()
putln = lift . putStrLn . toShow

main :: IO ()
main = do
    o <- runExceptT main_
    case o of
        Right () -> return ()
        Left s -> putStrLn s

main_ :: EIO ()
-- template --
main_ = do
    t <- get
    replicateM_ t f1

f1 :: EIO ()
f1 = do
    n <- get
    a <- replicateM n get
    b <- replicateM n get
    let (x, y) = f2 n a b in do
        putln x
        putln y

f2 :: Int -> [Int] -> [Int] -> ([Int], [Int])
f2 n a b = (sort a, sort b)

import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn
  replicateM_ n routine

routine :: IO ()
routine = do
  _ <- getLine
  as <- (map read.words) <$> getLine
  bs <- (map read.words) <$> getLine
  putStrLn $ (unwords.map show) $ sort (as:: [Int])
  putStrLn $ (unwords.map show) $ sort (bs :: [Int])

import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe
import Data.Array

onecase = do
		getLine
		a<- sort <$> map read <$> words <$> getLine ::IO [Int]
		b<- sort <$> map read <$> words <$> getLine ::IO [Int]
		putStrLn $ intercalate " " $ map show a
		putStrLn $ intercalate " " $ map show b

main = do
		n<- read <$> getLine ::IO Int
		replicateM_ n onecase

import Data.List (sort)

process :: ([Int],[Int]) -> ([Int],[Int])
process (as,bs) = (sort as, sort bs)

readInt :: String -> Int
readInt = read

run :: Int -> IO ()
run 0 = return ()
run t = do
    n <- fmap readInt getLine
    as <- fmap (map readInt.words) getLine
    bs <- fmap (map readInt.words) getLine
    let (xs, ys) = process (as,bs)
    putStrLn . unwords . map show $ xs
    putStrLn . unwords . map show $ ys
    run (t-1)

main :: IO ()
main = do
    t <- fmap readInt getLine
    run t

import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe
import Data.Array

onecase = do
		getLine
		a<- sort <$> map read <$> words <$> getLine ::IO [Int]
		b<- sort <$> map read <$> words <$> getLine ::IO [Int]
		print $ intercalate " " $ map show a
		print $ intercalate " " $ map show b

main = do
		n<- read <$> getLine ::IO Int
		replicateM_ n onecase


import Control.Applicative
import Control.Monad
import Data.List

main = sol <$> readLn >>= mapM_ putStrLn

sol n = if n > 2
    then ["Yes", put s1, put s2]
    else ["No"]
    where
    s1 = 1:[n]
    s2 = (n-1):[1..n-1]

put = unwords . fmap show

module Main where
import Data.Maybe

default (Int)
main = interact $ maybe "No" (\(xs, ys) -> unlines ["Yes", unwords $ map show $ length xs:xs, unwords $ map show $ length ys:ys]) . solve . read

solve 1 = Nothing
solve n | s <- n * (n + 1) `quot` 2 = case [i | i <- [1..n], gcd i (s - i) /= 1] of
  [] -> Nothing
  (i:_) -> Just ([i], [1..i - 1] ++ [i + 1..n])

import Data.List

main = do
  n <- readLn :: IO Int

  case solve n of
    Nothing -> putStrLn "No"
    Just x -> do
      putStrLn "Yes"
      putStrLn $ unwords . map show $ [1,x]
      putStrLn $ unwords . map show $ (n-1):(delete x [1..n])

solve 1 = Nothing
solve n = find (\x -> gcd (s-x) x > 1) [1..n]
  where
    s = n*(n+1)`div`2

import Control.Applicative
import Control.Monad
import Data.List

main = sol <$> readLn >>= mapM_ putStrLn

sol n = if n > 2
    then ["Yes", put s1, put s2]
    else ["No"]
    where
    s1 = 1:[n]
    s2 = 2:[1..n-1]

put = unwords . fmap show

module Main where
import Data.Maybe

default (Int)
main = interact $ maybe "No" (\(xs, ys) -> unlines ["Yes", unwords $ map show $ length xs:xs, unwords $ map show $ length ys:ys]) . solve . read

solve 1 = Nothing
solve 2 = Just ([1], [2])
solve n
  | odd (length os) = Just (tail es, 2:os)
  | otherwise = Just (es, os)
  where
    es = [2, 4..n]
    os = [1, 3..n]


{-# OPTIONS_GHC -O2 -optc-O2 #-}

import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC
import qualified Data.IntMap as IntMap

createRow [] acc = acc
createRow ((row,col) : xs) acc
  | (IntMap.member row acc) == False = createRow xs (IntMap.insert row (col,col) acc)
  | otherwise                        = let (minCol,maxCol) = (IntMap.findWithDefault (0,0) row acc)
                                       in
                                       if (col < minCol) then createRow xs (IntMap.update (\x -> Just (col,maxCol)) row acc)
                                       else if (col > maxCol) then createRow xs (IntMap.update (\x -> Just (minCol,col)) row acc)
                                        else createRow xs acc

createCol [] acc = acc
createCol ((row,col) : xs) acc
  | (IntMap.member col acc) == False = createCol xs (IntMap.insert col (row,row) acc)
  | otherwise                        = let (minRow,maxRow) = (IntMap.findWithDefault (0,0) col acc)
                                       in
                                       if (row < minRow) then createCol xs (IntMap.update (\x -> Just (row,maxRow)) col acc)
                                       else if (row > maxRow) then createCol xs (IntMap.update (\x -> Just (minRow,row)) col acc)
                                        else createCol xs acc

createDiag [] acc f = acc
createDiag ((row,col) : xs) acc f
  | (IntMap.member (f row col) acc) == False = createDiag xs (IntMap.insert (f row col) ((row,col),(row,col)) acc) f
  | otherwise                        = let ((minRow,minCol),(maxRow,maxCol)) = (IntMap.findWithDefault ((0,0),(0,0)) (f row col) acc)
                                       in
                                       if (row < minRow) then createDiag xs (IntMap.update (\x -> Just ((row,col),(maxRow,maxCol))) (f row col) acc) f
                                       else if (row > maxRow) then createDiag xs (IntMap.update (\x -> Just ((minRow,minCol),(row,col))) (f row col) acc) f
                                        else createDiag xs acc f

checkRow (row,col) rows =
  let (minCol,maxCol) = (IntMap.findWithDefault (0,0) row rows)
  in
  case (col > minCol) of True -> if (col < maxCol) then 2 else 1
                         False -> if (col < maxCol) then 1 else 0

checkCol (row,col) cols =
  let (minRow,maxRow) = (IntMap.findWithDefault (0,0) col cols)
  in
  case (row > minRow) of True -> if (row < maxRow) then 2 else 1
                         False -> if (row < maxRow) then 1 else 0

checkDiag (row,col) diag f =
  let d = f row col in
  let ((minRow,minCol),(maxRow,maxCol)) = (IntMap.findWithDefault ((0,0),(0,0)) d diag)
  in
  case (row > minRow) of True -> if (row < maxRow) then 2 else 1
                         False -> if (row < maxRow) then 1 else 0

check [] rows cols diag1 diag2 t = t
check ((row,col) : xs) rows cols diag1 diag2 t =
  let threats = (checkRow (row,col) rows) + (checkCol (row,col) cols) + (checkDiag (row,col) diag1 (-)) + (checkDiag (row,col) diag2 (+)) in
    case (IntMap.member threats t) of False -> check xs rows cols diag1 diag2 (IntMap.insert threats 1 t)
                                      True -> check xs rows cols diag1 diag2 (IntMap.adjust (1+) threats t)

main :: IO ()
main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (m, r2) = readInt r1
     let Just (board, r3) = readIntList m r2
     let rows = createRow board (IntMap.empty)
     let cols = createCol board (IntMap.empty)
     let diag1 = createDiag board (IntMap.empty) (-)
     let diag2 = createDiag board (IntMap.empty) (+)
     let tSeq = check board rows cols diag1 diag2 (IntMap.empty)
     printResult tSeq 0
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readIntList 0 s = do return ([], s)
        readIntList n s = do (row, r) <- readInt s
                             (col, z) <- readInt r
                             (l, t) <- readIntList (n-1) z
                             return ((row,col) : l, t)
        printResult l 9 = putStrLn ""
        printResult l n = do
                            let v = IntMap.findWithDefault 0 n l
                            putStr $ show v ++ " "
                            printResult l (n+1)


--
-- Michael V. Antosha
-- 2022
-- Michael.Antosha@gmail.com
--

{-# language Safe                      #-}
{-# language ImportQualifiedPost       #-}
{-# language NoMonomorphismRestriction #-}

{-# options_ghc -O3                              #-}

{-# options_ghc -Weverything                     #-}
{-# options_ghc -Werror                          #-}

{-# options_ghc -Wno-missing-import-lists        #-}
{-# options_ghc -Wno-missing-local-signatures    #-}

import Prelude               hiding (getLine)
import Control.Arrow
import Control.Monad
import Data.ByteString.Char8 qualified as B
import Data.Char
import Data.List             qualified as L

ri = readInts <$> B.getLine :: IO [Int]
  where
    readInts  = L.unfoldr ((second dropSpace <$>) . B.readInt) . dropSpace
    dropSpace = B.dropWhile isSpace

main :: IO ()
main = do
    [t] <- ri
    tcs <- replicateM t $ do
        [[n], xs] <- replicateM 2 ri
        return (n,xs)
    mapM_ (putStrLn.showB.solve) tcs

showB False = "NO"
showB True  = "YES"

solve (_n,xs) = null adSkipped
  where
    dw = dropWhile . uncurry
    adSkipped = dw (>=) . dw (<=) $ zip xs (tail xs)

--
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DatatypeContexts #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TupleSections #-}
{-# OPTIONS_GHC -O3 -funbox-strict-fields -fvia-C -optc-O3 #-}

import Control.Arrow ((>>>))
import Control.Monad (
    MonadPlus (mplus),
    foldM_,
    forM_,
    guard,
    join,
    replicateM,
    replicateM_,
 )
import qualified Control.Monad as M
import qualified Control.Monad.ST.Strict as ST
import qualified Control.Monad.State.Strict as S
import qualified Control.Monad.Trans.Class as T

import qualified Data.Array as A
import qualified Data.Array.MArray.Safe as MA
import qualified Data.Array.IO.Safe as IOA
import qualified Data.Array.ST.Safe as STA
import qualified Data.Array.Unboxed as UA

import Data.Bits
import qualified Data.ByteString.Char8 as B8
import Data.Char
import Data.Int

import Data.Function (on)
import Data.Functor ((<&>))
import Data.Bifunctor (bimap)
import Data.Maybe (fromJust, fromMaybe, isJust)
import qualified Data.Maybe as MB

import qualified Data.IntMap as IM
import qualified Data.IntSet as IS
import qualified Data.List   as L
import Data.List (
    elemIndices,
    find,
    findIndices,
    intersect,
    isPrefixOf,
    nub,
    sort,
    sortOn,
 )
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Ix as Ix
import qualified Data.Ratio as R

import Control.Monad.Cont (MonadIO (liftIO))
import Data.IORef (modifyIORef, newIORef, readIORef)
import GHC.IO.Handle (hDuplicateTo)
import System.IO (
    IOMode (ReadMode, WriteMode),
    openFile,
    stdin,
    stdout,
    hFlush
 )
import System.Posix.Internals (puts)
import Text.Printf (printf)
import qualified Data.Array.IO.Safe as UOA

-- import Debug.Trace (trace, traceM, traceShowM)
-- debug = flip trace
--
-- tracing t x = trace (t ++ " = " ++ show x) x
-- debugging x t = tracing t x

-- debug x t = x
-- trace t x = x
-- tracing t x = x
-- debugging x t = x

readIntB8 :: B8.ByteString -> Int
readIntB8 = B8.readInt >>> (fst . fromJust)

readIntB8s :: B8.ByteString -> [Int]
readIntB8s = B8.words >>> map (B8.readInt >>> (fst . fromJust))

readIntegerB8 :: B8.ByteString -> Integer
readIntegerB8 = B8.readInteger >>> (fst . fromJust)

readIntegerB8s :: B8.ByteString -> [Integer]
readIntegerB8s = B8.words >>> map (B8.readInteger >>> (fst . fromJust))

modifyArray :: (MA.MArray a e m, MA.Ix i) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = do
    value <- MA.readArray arr ix
    MA.writeArray arr ix $ f value

putsYesNo :: Bool -> IO ()
putsYesNo value = do
    let result :: String =
            if value
                then "YES"
                else "NO"
    printf "%s\n" result

{- END OF GENERAL -}

solve :: Int -> [Int] -> Bool
solve n as = (increasingA + decreasingA) >= length as
    where
        increasingA = increasingSeq as
        decreasingA = increasingSeq $ reverse as

        increasingSeq :: [Int] -> Int
        increasingSeq as = length . takeWhile (uncurry (>=)) $ zip as (0 : as)

main :: IO ()
main = do
    t <- B8.getLine <&> readIntB8
    replicateM_ t $ do
        n <- B8.getLine <&> readIntB8
        as <- B8.getLine <&> readIntB8s
        let answer = solve n as
        putsYesNo answer


{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad

count :: (Int, Int) -> Char -> (Int, Int)
count state@(!n, !answer) c
  | c == '('   = (n + 1, answer)
  | n > 0      = (n - 1, answer + 2)
  | otherwise  = state

solve :: String -> IO ()
solve = putStrLn . show . snd . foldl count (0, 0)

main :: IO ()
main = getLine >>= solve

import Data.List

minDelCount :: String -> Int
minDelCount xs =
    let (d, h) = foldl' counter (0, 0) xs in
    if d < 0 then (- d) + max (h - d) 0
             else max h 0
    where
    counter (d, h) c = h' `seq` d `seq` (min h' d, h')
        where
        h' = case c of
            '(' -> h + 1
            ')' -> h - 1

main :: IO ()
main = do
    line <- getLine
    putStrLn $ show $ (length line) - (minDelCount line)

f l [] = -l
f l (x:xs)
	| x == '(' = f (l + 1) xs + 1
	| x == ')' = if l > 0 then f (l - 1) xs + 1 else f l xs

main = do
	s <- getLine
	putStrLn . show $ f 0 s

import Data.List
main = do getLine >>= print . fst . foldl f (0, 0)
f (a, b) '(' = (a, b + 1)
f (a, 0) ')' = (a, 0)
f (a, b) ')' = (a + 2, b - 1)

solve ans _ [] = ans
solve ans n ('(':xs) = solve ans (n+1) xs
solve ans 0 (')':xs) = solve ans 0 xs
solve ans n (')':xs) = solve (ans+2) (n-1) xs

main = getLine >>= print . solve 0 0

count_regular b ct [] = ct - b
count_regular b ct ('(':xs) = count_regular (succ b) (succ ct) xs
count_regular b ct (')':xs)
    | b > 0 = count_regular (pred b) (succ ct) xs
    | otherwise = count_regular b ct xs

main :: IO ()
main = do
    seq <- getLine
    print (count_regular 0 0 seq)

import Control.Monad (liftM, replicateM, replicateM_)
import Data.Array
import Data.List (intercalate)
import Prelude hiding (reads)

reads :: Read a => IO [a]
reads  =  liftM (map read . words) getLine

prints :: Show a => [a] -> IO ()
prints  =  putStrLn . intercalate " " . map show

solve :: String -> Int
solve s  =  solve' 0 s
  where
    solve' n ""  =  (-n)
    solve' 0 (')':s)  =  solve' 0 s
    solve' n ('(':s)  =  1 + solve' (n+1) s
    solve' n (')':s)  =  1 + solve' (n-1) s

main :: IO ()
main  =  getLine >>= print . solve

-- Codeforces 26B

{-# OPTIONS_GHC -O2 #-}
{-# OPTIONS_GHC -optc-O2 #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Data.List

main :: IO ()
main = let match !(!a, !b) '(' = (a, b + 1)
           match !(!a, 0) ')' = (a, 0)
           match !(!a, !b) ')' = (a + 2, b - 1)
        in getLine >>= print . fst . foldl' match (0, 0)

correct good open [] = good
correct good open ('(':xs) = correct good (open+1) xs
correct good open (')':xs) | open > 0 = correct (good+2) (open-1) xs
                           | otherwise = correct good open xs
main = correct 0 0 `fmap` getLine >>= print

{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Data.List

type Index = Int
type Range = (Index, Index)
type State = ([Index], [Range])

automata :: State -> (Index, Char) -> State
automata state@(stack, ranges) (i, c)
  | c == '('   = (i : stack, ranges)
  | null stack = state
  | otherwise  = update state i

update :: State -> Index -> State
update (!i : stack, ranges) !j = (,) stack . ((i, j) :) $ do
  x@(i', j') <- ranges
  guard $ j' < i || j < i'
  return x

exec :: String -> [Range]
exec = reverse . snd . foldl automata ([], []) . zip [0 ..]

merge :: [Range] -> [Int]
merge (x@(a, b) : y@(c, d) : zs)
  | b + 1 == c      = merge ((a, d) : zs)
  | otherwise       = b - a + 1 : merge (y : zs)
merge ((a, b) : zs) = b - a + 1 : merge zs
merge _             = [ 0 ]

solve :: String -> IO ()
solve = putStrLn . show . maximum . merge . exec

main = getLine >>= solve

{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Data.List

type Index  = Int
type Depth  = Int
type Stack  = (Depth, Depth, [Index])
type State  = (Stack, (Int, Int))

push :: Index -> State -> State
push i ((d, e, is), best)
  | d == e    = ((d', d', i : is), best)
  | otherwise = ((d', e, is), best)
 where d' = d + 1

pop :: Index -> State -> State
pop i ((!d, !e, is), best@(!longest, !count))
  | d == 0    = ((0, 0, []), best)
  | otherwise = (,) (d - 1, d, is') $ case compare l longest of
    LT -> best
    EQ -> fmap succ best
    GT -> (l, 1)
 where is' = drop (e - d) is
       l = i - head is' + 1

automata :: State -> (Index, Char) -> State
automata state (i, c)
  | c == '('   = push i state
  | otherwise  = pop  i state

solve :: String -> IO ()
solve = putStrLn . show . fst
      . snd . foldl automata ((0, 0, []), (0, 1)) . zip [0 ..]

main :: IO ()
main = getLine >>= solve

{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Data.List

type Index = Int
type Longest = Int
type State = ([Index], Longest)

automata :: State -> (Index, Char) -> State
automata state@(stack, !best) (i, c)
  | c == '('   = (i : stack, best)
  | null stack = state
  | otherwise  = update state i

update :: State -> Index -> State
update (j : stack, best) i =
  case compare l best of
    GT -> (stack, l)
    _  -> (stack, best)
 where l = i - j + 1

exec :: String -> Longest
exec = snd . foldl automata ([], 0) . zip [0 ..]

solve :: String -> IO ()
solve = putStrLn . show . exec

main = getLine >>= solve

import Data.List

minDelCount :: String -> Int
minDelCount xs =
    let (d, h) = foldl' counter (0, 0) xs in
    if      d < 0 then (- d) + max (h - d) 0
    else if h > 0 then h
    else               0
    where
    counter (d, h) c = h' `seq` d `seq` (min h' d, h')
        where
        h' = case c of
            '(' -> h - 1
            ')' -> h + 1

main :: IO ()
main = do
    line <- getLine
    putStrLn $ show $ (length line) - (minDelCount line)