type Input  = [[Integer]]
type Output = [Exp]

parse :: String -> Input
parse = toList . unzip . map pair . tail . lines
    where pair l        = let [x, y, _] = map read . words $ l in (x, y)
          toList (a, b) = [a, b]

data Exp = Abs      Exp
         | Add      Exp Exp
         | Subtract Exp Exp
         | Multiply Exp Exp
         | Constant Integer
         | Variable

instance Show Exp where
    show g = go g ""
        where go :: Exp -> String -> String
              go (Abs      e)   = ("abs(" ++) . go e . (")" ++)
              go (Add      e f) = ("(" ++) . go e . ("+" ++) . go f . (")" ++)
              go (Subtract e f) = ("(" ++) . go e . ("-" ++) . go f . (")" ++)
              go (Multiply e f) = ("(" ++) . go e . ("*" ++) . go f . (")" ++)
              go (Constant c)   = (show c ++)
              go (Variable)     = ("t" ++)

instance Num Exp where
    abs         = Abs
    (+)         = Add
    (-)         = Subtract
    (*)         = Multiply
    fromInteger = Constant
    signum      = undefined

at :: Integer -> Exp
at x = 2 - abs (d (x - 1) - d (x + 1))
    where d :: Integer -> Exp
          d a
            | a >= 0    = abs (Variable - fromInteger   a)
            | otherwise = abs (Variable + fromInteger (-a))

solve :: Input -> Output
solve = map solve1
    where solve1 :: [Integer] -> Exp
          solve1 = sum . zipWith (*) (map at [0..]) . map (fromInteger . (`div` 2))

format :: Output -> String
format = unlines . map show

main :: IO ()
main = putStrLn . format . solve . parse =<< getContents

type Input  = [[Integer]]
type Output = [Exp]

parse :: String -> Input
parse = toList . unzip . map pair . tail . lines
    where pair l        = let [x, y, _] = map read . words $ l in (x, y)
          toList (a, b) = [a, b]

data Exp = Abs      Exp
         | Add      Exp Exp
         | Subtract Exp Exp
         | Multiply Exp Exp
         | Constant Integer
         | Variable

instance Show Exp where
    show = go
        where go :: Exp -> String
              go (Abs      e)   = "abs(" ++ go e ++ ")"
              go (Add      e f) = "(" ++ go e ++ "+" ++ go f ++ ")"
              go (Subtract e f) = "(" ++ go e ++ "-" ++ go f ++ ")"
              go (Multiply e f) = "(" ++ go e ++ "*" ++ go f ++ ")"
              go (Constant c)   = show c
              go Variable       = "t"

instance Num Exp where
    abs         = Abs
    (+)         = Add
    (-)         = Subtract
    (*)         = Multiply
    fromInteger = Constant
    signum      = undefined

at :: Integer -> Exp
at x = 2 - abs (d (x - 1) - d (x + 1))
    where d :: Integer -> Exp
          d a
            | a >= 0    = abs (Variable - fromInteger   a)
            | otherwise = abs (Variable + fromInteger (-a))

solve :: Input -> Output
solve = map solve1
    where solve1 :: [Integer] -> Exp
          solve1 = sum . zipWith (*) (map at [0..]) . map (fromInteger . (`div` 2))

format :: Output -> String
format = unlines . map show

main :: IO ()
main = putStrLn . format . solve . parse =<< getContents

import Control.Arrow ((&&&))
import Data.List (intercalate)

data Circle = Circle { circleX :: Int, circleY :: Int }

type Input  = [Circle]
type Output = (String, String)

parse :: String -> Input
parse = map circle . tail . lines
    where circle l = let [x, y, _] = map read . words $ l in Circle x y

solve1 :: [Int] -> String
solve1 = intercalate "+" . zipWith f [0..]
    where f :: Int -> Int -> String
          f i x = concat ["(", g i, "*", show (x `div` 2), ")"]
          g :: Int -> String
          g i   = concat ["(2-abs((", a (i - 1), "-", a (i + 1), ")))"]
          a :: Int -> String
          a i
            | i < 0     = concat ["abs((t+", show (-i), "))"]
            | otherwise = concat ["abs((t-", show i, "))"]

solve :: Input -> Output
solve = (solve1 . map circleX) &&& (solve1 . map circleY)

format :: Output -> String
format (f, g) = unlines [f, g]

main :: IO ()
main = putStrLn . format . solve . parse =<< getContents

import Control.Arrow ((&&&))
import Data.List (intercalate)

data Circle = Circle { circleX :: Int, circleY :: Int }

type Input  = [Circle]
type Output = (String, String)

parse :: String -> Input
parse = map circle . tail . lines
    where circle l = let [x, y, _] = map read . words $ l in Circle x y

fit :: Int -> Int
fit x
    | even x    = x
    | otherwise = x + 1

solve1 :: [Int] -> String
solve1 = intercalate "+" . zipWith f [0..]
    where f :: Int -> Int -> String
          f i x = concat ["(", g i, "*", show . fit $ x, ")"]
          g :: Int -> String
          g i   = concat ["abs((", a (i - 1), "-", a (i + 1), "))"]
          a :: Int -> String
          a i   = concat ["abs((t-", show i, "))"]

solve :: Input -> Output
solve = (solve1 . map circleX) &&& (solve1 . map circleY)

format :: Output -> String
format (f, g) = unlines [f, g]

main :: IO ()
main = putStrLn . format . solve . parse =<< getContents

type Input  = [[Integer]]
type Output = [Exp]

parse :: String -> Input
parse = toList . unzip . map pair . tail . lines
    where pair l        = let [x, y, _] = map read . words $ l in (x, y)
          toList (a, b) = [a, b]

data Exp = Abs      Exp
         | Add      Exp Exp
         | Subtract Exp Exp
         | Multiply Exp Exp
         | Constant Integer
         | Variable

instance Show Exp where
    show g = go g ""
        where go :: Exp -> String -> String
              go (Abs      e)   = ("abs(" ++) . go e . (")" ++)
              go (Add      e f) = ("(" ++) . go e . ("+" ++) . go f . (")" ++)
              go (Subtract e f) = ("(" ++) . go e . ("-" ++) . go f . (")" ++)
              go (Multiply e f) = ("(" ++) . go e . ("*" ++) . go f . (")" ++)
              go (Constant c)   = (show c ++)
              go (Variable)     = ("t" ++)

instance Num Exp where
    abs         = Abs
    (+)         = Add
    (-)         = Subtract
    (*)         = Multiply
    fromInteger = Constant
    signum      = undefined

at :: Integer -> Exp
at x = 2 - abs (d (x - 1) - d (x + 1))
    where d :: Integer -> Exp
          d a
            | a >= 0    = abs (Variable - fromInteger a)
            | otherwise = abs (Variable + fromInteger a)

solve :: Input -> Output
solve = map solve1
    where solve1 :: [Integer] -> Exp
          solve1 = sum . zipWith (*) (map at [0..]) . map (fromInteger . (`div` 2))

format :: Output -> String
format = unlines . map show

main :: IO ()
main = putStrLn . format . solve . parse =<< getContents

type Input  = [[Integer]]
type Output = [Exp]

parse :: String -> Input
parse = toList . unzip . map pair . tail . lines
    where pair l        = let [x, y, _] = map read . words $ l in (x, y)
          toList (a, b) = [a, b]

data Exp = Abs      Exp
         | Add      Exp Exp
         | Subtract Exp Exp
         | Multiply Exp Exp
         | Constant Integer
         | Variable

instance Show Exp where
    show g = go g ""
        where go :: Exp -> String -> String
              go (Abs      e)   = ("abs(" ++) . go e . (")" ++)
              go (Add      e f) = ("(" ++) . go e . ("+" ++) . go f . (")" ++)
              go (Subtract e f) = ("(" ++) . go e . ("-" ++) . go f . (")" ++)
              go (Multiply e f) = ("(" ++) . go e . ("*" ++) . go f . (")" ++)
              go (Constant c)   = (show c ++)
              go (Variable)     = ("t" ++)

instance Num Exp where
    abs         = Abs
    (+)         = Add
    (-)         = Subtract
    (*)         = Multiply
    fromInteger = Constant
    signum      = undefined

at :: Integer -> Exp
at x = 2 - abs (d (x - 1) - d (x + 1))
    where d :: Integer -> Exp
          d a
            | a >= 0    = abs (Variable - fromInteger a)
            | otherwise = abs (Variable + fromInteger a)

solve :: Input -> Output
solve = map solve1
    where solve1 :: [Integer] -> Exp
          solve1 = sum . zipWith (*) (map at [0..]) . map fromInteger

format :: Output -> String
format = unlines . map show

main :: IO ()
main = putStrLn . format . solve . parse =<< getContents

import Control.Arrow ((&&&))
import Data.List (intercalate)

data Circle = Circle { circleX :: Int, circleY :: Int }

type Input  = [Circle]
type Output = (String, String)

parse :: String -> Input
parse = map circle . tail . lines
    where circle l = let [x, y, _] = map read . words $ l in Circle x y

solve1 :: [Int] -> String
solve1 = intercalate "+" . zipWith f [0..]
    where f :: Int -> Int -> String
          f i x = concat ["(", g i, "*", show (x `div` 2), ")"]
          g :: Int -> String
          g i   = concat ["abs((", a (i - 1), "-", a (i + 1), "))"]
          a :: Int -> String
          a i
            | i < 0     = concat ["abs((t+", show (-i), "))"]
            | otherwise = concat ["abs((t-", show i, "))"]

