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

solve[1,0]=[1]
solve[1,_]=[-1]
solve[n,k]
  | k < n`div`2 = [-1]
  | k - q > 0 = (k-q):2*(k-q):take(n-2)[2*(k-q)+1..]
  | otherwise = [-1]
   where
     q = (n-2)`div`2

import Data.List (intercalate,nub)
import Data.Ord

solve :: Int -> Int -> [Int]
solve 1 0 = [1]
solve 1 _ = []
solve n k | n `div` 2 > k = []
solve n k =
  let parts = n `div` 2
      m = k - (parts-1)
      r = if odd n then 1 else 0
      fit m c o | c+o < m   = [1..c+o]
                | c < m     = [1..c] ++ [m+1..m+o]
                | otherwise = [2*m+1..2*m+c+o]
  in [m,2*m] ++ (fit m (2*(parts-1)) r)

score (a:b:rest) = gcd a b + score rest
score _ = 0

check :: Int -> Int -> [Int] -> Bool
check n k xs = length xs == n && score xs == k && length (nub xs) == n

main = do
  (n:k:_) <- (map read . words) `fmap` getLine
  case solve n k of
    [] -> putStrLn "-1"
    xs -> putStrLn $ intercalate " " (map show xs)

solve :: [Int] -> [Int]
solve [1, 0] = [ 1]
solve [1, _] = [-1]
solve [n, k] = case compare q k of
    LT -> a : a' : take (n - 2) (iterate f 1)
    EQ -> [1..n]
    GT -> [-1]
    where q = n `div` 2
          a = k - q + 1
          a' = 2 * a
          f x = let x' = x + 1 in x' + fromEnum (elem x' [a, a'])
main = interact $ unwords . map show . solve . map read . words

main = interact $ unwords . map show . solve . map read . words
solve [n,k] | k == 0 && n == 1 = [1]
            | k < n' || n == 1 = [-1]
            | otherwise = take n $ [k-n''] ++ [2*(k-n''),2*(k-n'')+1..]
  where n' = n `div` 2
        n'' = (n-2) `div` 2

solve :: Int -> Int -> [Int]
solve 1 0 = [ 1]
solve 1 _ = [-1]
solve n k = case compare q k of
    LT -> a : a' : take (n - 2) (iterate f 1)
    EQ -> [1..n]
    GT -> [-1]
    where q = n `div` 2
          a = k - q + 1
          a' = 2 * a
          f x = let x' = x + 1 in x' + fromEnum (elem x' [a, a'])
main = putStrLn . unwords . map show . (\[x, y] -> solve (read x) (read y)) . words =<< getLine

main :: IO()
main = output . solve . map read . words =<< getContents