solve :: Input -> Output
solve = (solve1 . map circleX) &&& (solve1 . map circleY)

format :: Output -> String
format (f, g) = unlines [f, g]

main :: IO ()
main = putStrLn . format . solve . parse =<< getContents


module Main where

import Prelude
import Data.List
import Data.Maybe
import Data.Function
import Data.Char
import Data.Graph
import Data.Tree
import Data.Int
import Data.Bits
import Data.Tuple
import Control.Monad
import Control.Applicative
import qualified Data.Set as Set
import qualified Data.Map.Lazy as Map

main :: IO()
main =
  print =<< (Map.foldl' (+) 0) <$>
    liftM2 (foldl' $
      flip $ Map.update (\ x -> if x > 1 then Just (x - 1) else Nothing))
      (Map.fromList . map (liftA2 (,) head length) . group . sort <$>
        (read <$> getLine >>= flip replicateM getLine))
      (words <$> getContents)

module Main where
import Control.Monad
import Data.List
main = do
  nIO <- getLine
  let n = read nIO :: Int
  old <- replicateM n getLine
  new <- replicateM n getLine
  let (ans, _) = foldl (\(cnt, rr) el -> if el `elem` (new \\ rr) then (cnt, el:rr) else (cnt+1, rr)) (0, []) old
  print ans

module Main where

import Prelude
import Data.List
import Data.Maybe
import Data.Function
import Data.Char
import Data.Graph
import Data.Tree
import Data.Int
import Data.Bits
import Data.Tuple
import Control.Monad
import Control.Applicative
import qualified Data.Set as Set

main :: IO()
main = do
  n <- (read :: String -> Int) <$> getLine
  a <- f n
  b <- f n
  print . length . filter (uncurry (/=)) $ on zip sort a b
  where f = sequence . flip replicate getLine

module Main where

import Prelude
import Data.List
import Data.Maybe
import Data.Function
import Data.Char
import Data.Graph
import Data.Tree
import Data.Int
import Data.Bits
import Data.Tuple
import Control.Monad
import Control.Applicative
import qualified Data.Set as Set

main :: IO()
main = do
  n <- (read :: String -> Int) <$> getLine
  a <- f n
  b <- f n
  print . sum . map (uncurry (((length . filter (uncurry (/=))).) . zip)) $ on zip sort a b
  where f = sequence . flip replicate getLine


import qualified Data.Map.Strict               as Map
import qualified Data.Set                      as Set
import           Data.List

dfs
    :: Int
    -> Map.Map Int [Int]
    -> Map.Map Int Bool
    -> Int
    -> Int
    -> Set.Set Int
    -> Int
dfs maxCats edgeMap hasCat nCats node visited
    | node `Set.member` visited = 0
    | nCats' > maxCats = 0
    | all (`Set.member` visited) (edgeMap Map.! node) = 1
    | otherwise = sum
        [ dfs maxCats edgeMap hasCat nCats' n (Set.insert node visited)
        | n <- edgeMap Map.! node
        ]
    where nCats' = if hasCat Map.! node then nCats + 1 else 0

g :: Int -> Int -> [Int] -> [(Int, Int)] -> Int
g n maxCats cats edges =
    let hasCat  = Map.fromAscList $ zip [0 ..] [ v == 1 | v <- cats ]
        edgeMap = Map.fromListWith (++) [ (a, [b]) | (a, b) <- edges ]
    in  dfs maxCats edgeMap hasCat 0 0 Set.empty

f :: [String] -> Int
f (nm : cats : edges) =
    let [n, maxCats] = map read . words $ nm :: [Int]
        cats'        = map read . words $ cats :: [Int]
        edges' :: [(Int, Int)]
        edges'  = map ((\[a, b] -> (a - 1, b - 1)) . (map read . words)) edges
        edges'' = edges' ++ [ (b, a) | (a, b) <- edges' ]
    in  g n maxCats cats' edges''

-- TOOD: Nicer way to extract the lines?
main = interact $ show . f . lines

import Data.Array
dfs cat edges now ccat maxcat pre| isOne nextList && now /= 1 = if catnum <= maxcat then 1 else 0
                                 | otherwise = if catnum > maxcat then 0 else sum [dfs cat edges next catnum maxcat now| next <- nextList,next /= pre]
    where nextList = (edges ! now)
          hascat = (cat ! now)
          catnum = getCat hascat ccat
getCat a b | a == 0 = 0
           | otherwise = (a+b)
isOne (x:xs) = null xs
getTuple s = (a0,a1)
  where [a0,a1] = [read n::Int|n <- (words s)]
main = do
  w0 <- getLine
  let [n,m] = [read n::Int|n <- (words w0)]
  w1 <- getLine
  let hasCat = listArray (1,n) [read n::Int|n <- (words w1)]
  w2 <- getContents
  let e = [getTuple s | s <- (lines w2)]
  let e2 = e ++ (map (\x -> (snd x,fst x)) e)
  let edges = accumArray (flip (:)) [] (1,n) e2
  print $ dfs hasCat edges 1 0 m 0

import Data.Array
import Data.Graph
import Control.Monad
main = do
  [n,m] <- map read . words <$> getLine
  cats <- listArray (1,n) . map (toEnum . read) . words <$> getLine
  g <- fmap (buildG (1,n) . concat) $ replicateM (n-1) $ do
    [x,y] <- map read . words <$> getLine
    return [(x,y),(y,x)]
  let [t] = dfs g [1]
      count c (Node n ts) | c' > m = 0
                          | null ts = 1
                          | otherwise = sum (map (count c') ts)
        where c' = if cats!n then c+1 else 0
  print $ count 0 t

import Data.Array
import Data.Char (ord)
import Data.List (groupBy, sortBy)
import Data.Ord (comparing)
import Data.Tuple (swap)

type IntArray a = Array Int a

type Input = (Int, IntArray Int, IntArray [Int])

readInt :: String -> Int
readInt = foldl step 0 where step s a = s * 10 + ord a - 48

readPair :: String -> (Int, Int)
readPair s = (a, b)
    where [a, b] = map readInt . words $ s

parseV :: Int -> String -> IntArray Int
parseV n l = listArray (1, n) a
    where a = map readInt . words $ l

sortOn :: Ord b => (a -> b) -> [a] -> [a]
sortOn f = map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x))

groupOn :: Ord b => (a -> b) -> [a] -> [[a]]
groupOn k = groupBy f . sortOn k
    where f x y = k x == k y

parseE :: Int -> [String] -> IntArray [Int]
parseE n ls =
    let es = map readPair ls
        gs = groupOn fst (es ++ map swap es)
    in  listArray (1, n) (map (map snd) gs)

parse :: String -> Input
parse contents =
    let (l0 : l1 : ls) = lines contents
        [n, m] = map readInt . words $ l0
    in  (m, parseV n l1, parseE n ls)

solve :: Input -> Int
solve (m, a, tree) = dfs (-1) 0 1
    where dfs :: Int -> Int -> Int -> Int
          dfs p k v =
              let a' = a ! v
                  k' = if a' == 0 then 0 else k + 1
                  nv = filter (/= p) $ tree ! v in
              if   k' > m
              then 0
              else if   null nv
                   then 1
                   else sum . map (dfs v k') $ nv

main :: IO ()
main = print . solve . parse =<< getContents

import Control.Applicative ((<$>))
import Data.Map (empty, (!), fromList, insert, adjust)
import Debug.Trace

-- 580C

solve :: Int -> Int -> [Bool] -> [[Int]] -> Int
solve n m hasCatLst edges =
  countRestaurants 0 m 1
  where
    empty_map = fromList [(i, []) | i <- [1..n]]
    append u v =
      adjust (v:) u . adjust (u:) v
    childrenArr = foldr (\[u, v] -> \mapping -> append u v mapping) empty_map edges
    hasCatArr = fromList $ zip [1..] hasCatLst
    countRestaurants parent m' i
      | m'' >= 0 && leaf = 1
      | leaf = 0
      | m'' < 0 = 0
      | otherwise = sum $ map (countRestaurants i m'') children
      where
        children = filter (/= parent) $ childrenArr ! i
        hasCat = hasCatArr ! i
        leaf = length children == 0
        m'' = if hasCat then m' - 1 else m

main = do
  let f = map read . words <$> getLine
  [n, m] <- f
  hasCatLst <- map toEnum <$> f
  edges <- map (map read . words) . lines <$> getContents
  putStrLn $ show $ solve n m hasCatLst edges

import qualified Data.Map.Strict               as Map
import qualified Data.Set                      as Set
import           Data.List

dfs :: Int -> Map.Map Int [Int] -> Map.Map Int Bool -> Int -> Int -> Int
dfs maxCats edgeMap hasCat nCats node
    | nCats' > maxCats = 0
    | null $ Map.findWithDefault [] node edgeMap = 1
    | otherwise = sum
        [ dfs maxCats edgeMap hasCat nCats' n | n <- edgeMap Map.! node ]
    where nCats' = if hasCat Map.! node then nCats + 1 else 0

g :: Int -> Int -> [Int] -> [(Int, Int)] -> Int
g n maxCats cats edges =
    let hasCat  = Map.fromAscList $ zip [0 ..] [ v == 1 | v <- cats ]
        edgeMap = Map.fromListWith (++) [ (a, [b]) | (a, b) <- edges ]
        root    = Set.elemAt 0 $ Set.difference
            (Set.fromAscList [0 .. n - 1])
            (Set.fromList $ Map.foldr (++) [] edgeMap)
    in  dfs maxCats edgeMap hasCat 0 root

f :: [String] -> Int
f (nm : cats : edges) =
    let [n, maxCats] = map read . words $ nm :: [Int]
        cats'        = map read . words $ cats :: [Int]
        edges' :: [(Int, Int)]
        edges' = map ((\[a, b] -> (a - 1, b - 1)) . (map read . words)) edges
    in  g n maxCats cats' edges'

-- TOOD: Nicer way to extract the lines?
main = interact $ show . f . lines

import Data.Array
dfs cat edges now ccat maxcat | null nextList = if (hascat + ccat) <= maxcat then 1 else 0
                              | otherwise = sum [dfs cat edges next (getCat hascat ccat) maxcat| next <- nextList]
    where nextList = (edges ! now)
          hascat = (cat ! now)
getCat a b | a == 0 = 0
           | otherwise = (a+b)
getTuple s = (a0,a1)
  where [a0,a1] = [read n::Int|n <- (words s)]
main = do
  w0 <- getLine
  let [n,m] = [read n::Int|n <- (words w0)]
  w1 <- getLine
  let hasCat = listArray (1,n) [read n::Int|n <- (words w1)]
  w2 <- getContents
  let e = [getTuple s | s <- (lines w2)]
  let edges = accumArray (flip (:)) [] (1,n) e
  print $ dfs hasCat edges 1 0 m

import Data.Array
dfs cat edges now ccat maxcat pre| isOne nextList && now /= 1 = if (hascat + ccat) <= maxcat then 1 else 0
                                 | otherwise = sum [dfs cat edges next (getCat hascat ccat) maxcat now| next <- nextList,next /= pre]
    where nextList = (edges ! now)
          hascat = (cat ! now)
getCat a b | a == 0 = 0
           | otherwise = (a+b)
isOne (x:xs) = null xs
getTuple s = (a0,a1)
  where [a0,a1] = [read n::Int|n <- (words s)]
main = do
  w0 <- getLine
  let [n,m] = [read n::Int|n <- (words w0)]
  w1 <- getLine
  let hasCat = listArray (1,n) [read n::Int|n <- (words w1)]
  w2 <- getContents
  let e = [getTuple s | s <- (lines w2)]
  let e2 = e ++ (map (\x -> (snd x,fst x)) e)
  let edges = accumArray (flip (:)) [] (1,n) e2
  print $ dfs hasCat edges 1 0 m 0

import Data.Array
dfs cat edges now ccat maxcat pre| null nextList = if (hascat + ccat) <= maxcat then 1 else 0
                                 | otherwise = sum [dfs cat edges next (getCat hascat ccat) maxcat now| next <- nextList,next /= pre]
    where nextList = (edges ! now)
          hascat = (cat ! now)
getCat a b | a == 0 = 0
           | otherwise = (a+b)
getTuple s = (a0,a1)
  where [a0,a1] = [read n::Int|n <- (words s)]
main = do
  w0 <- getLine
  let [n,m] = [read n::Int|n <- (words w0)]
  w1 <- getLine
  let hasCat = listArray (1,n) [read n::Int|n <- (words w1)]
  w2 <- getContents
  let e = [getTuple s | s <- (lines w2)]
  let e2 = e ++ (map (\x -> (snd x,fst x)) e)
  let edges = accumArray (flip (:)) [] (1,n) e
  print $ dfs hasCat edges 1 0 m 0

import Data.Array
dfs cat edges now ccat maxcat pre| isOne nextList = if (hascat + ccat) <= maxcat then 1 else 0
                                 | otherwise = sum [dfs cat edges next (getCat hascat ccat) maxcat now| next <- nextList,next /= pre]
    where nextList = (edges ! now)
          hascat = (cat ! now)
getCat a b | a == 0 = 0
           | otherwise = (a+b)
isOne (x:xs) = null xs
getTuple s = (a0,a1)
  where [a0,a1] = [read n::Int|n <- (words s)]
main = do
  w0 <- getLine
  let [n,m] = [read n::Int|n <- (words w0)]
  w1 <- getLine
  let hasCat = listArray (1,n) [read n::Int|n <- (words w1)]
  w2 <- getContents
  let e = [getTuple s | s <- (lines w2)]
  let e2 = e ++ (map (\x -> (snd x,fst x)) e)
  let edges = accumArray (flip (:)) [] (1,n) e2
  print $ dfs hasCat edges 1 0 m 0

import Control.Applicative
import Data.List
import Data.Array
import Debug.Trace

-- 580C

data TreeNode = TreeNode {
  hasCat :: Bool,
  children :: [Int]
} deriving (Show)

solve :: Int -> Int -> [Bool] -> [[Int]] -> Int
solve n m hasCatLst edges =
  countRestaurants m 1
  where
    track a = trace (show a) a
    edgeGroups = groupBy (\a -> \b -> head a == head b) (sort (map sort edges))

    makeNodes (x:rst) (hasCat:rstHasCat) nextIdx =
      let nodeIdx = head (head x)
          children = map last x
      in
       if nodeIdx == nextIdx then
         (TreeNode {hasCat = hasCat,
                   children = children}):makeNodes rst rstHasCat (nextIdx + 1)
       else
         (TreeNode {hasCat = hasCat,
                    children = []}):makeNodes (x:rst) rstHasCat (nextIdx + 1)

    makeNodes [] (hasCat:rstHasCat) nextIdx =
      (TreeNode {hasCat = hasCat,
                 children = []}):makeNodes [] rstHasCat (nextIdx + 1)
    makeNodes [] [] _ = []

    q = makeNodes edgeGroups hasCatLst 1
    nodes = listArray (1, n)  q

    countRestaurants m' rootIdx
      | m'' >= 0 && children root == [] = 1
      | m'' >= 0 =  sum $ map (countRestaurants m'') (children root)
      | otherwise = 0
      where
        root = nodes ! rootIdx
        m'' = if hasCat root then m' - 1 else m

main = do
  let f = map read . words <$> getLine
  [n, m] <- f
  hasCatLst <- map toEnum <$> f
  edges <- map (map read . words) . lines <$> getContents
  putStrLn $ show $ solve n m hasCatLst edges

import Control.Applicative
import Data.List
import Data.Array
import Debug.Trace

-- 580C

data TreeNode = TreeNode {
  hasCat :: Bool,
  children :: [Int]
} deriving (Show)

solve :: Int -> Int -> [Bool] -> [[Int]] -> Int
solve n m hasCatLst edges =
  countRestaurants m 1
  where
    track a = trace (show a) a
    edgeGroups = groupBy (\a -> \b -> head a == head b) (sort edges)

    makeNodes (x:rst) (hasCat:rstHasCat) nextIdx =
      let nodeIdx = head (head x)
          children = map last x
      in
       if nodeIdx == nextIdx then
         (TreeNode {hasCat = hasCat,
                   children = children}):makeNodes rst rstHasCat (nextIdx + 1)
       else
         (TreeNode {hasCat = hasCat,
                    children = []}):makeNodes (x:rst) rstHasCat (nextIdx + 1)

    makeNodes [] (hasCat:rstHasCat) nextIdx =
      (TreeNode {hasCat = hasCat,
                 children = []}):makeNodes [] rstHasCat (nextIdx + 1)
    makeNodes [] [] _ = []

    q = makeNodes edgeGroups hasCatLst 1
    nodes = listArray (1, n)  q

    countRestaurants m' rootIdx
      | m'' >= 0 && children root == [] = 1
      | m'' >= 0 =  sum $ map (countRestaurants m'') (children root)
      | otherwise = 0
      where
        root = nodes ! rootIdx
        m'' = if hasCat root then m' - 1 else m

main = do
  let f = map read . words <$> getLine
  [n, m] <- f
  hasCatLst <- map toEnum <$> f
  edges <- map (map read . words) . lines <$> getContents
  putStrLn $ show $ solve n m hasCatLst edges

import Data.Array
import Data.Graph
import Control.Monad
main = do
  [n,m] <- map read . words <$> getLine
  cats <- listArray (1,n) . map (toEnum . read) . words <$> getLine
  g <- fmap (buildG (1,n)) $ replicateM (n-1) $ do
    [x,y] <- map read . words <$> getLine
    return (x,y)
  let [t] = dfs g [1]
      count c (Node n ts) | c' > m = 0
                          | null ts = 1
                          | otherwise = sum (map (count c') ts)
        where c' = if cats!n then c+1 else 0
  print $ count 0 t


import qualified Data.ByteString.Char8 as B

main :: IO ()
main = mapM_ print . solve . map (map (maybe 0 fst . B.readInt) . B.words) . B.lines =<< B.getContents

solve :: [[Int]] -> [Int]
solve ([n, m] : as : qs) = map f qs
  where
  pos = length $ filter (== 1) as
  neg = n - pos
  f [l, r] = fromEnum $ m == 0 && pos >= d && neg >= d
    where
    (d, m) = (r - l + 1) `quotRem` 2

import Data.Char
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main = B.interact $ B.unwords . map showBI . rd . B.lines
rd (nm:a:ql) = go (map (fst . fromJust . B.readInt) (B.words a)) (map (map $ fst . fromJust . B.readInt) . map B.words $ ql)
go a ql = foldr (\(l:r:[]) ans -> (ch l r):ans) [] ql
          where ch l r | (r-l+1)`mod`2 == 1 = 0
                       | otherwise = if (p>=cnt)&&(n>=cnt) then 1 else 0
                                     where cnt = (r-l+1)`div`2
                                           p = length $ filter (>0) a
                                           n = length $ filter (<0) a

showBI :: Int -> B.ByteString
showBI = B.pack . show

import Control.Monad (liftM, replicateM)
import Prelude hiding (read, reads)

read :: String -> Int
read ('-':s)  =  (-1) * read s
read s  =  read' 0 s
  where
    read' a ""  =  a
    read' a (c:s)  =  read' a' s
      where
        a'  =  10*a + fromEnum c - fromEnum '0'

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

solve :: Int -> [Int] -> [[Int]] -> [Int]
solve n as qs  =  map solve' qs
  where
    x  =  length $ filter (== 1) as
    y  =  n - x
    solve' [l,r]
      | odd (r - l + 1)  =  0
      | (r - l + 1) > 2 * min x y  =  0
      | otherwise  =  1

main :: IO ()
main  =  do
    [n, m]  <-  reads
    as  <-  reads
    qs  <-  replicateM m reads
    mapM_ print $ solve n as qs

import Control.Monad (liftM, replicateM)
import Prelude hiding (read, reads)

read :: String -> Int
read ('-':s)  =  (-1) * read s
read s  =  read' 0 s
  where
    read' a ""  =  a
    read' a (c:s)  =  read' a' s
      where
        a'  =  10*a + fromEnum c - fromEnum '0'

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

solve :: Int -> [Int] -> [Int] -> [Int]
solve n as qs  =  solve' qs
  where
    x  =  length $ filter (== 1) as
    y  =  n - x
    solve' (l:r:qs)
      | odd (r - l + 1)  =  0 : solve' qs
      | (r - l + 1) > 2 * min x y  =  0 : solve' qs
      | otherwise  =  1 : solve' qs
    solve' _  =  []

main :: IO ()
main  =  do
    ints  <-  reads
    let [n, m]  =  take 2 ints
    let as  =  take n $ drop 2 ints
    let qs  =  take (2*m) $ drop n $ drop 2 ints
    mapM_ print $ solve n as qs

import Data.List
import Data.Char
import Data.Maybe
import Control.Monad
import Control.Applicative
import qualified Data.ByteString.Char8 as C
import Data.Array
import Data.Bits

main = do
  [n, m] <- getList
  a <- getList
  let aminus = foldl' (\acc x -> if x < 0 then acc+1 else acc) 0 a
  let aplus = length(a) - aminus
  m <- replicateM m getList
  mapM_ (\x -> print $ f x aminus aplus) m
  where
    f [l, r] aminus aplus = if t `mod` 2 == 0 && t2 <= aminus && t2 <= aplus && t > 0 then 1 else 0
      where
	t = r - l + 1
	t2 = t `div` 2
    getList = fmap (map (fst . fromJust . C.readInt) . C.words) C.getLine

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

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

readInt :: B.ByteString -> Int
readInt bs = case B.readInt bs of Just (n,_) -> n

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine
  xs <- map readInt.B.words <$> B.getLine
  lrs <- map readInt.B.words <$> B.getContents
  putStr.unlines.map show $ solve n xs lrs

solve :: Int -> [Int] -> [Int] -> [Int]
solve n xs lrs = go lrs
   where
     !ts = sum[1|1<-xs]
     !fs = n - ts
     go (l:r:rest)
       | even (r-l) = 0 : go rest
       | 2 * min ts fs >= r-l+1 = 1 : go rest
       | otherwise = 0 : go rest
     go _ = []

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

process [] _ _ = do
			putStr ""

process ([b1,b2]:b) a1 a2 = do
				process1 b1 b2 a1 a2
				process b a1 a2

process1 b1 b2 a1 a2 = do
				print $ if even (b2-b1) then 0
						        else if a1> div (b2-b1) 2 && a2 >div (b2-b1) 2 then 1 else 0

main = do
		[ne,nq]<- map read <$> words <$> getLine ::IO [Int]
		a<- words <$> getLine
		let a1= length $ filter (=="1") a
		let a2= (length a) - a1
		b<- map (map read) <$> map words <$> replicateM nq getLine ::IO [[Int]]
		process b a1 a2


{-# LANGUAGE RankNTypes #-}

import Control.Monad
import Data.List
import Data.Array
import System.IO

import Data.List
import Data.Ord
import Data.Array
import Control.Monad

{-
メモ化
-}
memoise :: forall a b. Ix a => ((a -> b) -> a -> b) -> (a,a) -> a -> b
memoise f r = let mem = listArray r . map (f (mem!)) $ range r in (mem!)

{-
メモ化フィボナッチ
-}
fib :: (Integer -> Integer) -> Integer -> Integer
fib f n | n <= 1 = n
        | True = f (n-1) + f (n-2)

max_memo :: Integer
max_memo = 500

memoFib :: Integer -> Integer
memoFib = memoise fib (0,100000)

{-
パスカルの三角形
-}
pascalTriangle :: Integer -> Integer -> Integer
pascalTriangle = memoise row (0,1000000)
  where
    row memo n = memoise col rng
        where
          rng = (0,n)
          col _ r
            | r == 0 = 1
            | r == n = 1
            | True     = memo (n-1) (r-1) + memo (n-1) r

comb :: Integer -> Integer -> Integer
comb = pascalTriangle

--memoise

toTuple :: [String] -> (String,Integer)
toTuple (a:b:[]) = (a,read b)

eqFst (a,b) (c,d) = a==c

--calc :: Array Int (String, Integer) -> Int -> Integer
calc xs memo k
  | k <= 1                = 0
  | fst (xs ! k) == "win" = y
  | True                  = maximum $ (y : map f [1..k-1])
  where
    y = memo (k-1)
    --y = calc xs (k-1)
    f m | fst (xs ! m) == "sell"   = 0
        | snd (xs!m) /= snd (xs!k) = 0
       -- | m == 1                   = 0
        | True                     = 2 ^ (snd (xs ! m)) + memo (m-1)

memoCalc xs n = memoise (calc xs) (0,n)

main = do
    n <- readLn :: IO Int
    xs' <- replicateM n $ (toTuple . words) `liftM` getLine
    let xs = listArray (1,n) xs'

    print $ memoCalc xs n n

tryX :: Int -> [(String, Int)] -> Integer
tryX (-1) _ = 0
tryX x events = let sells = [j | (j, ("sell", y)) <- eventsWithIds, y == x] in
                    if null sells then tryX (x - 1) events
                    else let j = head sells; wins = [i | (i, ("win", y)) <- take j eventsWithIds, y == x] in
                         if null wins then tryX (x - 1) events
                         else let i = last wins in
                              2 ^ x + tryX (x - 1) (take i events) + tryX (x - 1) (drop (j + 1) events)
                where eventsWithIds = zip [0..] events

solve :: [(String, Int)] -> Integer
solve events = tryX 2000 events

main = do
    contents <- getContents
    let n = read $ head $ lines contents
    let events = map (\s -> let [t, x] = words s in (t, read x)) $ take n $ tail $ lines contents
    putStrLn $ show $ solve events

{-# LANGUAGE RankNTypes #-}

import Control.Monad
import Data.List
import Data.Array
import System.IO

import Data.List
import Data.Ord
import Data.Array
import Control.Monad

{-
メモ化
-}
memoise :: forall a b. Ix a => ((a -> b) -> a -> b) -> (a,a) -> a -> b
memoise f r = let mem = listArray r . map (f (mem!)) $ range r in (mem!)

{-
メモ化フィボナッチ
-}
fib :: (Integer -> Integer) -> Integer -> Integer
fib f n | n <= 1 = n
        | True = f (n-1) + f (n-2)

max_memo :: Integer
max_memo = 500

memoFib :: Integer -> Integer
memoFib = memoise fib (0,100000)

{-
パスカルの三角形
-}
pascalTriangle :: Integer -> Integer -> Integer
pascalTriangle = memoise row (0,1000000)
  where
    row memo n = memoise col rng
        where
          rng = (0,n)
          col _ r
            | r == 0 = 1
            | r == n = 1
            | True     = memo (n-1) (r-1) + memo (n-1) r

comb :: Integer -> Integer -> Integer
comb = pascalTriangle

--memoise

toTuple :: [String] -> (String,Integer)
toTuple (a:b:[]) = (a,read b)

eqFst (a,b) (c,d) = a==c

--calc :: Array Int (String, Integer) -> Int -> Integer
calc xs memo k
  | k <= 1                = 0
  | fst (xs ! k) == "win" = y
  | True                  = maximum $ (y : map f [1..k-1])
  where
    y = memo (k-1)
    --y = calc xs (k-1)
    f m | fst (xs ! m) == "sell"   = 0
        | snd (xs!m) /= snd (xs!k) = 0
        | m == 1                   = 0
        | True                     = 2 ^ (snd (xs ! m)) + memo (m-1)

memoCalc xs n = memoise (calc xs) (1,n)

main = do
    n <- readLn :: IO Int
    xs' <- replicateM n $ (toTuple . words) `liftM` getLine
    let xs = listArray (1,n) xs'

    print $ memoCalc xs n n

tryX :: Int -> [(String, Int)] -> Integer
tryX (-1) _ = 0
tryX x events = let sells = [j | (j, ("sell", y)) <- eventsWithIds, y == x] in
                    if null sells then tryX (x - 1) events
                    else let j = head sells; wins = [i | (i, ("win", y)) <- take j eventsWithIds, y == x] in
                         if null wins then tryX (x - 1) events
                         else let i = last wins in
                              2 ^ x + tryX (x - 1) (take i events ++ drop (j + 1) events)
                where eventsWithIds = zip [0..] events

solve :: [(String, Int)] -> Integer
solve events = tryX 2000 events

main = do
    contents <- getContents
    let n = read $ head $ lines contents
    let events = map (\s -> let [t, x] = words s in (t, read x)) $ take n $ tail $ lines contents
    putStrLn $ show $ solve events

tryX :: Int -> [(String, Int)] -> Integer
tryX (-1) _ = 0
tryX x events = let sells = [j | (j, ("sell", y)) <- eventsWithIds, y == x] in
                    if null sells then tryX (x - 1) events
                    else let j = head sells; wins = [i | (i, ("win", y)) <- take j eventsWithIds, y == x] in
                         if null wins then tryX (x - 1) events
                         else let i = last wins in
                              2 ^ x + tryX (x - 1) (take i events ++ drop (j + 1) events)
                where eventsWithIds = zip [0..] events

solve :: [(String, Int)] -> Integer
solve events = tryX 2000 events

main = do
    contents <- getContents
    let events = map (\s -> let [t, x] = words s in (t, read x)) $ tail $ lines contents
    putStrLn $ show $ solve events


{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns, OverloadedStrings #-}
{-# 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 = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

main = do
  [n, c] <- getInts
  ts <- getInts

  print $ (length $ takeWhile id $ reverse $ zipWith (\x y -> y <= x+c) ts (tail ts)) + 1

main = do
    [n,c] <- return . map read . words =<< getLine
    times <- return . map read . words =<< getLine
    let revTm = map negate . reverse $ times
	pass = takeWhile (<=c) . tail $ adjaDiffs revTm
    print $ 1+length pass

adjaDiffs::Num n => [n] -> [n]
adjaDiffs list = zipWith (-) list $ 0:list

import Data.Functor

sol :: Int -> [Int] -> Int
sol c (t1:t2:ts)
  | t1 - t2 > c = 1
  | otherwise   = 1 + sol c (t2:ts)
sol _ (t:[]) = 1

main = do
  c <- (read . head . tail . words) <$> getLine
  ts <- (reverse . fmap read . words) <$> getLine
  putStrLn $ show $ sol c ts

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

process [a,b,c,d] | mod  (b-a) (c+d)>0 = -1
                  | otherwise = div (b-a) (c+d)

main::IO ()
main=do
  	[t,s]<- map read<$>words <$> getLine ::IO [Int]
	a<-  map read<$> words <$>getLine::IO [Int]
	let b = length $ takeWhile (<=s)$ reverse $ zipWith (\x y ->y-x) a (tail a)
	print $ b+1

merge res1 res2 x y len c = if res2 == len && x + c >= y
                          then len + res1
                          else res2
pre_merge c pair = merge (solve c (fst pair)) (solve c (snd pair)) (last (fst pair)) (head (snd pair)) (length (snd pair)) c
solve c t = if length t == 1
               then 1
               else pre_merge c (splitAt (quot (length t) 2) t)
parse str1 str2 = solve (read ((words str1) !! 1) :: Int) ([read x :: Int | x <- (words str2)])
main = do
  line1 <- getLine
  line2 <- getLine
  print (parse line1 line2)

process :: Int -> [Int] -> Int
process c xs = (+1) . length . takeWhile (<=c) $ zipWith (-) xs' (tail xs')
    where xs' = reverse xs

readInt :: String -> Int
readInt = read

main :: IO ()
main = do
    line <- getLine
    let [n,c] = map readInt (words line)
    xs <- fmap (map readInt.words) getLine
    print $ process c xs

main :: IO ()
main = do
        _:c:xs <- getReadAll
        print $ solve c xs

solve :: Int -> [Int] -> Int
solve delay = fst . foldl (transition delay) (0, 0)

transition :: Int -> (Int, Int) -> Int -> (Int, Int)
transition delay (oldCount, lastTs)  newTs = (newCount, newTs)
    where newCount = if newTs - lastTs > delay then 1 else oldCount + 1

getReadAll :: (Read a) => IO [a]
getReadAll = fmap (fmap read. words) getContents

solve :: Int -> Int -> Int -> [Int] -> Int
solve n _ _ [] = n
solve n c t (x:xs)
    | x - t <= c = solve (n + 1) c x xs
    | otherwise = solve 1 c x xs

main :: IO ()
main = do
    line <- getLine
    let [n, c] = map read $ words line :: [Int]
    line <- getLine
    let ts = map read $ words line :: [Int]
    print $ solve 0 c 0 ts

import Data.Array as A
main = do
    cin <- getContents
    let n:c:a = map read (words cin) :: [Int]
    let b = A.listArray (1, n) a
    let f r i = if b A.! i - b A.! (i-1) > c then 0 else r + 1
    print $ 1 + foldl f 0 [2..n]

process :: Int -> (Int, Int) -> Int -> (Int, Int)
process timeDiff prev curTime =
  let
    prevCnt = fst prev
    prevTime = snd prev
  in if curTime - prevTime <= timeDiff
    then (prevCnt + 1, curTime)
    else (1, curTime)

main :: IO ()
main = do
  s1 <- getLine
  let [n, c] = map read $ words s1
  s2 <- getLine
  let vals = map read $ words s2
  let r = foldl (process c) (0, 0) vals
  putStrLn (show (fst r))

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns, OverloadedStrings #-}
{-# 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, c] <- map read . words <$> getLine
  ts <- map read . words <$> getLine

  print $ (length $ takeWhile id $ reverse $ zipWith (\x y -> y <= x+c) ts (tail ts)) + 1

import Data.List
import Data.Tree
import Data.Int
import Data.Maybe
import Data.Char
import Data.Functor
import Control.Monad
import Control.Monad.ST.Safe
import Control.Arrow
import Data.Array
import Data.Array.ST.Safe
import Data.STRef
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.ByteString.Char8 as C
main=   readsolveprint
readsolveprint::IO()
readsolveprint = (solve.tail.concat =<< forM [1 .. 2] ( \i -> map (fst.fromJust.C.readInt).C.words <$> C.getLine))
solve (x:xs) = print $ fst $ foldl (\(b1,b2) a-> if a-b2<=x then (b1+1,a) else (1,a)) (0,0) xs

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

main = do
  [a,b]<-map read <$> words <$> getLine ::IO [Int]
  m<-map read <$> words <$> getLine ::IO [Int]
  print $ (+1) $ length $ takeWhile (<=b) $ reverse $ zipWith (-) (tail m) m

main = interact $ show . solve . map read . tail . words
solve (c:ts) = go 0 0 ts where
  go i p (t:ts) | t-p > c = go 1 t ts
                | otherwise = go (i+1) t ts
  go i _ _ = i

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

solve cnt (c:[_]) = cnt + 1
solve cnt (c:t0:t1:ts) = if t1 - t0 <= c
                     then solve (cnt + 1) (c:t1:ts)
                     else solve 0 (c:t1:ts)

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 -> Int
  readInt s = read s :: Int

  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

  solve :: Int -> Int -> [Int] -> Int
  solve k c (x:y:xs)
    | y - x <= k = solve k (c + 1) (y:xs)
    | otherwise = solve k 1 (y:xs)
  solve _ c (y:xs) = c
  solve _ c [] = c

  main :: IO()
  main = do
    [n, k] <- getLine >>= return . map readInt . words
    xs <- getLine >>= return . map readInt . words
    print $ solve k 1 $ sort xs

module Main where
import Data.List
parseLine line =
    map (\numStr -> read numStr :: Int) $ words line

calculateElapsedSeconds array =
    zipWith (\a b -> a - b) (drop 1 array ++ [last array]) array

solve wordCount maxSeconds array =
    case findIndex (\et -> et > maxSeconds) $ reverse $ calculateElapsedSeconds array of
        Just result -> result
        Nothing -> wordCount

main =
    do
        firstLine <- getLine
        secondLine <- getLine
        let firstLineParsed = parseLine firstLine
        let seconds = parseLine secondLine
        putStrLn $ show $ solve (firstLineParsed!!0) (firstLineParsed!!1) seconds

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns, OverloadedStrings #-}
{-# 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, c] <- map read . words <$> getLine
  ts <- map read . words <$> getLine

  let rs = map length $ filter (id . head) $ group $ zipWith (\x y -> y <= x+c) ts (tail ts)

  print $ if null rs then 1 else maximum rs + 1

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns, OverloadedStrings #-}
{-# 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, c] <- map read . words <$> getLine
  ts <- map read . words <$> getLine

  let rs = map length $ filter (id . head) $ group $ zipWith (\x y -> y <= x+c) ts (tail ts)

  print $ if null rs then 1 else last rs + 1

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 -> Int
  readInt s = read s :: Int

  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

  solve :: Int -> Int -> [Int] -> Int
  solve k c (x:y:xs)
    | y - x <= k = solve k (c + 1) (y:xs)
    | otherwise = solve k 1 (y:xs)
  solve _ c (y:xs) = c
  solve _ c [] = c

  main :: IO()
  main = do
    [n, k] <- getLine >>= return . map readInt . words
    xs <- getLine >>= return . map readInt . words
    print $ solve k 0 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 -> Int
  readInt s = read s :: Int

  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

  solve :: Int -> Int -> [Int] -> Int
  solve k c (x:y:xs)
    | y - x <= k = solve k (c + 1) (y:xs)
    | otherwise = solve k 1 (y:xs)
  solve _ c (y:xs) = c
  solve _ c [] = c

  main :: IO()
  main = do
    [n, k] <- getLine >>= return . map readInt . words
    xs <- getLine >>= return . map readInt . words
    print $ solve k 0 $ sort xs

module Main where
import Data.List
parseLine line =
    map (\numStr -> read numStr :: Integer) $ words line

calculateElapsedSeconds array =
    zipWith (\a b -> a - b) (drop 1 array ++ [last array]) array

solve maxSeconds array =
    case findIndex (\et -> et > 5) $ reverse (calculateElapsedSeconds array) of
        Just result -> result
        Nothing -> -1

main =
    do
        firstLine <- getLine
        secondLine <- getLine
        let firstLineParsed = parseLine firstLine
        let seconds = parseLine secondLine
        putStrLn $ show $ solve (firstLineParsed!!1) seconds

module Main where
import Data.List
parseLine line =
    map (\numStr -> read numStr :: Integer) $ words line

calculateElapsedSeconds array =
    zipWith (\a b -> a - b) (drop 1 array ++ [last array]) array

solve maxSeconds array =
    case findIndex (\et -> et > maxSeconds) $ reverse elapsedSeconds of
        Just result -> result
        Nothing -> 1
    where
        elapsedSeconds = calculateElapsedSeconds array

main =
    do
        firstLine <- getLine
        secondLine <- getLine
        let firstLineParsed = parseLine firstLine
        let seconds = parseLine secondLine
        putStrLn $ show $ solve (firstLineParsed!!1) seconds

module Main where
import Data.List
parseLine line =
    map (\numStr -> read numStr :: Integer) $ words line

calculateElapsedSeconds array =
    zipWith (\a b -> a - b) (drop 1 array ++ [last array]) array

solve maxSeconds array =
    case findIndex (\et -> et > maxSeconds) $ reverse elapsedSeconds of
        Just result -> result
        Nothing -> -1
    where
        elapsedSeconds = calculateElapsedSeconds array

main =
    do
        firstLine <- getLine
        secondLine <- getLine
        let firstLineParsed = parseLine firstLine
        let seconds = parseLine secondLine
        putStrLn $ show $ solve (firstLineParsed!!1) seconds

solve c t = sum [1 | x <- t, (x + c) >= (last t)]
parse str1 str2 = solve (read ((words str1) !! 1) :: Int) ([read x :: Int | x <- (words str2)])
main = do
  line1 <- getLine
  line2 <- getLine
  print (parse line1 line2)

solve :: Int -> Int -> Int -> [Int] -> Int
solve n _ _ [] = n
solve n c t (x:xs)
    | x - t <= c = solve (n + 1) c x xs
    | otherwise = solve 1 c x xs

main :: IO ()
main = do
    line <- getLine
    let [n, c] = map read $ words line :: [Int]
    line <- getLine
    let ts = map read $ words line :: [Int]
    print $ solve n c (head ts) ts


import qualified Data.ByteString.Lazy.Char8 as P
import qualified Data.ByteString.Builder as B
import System.IO

import Control.Monad
import Control.Monad.Trans.State
import Control.Monad.Trans.Class
import Data.List
import Data.Semigroup

import Data.Array.Unboxed

solve :: Int -> [Int] -> Int
solve m li = let
  buckets :: UArray Int Int
  buckets = accumArray (const . (+ 1)) 0 (0, m-1) $ zip (map (`mod` m) li) li
  in  foldl' (+) 0 $ do --'
  (v, ct) <- assocs buckets
  let
    sv = mod (negate v) m
    sct = buckets ! sv
  guard $ (ct, v) >= (sct, sv)
  pure $ if  ct == 0
    then  0
    else  max 1 (ct - sct)

main :: IO ()
main = (P.getContents >>=) . evalStateT $ do
  [t] <- readInts
  replicateM_ t $ do
    [_n, m] <- readInts
    a <- readInts
    putInts [solve m a]

type SIO = StateT P.ByteString IO

readLine :: SIO P.ByteString
readLine = do
  (out, next) <- P.break (<= '\r') <$> get
  put $ P.dropWhile (<= '\r') next
  pure out

readInts :: SIO [Int]
readInts = do
  currLine <- readLine
  pure [x | Just (x, _) <- P.readInt <$> P.words currLine]

putInts :: [Int] -> SIO ()
putInts li = let
  outBuilder = foldr (<>) (B.char7 '\n')
    $ intersperse (B.char7 ' ') (map B.intDec li)
  in  lift $ B.hPutBuilder stdout outBuilder

import Control.Monad
import Data.List
import qualified Data.Map as Map
import qualified Data.Map.Strict as MapS

main = do
    t <- readLn
    replicateM t testcase

testcase :: IO ()
testcase = do
    firstLine <- getLine
    let [_,m] = map read . words $ firstLine
    a <- fmap (map read . words) getLine
    putStrLn $ solve a m

solve :: [Int] -> Int -> String
solve a m =
    if MapS.member 0 counts then
        show $ solution + 1
    else show solution
    where
        modded = map (`mod` m) a
        counts = foldl' (\acc curr -> MapS.insertWith (+) curr 1 acc) MapS.empty modded :: Map.Map Int Int
        mapFoldF :: Int -> Int -> Int -> Int
        mapFoldF k a b
            | k == 0 = b
            | MapS.member (m-k) counts && k < m-k = b
            | otherwise = (b+) . (1+) . max 0 . (subtract 1) . abs . (a-) $ MapS.findWithDefault 0 (m-k `mod` m) counts
        solution = MapS.foldrWithKey mapFoldF 0 counts :: Int

{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.Char
import Data.List (sort, group)
import Data.Map ((!))
import qualified Data.Map  as M
import qualified Data.ByteString.Char8 as B
-- import Debug.Trace
import System.IO
import Text.Read
import Data.Maybe (fromJust)

getNums :: IO [Int]
getNums = do
  line <- B.getLine
  return $ map ((fst . fromJust) . B.readInt) . B.split ' ' $ line

main :: IO ()
main = do
  t <- readLn :: IO Integer
  forM_ [1 .. t] handleCase

handleCase :: Integer -> IO ()
handleCase c = do
  [n, m] <- getNums
  as <- getNums
  print $ solve m as

solve m as = sum solves
  where
    ams = map (`mod` m) as
    sizes = M.fromList $ map (\xs -> (head xs, length xs)) $ group $ sort ams

    solveForSize i
      | i == 0 = 1
      | i < i' && M.member i' sizes = 0
      | otherwise = max 1 $ abs (curSize - compSize)
      where
        i' = m - i
        curSize = sizes ! i
        compSize = M.findWithDefault 0 i' sizes

    solves = map solveForSize $ M.keys sizes

import Control.Monad
import Data.List
import qualified Data.Map as Map
import qualified Data.Map.Strict as MapS

main = do
    t <- readLn
    replicateM t testcase

testcase :: IO ()
testcase = do
    firstLine <- getLine
    let [_,m] = map read . words $ firstLine
    a <- fmap (map read . words) getLine
    putStrLn $ solve a m

solve :: [Int] -> Int -> String
solve a m =
    if MapS.member 0 counts then
        show $ solution + 1
    else show solution
    where
        modded = map (`mod` m) a
        counts = foldl' (\acc curr -> MapS.insertWith (+) curr 1 acc) MapS.empty modded :: Map.Map Int Int
        mapFoldF :: Int -> Int -> Int -> Int
        mapFoldF k a b
            | k == 0 = b
            | MapS.member (m-k) counts && k < m `div` 2 = b
            | otherwise = (b+) . (1+) . max 0 . (subtract 1) . abs . (a-) $ MapS.findWithDefault 0 (m-k `mod` m) counts
        solution = MapS.foldrWithKey mapFoldF 0 counts :: Int


{-# LANGUAGE LambdaCase #-}

import           Control.Arrow
import           Control.Monad.State
import           Data.List

main = interact $
  runScanner (numberOf tc) >>> map (solve >>> show) >>> unlines

tc :: Scanner (Int, [[Int]])
tc = do
  n <- int
  (,) <$> int <*> two (replicateM n int)

solve :: (Int, [[Int]]) -> Int
solve (k, [as, bs]) = sum $ zipWith max (sort as) (take k (reverse (sort bs)) ++ repeat 0)

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

type Scanner = State [String]

runScanner :: Scanner a -> String -> a
runScanner = runScannerWith words

runScannerWith :: (String -> [String]) -> Scanner a -> String -> a
runScannerWith t s = evalState s . t

str :: Scanner String
str = get >>= \case { s:ss -> put ss >> return s }

int :: Scanner Int
int = read <$> str

integer :: Scanner Integer
integer = read <$> str

double :: Scanner Double
double = read <$> str

numberOf :: Scanner a -> Scanner [a]
numberOf s = int >>= flip replicateM s

many :: Scanner a -> Scanner [a]
many s = get >>= \case { [] -> return []; _ -> (:) <$> s <*> many s }

two, three, four :: Scanner a -> Scanner [a]
[two, three, four] = map replicateM [2..4]

import Control.Monad.State
import Control.Monad
import Data.List

fmapfst :: (a -> c) -> (a,b) -> (c,b)
fmapfst f (a,b) = (f a, b)

alg ::  Int -> State ([Int],[Int]) ()
alg n= do
  forM_ [1..n] (\_ -> do
    a' <- fmap (minimum . fst) get
    b' <- fmap (maximum . snd) get
    modify (fmapfst ((b':) . delete a'))
    modify (fmap ((a':) . delete b'))
     )

finAlg_ :: [Int] -> [Int] -> Int -> Int
finAlg_ a b n = sum $ fst $ execState (alg n) (a,b)

finAlg :: [Int] -> [Int] -> Int -> Int
finAlg a b n = maximum $ map (finAlg_ a b)[0..n]

getOnes :: IO ([Int],[Int],Int)
getOnes = do
  (_:n:_) <- fmap ( map read .words) getLine
  a <- fmap ( map read .words) getLine
  b <- fmap ( map read .words) getLine
  return (a,b,n)

main :: IO()
main = do
  x <- fmap read getLine
  ls <- replicateM x getOnes
  mapM_ (print . (\(a,b,n) -> finAlg a b n)) ls

import Control.Monad
import Data.List
import Data.Ord

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

routine :: IO ()
routine = do
    [_,k]<- (map read.words) <$> getLine
    as <- (map read.words) <$> getLine
    bs <- (map read.words) <$> getLine
    print $ solve k as bs

solve :: Int -> [Int] -> [Int] -> Int
solve k as bs = sum $ (drop k ass) ++ (take k $ sortOn Down c)
  where
    ass = sort as
    bss = sortOn Down bs
    c = take k ass ++ take k bss

module Main where
import Data.List

solve [] = []
solve ([_,n] : xs : ys : zss) = (show $ sum $ solve' xs ys ) : solve zss
	where
		solve' xs ys = zipWith max (take n (reverse $ sort ys)) (take n (sort xs))  ++ drop n (sort xs)

main = interact $ unlines . solve . map (map (read :: String -> Int) . words)   . tail . lines

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

onecase = do
		[n,k]<- map read <$> words <$> getLine::IO [Int]
		a<- sort <$> map read <$> words <$> getLine::IO [Int]
		b<- reverse<$> sort <$> map read <$> words <$> getLine::IO [Int]
		let c = sum $ map (\(a,b)-> b-a) $ take k $takeWhile (\(x,y)->y>=x) $ zip a b
		print $ c+ sum a
main = do
	n<- read <$> getLine ::IO Int
	replicateM_ n onecase

import Data.Map as M
import Data.List as L

fun :: [Integer] -> [Integer] -> Integer -> Integer
fun as _  0 = sum as
fun as bs k = if a < b then (b + fun as' bs' (k-1)) else sum as
  where (a:as') = L.sort as
        (b:bs') = reverse $ L.sort bs

partitionBy :: [String] -> [[String]]
partitionBy [] = []
partitionBy (a:b:c:xs) = [[a, b, c]] ++ (partitionBy xs)

solve' :: String -> String -> String -> String
solve' k' as' bs' = show $ fun as bs k
  where k  = head $ tail $ L.map (\x -> read x :: Integer) $ words k'
        as = L.map (\x -> read x :: Integer) $ words as'
        bs = L.map (\x -> read x :: Integer) $ words bs'

solve :: String -> String
solve input = unlines $ [solve' a b c | [a, b, c] <- partitionBy lines']
  where lines' = tail $ lines input

main :: IO()
main = do
  contents <- getContents
  putStr (solve contents)

import Control.Monad.State
import Control.Monad
import Data.List

fmapfst :: (a -> c) -> (a,b) -> (c,b)
fmapfst f (a,b) = (f a, b)

alg ::  Int -> State ([Int],[Int]) ()
alg n= do
  forM_ [1..n] (\_ -> do
    a' <- fmap (minimum . fst) get
    b' <- fmap (maximum . snd) get
    modify (fmapfst ((b':) . delete a'))
    modify (fmap ((a':) . delete b'))
     )

finAlg :: [Int] -> [Int] -> Int -> Int
finAlg a b n = sum $ fst $ execState (alg n) (a,b)

getOnes :: IO ([Int],[Int],Int)
getOnes = do
  (_:n:_) <- fmap ( map read .words) getLine
  a <- fmap ( map read .words) getLine
  b <- fmap ( map read .words) getLine
  return (a,b,n)

main :: IO()
main = do
  x <- fmap read getLine
  ls <- replicateM x getOnes
  mapM_ (print . (\(a,b,n) -> finAlg a b n)) ls

module Main where
import Data.List

solve [] = []
solve ([_,n] : xs : ys : zss) = (show $ sum $ solve' xs ys ) : solve zss
	where
		solve' xs ys = take n (reverse $ sort ys) ++ drop n (sort xs)

main = interact $ unlines . solve . map (map (read :: String -> Int) . words)   . tail . lines

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

onecase = do
		[n,k]<- map read <$> words <$> getLine::IO [Int]
		a<- sort <$> map read <$> words <$> getLine::IO [Int]
		b<- reverse<$> sort <$> map read <$> words <$> getLine::IO [Int]
		let c = sum $ map (\(a,b)-> b-a) $ take k $takeWhile (\(x,y)->x>=y) $ zip a b
		print $ c+ sum a
main = do
	n<- read <$> getLine ::IO Int
	replicateM_ n onecase

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

onecase = do
		[n,k]<- map read <$> words <$> getLine::IO [Int]
		a<- sort <$> map read <$> words <$> getLine::IO [Int]
		b<- reverse<$> sort <$> map read <$> words <$> getLine::IO [Int]
		print $ sum a + sum(take k b)- sum (take k a)

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


import qualified Data.ByteString.Char8 as C
import Data.Maybe (fromJust)

getInteger :: IO Integer
getInteger = fmap (fst . fromJust) $ fmap C.readInteger C.getLine

main = do
    a <- getInteger
    b <- getInteger
    putStrLn $ case a `compare` b of
                 LT -> "<"
                 EQ -> "="
                 GT -> ">"

import Control.Applicative ((<$>))
import Data.ByteString.Char8 (readInteger, words, unpack, getLine)
import Data.Maybe (fromJust)
import Prelude hiding (words, getLine)

main = do
  a <- fst . fromJust . readInteger <$> getLine :: IO Integer
  b <- fst . fromJust . readInteger <$> getLine :: IO Integer

  putStrLn $ case compare a b of
             LT -> "<"
             EQ -> "="
             GT -> ">"

import qualified Data.ByteString.Char8 as B
import Data.Maybe

main = B.getContents >>= (B.putStr . B.pack . compare. map (fst . fromJust . B.readInteger) . B.lines)
    where
        myread x = read x :: Integer
        compare (a:b:xc) = fun (a - b)
            where
                fun x   | x == 0 = "="
                        | x < 0 = "<"
                        | otherwise = ">"

compareNumbers :: String -> String -> String
compareNumbers fst snd =
    let fstLength = length fst
        sndLength = length snd
        deltaLength = fstLength - sndLength
        prefix = replicate (abs deltaLength) '0' in
    if deltaLength < 0 then compareNumbers (prefix ++ fst) snd
    else if deltaLength > 0 then compareNumbers fst (prefix ++ snd)
    else case (compare fst snd) of
        LT -> "<"
        EQ -> "="
        GT -> ">"

main :: IO ()
main = do
    fst <- getLine :: IO String
    snd <- getLine :: IO String
    putStrLn (compareNumbers fst snd)

import Data.List
import Data.Int
import qualified Data.Array as A
import Data.Array((!))
import Numeric

fastRead :: String -> Int64
fastRead ('-':s) = case readDec s of [(n, "")] -> (-n)
fastRead s = case readDec s of [(n, "")] -> n

main = interact solve

solve input = answer
    where
        (aw:bw:xs) = words input
        raw = reverse aw
        rbw = reverse bw

        answer = amap (go raw rbw)

amap 0 = "="
amap 1 = ">"
amap (-1) = "<"

go:: String -> String -> Int

go [] [] = 0
go (ca:xa) [] = if ca /= '0' then
                        1
                    else
                        go xa []
go [] (cb:xb) = if cb /= '0' then
                        -1
                    else
                        go [] xb

go (ca:xa) (cb:xb) =
    if next == 0 then
        if ca == cb then
            next
        else if ca > cb then
            1
        else
            -1
    else
        next

    where
        next = go xa xb

module Main where

import Data.List
import Data.String
import Data.Maybe
import Data.Either
import Control.Monad
import Control.Applicative
import Control.Arrow

foo :: String -> String -> Bool -> String
foo "" "" _ = "="
foo ('0':xs) ys True = foo xs ys True
foo xs ('0':ys) True = foo xs ys True
foo _ "" _ = ">"
foo "" _ _ = "<"
foo a@(x:xs) b@(y:ys) f = if f && length a /= length b
                          then if length a > length b then ">" else "<"
                          else if x == y
                               then foo xs ys False
                               else if x < y then "<" else ">"

main :: IO()
main = do
    s1 <- getLine
    s2 <- getLine
    putStrLn $ foo s1 s2 True

import Data.Char

solve :: [String] -> String

solve xs
    | a > b = ">"
    | a < b = "<"
    | otherwise = "="
    where a = read (head xs) :: Integer
          b = read (last xs) :: Integer

main = interact $ solve . words

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

cmp :: B.ByteString -> B.ByteString -> String
cmp str1 str2 = case compare (B.length str1') (B.length str2') of
                  LT -> "<"
                  GT -> ">"
                  EQ -> case compare str1' str2' of
                          LT -> "<"
                          GT -> ">"
                          EQ -> "="
  where [str1', str2'] = map (B.dropWhile (== '0')) [str1, str2]

main :: IO ()
main = cmp <$> B.getLine <*> B.getLine >>= putStrLn

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

main = do
	[a,b] <- replicateM 2 $ fmap (fst . fromJust . B.readInteger) B.getLine
	putStrLn $ case (compare a b) of
		EQ -> "="
		LT -> "<"
		GT -> ">"

import Control.Applicative
import qualified Data.ByteString as BS

main :: IO ()
main = do
  a <- (BS.dropWhile (== 48)) <$> BS.getLine
  b <- (BS.dropWhile (== 48)) <$> BS.getLine

  putStrLn $ case (compare (BS.length a) (BS.length b), compare a b) of
    (LT, _) -> "<"
    (GT, _) -> ">"
    (_, LT) -> "<"
    (_, GT) -> ">"
    _       -> "="

import Control.Applicative

main :: IO ()
main = do
  a <- (dropWhile (== '0')) <$> getLine
  b <- (dropWhile (== '0')) <$> getLine

  putStrLn $ case (compare (length a) (length b), compare a b) of
    (LT, _) -> "<"
    (GT, _) -> ">"
    (_, LT) -> "<"
    (_, GT) -> ">"
    _       -> "="

check :: String -> String -> String
check a b
  | la < lb = "<"
  | la > lb = ">"
  | otherwise = cmpr ca cb
  where
    ca' = dropWhile (=='0') a
    cb' = dropWhile (=='0') b
    ca = if ca' == [] then "0" else ca'
    cb = if cb' == [] then "0" else cb'
    la = length ca
    lb = length cb
    cmpr [] [] = "="
    cmpr (x:xs) (y:ys)
      | x < y = "<"
      | x > y = ">"
      | otherwise = cmpr xs ys

main :: IO ()
main = do
  a <- getLine
  b <- getLine
  putStrLn $ check a b

import Control.Applicative ((<$>))
import Data.ByteString.Char8 (readInt, words, unpack, getLine)
import Data.Maybe (fromJust)
import Prelude hiding (words, getLine)

readInts = map (fst . fromJust . readInt) . words

main = do
  a <- fst . fromJust . readInt <$> getLine
  b <- fst . fromJust . readInt <$> getLine

  putStrLn $ case compare a b of
             LT -> "<"
             EQ -> "="
             GT -> ">"

import Data.List
import Data.Int
import qualified Data.Array as A
import Data.Array((!))
import Numeric

fastRead :: String -> Int64
fastRead ('-':s) = case readDec s of [(n, "")] -> (-n)
fastRead s = case readDec s of [(n, "")] -> n

main = interact solve

solve input = answer
    where
        (aw:bw:xs) = words input
        raw = reverse aw
        rbw = reverse bw

        go:: String -> String -> Int
        go [] [] = 0
        go (ca:xa) [] = if ca /= '0' then
                                1
                            else
                                go xa []
        go [] (cb:xb) = if cb /= '0' then
                                -1
                            else
                                go [] xb

        go (ca:xa) (cb:xb) =
            if ca == cb then
                go xa xb
            else if ca > cb then
                1
            else
                -1

        answer = case (go raw rbw)
                    of 0 -> "="
                       1 -> ">"
                       -1 -> "<"


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

-- myShow = show :: Int -> String
main = do
  _ <- C.getLine
  xs <- C.getLine
  print $ solve xs

solve :: C.ByteString -> Integer
solve = product . map ((\(Just x) -> fst x) . C.readInteger) . C.words

main = interact $  solve "" "1" . tail .  words
solve zero fail [] = fail ++ zero
solve _ "0" _ = "0"
solve zero fail ((h:t):xs) = if h == '1' && all (== '0') t then solve (t ++ zero) fail xs else solve zero (h:t) xs

module Main where

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

main :: IO ()
main = do
    _ <- C.getLine
    xs <- map ((\(Just x) -> fst x) . C.readInteger) . C.words <$> C.getLine
    putStrLn $ show $ product xs

import Data.Functor
import Data.List

getStrings :: IO [String]
getStrings = tail . words <$> getContents

isBeautiful :: String -> Bool
isBeautiful (c:cs) = c == '1' && and [x == '0' | x <- cs]

solve :: [String] -> String
solve ss = if any (== "0") ss then "0" else r
  where
    start = case find (not . isBeautiful) ss of
        Just s -> s
        Nothing -> "1"
    end = replicate (sum [length s - 1 | s <- filter isBeautiful ss]) '0'
    r = start ++ end

main :: IO ()
main = getStrings >>= putStrLn . solve

import qualified Data.ByteString.Char8 as B
import Data.Maybe

main = B.getLine >> (B.putStr . B.pack .show . product . map (fst. fromJust . B.readInteger) . B.words =<< B.getLine)

main = interact $  solve "" "" . tail .  words
solve zero fail [] =  fail ++ zero
solve _ "0" _ = "0"
solve zero fail ((h:t):xs) = if h == '1' && all (== '0') t then solve (t ++ zero) fail xs else solve zero (h:t) xs

import Data.Functor
import Data.List

getStrings :: IO [String]
getStrings = tail . words <$> getContents

isBeautiful :: String -> Bool
isBeautiful (c:cs) = c == '1' && and [x == '0' | x <- cs]

solve :: [String] -> String
solve ss = start ++ end
  where
    start = case find (not . isBeautiful) ss of
        Just s -> s
        Nothing -> "1"
    end = replicate (sum [length s - 1 | s <- filter isBeautiful ss]) '0'

main :: IO ()
main = getStrings >>= putStrLn . solve

import Data.Functor

getInts :: IO [Integer]
getInts = map read . words . tail <$> getContents

main :: IO ()
main = getInts >>= putStrLn . show . product

import Data.Functor
import Data.List

getStrings :: IO [String]
getStrings = tail . words <$> getContents

isBeautiful :: String -> Bool
isBeautiful (c:cs) = c == '1' && and [x == '0' | x <- cs]

solve :: [String] -> String
solve ss = if head r == '0' then "0" else r
  where
    start = case find (not . isBeautiful) ss of
        Just s -> s
        Nothing -> "1"
    end = replicate (sum [length s - 1 | s <- filter isBeautiful ss]) '0'
    r = start ++ end

main :: IO ()
main = getStrings >>= putStrLn . solve

module Main where

import Control.Applicative

main :: IO ()
main = do
    _ <- getLine
    xs <- (map (\s -> read s::Int) . words) <$> getLine
    putStrLn $ show $ foldr (\x acc -> acc * x) 1 xs

module Main where

import Control.Applicative

main :: IO ()
main = do
    _ <- getLine
    xs <- (map (\s -> read s::Int) . words) <$> getLine
    -- putStrLn $ show $ foldr (\x acc -> acc * x) 1 xs
    putStrLn $ show $ product 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 = do
  [n,m] <- map read.words <$> getLine
  arr <- listArray(0,n-1).map readInt.B.words <$> B.getLine
  abcs <- map readInt.B.words <$> B.getContents
  print $ solve arr abcs

solve :: UArray Int Int -> [Int] -> Double
solve arr abcs = go 0.0 abcs
   where
     go !acc (a:b:c:abcs) = go (max acc $ v / e) abcs
      where
       v = fromIntegral . sum $ map (unsafeAt arr.subtract 1) [a,b]
       e = fromIntegral c
     go acc _ = acc

{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}

import Data.List (foldl')
import Control.Applicative ((<$>))
import Data.Array (Array, listArray, (!))
import Control.Monad (replicateM, sequence)
import Data.ByteString (ByteString)
import qualified Data.ByteString as ByteString
import qualified Data.ByteString.Char8 as Char8

-- parse :: Read a => String -> [a]
-- parse = map read . words

getLine' :: IO ByteString
getLine' = ByteString.getLine

parse :: ByteString -> [Int]
parse line =
    case out of Just xs -> xs
                Nothing -> []
    where
    out = sequence . map read' . Char8.words $ line :: Maybe [Int]
    read' :: ByteString -> Maybe Int
    read' = (fst <$>) . Char8.readInt

solve :: Array Int Int -> [[Int]] -> Double
solve a = foldl' max 0 . map den
    where
    den :: [Int] -> Double
    den [i, j, w] = fromIntegral (a ! i + a ! j) / fromIntegral w
    den _ = error "fail!"

main :: IO ()
main = do
    [n, m] <- map read . words <$> getLine
    a <- listArray (1, n) . parse <$> getLine'
    e <- map parse <$> replicateM m getLine'
    print $ solve a e