solve :: [Int] -> Maybe [Int]
solve [n, k] | (div n 2) > k   = Nothing
             | n == 1 && k > 0 = Nothing
             | n == 1          = Just [1]
             | otherwise       = let a = div n 2
                                     b = k - (a - 1)
                                 in  Just (b:(b*2):(solve' (b*2 + 1) (n - 2)))

solve' :: Int -> Int -> [Int]
solve' _ 0 = []
solve' i n = i : (solve' (i + 1) (n - 1))

output :: Maybe [Int] -> IO()
output Nothing       = putStrLn "-1"
output (Just [])     = putStrLn ""
output (Just (a:ax)) = do putStr ((show a) ++ " ")
                          output (Just ax)

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST.Safe
import Control.Monad.State
-- import Data.Array
import Data.Array.IArray
import Data.Array.IO.Safe
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Builder as BB
import Data.Char
import qualified Data.Foldable as F
import Data.Function
-- import Data.Graph
import Data.Int
import Data.List
import Data.List.Split
import Data.Maybe
import Data.Monoid
import Data.Ratio
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
-- import Data.Tree
import Data.Tuple
import Data.Map (Map)
import qualified Data.Map as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
-- import Debug.Trace
import System.IO

-- getInts = fmap (map read . words) getLine
getInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

main = do
  [n, k] <- getInts

  let
    n' = 2*(n `div` 2)

    a =  k - (n`div`2 - 1)
    b = 2*a

    s = [a, b] ++ s'
    s' = take (n-2) $ concat $ filter (\[x, y] -> x /= a && y /= a && y /= b) $ [[a,a+1] | a <- [1,3..]]

  if n == 1
    then print (if k == 0 then 1 else -1)
    else
      if k < n `div` 2
        then print $ -1
        else
          putStrLn $ unwords $ map show $
            if k == n `div` 2
              then take n [1..]
              else s

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

inf :: Int
inf = 10^9
solve[1,_]=[-1]
solve[n,k]
  | k - q > 0 = (k-q):2*(k-q):take(n-2)[inf,inf-1..]
  | otherwise = [-1]
   where
     q = (n-2)`div`2

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

solve[1,_]=[-1]
solve[n,k]
  | k < n`div`2 = [-1]
  | k - q > 0 = (k-q):2*(k-q):take(n-2)[2*(k-q)+1..]
  | otherwise = [-1]
   where
     q = (n-2)`div`2

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

inf :: Int
inf = 10^9

solve[n,k]
  | n`div`2 > k = [-1]
  | otherwise = (k-q):2*(k-q):take(n-2)[inf,inf-1..]
   where
     q = (n-2)`div`2

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST.Safe
import Control.Monad.State
-- import Data.Array
import Data.Array.IArray
import Data.Array.IO.Safe
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Builder as BB
import Data.Char
import qualified Data.Foldable as F
import Data.Function
-- import Data.Graph
import Data.Int
import Data.List
import Data.List.Split
import Data.Maybe
import Data.Monoid
import Data.Ratio
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
-- import Data.Tree
import Data.Tuple
import Data.Map (Map)
import qualified Data.Map as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
-- import Debug.Trace
import System.IO

-- getInts = fmap (map read . words) getLine
getInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

main = do
  [n, k] <- getInts

  let
    n' = 2*(n `div` 2)

    a =  k - (n`div`2 - 1)
    b = 2*a

    s = [a, b] ++ s'
    s' = take (n-2) $ concat $ filter (\[x, y] -> x /= a && y /= a && y /= b) $ [[a,a+1] | a <- [1,3..]]

  if k < n `div` 2
    then print $ -1
    else
      putStrLn $ unwords $ map show $
        if k == n `div` 2
          then take n [1..]
          else s

import Data.List (intercalate,nub)
import Data.Ord

solve :: Int -> Int -> [Int]
solve n k | n `div` 2 > k = []
solve n k =
  let parts = n `div` 2
      m = k - (parts-1)
      r = if odd n then 1 else 0
      fit m c o | c+o < m   = [1..c+o]
                | c < m     = [1..c] ++ [m+1..m+o]
                | otherwise = [2*m+1..2*m+c+o]
  in [m,2*m] ++ (fit m (2*(parts-1)) r)

score (a:b:rest) = gcd a b + score rest
score _ = 0

check :: Int -> Int -> [Int] -> Bool
check n k xs = length xs == n && score xs == k && length (nub xs) == n

main = do
  (n:k:_) <- (map read . words) `fmap` getLine
  case solve n k of
    [] -> putStrLn "-1"
    xs -> do putStrLn $ intercalate " " (map show xs)
             putStrLn $ show $ check n k xs

import Data.List (intercalate,nub)
import Data.Ord

solve :: Int -> Int -> [Int]
solve 1 _ = []
solve n k | n `div` 2 > k = []
solve n k =
  let parts = n `div` 2
      m = k - (parts-1)
      r = if odd n then 1 else 0
      fit m c o | c+o < m   = [1..c+o]
                | c < m     = [1..c] ++ [m+1..m+o]
                | otherwise = [2*m+1..2*m+c+o]
  in [m,2*m] ++ (fit m (2*(parts-1)) r)

score (a:b:rest) = gcd a b + score rest
score _ = 0

check :: Int -> Int -> [Int] -> Bool
check n k xs = length xs == n && score xs == k && length (nub xs) == n

main = do
  (n:k:_) <- (map read . words) `fmap` getLine
  case solve n k of
    [] -> putStrLn "-1"
    xs -> putStrLn $ intercalate " " (map show xs)

import Data.List (intercalate,nub)
import Data.Ord

solve :: Int -> Int -> [Int]
solve n k | n `div` 2 > k = []
solve n k =
  let parts = n `div` 2
      m = k - (parts-1)
      r = if odd n then 1 else 0
      fit m c o | c+o < m   = [1..c+o]
                | c < m     = [1..c] ++ [m+1..m+o]
                | otherwise = [2*m+1..2*m+c+o]
  in [m,2*m] ++ (fit m (2*(parts-1)) r)

score (a:b:rest) = gcd a b + score rest
score _ = 0

check :: Int -> Int -> [Int] -> Bool
check n k xs = length xs == n && score xs == k && length (nub xs) == n

main = do
  (n:k:_) <- (map read . words) `fmap` getLine
  case solve n k of
    [] -> putStrLn "-1"
    xs -> putStrLn $ intercalate " " (map show xs)

main = interact $ unwords . map show . solve . map read . words
solve [n,k] | k < n' = [-1]
            | k `mod` n' == 0 = concatMap pair (replicate n' (k `div` n')) ++ c
            | otherwise = concatMap pair ((k `div` n' + k `mod` n') : replicate (n'-1) (k `div` n')) ++ c
  where n' = n `div` 2
        c | odd n = [1] | even n = []
pair x = [x,x]

main = interact $ unwords . map show . solve . map read . words
solve [n,k] | k == 0 = [1]
            | k < n' || n == 1 = [-1]
            | otherwise = take n $ [k-n''] ++ [2*(k-n''),2*(k-n'')+1..]
  where n' = n `div` 2
        n'' = (n-2) `div` 2

main = interact $ unwords . map show . solve . map read . words
solve [n,k] | k == 0 = [1..n]
            | k < n' || n == 1 = [-1]
            | otherwise = take n $ [k-n''] ++ [2*(k-n''),2*(k-n'')+1..]
  where n' = n `div` 2
        n'' = (n-2) `div` 2

main = interact $ unwords . map show . solve . map read . words
solve [n,k] | k < n' = [-1]
            | otherwise = take n $ [k-n''] ++ [2*(k-n''),2*(k-n'')+1..]
  where n' = n `div` 2
        n'' = (n-2) `div` 2

main = interact $ unwords . map show . solve . map read . words
solve [n,k] | k < n' || n == 1 = [-1]
            | otherwise = take n $ [k-n''] ++ [2*(k-n''),2*(k-n'')+1..]
  where n' = n `div` 2
        n'' = (n-2) `div` 2


solve [[n, k], xs] =
    show $ fst $ head $ dropWhile ((==0).snd) $ dropWhile ((/=k).fst) $ cycle $ zip [1..n] xs

main = do text <- readFile "input.txt"
          writeFile "output.txt" (solve $ map (map read.words) $ lines text)

solve (1:_) = 0
solve (_:xs) = solve xs + 1

main = do
	input <- fmap lines $ readFile "input.txt"
	let [n, k] = map read . words . head $ input
	let k' = k - 1
	let as = map read . words $ input !! 1
	writeFile "output.txt" . (++"\n") . show . (+1) . (`mod`n) . (+k') . solve $ drop k' as ++ take k' as

solve [[n,k],xs] = show.fst.head.dropWhile ((==0).snd). drop (k-1).cycle.zip [1..n] $ xs
main = readFile "input.txt" >>= writeFile "output.txt".solve.map(map read.words).lines

#! /usr/bin/runhaskell
import Data.List
import Data.Maybe
main = do
  file <- readFile "input.txt"
  writeFile "output.txt" (show $ (f file))

f file =
  if i <= n
     then i
     else i `mod` n
    where str = map read (words file) :: [Int]
	  n = str !! 0
	  k = (str !! 1) - 1
          lstr = tail (tail str)
	  list = lstr ++ lstr
	  i = (fromJust $ find (\x -> x >= k) (elemIndices 1 list)) + 1

import IO

solve :: Int -> [Int] -> Int
solve k xs  =  solve' (k-1) xs
  where
    n  =  length xs
    solve' k xs
      | xs !! k == 1  =  k + 1
      | otherwise  =  solve' (mod (k + 1) n) xs

main :: IO ()
main  =  do
    hInput  <-  openFile "input.txt" ReadMode
    hOutput  <-  openFile "output.txt" WriteMode

    [n, k]  <-  hGetLine hInput >>= return . map read . words
    xs  <-  hGetLine hInput >>= return . map read . words
    hPutStrLn hOutput (show $ solve k xs)

    hClose hOutput
    hClose hInput

import System.IO
solve k a = let ai = zip a [1..]
                (f,l) = splitAt (k-1) ai
                ai' = l++f
            in
              snd.head.dropWhile ((==0).fst) $ ai'

main = do fin <- openFile "input.txt" ReadMode
          l <- hGetLine fin
          a <- hGetLine fin
          hClose fin
          fout <- openFile "output.txt" WriteMode
          hPutStrLn fout.show $ solve (read (head.tail.words $ l)::Int) (map (read :: String -> Int) (words a))
          hClose fout

solve (1:_) = 0
solve (_:xs) = solve xs + 1

main = do
	input <- fmap lines $ readFile "input.txt"
	let [n, k] = map read . words . head $ input
	let as = map read . words $ input !! 1
	writeFile "output.txt" . (++"\n") . show . (`mod`n) . (+n) . solve $ drop (n-1) as ++ take (n-1) as


import qualified Data.Map as Map

main = getContents >>= putStrLn . solve . tail . words

solve :: [String] -> String
solve (s:t:[]) = let (v, i, j) = foldl1 min options in unlines [show (v + v0), show i ++ " " ++ show j]
    where table = getTable s t
          options = (0, -1, -1) : concat [zipWith getOption table $ drop i table | i <- [1..length table]]
          v0 = diff s t

diff :: String -> String -> Int
diff s t = length . filter (uncurry (/=)) $ zip s t

getTable :: String -> String -> [(Char, Char, Int)]
getTable s t = map (\((c1, c2), i) -> (c1, c2, i)) . Map.toList $ foldl f Map.empty (zip3 s t [1..])
    where f m (c1, c2, i) = Map.insert (c1, c2) i m

getOption :: (Char, Char, Int) -> (Char, Char, Int) -> (Int, Int, Int)
getOption (a1, a2, ai) (b1, b2, bi) = (v12 + v21 - v11 - v22, ai, bi)
    where v11 = if a1 == b1 then 1 else 2
          v12 = if a1 == b2 then 1 else 2
          v21 = if a2 == b1 then 1 else 2
          v22 = if a2 == b2 then 1 else 2

import Data.List
import Data.Int
import Data.Map

getDifference :: String -> String -> Int
getDifference xs ys = length . Data.List.filter (\ (a, b) -> a /= b) $ zip xs ys

getPositions :: String -> String -> Map (Char, Char) Int
getPositions xs ys =
    Data.List.foldl' (\ acc (x, y, pos) -> Data.Map.insert (x, y) pos acc)
           empty (zip3 xs ys [1..])

findBest :: [((Char, Char), Int)] -> (Int, Int, Int)
findBest entries =
    let res@(delta, p1, p2) =
            Data.List.foldl' max (0, -1, -1)
            [getCost x y | x <- entries, y <- entries]
    in if delta == 0 then (0, -1, -1) else res
    where
        getMatching :: (Char, Char) -> (Char, Char) -> Int
        getMatching (a1, b1) (a2, b2) =
            let m1 = if a1 == b1 then 1 else 0
                m2 = if a2 == b2 then 1 else 0
            in m1 + m2
        getCost :: ((Char, Char), Int) -> ((Char, Char), Int) -> (Int, Int, Int)
        getCost ((a1, b1), p1) ((a2, b2), p2) =
            (getMatching (a1, b2) (a2, b1) - getMatching (a1, b1) (a2, b2), p1, p2)

main = do
    getLine
    s <- getLine
    t <- getLine
    let positions = getPositions s t
    let entries = zip (keys positions) (elems positions)
    let (delta, p1, p2) = findBest entries
    putStrLn $ show (getDifference s t - delta)
    putStrLn $ show p1 ++ " " ++ show p2


{-# LANGUAGE TypeFamilies, UndecidableInstances, FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables #-}
module Main (main) where
import System.IO
import Data.Ord
import Data.Int
import Data.Bits
import Data.Char
import Data.Foldable
import Data.List
import Data.Maybe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import Control.Monad
import Control.Monad.ST.Safe
import Control.Monad.Trans.Class
import Control.Monad.Trans.State.Strict (StateT)
import qualified Control.Monad.Trans.State.Strict as StateT
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as C

getNewLine :: SIO ByteString
getNewLine = (lift $ C.hGetLine stdin) >>= (\z -> let x = C.dropWhile isSpace z in if C.null x then getNewLine else return x)

getRemain :: ByteString -> SIO ByteString
getRemain b = let bns = C.dropWhile isSpace b in
                if C.null bns then getNewLine >>= liftM2 (>>=) StateT.put (const . return)
                else return bns

data HInt
data HInt64
data HNormal
data HString
data HList

type SIO a = StateT ByteString IO a

class IOInteract a where
    convert :: ByteString -> (a, ByteString)
    toShowS :: a -> String -> String
    toShow :: a -> String
    toShow x = toShowS x []

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

type family IOType x where
    IOType Int = HInt
    IOType Int64 = HInt64
    IOType String = HString
    IOType [x] = HList
    IOType x = HNormal

class IOInteractp flag a where
    convertp :: flag -> ByteString -> (a, ByteString)
    toShowSp :: flag -> a -> String -> String

instance (Show a, Read a) => IOInteractp HNormal a where
    convertp _ x = let (a, b) = C.break isSpace x in (read $ C.unpack a, b)
    toShowSp _ x = shows x

instance IOInteractp HInt Int where
    convertp _ x = fromMaybe (error "parse") $ C.readInt x
    toShowSp _ x = shows x

instance IOInteractp HInt64 Int64 where
    convertp _ x = let (a, b) = fromMaybe (error "parse") $ C.readInteger x in (fromIntegral a, b)
    toShowSp _ x = shows x

instance IOInteractp HString String where
    convertp _ x = let (a, b) = C.break isSpace x in (C.unpack a, b)
    toShowSp _ x = showString x

instance (IOInteract a) => IOInteractp HList [a] where
    convertp _ x = let (a, b) = convert x in ([a], b)
    toShowSp _ [] = id
    toShowSp _ (x : []) = toShowS x
    toShowSp dum (x : xs) = toShowS x . showChar ' ' . toShowSp dum xs

get :: IOInteract a => SIO a
get = uncurry (flip (liftM2 seq . StateT.put) . return) =<< fmap convert . getRemain =<< StateT.get
put :: IOInteract a => a -> SIO ()
put = lift . (hPutStr stdout) . toShow
putln :: IOInteract a => a -> SIO ()
putln = lift . (hPutStrLn stdout) . toShow
flush :: SIO ()
flush = lift (hFlush stdout)

main :: IO ()
main = StateT.evalStateT main_ C.empty

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

f1 :: SIO ()
f1 = do
  (a, b, x, y, n) <- liftM5 (,,,,) get get get get get
  putln $ f2 a b x y n

f2 :: Int64 -> Int64 -> Int64 -> Int64 -> Int64 -> Int64
f2 a b x y n = let n1 = a - x in let n2 = b - y in
              let v1 = if n > n1 then x * (if n - n1 > n2 then y else (b - (n - n1))) else (a - n) * b in
              let v2 = if n > n2 then y * (if n - n2 > n1 then x else (a - (n - n2))) else a * (b - n) in
              min v1 v2

import Control.Monad

main = do
  t <- read <$> getLine
  replicateM_ t $ do
    [a, b, x, y, n] <- map read . words <$> getLine
    let
      (a1, b1)
        | a - x >= n = (a - n, b)
        | b - y >= n - (a - x) = (x, b - (n - (a - x)))
        | otherwise = (x, y)
      (a2, b2)
        | b - y >= n = (a, b - n)
        | a - x >= (n - (b - y)) = (a - (n - (b - y)), y)
        | otherwise = (x, y)
      ans = min (a1 * b1) (a2 * b2)

    putStrLn $ show ans

import Control.Monad ( replicateM_ )

main :: IO ()
main = do
  t <- read <$> getLine
  replicateM_ t $ do
    [a,b,x,y,n] <- map read . words <$> getLine
    let
      s1 = a - x
      s2 = b - y
      t1 = if  (n <= s1)  then  (a-n)*b
        else  if  (n <= s1 + s2)  then  x*(b-(n-s1))
        else  x*y
      t2 = if  (n <= s2)  then  a*(b-n)
        else  if  (n <= s1 + s2)  then  (a-(n-s2))*y
        else  x*y
    print (min t1 t2 :: Integer)


import Data.List(nub)
import Control.Arrow

solve =
    (\x -> case x of {
        (_, y) | y > 26 -> (-1);
        (x, y) -> y - x
    })
    . (length . nub &&& length)

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

import Data.List (group, sort)
main = getLine >> getLine >>= (\x -> do
  let cs = (group . sort) x
  print $ if length x > 26 then -1 else length x - length cs)

import Data.List

main :: IO()
main = do
    sn <- getLine
    let n = read sn
    s <- getLine
    print $ solve n s

solve :: Int -> String -> Int
solve n s | n > 26 = -1
          | otherwise = n - length (nub s)

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

main = print =<< (\(x,y) -> if x+y <= 26 then x else -1) . (sum &&& length)  . map (pred . B.length ) . B.group . B.sort .  B.filter isLower <$> (B.getLine >> B.getLine)

{-# OPTIONS_GHC -fno-warn-tabs #-}
import Data.List;
import System.IO;
import Data.Maybe;

solve :: String -> String -> Int;
solve [] a = length a;
solve s a
	| length s > 26 = -1
	| elem (head s) a = solve (tail s) a
	| otherwise = solve (tail s) ((head s):a);

main = do
	getLine;
	str <- getLine;
	if(solve str "" == (-1))
		then print (-1)
		else print (length str - solve str "");

import Data.List
main = do
  n <- readLn
  s <- getLine
  let ls = length $ group $ sort s
  print $ if n > 26 then -1 else n - ls

import Data.List
main = do
  n <- readLn
  if n > 26 then print (-1)
  else getLine >>= print.solve

solve :: String -> Int
solve cs = sum.map (pred.length).group$ sort cs

import Data.List( nub)
main = do
    tokens <- return . words =<< getContents
    let n = read $ tokens!!0
        str = tokens!!1
    if n>26 then print (negate 1) else print $ n - length (nub str)

import Data.List
main = do
        tmp <- getLine
        str <- getLine
        let n = read tmp::Int
        if n > 26 then
            putStrLn "-1"
        else
            putStrLn $ show ((length str) - (length $ nub str))

import Data.List
main = do
    s <- getLine >> getLine
    let n = length . group . sort $ s
        ls = length s
    print $ if ls <= 26 then ls - n else -1

import Data.List (group, sort)
main = getLine >>= (\x -> do
  let cs = (group . sort) x
  print $ if length x > 26 then -1 else length cs - length x)

import Data.List (group, sort)
main = getLine >>= (\x -> do
  let cs = (group . sort) x
  print $ if length x > 26 then -1 else length x - length cs)

import qualified Data.ByteString.Char8 as B
import Control.Arrow

main = print =<< (\(x,y) -> if x+y <= 26 then x else -1) . (sum &&& length)  . map (pred . B.length ) . B.group . B.sort  <$> (B.getLine >> B.getLine)

import qualified Data.ByteString.Char8 as B
import Control.Arrow

main = print =<< (\(x,y) -> if x+y <= 26 then x else -1) . (sum &&& length)  . map (pred . B.length ) . B.group  <$> (B.getLine >> B.getLine)

import qualified Data.ByteString.Char8 as B
import Control.Arrow

main = print =<< (\(x,y) -> if x+y <= 26 then x else -1) . (sum &&& length)  . map (pred . B.length ) . B.group  <$> B.getLine <* B.getLine

import Data.List
main = do
  n <- readLn
  if n > 26 then print (-1)
  else getLine >>= print.solve

solve :: String -> Int
solve cs = go ['a'..'z'] $ sort cs
  where
    go rest (x:xs)
      | elem x rest = go (delete x rest) xs
      | otherwise = 1 + go (tail rest) xs
    go _ _ = 0

import Data.List(nub)
import Control.Arrow

solve =
    (\x -> case x of {
        (_, y) | y > 27 -> (-1);
        (x, y) -> y - x
    })
    . (length . nub &&& length)

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

import Data.List
main = do
    s <- getLine >> getLine
    let n = length . group . sort $ s
    print $ length s - n


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

main=do
	[n,a]<-map read. words <$> getLine:: IO [Int]
	s<-map (minimum.tail) .map (map read). map words. lines <$> getContents:: IO [Int]
	let t=  map snd $ filter (\z->fst z <a) $ zip s [1..]
	print $ length t
        putStrLn $ intercalate " " $ map show t

{-# LANGUAGE NPlusKPatterns #-}

module Main where

main :: IO ()
main = do
    [n, v] <- getVec
    s <- getVecN n
    output $ solve v $ map tail s

type Nat = Integer
type Vector = [Nat]
type Predicate a = a -> Bool
type Selector a = [a] -> [Nat]

getVec :: IO Vector
getVec = fmap readVec getLine

readVec :: String -> Vector
readVec = map read . words

getVecN :: Integer -> IO [Vector]
getVecN 0       = return []
getVecN (n + 1) = do
    vc  <- getVec
    vcs <- getVecN n
    return (vc : vcs)

solve :: Nat -> [Vector] -> [Nat]
solve v = countUpFilter (accepts v)

countUpFilter :: Predicate a -> Selector a
countUpFilter = countUpFilter' 1

countUpFilter' :: Nat -> Predicate a -> Selector a
countUpFilter' _ _ [] = []
countUpFilter' n p (a : as) = if p a
    then n : countUpFilter' (n + 1) p as
    else     countUpFilter' (n + 1) p as

accepts :: Nat -> Predicate Vector
accepts v = any (< v)

output :: Vector -> IO ()
output vecs = do
    print $ length vecs
    putStrLn $ unwords $ map show vecs

import Data.List

main :: IO()
main = output . solve . map (map read . words) . lines =<< getContents

output :: [Int] -> IO()
output (a:ax) = putStrLn ((show a) ++ "\n" ++ (unwords (map show ax)))

solve :: [[Int]] -> [Int]
solve ([n, v]:a) =
    let ans = solve' a 1
    in ((length ans):ans)
    where solve' :: [[Int]] -> Int -> [Int]
          solve' []          _ = []
          solve' ((w:ws):ax) i | v > (minimum ws) = (i:(solve' ax (i + 1)))
                               | otherwise        = solve' ax (i + 1)

import Data.List
import Data.Function

main = interact $ unlines . map (unwords . map show) . getAns . map (map read . words) . lines

getAns :: [[Int]] -> [[Int]]
getAns ((_:v:_):xs) =
	let ans = map succ $ findIndices (any (<v) . tail) xs
	in [[length ans], ans]

import Data.List
import Data.Function

main = interact $ unlines . map (unwords . map show) . getAns . getArrays

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

getAns :: [[Int]] -> [[Int]]
getAns ((n:v:_):xs) =
	let ans = getSellers v $ zip [1..n] xs
	in [[length ans], ans]

getSellers :: Int -> [(Int, [Int])] -> [Int]
getSellers _ [] = []
getSellers v (x:xs) = if (any (<v) . tail . snd) x then (fst x) : getSellers v xs else getSellers v xs

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Applicative
import Control.Monad hiding ((<$!>))
import Control.Monad.ST.Safe
import Control.Monad.State hiding ((<$!>))
-- import Data.Array
import Data.Array.IArray
import Data.Array.IO.Safe
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Builder as BB
import Data.Char
import qualified Data.Foldable as F
import Data.Function
import Data.Graph
import Data.Int
import Data.List
import Data.List.Split
import Data.Maybe
import Data.Monoid
import Data.Ord
import Data.Ratio
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
-- import Data.Tree
import Data.Tuple
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
-- import Debug.Trace
import System.IO

-- getInts = fmap (map read . words) getLine
getInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

main = do
  [n, v] <- getInts
  xss <- replicateM n $ tail <$> getInts

  let r = map snd $ filter (\(xs, _) -> any (< v) xs) $ zip xss [1..]
  print $ length r
  putStrLn $ unwords $ map show r

import Control.Monad

main = do
  (n:v:_) <- fmap (map read . words) getLine
  items <- forM [1..n] $ \i -> do is <- fmap (tail . map read . words) getLine; return (i,is)
  let _ = items :: [(Int,[Int])]
  let answer = [ i | (i,is) <- items, any (<v) is ]
  print $ length answer
  putStrLn $ unwords (map show answer)

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

import qualified    Data.ByteString.Char8 as C
import              Data.ByteString.Lazy.Builder
import              Data.Maybe
import              Data.Monoid
import              System.IO

getIntList :: IO [Int]
getIntList = map fst . mapMaybe C.readInt . C.words <$> C.getLine

main = do
    [n, v] <- getIntList
    ps <- replicateM n getIntList
    let qs = sol n v ps
    print $ length qs
    putStrLn $ foldr (\c s -> show c ++ (' ':s)) "" $ qs

sol n v ps = [i+1 | i <- [0..n-1], bs!!i]
    where
    bs = map bid ps
    bid (_:ss) =  or $ map (< v) ss

import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.List (sort)
import Data.Maybe (mapMaybe)

readInts :: B.ByteString -> [Int]
readInts = map fst . mapMaybe B.readInt . B.words

getInts :: IO [Int]
getInts = readInts <$> B.getLine

main = do
  [n, v] <- getInts
  xs <- zip [1..] <$> (replicateM n $ tail <$> getInts)
  let
    can (_,ss) = head (sort ss) < v
    xs' = map fst . filter can $ xs
   in putStrLn $ (show (length xs')) ++ "\n" ++ unwords (map show xs')

main :: IO ()
main = getContents >>= mapM_ (putStrLn . unwords . map show) . solve . map (map read . words) . lines

solve :: [[Int]] -> [[Int]]
solve ([_, v] : kss) = [ [ length is ], is ]
  where is = [ i | (i, _:ss) <- zip [1..] kss, any (<v) ss ]
solve _ = undefined

import Data.List (findIndices)
import Control.Monad (replicateM)
readInts = fmap (map read . words) getLine
main = do
  [n,v] <- readInts
  ks <- fmap (findIndices (any (< v)) . ([]:) . map tail) (replicateM n readInts)
  print (length ks)
  putStrLn $ unwords $ map show ks

module Main where

import Control.Monad

rv:: String -> (Int, Int)
rv str = let xs = map read $ words str in
                (head xs, xs !! 1)

rm:: String -> [Int]
rm str = map read $ words str

pa:: [Int] -> String
pa ans = show (length ans) ++ "\n" ++
            unwords (map show ans)

solve:: (Int, Int) -> [[Int]] -> [Int]
solve valera merchants = map fst $ filter buyable zmerchants where
            budget = snd valera
            zmerchants = zip [1..] $ map tail merchants
            buyable merchant = not $ null buyablegoods  where
                goods = snd merchant
                buyablegoods = filter (< budget) goods

main :: IO ()
main = do
        valera <- getLine
        merchants <- replicateM (fst $ rv valera) getLine
        putStrLn $ pa $ solve (rv valera) (map rm merchants)

import Control.Monad
import Data.List

main = do
    [n,v] <- fmap (map read . words) getLine
    sellers <- forM [1..n] (\_ -> fmap (tail . map read . words) getLine)
    let solution = solve sellers v
    print $ length solution
    putStrLn . intercalate " " . map show $ solution

solve :: [[Integer]] -> Integer -> [Integer]
solve sellers v = [ snd x | x <- pairs, deal (fst x) v ]
    where pairs = zip sellers [1..]

deal :: [Integer] -> Integer -> Bool
deal xs v = any (<v) xs

import Data.List

main = do
  [_,v] <- fmap(map read.words)getLine
  xss <- fmap(map(map read.tail.words).lines)getContents :: IO [[Int]]
  case findIndices (any (<v)) xss of
       [] -> putStrLn "0\n"
       xs -> do
         print $ length xs
         putStrLn.unwords.map(show.succ) $ xs

main :: IO ()
main = interact selesaian

selesaian :: String -> String
selesaian s = let
    (kep:ekor) = angkaify s
    [_, v]     = kep
    beli       = dibeli v ekor
    -- Jawaban Disini
    in show (length beli)
    ++ "\n"
    ++ (unwords . map show) beli
    ++ "\n"

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

lolos :: Int -> [Int] -> Bool
lolos n = any (< n) . tail

asli :: [Int]
asli = [1..]

dibeli :: Int -> [[Int]] -> [Int]
dibeli v = map fst . filter (lolos v . snd) . zip asli

main :: IO ()
main = interact selesaian

nat :: [Int]
nat = [1..]

selesaian :: String -> String
selesaian s = let
    baris = lines s
    (kep:ekor) = angkaify baris
    (_:v:_) = kep
    beli =  map snd . filter (\(x, _) -> lolos v x) $ zip ekor nat
    in show (length beli)
    ++ "\n"
    ++ (unwords . map show) beli
    ++ "\n"

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

lolos :: Int -> [Int] -> Bool
lolos n xs = any (< n) $ tail xs

main :: IO ()
main = interact selesaian

selesaian :: String -> String
selesaian s = let
    baris = lines s
    (kep:ekor) = angkaify baris
    (_:v:_) = kep
    beli =  map snd . filter (\(x, _) -> lolos v x) $ zip ekor [1..]
    in show (length beli)
    ++ "\n"
    ++ (unwords . map show) beli
    ++ "\n"

angkaify :: [String] -> [[Integer]]
angkaify = map (map read . words)

lolos :: Integer -> [Integer] -> Bool
lolos n xs = any (< n) $ tail xs

{-# LANGUAGE NPlusKPatterns #-}

module Main where

main :: IO ()
main = do
    [n, v] <- getVec
    s <- getVecN n
    output $ solve v $ map tail s

type Nat = Integer
type Vector = [Nat]
type Predicate a = a -> Bool

getVec :: IO Vector
getVec = fmap readVec getLine

readVec :: String -> Vector
readVec = map read . words

getVecN :: Integer -> IO [Vector]
getVecN 0       = return []
getVecN (n + 1) = do
    vc  <- getVec
    vcs <- getVecN n
    return (vc : vcs)

solve :: Nat -> [Vector] -> [Nat]
solve v = countUp . filter (accepts v)

countUp :: [a] -> [Nat]
countUp = countUp' 1

countUp' :: Nat -> [a] -> [Nat]
countUp' _ [] = []
countUp' n (_ : as) = n : countUp' (n + 1) as

accepts :: Nat -> Predicate Vector
accepts v = any (< v)

output :: Vector -> IO ()
output vecs = do
    print $ length vecs
    putStrLn $ unwords $ map show vecs

import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.List (sort)
import Data.Maybe (mapMaybe)

readInts :: B.ByteString -> [Int]
readInts = map fst . mapMaybe B.readInt . B.words

getInts :: IO [Int]
getInts = readInts <$> B.getLine

main = do
  [n, v] <- getInts
  xs <- replicateM n $ do {(k:ss) <- getInts; return (k, ss);}
  let
    can (_,ss) = head (sort ss) < v
    xs' = map fst . filter can $ xs
   in putStrLn $ (show (length xs')) ++ "\n" ++ unwords (map show xs')

module Main where

import Control.Monad

rv:: String -> (Int, Int)
rv str = let xs = map read $ words str in
                (head xs, xs !! 1)

rm:: String -> [Int]
rm str = map read $ words str

pa:: [Int] -> String
pa ans = show (length ans) ++ "\n" ++
            unwords (map show ans)

solve:: (Int, Int) -> [[Int]] -> [Int]
solve valera merchants = map fst $ filter buyable zmerchants where
            budget = snd valera
            zmerchants = zip [1..] $ map tail merchants
            buyable merchant = not $ null buyablegoods  where
                goods = snd merchant
                buyablegoods = filter (< budget) goods

main :: IO ()
main = do
        valera <- getLine
        merchants <- replicateM (fst $ rv valera) getLine
        print $ pa $ solve (rv valera) (map rm merchants)

module Main where

import Control.Monad

rv:: String -> (Int, Int)
rv str = let xs = map read $ words str in
                (head xs, xs !! 1)

rm:: String -> [Int]
rm str = map read $ words str

pa:: [Int] -> String
pa ans = show (length ans) ++ "\n" ++
            unwords (map show ans)

solve:: (Int, Int) -> [[Int]] -> [Int]
solve valera merchants = map fst $ filter buyable zmerchants where
            budget = snd valera
            zmerchants = zip [1..] $ map tail merchants
            buyable merchant = not $ null buyablegoods  where
                goods = snd merchant
                buyablegoods = filter (< budget) goods

main :: IO ()
main = do
        valera <- getLine
        merchants <- replicateM (fst $ rv valera) getLine
        print $ solve (rv valera) (map rm merchants)

main :: IO ()
main = interact selesaian

selesaian :: String -> String
selesaian s = let
    baris = lines s
    (kep:ekor) = angkaify baris
    (_:v:_) = kep
    beli = map head . filter (lolos v) $ ekor
    in show (length beli)
    ++ "\n"
    ++ (unwords . map show) beli
    ++ "\n"

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

lolos :: Int -> [Int] -> Bool
lolos n xs = any (< n) $ tail xs

main :: IO ()
main = interact selesaian

selesaian :: String -> String
selesaian s = let
    baris = lines s
    (kep:ekor) = angkaify baris
    (_:v:_) = kep
    beli = map head . filter (lolos v) $ ekor
    in show (length beli)
    ++ "\n"
    ++ (unwords . map show) beli
    ++ "\n"

angkaify :: [String] -> [[Integer]]
angkaify = map (map read . words)

lolos :: Integer -> [Integer] -> Bool
lolos n xs = any (< n) $ tail xs


import Control.Monad
import Data.List

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

routine :: IO ()
routine = do
    n <- readLn
    xs <- (map read.words) <$> getLine
    putStr $ solve n xs

getOptions :: Int -> [Int] -> [Int]
getOptions n xs = nub [m,n-m]
  where
    m = maximum xs

solve :: Int -> [Int] -> String
solve n xs= unlines $ (show k) : c
  where
    a = filter (check xs) (getOptions n xs)
    k = length a
    b = map (\x -> [x,n-x]) a
    c =  map (unwords.map show) b

checkPerm :: [Int] -> Bool
checkPerm perm = and $ zipWith (==) (sort perm) [1..]

check :: [Int] -> Int -> Bool
check xs l1 = (checkPerm (take l1 xs)) && (checkPerm (drop l1 xs))

import Control.Arrow
import Data.List (sort)

main = interact $
  lines >>> drop 1
  >>> map (words >>> map read)
  >>> process
  >>> map (map show >>> unwords) >>> unlines

process :: [[Int]] -> [[Int]]
process [] = []
process ([n]:a:ps) = solve n a ++ process ps

solve :: Int -> [Int] -> [[Int]]
solve n a
  | length ans > 2 = [[0]]
  | and (map (check a) ans) = [length ans] : ans
  | otherwise = [[0]]
  where
    ans =
      map(\(i, _, _) -> [i, n - i])
        $ filter (\(i, (mnl, mxl), (mnr, mxr)) ->
                    mnl == 1 && mnr == 1 && mxl == i && mxr == n - i)
          $ zip3 [1..]
            (zip (scanl1 min a) (scanl1 max a))
            $ tail (zip (scanr1 min a) (scanr1 max a))

check a [l,_] = valid (take l a) && valid (drop l a)
  where
    valid a = and $ zipWith (==) (sort a) [1..]

import Control.Arrow
import Data.List (sort)

main = interact $
  lines >>> drop 1
  >>> map (words >>> map read)
  >>> process
  >>> map (map show >>> unwords) >>> unlines

process :: [[Int]] -> [[Int]]
process [] = []
process ([n]:a:ps) = solve n a ++ process ps

solve :: Int -> [Int] -> [[Int]]
solve n a
  | length ans > 2 = [[0]]
  | null ans = [[0]]
  | let l = head (last ans) in sort (take l a) /= [1..l] = [[0]]
  | otherwise = [length ans] : ans
  where
    ans =
      map(\(i, _, _) -> [i, n - i])
        $ filter (\(i, (mnl, mxl), (mnr, mxr)) ->
                    mnl == 1 && mnr == 1 && mxl == i && mxr == n - i)
          $ zip3 [1..]
            (zip (scanl1 min a) (scanl1 max a))
            $ tail (zip (scanr1 min a) (scanr1 max a))

import Control.Monad
import Data.List

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

routine :: IO ()
routine = do
    n <- readLn
    xs <- (map read.words) <$> getLine
    putStr $ solve n xs

getOptions :: Int -> [Int] -> [Int]
getOptions n xs = [m,n-m]
  where
    m = maximum xs

solve :: Int -> [Int] -> String
solve n xs= unlines $ (show k) : c
  where
    a = filter (check xs) (getOptions n xs)
    k = length a
    b = map (\x -> [x,n-x]) a
    c =  map (unwords.map show) b

checkPerm :: [Int] -> Bool
checkPerm perm = and $ zipWith (==) (sort perm) [1..]

check :: [Int] -> Int -> Bool
check xs l1 = (checkPerm (take l1 xs)) && (checkPerm (drop l1 xs))