{-# LANGUAGE BangPatterns #-}

import System.IO
import Data.List

main :: IO ()
main = do
  (n:k:_) <- readLineNum
  as <- readLineNum
  bs <- readLineNum
  let ttt = (sortBy compare' $ zipWith (\a b -> (a, b, a-b)) as bs)
  print $ summer k ttt 0
    where
      readLineNum :: IO [Int]
      readLineNum = getLine >>= return . words >>= return . map (read :: String -> Int)

      compare' (_, _, t1) (_, _, t2) = t1 `compare` t2

      summer :: Int -> [(Int, Int, Int)] -> Int -> Int
      summer _ [] !acc = acc
      summer !i !((a, b, c):es) !acc = summer (i-1) es (if i>0 then (acc+a) else (acc+(if a<=b then a else b)))

{-# LANGUAGE BangPatterns #-}

import System.IO
import Data.List

main :: IO ()
main = do
  (n:k:_) <- readLineNum
  as <- readLineNum
  bs <- readLineNum
  let ttt = (sortBy compare' $ zipWith (\a b -> (a, b, a-b)) as bs)
  print $ summer k ttt 0
    where
      readLineNum :: IO [Int]
      readLineNum = getLine >>= return . words >>= return . map (read :: String -> Int)

      compare' (_, _, t1) (_, _, t2) = t1 `compare` t2

      summer :: Int -> [(Int, Int, Int)] -> Int -> Int
      summer _ [] !acc = acc
      summer !i !((a, b, c):es) acc = summer (i-1) es (if i>0 then (acc+a) else (acc+(if a<=b then a else b)))

{-# LANGUAGE BangPatterns #-}

import System.IO
import Data.List

main :: IO ()
main = do
  (n:k:_) <- readLineNum
  (as:bs:_) <- getContents >>= return . lines >>= return . (map (map read . words))
  let ttt = (sortBy compare' $ zipWith (\a b -> (a, b, a-b)) as bs)
  print $ summer k ttt 0
    where
      readLineNum :: IO [Int]
      readLineNum = getLine >>= return . words >>= return . map (read :: String -> Int)

      compare' (!_, !_, !t1) (!_, !_, !t2) = t1 `compare` t2

      summer :: Int -> [(Int, Int, Int)] -> Int -> Int
      summer !_ [] !acc = acc
      summer !i !((a, b, c):es) !acc = summer (i-1) es (if i>0 then (acc+a) else (acc+(if a<=b then a else b)))

{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Safe              #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.State.Strict
import           Data.Array.Unboxed
import           Data.Bits
import           Data.Bool
import qualified Data.ByteString.Char8      as B
import           Data.Char
import           Data.Function
import           Data.Int
import qualified Data.IntMap.Strict         as IM
import qualified Data.IntSet                as IS
import           Data.List
import           Data.List.Split
import qualified Data.Map.Strict            as M
import           Data.Monoid
import           Data.Ord
import qualified Data.Set                   as S
import           Data.Tuple
import           Data.Word

readInt :: B.ByteString -> Int
readInt bs=case B.readInt bs of{Just(n,_)->n;_->error$"readInt error : bs = "++show bs;}
readInteger :: B.ByteString -> Integer
readInteger bs=case B.readInteger bs of{Just(n,_)->n;_->error$"readInteger error : bs = "++show bs;}

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

solve :: Int -> [Int] -> [Int] -> Int64
solve k xs ys = sum[fromIntegral x | (d,x)<-zs0++zs2] + sum[fromIntegral $ x +d| (d,x)<-zs3]
  where
    diffs = reverse.sort $ zipWith(\x y->(y-x,x)) xs ys
    (zs0, zs1) = splitAt k diffs
    (zs2, zs3) = span ((>0).fst) zs1

import Data.List
import Data.Maybe ( fromJust )
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8

fast_read_Int = fmap (map (fst . fromJust . BS8.readInt) . BS8.words) BS.getLine :: IO [Int]

main = do
    [n,k] <- fast_read_Int
    a <- fast_read_Int
    b <- fast_read_Int
    let bf =  sortBy (\(a, b) (a', b') -> compare (a - b) (a' - b'))  $ zip a b
    let pozzitive = takeWhile (\(a, b) -> a < b) bf
    --print pozzitive
    let cate = max k $ length pozzitive
    let sum1 = sum $ map fst $ take cate bf
    let sum2 = sum $ map snd $ take (n-cate) $ reverse bf
    print $ sum1 + sum2

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

main = do
  [n, k] <- fmap readInts B.getLine
  as <- fmap readInts B.getLine
  bs <- fmap readInts B.getLine
  print $ solve n k as bs

solve n k as bs = (\(f, s) -> sum (map fst f) + sum (map (uncurry min) s)) $ splitAt k $ sortBy (comparing (uncurry (-))) $ zip as bs

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

import System.IO
import Data.List

main :: IO ()
main = do
  (n:k:_) <- readLineNum
  as <- readLineNum
  bs <- readLineNum
  let ttt = (sort $ zipWith (\a b -> (a, b, a-b)) as bs)
  print $ summer k ttt 0
    where
      readLineNum :: IO [Int]
      readLineNum = getLine >>= return . words >>= return . map (read :: String -> Int)

      sort :: [(Int, Int, Int)] -> [(Int, Int, Int)]
      sort [] = []
      sort ((t@(ta, tb, tc)):remain) = former ++ [t] ++ latter
        where
          former = [tmp | tmp@(tmpa, tmpb, tmpc) <- remain, tmpc <= tc]
          latter = [tmp | tmp@(tmpa, tmpb, tmpc) <- remain, tmpc > tc]

      summer :: Int -> [(Int, Int, Int)] -> Int -> Int
      summer _ [] acc = acc
      summer i ((a, b, c):es) acc = summer (i-1) es (if i>0 then (acc+a) else (acc+(if a<b then a else b)))

{-# LANGUAGE BangPatterns #-}

import System.IO
import Data.List

main :: IO ()
main = do
  (n:k:_) <- readLineNum
  as <- readLineNum
  bs <- readLineNum
  let ttt = (sort $ zipWith (\a b -> (a, b, a-b)) as bs)
  print $ summer k ttt 0
    where
      readLineNum :: IO [Int]
      readLineNum = getLine >>= return . words >>= return . map (read :: String -> Int)

      sort :: [(Int, Int, Int)] -> [(Int, Int, Int)]
      sort [] = []
      sort (t@(ta, tb, tc):remain) = former ++ [t] ++ latter
        where
          former = [tmp | tmp@(tmpa, tmpb, tmpc) <- remain, tmpc <= tc]
          latter = [tmp | tmp@(tmpa, tmpb, tmpc) <- remain, tmpc > tc]

      summer :: Int -> [(Int, Int, Int)] -> Int -> Int
      summer _ [] acc = acc
      summer i ((a, b, c):es) acc = summer (i-1) es (if i>0 then (acc+a) else (acc+(if a<=b then a else b)))

import Data.List
import Data.Maybe ( fromJust )
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8

fast_read_Int = fmap (map (fst . fromJust . BS8.readInt) . BS8.words) BS.getLine :: IO [Int]

main = do
    [n,k] <- fast_read_Int
    a <- fast_read_Int
    b <- fast_read_Int
    let bf =  sortBy (\(a, b) (a', b') -> compare (a - b) (a' - b'))  $ zip a b
    let pozzitive = takeWhile (\(a, b) -> a < b) bf
    --print pozzitive
    let cate = max k $ length pozzitive
    print cate
    print bf
    let sum1 = sum $ map fst $ take cate bf
    let sum2 = sum $ map snd $ take (n-cate) $ reverse bf
    print $ sum1 + sum2

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

main = do
  [n, k] <- fmap readInts B.getLine
  as <- fmap readInts B.getLine
  bs <- fmap readInts B.getLine
  print $ solve n k as bs

solve n k as bs = sum $ zipWith min as bs

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


{-# 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, m] <- getInts
  xs <- replicateM n (tail <$> getInts)

  let r = [1..m] == (map head $ group $ sort $ concat xs)

  putStrLn $ if r then "YES" else "NO"

module Main where

import Control.Monad
import Data.List

sortUnique :: (Ord a) => [a] -> [a]
sortUnique = map head . group . sort

solve :: Int -> [[Int]] -> Bool
solve n lss = ls == [1 .. n]
    where ls = sortUnique $ concat lss

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

main :: IO ()
main = do
  [n, m] <- readInts
  lss <- replicateM n $ liftM tail readInts
  putStrLn $ if solve m lss then "YES" else "NO"

import Data.List

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

transform :: [Int] -> [Int]
transform [] = []
transform (x:s) = let (ys, zs) = splitAt x s in ys ++ transform zs

solve :: [Int] -> Bool
solve (_:m:x) = length (nub $ transform x) == m

output :: Bool -> IO()
output b = putStrLn $ if b then "YES" else "NO"

{-# LANGUAGE TupleSections, MultiParamTypeClasses, ExistentialQuantification,
             RankNTypes, FlexibleContexts, DeriveFunctor #-}

import Control.Monad
import Control.Applicative
--import Control.Lens
--import Control.Zipper
import Control.Arrow
import qualified Data.Map as M
--import qualified Data.Vector as V
import qualified Data.Set as S
import Data.List
--import Debug.Trace
--import Control.Comonad
import Data.Monoid
--import Data.Functor.Foldable
--import Test.QuickCheck
import Data.Tree
--import Data.Machine
--import Data.Traversable
--import Data.Distributive
--import Linear
import Control.Monad.Cont

main = do
  [n, m] <- fmap (map read . words) getLine
  inp <- forM [1..n] $ \_ -> do
         (_:m) <- fmap (map read . words) getLine
         return m
  putStrLn $ solve inp m

solve :: [[Int]] -> Int -> String
solve inp n | (length . nub) (concat inp) == n = "YES"
            | otherwise = "NO"

import Data.List
import Data.Tree
import Data.Int
import Data.Maybe
import Data.Char
import Data.Functor
import Data.Function
import Data.Ord
import Data.Bits
import Data.Monoid
import Control.Monad
import Control.Monad.ST.Safe
import Control.Arrow
import Data.Array
import Data.Array.ST.Safe
import Data.Array.Unboxed as UA
import Data.STRef
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.ByteString.Char8 as C
main= someFunc
rIn x= fst $ fromJust  $ C.readInt x
someFunc::IO()
someFunc = C.getLine >>= \ns -> let [n,m] = map rIn $ C.words ns in (solve.((:) m).concat=<<forM [1..n] (\i->tail.map rIn.C.words <$>C.getLine) )
solve (x:xs)= let xs1=nub xs;l=length xs1 in if l==x then putStr "YES" else putStr "NO"

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

main::IO ()
main=do
   [n,m]<- map read <$> words <$> getLine ::IO [Int]
   x <- map head <$> group <$> sort <$> concatMap (map (fromIntegral.fst.fromJust.C.readInteger)) <$>map tail <$>   map  C.words <$> C.lines <$> C.getContents::IO [Int]
   putStrLn $ if x==[1..m] then "YES" else "NO"

import Data.List (nub)
main = do
  [_,m] <- fmap (map read . words) getLine
  bs <- fmap (nub . concat . map (tail . words) . lines) getContents
  putStrLn $ if length bs == m then "YES" else "NO"

import Data.Map as M
import Prelude as P
import Control.Monad

parse f str = P.map read (f $ words str) :: [Int]
fillMap b bu inputs = P.foldl (\ mmap x -> M.insert x True mmap)(newMap) inputs
						where newMap = M.fromList $ zip [1..bu] (repeat False)

main = do
	num <- getLine
	let (b : bu : []) = parse id num
	inputs <- replicateM b getLine
	let ans = M.foldr (\ a b -> a && b) True (fillMap b bu (concat $ P.map (parse tail) inputs))
	if ans == True then putStrLn "YES" else putStrLn "NO"

import Control.Applicative
import Data.List
import qualified Data.Set as S

main= do
	[n,m]<- map read.words  <$> getLine ::IO [Int]
	s<- concat.map tail. map (map read). map words . lines <$> getContents::IO [Int]
	let t=   S.toList $ foldr (S.insert) S.empty s
	putStrLn $ if length t ==m then "YES" else "NO"

import Data.List (nub, union)

process :: Int -> [[Int]] -> Bool
process m xss = (==) m $ length $ foldl union (nub (head xss)) (tail xss)

readInt :: String -> Int
readInt = read

showPair :: (Int, Int) -> String
showPair (x,y) = show x ++ " " ++ show y

main :: IO ()
main = do
    [n,m] <- fmap (map readInt.words) getLine
    ts <- fmap (map (map readInt.words).lines) getContents
    if process m $ map tail ts
        then putStrLn "YES"
        else putStrLn "NO"

module Main where

import Control.Monad
import Data.List

sortUnique :: (Ord a) => [a] -> [a]
sortUnique = map head . group . sort

solve :: Int -> [[Int]] -> Bool
solve n lss = ls == [1 .. n]
    where ls = sortUnique $ concat lss

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

main :: IO ()
main = do
  [n, m] <- readInts
  lss <- replicateM n readInts
  putStrLn $ if solve m lss then "YES" else "NO"

import Data.List
import Data.Tree
import Data.Int
import Data.Maybe
import Data.Char
import Data.Functor
import Data.Function
import Data.Ord
import Data.Bits
import Data.Monoid
import Control.Monad
import Control.Monad.ST.Safe
import Control.Arrow
import Data.Array
import Data.Array.ST.Safe
import Data.Array.Unboxed as UA
import Data.STRef
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.ByteString.Char8 as C
main= someFunc
rIn x= fst $ fromJust  $ C.readInt x
someFunc::IO()
someFunc = C.getLine >>= \ns -> let n = rIn $ head $ C.words ns in (solve.((:) n).concat=<<forM [1..n] (\i->tail.map rIn.C.words <$>C.getLine) )
solve (x:xs)= let xs1=nub xs;l=length xs1 in if l==x then putStr "YES" else putStr "NO"

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

main::IO ()
main=do
   [n,m]<- map read <$> words <$> getLine ::IO [Int]
   x <- map head <$> group <$> sort <$> concatMap (map (fromIntegral.fst.fromJust.C.readInteger)) <$> map C.words <$> C.lines <$> C.getContents::IO [Int]
   putStrLn $ if x==[1..m] then "YES" else "NO"

import Data.Map as M
import Prelude as P
import Control.Monad

parse str = P.map read $ words str :: [Int]
fillMap b bu inputs = P.foldl (\ mmap x -> M.insert x True mmap)(newMap) inputs
						where newMap = M.fromList $ zip [1..bu] (repeat False)

main = do
	num <- getLine
	let (b : bu : []) = parse num
	inputs <- replicateM b getLine
	print $ M.foldr (\ a b -> a && b) True (fillMap b bu (concat $ P.map parse inputs))

import Data.Map as M
import Prelude as P
import Control.Monad

parse str = P.map read $ words str :: [Int]
fillMap b bu inputs = P.foldl (\ mmap x -> M.insert x True mmap)(newMap) inputs
						where newMap = M.fromList $ zip [1..bu] (repeat False)

main = do
	num <- getLine
	let (b : bu : []) = parse num
	inputs <- replicateM b getLine
	let ans = M.foldr (\ a b -> a && b) True (fillMap b bu (concat $ P.map parse inputs))
	if ans == True then print "YES" else print "NO"

import Data.Map as M
import Prelude as P
import Control.Monad

parse str = P.map read $ words str :: [Int]
fillMap b bu inputs = P.foldl (\ mmap x -> M.insert x True mmap)(newMap) inputs
						where newMap = M.fromList $ zip [1..bu] (repeat False)

main = do
	num <- getLine
	let (b : bu : []) = parse num
	inputs <- replicateM b getLine
	let ans = M.foldr (\ a b -> a && b) True (fillMap b bu (concat $ P.map parse inputs))
	if ans == True then putStrLn "YES" else putStrLn "NO"


{-# LANGUAGE LambdaCase #-}

import Data.Bits(Bits, (.&.))

main :: IO ()
main = interact $ format . solve . parse

parse :: String -> [Integer]
parse input = case lines input of
    [] -> undefined
    (w:ws) -> readN (read w) ws
    where
        readN :: Integer -> [String] -> [Integer]
        readN 0 _ = []
        readN n (w:ws) = read w : readN (n-1) ws
        readN _ _ = undefined

format :: [Bool] -> String
format = unlines . map (\case
        True -> "YES"
        False -> "NO"
    )

solve :: [Integer] -> [Bool]
solve = map (not . isPower2)

isPower2 :: (Bits i, Integral i) => i -> Bool
isPower2 n = n /= 1 && n .&. (n-1) == 0

{-# LANGUAGE LambdaCase #-}

import Data.Bits(Bits, (.&.))
import Data.Int(Int64)

main :: IO ()
main = interact $ format . solve . parse

parse :: String -> [Int64]
parse input = case lines input of
    [] -> undefined
    (w:ws) -> readN (read w) ws
    where
        readN :: Int64 -> [String] -> [Int64]
        readN 0 _ = []
        readN n (w:ws) = read w : readN (n-1) ws
        readN _ _ = undefined

format :: [Bool] -> String
format = unlines . map (\case
        True -> "YES"
        False -> "NO"
    )

solve :: [Int64] -> [Bool]
solve = map (not . isPower2)

isPower2 :: (Bits i, Integral i) => i -> Bool
isPower2 n = n /= 1 && n .&. (n-1) == 0

{-main :: IO()
main = do
       putStrLn "Ingrese una Lista : ";
       xs <- readLn;
       print (todosPares xs)

--Import Data.Char

--main = do
--    contents <- getContents
--    putStr (map toUpper contents)

leerLista :: [Double] ->[String]
leerLista [] = []
leerLista (x:xs) = poTenciaDEDos x : leerLista xs

poTenciaDEDos :: Double -> [Char]
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

todosPares :: [Int] ->Bool
todosPares [] = True
todosPares (x:xs) = even x && todosPares xs-}

{-# LANGUAGE LambdaCase #-}

import Data.Bits(Bits, (.&.))
import Data.Int(Int64)

main :: IO ()
main = interact $ format . solve . parse

parse :: String -> [Int64]
parse input = case lines input of
    [] -> undefined
    (w:ws) -> readN (read w) ws
    where
        readN :: Int -> [String] -> [Int64]
        readN 0 _ = []
        readN n (w:ws) = read w : readN (n-1) ws
        readN _ _ = undefined

format :: [Bool] -> String
format = unlines . map (\case
        True -> "YES"
        False -> "NO"
    )

solve :: [Int64] -> [Bool]
solve = map (not . isPower2)

isPower2 :: (Bits i, Integral i) => i -> Bool
isPower2 n = n /= 1 && n .&. (n-1) == 0

module Main where

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

getStrList :: IO [String]
getStrList = words <$> getLine

getIntList :: IO [Int]
getIntList = map read <$> getStrList

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . list2Str

list2Str :: (Show a) => [a] -> String
list2Str = concat . intersperse " " . fmap show

yesOrNo :: Bool -> String
yesOrNo True = "YES"
yesOrNo False = "NO"

tCase :: IO () -> IO ()
tCase x = do
    t <- readLn
    replicateM_ t $ x

main :: IO ()
main = tCase process

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

process :: IO ()
process = do
    x <- readLn :: IO Integer
    putStrLn $ yesOrNo . (>1) $ head . filter odd $ iterate (`div` 2) $ x

{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE ScopedTypeVariables #-}

import Data.Array
import Data.Char
import Data.List
import Data.Int
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe
import Control.Applicative
import System.IO
import Data.Bits

-- import qualified Data.Set as Set

readInt :: String -> Int
readInt = read

printArr :: (Show a) => String -> [a] -> IO ()
printArr sep arr = do
    putStrLn . intercalate sep $ (show <$> arr)

print2DArr :: (Show a) => String -> [[a]] -> IO ()
print2DArr sep arr = sequence_ (printArr sep <$> arr)

every n xs = case drop (n-1) xs of
            (y:ys) -> y : every n ys
            [] -> []

yon True = "YES"
yon False = "NO"

main = do
    -- input <- openFile "in" ReadMode
    let input = stdin
    hSetBuffering input (BlockBuffering (Just 4096))
    hSetBuffering stdout (BlockBuffering (Just 4096))
    contents <- hGetContents input
    -- printArr (readIntArr $ head q) " "
    solve contents

solve inp = sequence do
    x :: Int64 <- read <$> tail (lines inp)
    let x' = 1 `shift` countTrailingZeros x
    [putStrLn $ yon (x /= x')]

import Control.Monad
import Data.Bits

oddDivisor :: Integer -> Bool
oddDivisor n = ((.&.) n $ n-1) /= 0

main :: IO()
main = do
  t <- readLn :: IO Integer
  forM_ [1..t] $ \x -> do
    n <- readLn :: IO Integer
    if oddDivisor n then
      putStrLn "YES"
    else putStrLn "NO"

import Data.Bits

solve :: String -> String
solve s = if popCount n == 1 then "NO" else "YES"
  where n = read s :: Integer

process :: [String] -> String
process (_ : inp) = unlines $ map solve inp

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

module Main where

import Data.Bool ( bool )

haveOddDivisor :: Int -> String
haveOddDivisor number = bool "NO" "YES" isAnyOdd
  where
    isAnyOdd = any odd $ takeWhile ((/=) 1) $ iterate (`div` 2) number

solve :: Int -> IO ()
solve 0    = return ()
solve test = do
  number <- getLine
  putStrLn $ haveOddDivisor (read number)
  solve (test - 1)

main :: IO ()
main = do
  tests <- getLine
  solve (read tests)

import Control.Monad
import Data.Bool

check 1 = False
check 2 = False
check n
  | odd n = True
  | even n = check (n `div` 2)

main = do
  n <- read <$> getLine
  replicateM_ n $ do
    i <- read <$> getLine
    putStrLn $ bool "NO" "YES" $ check i

import Data.List
import System.IO
import Control.Monad
convert :: Read a => String -> [a]
convert = map read . words

solve::Integer->Integer
solve n = if n`rem`2 == 0 then solve (n`div`2) else n

printSolve:: Integer -> IO()
printSolve n = if (n`rem`2>0) then putStrLn "YES" else printSolve2 n

printSolve2:: Integer->IO()
printSolve2 n = if (solve n == 1) then putStrLn "NO" else putStrLn "YES"

loop :: Integer -> IO ()
loop 0 = putStr ""
loop t = do{
    nn <- getLine;
    printSolve (read nn);
    loop(t-1);
}

main = do
    line <- getLine
    let t = read line :: Integer
    loop t

import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Set as S

import qualified Data.Array as A

import qualified Control.Monad.State.Strict as State
import Control.Monad.ST

import Data.Bits(xor, (.&.), (.|.))

import Data.Array((!))
import Control.Monad(replicateM)
import Data.Maybe

solve n
	| n == 1 = False
	| n > 1 && mod n 2 /= 0 = True
	| n > 1 && mod n 2 == 0 = solve $ div n 2

plotResult True = putStrLn "YES"
plotResult False = putStrLn "NO"

main = do
	t <- getLine >>= return . read :: IO Integer
	replicateM (fromInteger t) $ do
		[n] <- getLine >>= return . (fmap read) . words :: IO [Integer]
		plotResult $ solve n

main = interact $ unlines . map (solve . read) . tail . lines

solve n
    | any odd . takeWhile (>1) $ iterate (`div` 2) n = "YES"
	| otherwise = "NO"

-- Trying to use only ByteString I/O with a state monad this contest

import Control.Monad
import Control.Monad.Trans.State.Lazy
import qualified Data.ByteString.Lazy.Char8 as P

import Data.Bits

getSLine :: Monad m => StateT P.ByteString m P.ByteString
getSLine = do
  (out, next) <- P.break (== '\n') <$> get
  put $ P.tail next
  pure out

readInts :: Monad m => StateT P.ByteString m [Int]
readInts = do
  currLine <- getSLine
  pure [x | Just (x, _) <- P.readInt <$> P.words currLine]

readIntegers :: Monad m => StateT P.ByteString m [Integer]
readIntegers = do
  currLine <- getSLine
  pure [x | Just (x, _) <- P.readInteger <$> P.words currLine]

outLine :: P.ByteString -> StateT P.ByteString IO ()
outLine v = StateT $ \s -> ((), s) <$ P.putStrLn v

main :: IO ()
main = (P.getContents >>=) $ evalStateT $ do
  [t] <- readInts
  replicateM_ t $ do
    [n] <- readIntegers
    outLine . P.pack $ if  popCount n > 1
      then  "YES"
      else  "NO"

import Data.Char

main = do
       contents <- getContents
       putStr (map toUpper contents)

leerLista :: [Double] -> [[Char]]
leerLista [] = []
leerLista (x:xs) = poTenciaDEDos x : leerLista xs

poTenciaDEDos :: Double -> [Char]
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

import Data.Char

main = do
       contents <- getContents
       putStr (map toUpper contents)

leerLista :: [Double] -> [[Char]]
leerLista [] = []
leerLista (x:xs) = poTenciaDEDos x : leerLista xs

poTenciaDEDos :: Double -> [Char]
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "YES"
escribeBool False = "NO"

log_2 :: Double -> Double
log_2 n = log n/log 2

import Data.Char

main = do
  lineas <- getContents
  let (n:resto) = lines lineas
      datos = take (read n) resto
  mapM_ putStrLn $ leerLista (map read resto)

leerLista :: [Double] -> [String]
leerLista [] = []
leerLista (x:xs) = poTenciaDEDos x : leerLista xs

poTenciaDEDos :: Double -> String
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

-- ejemplos de prueba
--2
--3 jdjdjdjdjdjjdjdjdjdjdjdjdjddj
--4 jdjdjdjdjdjdjjdjdjdjdjdjdjdjjdj
--5
--998244353
--1099511627776

import Data.Char

main = do
  lineas <- getContents
  let (n:resto) = lines lineas
      datos = resto          --take (read n) resto
  mapM_ putStrLn $ leerLista (map read resto)

leerLista :: [Double] -> [String]
leerLista [] = []
leerLista (x:xs) = poTenciaDEDos x : leerLista xs

poTenciaDEDos :: Double -> String
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

-- ejemplos de prueba
--2
--3 jdjdjdjdjdjjdjdjdjdjdjdjdjddj
--4 jdjdjdjdjdjdjjdjdjdjdjdjdjdjjdj
--5
--998244353
--1099511627776

import Data.Char

main = do
    leerLista <- getContents
    putStr (map toUpper leerLista)

leerLista :: [Double] ->[String]
leerLista [] = []
leerLista (x:xs) = poTenciaDEDos x : leerLista xs

poTenciaDEDos :: Double -> [Char]
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

-- ejemplos de prueba
--2
--3 jdjdjdjdjdjjdjdjdjdjdjdjdjddj
--4 jdjdjdjdjdjdjjdjdjdjdjdjdjdjjdj
--5
--998244353
--1099511627776

import Data.Char

main = do
    leerLista <- getContents
    putStr (map toUpper leerLista)

leerLista :: [Double] ->[String]
leerLista [] = []
leerLista (x:xs) = poTenciaDEDos x : leerLista xs

poTenciaDEDos :: Double -> [Char]
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

-- ejemplos de prueba
--2
--3
--4
--5
--998244353
--1099511627776

main = do putStrLn "is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

poTenciaDEDos :: Double -> String
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

-- ejemplos de prueba
--2
--3
--4
--5
--998244353
--1099511627776

poTenciaDEDos :: Double -> String
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

main = do putStrLn "is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

-- ejemplos de prueba
--2
--3
--4
--5
--998244353
--1099511627776

module Main where
poTenciaDEDos :: Double -> String
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

log_2 :: Double -> Double
log_2 n = log n/log 2

escribeBool True = "NO"
escribeBool False = "YES"

main = do putStrLn "is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

-- ejemplos de prueba
--2
--3
--4
--5
--998244353
--1099511627776

module Main where

log_2 :: Double -> Double
log_2 n = log n/log 2

poTenciaDEDos :: Double -> String
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "NO"
escribeBool False = "YES"

main = do putStrLn "is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

-- ejemplos de prueba
--2
--3
--4
--5
--998244353
--1099511627776

main :: IO ()
main = do putStrLn "is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

poTenciaDEDos :: Double -> String
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

--main = do putStrLn "is Odd! ?"
--          x <- readLn
--          print (poTenciaDEDos x)

-- ejemplos de prueba
--2
--3
--4
--5
--998244353
--1099511627776

module Main where

main = do putStrLn "is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

poTenciaDEDos :: Double -> String
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

-- ejemplos de prueba
--2
--3
--4
--5
--998244353
--1099511627776

module Main where

escribeBool True = "YES"
escribeBool False = "NO"

log_2 :: Double -> Double
log_2 n = log n/log 2

poTenciaDEDos :: Double -> String
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

main = do putStrLn "is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

-- ejemplos de prueba
--2
--3
--4
--5
--998244353
--1099511627776

module Main where

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

poTenciaDEDos :: Double -> String
poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

main = do putStrLn "is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

module Main where

escribeBool True = "NO"
escribeBool False = "YES"

log_2 :: Double -> Double
log_2 n = log n/log 2

poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

main = do putStrLn "is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

module Main where

escribeBool True = "NO"
escribeBool False = "YES"

log_2 n = log n/log 2

poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

--main :: IO ()
--main = print (poTenciaDEDos n)

main = do putStrLn "is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

module Main where
escribeBool True = "No"
escribeBool False = "Yes"

log_2 n = log n/log 2

poTenciaDEDos n = escribeBool (floor (log_2 n) == ceiling (log_2 n))

--main :: IO ()
--main = print (poTenciaDEDos n)

main = do putStrLn "What is Odd! ?"
          x <- readLn
          print (poTenciaDEDos x)

module Main where

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

getStrList :: IO [String]
getStrList = words <$> getLine

getIntList :: IO [Int]
getIntList = map read <$> getStrList

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . list2Str

list2Str :: (Show a) => [a] -> String
list2Str = concat . intersperse " " . fmap show

yesOrNo :: Bool -> String
yesOrNo True = "YES"
yesOrNo False = "NO"

tCase :: IO () -> IO ()
tCase x = do
    t <- readLn
    replicateM_ t $ x

main :: IO ()
main = tCase process

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

process :: IO ()
process = do
    x <- readLn :: IO Integer
    putStrLn $ yesOrNo . odd $ x

{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE MultiWayIf #-}

import Data.Array
import Data.Char
import Data.List
import Data.Int
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe
import Control.Applicative
import System.IO
import Data.Bits

-- import qualified Data.Set as Set

readInt :: String -> Int
readInt = read

printArr :: (Show a) => String -> [a] -> IO ()
printArr sep arr = do
    putStrLn . intercalate sep $ (show <$> arr)

print2DArr :: (Show a) => String -> [[a]] -> IO ()
print2DArr sep arr = sequence_ (printArr sep <$> arr)

every n xs = case drop (n-1) xs of
            (y:ys) -> y : every n ys
            [] -> []

yon True = "YES"
yon False = "NO"

main = do
    -- input <- openFile "in" ReadMode
    let input = stdin
    hSetBuffering input (BlockBuffering (Just 4096))
    hSetBuffering stdout (BlockBuffering (Just 4096))
    contents <- hGetContents input
    -- printArr (readIntArr $ head q) " "
    solve contents

solve inp = sequence do
    x <- readInt <$> tail (lines inp)
    let x' = 1 `shift` countTrailingZeros x
    [putStrLn $ yon (x /= x')]

{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE MultiWayIf #-}

import Data.Array
import Data.Char
import Data.List
import Data.Int
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe
import Control.Applicative
import System.IO
import Data.Bits

-- import qualified Data.Set as Set

readInt :: String -> Int
readInt = read

printArr :: (Show a) => String -> [a] -> IO ()
printArr sep arr = do
    putStrLn . intercalate sep $ (show <$> arr)

print2DArr :: (Show a) => String -> [[a]] -> IO ()
print2DArr sep arr = sequence_ (printArr sep <$> arr)

every n xs = case drop (n-1) xs of
            (y:ys) -> y : every n ys
            [] -> []

yon True = "YES"
yon False = "NO"

main = do
    -- input <- openFile "in" ReadMode
    let input = stdin
    hSetBuffering input (BlockBuffering (Just 4096))
    hSetBuffering stdout (BlockBuffering (Just 4096))
    contents <- hGetContents input
    -- printArr (readIntArr $ head q) " "
    solve contents

solve inp = sequence do
    x <- readInt <$> tail (lines inp)
    let x' = 1 `shift` countTrailingZeros x
    [putStrLn $ yon (x == x')]

import Control.Monad
import Data.Bits

oddDivisor :: Int -> Bool
oddDivisor n = ((.&.) n $ n-1) /= 0

main :: IO()
main = do
  t <- readLn :: IO Int
  forM_ [1..t] $ \x -> do
    n <- readLn :: IO Int
    if oddDivisor n then
      putStrLn "YES"
    else putStrLn "NO"

import Data.Bits

solve :: String -> String
solve s = if popCount n == 1 then "NO" else "YES"
  where n = read s :: Int

process :: [String] -> String
process (_ : inp) = unlines $ map solve inp

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


{-# LANGUAGE Safe #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Text.Printf
import qualified Data.IntMap as IM
import Data.Ratio
import Control.Monad.State
import Data.Array.IO.Safe
import Data.Int

readIntBS = fst . fromJust . BS.readInt

main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  let m = 998244353

  --      UL
  -- 1 => BB
  -- 2 => BW
  -- 3 => WB
  -- 4 => WW

  dp <- newArray ((0,0,1),(n,k+2,4)) 0 :: IO (IOUArray (Int,Int,Int) Int64)

  writeArray dp (1,1,1) 1
  writeArray dp (1,2,2) 1
  writeArray dp (1,2,3) 1
  writeArray dp (1,1,4) 1

  forM_ [2..n] $ \i -> do
    forM_ [1..k] $ \j -> do
      --BB
      writeArray dp (i,j,1) =<< (\a b c d -> (a+b+c+d)`mod`m) <$>
        readArray dp (i-1,j,1) <*> readArray dp (i-1,j,2) <*> readArray dp (i-1,j,3) <*> readArray dp (i-1,j-1,4)
      --BW
      when (j>1) $ do
        writeArray dp (i,j,2) =<< (\a b c d -> (a+b+c+d)`mod`m) <$>
          readArray dp (i-1,j-1,1) <*> readArray dp (i-1,j,2) <*> readArray dp (i-1,j-2,3) <*> readArray dp (i-1,j-1,4)
      --WB
      when (j>1) $ do
        writeArray dp (i,j,3) =<< (\a b c d -> (a+b+c+d)`mod`m) <$>
          readArray dp (i-1,j-1,1) <*> readArray dp (i-1,j-2,2) <*> readArray dp (i-1,j,3) <*> readArray dp (i-1,j-1,4)
      --WW
      writeArray dp (i,j,4) =<< (\a b c d -> (a+b+c+d)`mod`m) <$>
        readArray dp (i-1,j-1,1) <*> readArray dp (i-1,j,2) <*> readArray dp (i-1,j,3) <*> readArray dp (i-1,j,4)

  --print =<< (forM [1..n] $ \i -> (forM [1..k] $ \j -> forM [1..4] $ \l -> readArray dp (i,j,l)))

  print =<< (\a b c d -> (a+b+c+d)`mod`m) <$> readArray dp (n,k,1) <*> readArray dp (n,k,2) <*> readArray dp (n,k,3) <*> readArray dp (n,k,1)

{-# LANGUAGE Safe #-}

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.IntMap as IM
import Data.Array.IO.Safe
import Data.Int

main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  let m = 998244353

  --      UL
  -- 1 => BB
  -- 2 => BW
  -- 3 => WB
  -- 4 => WW

  dp <- newArray ((0,0,1),(n,k+2,4)) 0 :: IO (IOUArray (Int,Int,Int) Int64)

  writeArray dp (1,1,1) 1
  writeArray dp (1,2,2) 1
  writeArray dp (1,2,3) 1
  writeArray dp (1,1,4) 1

  forM_ [2..n] $ \i -> do
    forM_ [1..k] $ \j -> do
      --BB
      writeArray dp (i,j,1) =<< (\a b c d -> (a+b+c+d)`mod`m) <$>
        readArray dp (i-1,j,1) <*> readArray dp (i-1,j,2) <*> readArray dp (i-1,j,3) <*> readArray dp (i-1,j-1,4)
      --BW
      when (j>1) $ do
        writeArray dp (i,j,2) =<< (\a b c d -> (a+b+c+d)`mod`m) <$>
          readArray dp (i-1,j-1,1) <*> readArray dp (i-1,j,2) <*> readArray dp (i-1,j-2,3) <*> readArray dp (i-1,j-1,4)
      --WB
      when (j>1) $ do
        writeArray dp (i,j,3) =<< (\a b c d -> (a+b+c+d)`mod`m) <$>
          readArray dp (i-1,j-1,1) <*> readArray dp (i-1,j-2,2) <*> readArray dp (i-1,j,3) <*> readArray dp (i-1,j-1,4)
      --WW
      writeArray dp (i,j,4) =<< (\a b c d -> (a+b+c+d)`mod`m) <$>
        readArray dp (i-1,j-1,1) <*> readArray dp (i-1,j,2) <*> readArray dp (i-1,j,3) <*> readArray dp (i-1,j,4)

  print =<< (\a b c d -> (a+b+c+d)`mod`m) <$> readArray dp (n,k,1) <*> readArray dp (n,k,2) <*> readArray dp (n,k,3) <*> readArray dp (n,k,4)


{-# LANGUAGE ViewPatterns #-}
import qualified Data.ByteString.Lazy.Char8 as P
import Data.ByteString.Builder
import qualified Data.ByteString.Builder.Prim as Prim
import System.IO
import Control.Monad.Trans.State

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

solve :: UArray Int Int -> Int -> Int
solve arr d = let
  (0, (+ 1) -> n) = bounds arr
  numOrbits = gcd n d
  orbitSize = n `div` numOrbits
  step incr ix = if  ix + incr >= n  then  ix + incr - n  else  ix + incr
  getOrbit k = map (arr !) $ take orbitSize $ iterate (step d) k
  evalOne orbit = if  foldl' (+) 0 orbit == orbitSize
    then  maxBound
    else  foldl' max 0 [length vs | vs@(1:_) <- group (orbit ++ orbit)]
  allOrbits = map getOrbit [0 .. numOrbits - 1]
  ans = foldl' max 0 $ map evalOne allOrbits
  in  if  ans == maxBound
  then  0-1
  else  ans

mainFun :: SO
mainFun = do
  ~[t] <- getInts 1
  fmap mconcat $ replicateM t $ do
    ~[n, d] <- getInts 2
    a <- listArray (0, n-1) <$> getInts n
    pure $ putInts [solve a d]

type SP = State [P.ByteString]
type SO = SP Builder

getNext :: Int -> SP [P.ByteString]
getNext = state . splitAt

getInts :: Int -> SP [Int]
getInts k = do
  vs <- getNext k
  pure [v | Just (v, _) <- map P.readInt vs]

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

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

{-# LANGUAGE ViewPatterns #-}
import qualified Data.ByteString.Lazy.Char8 as P
import Data.ByteString.Builder
import qualified Data.ByteString.Builder.Prim as Prim
import System.IO
import Control.Monad.Trans.State

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

solve :: UArray Int Int -> Int -> Int
solve arr d = let
  (0, (+ 1) -> n) = bounds arr
  numOrbits = gcd n d
  orbitSize = n `div` numOrbits
  step incr ix = if  ix + incr >= n  then  ix + incr - n  else  ix + incr
  getOrbitTwice k = map (arr !) $ take (2 * orbitSize) $ iterate (step d) k
  evalOne orbit -- Do not traverse an in-memory linked list: It's slow.
    = foldl' max 0 [length vs | vs@(1:_) <- group orbit]
  allOrbitsTwice = map getOrbitTwice [0 .. numOrbits - 1]
  ans = foldl' max 0 $ map evalOne allOrbitsTwice
  in  if  ans >= orbitSize
  then  0-1
  else  ans

mainFun :: SO
mainFun = do
  ~[t] <- getInts 1
  fmap mconcat $ replicateM t $ do
    ~[n, d] <- getInts 2
    a <- listArray (0, n-1) <$> getInts n
    pure $ putInts [solve a d]

type SP = State [P.ByteString]
type SO = SP Builder

getNext :: Int -> SP [P.ByteString]
getNext = state . splitAt

getInts :: Int -> SP [Int]
getInts k = do
  vs <- getNext k
  pure [v | Just (v, _) <- map P.readInt vs]

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

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


import Control.Monad
import Data.Bits
import Data.Char

printPair :: Int -> Int -> IO ()
printPair x y = putStrLn . unwords $ map show [x, y]

main :: IO ()
main = do
  t <- read <$> getLine
  replicateM_ t $ do
    n <- read <$> getLine
    a <- replicateM n getLine
    let
      ra = reverse $ map reverse a
      pc = (a !! 0) !! 1
      qc = (a !! 1) !! 0
      xc = (ra !! 0) !! 1
      yc = (ra !! 1) !! 0
      [p, q, x, y] = map (\v -> ord v - ord '0') [pc, qc, xc, yc]
      sw = p + q - x - y
      c = 2 - abs sw
    print c
    when (xor (sw >= 0) (p > 0)) (printPair 1 2)
    when (xor (sw >= 0) (q > 0)) (printPair 2 1)
    when (xor (sw >= 0) (x == 0)) (printPair n (n-1))
    when (xor (sw >= 0) (y == 0)) (printPair (n-1) n)

import Control.Arrow ((>>>))
import Data.Maybe (catMaybes)

main :: IO ()
main = interact $ lines >>> drop 1 >>> process >>> unlines

process :: [String] -> [String]
process [] = []
process (nn : xs) = show (length ys) : ys ++ process (drop n xs)
  where
    n = read nn
    ys = solve n (take n xs)

solve :: Int -> [String] -> [String]
solve n xs = map (\(x, y) -> show x ++ " " ++ show y) . catMaybes $ go (at 2 1) (at 1 2) (at n (n - 1)) (at (n - 1) n)
  where
    at i j = xs !! (i - 1) !! (j - 1)
    go l1 l2 r1 r2
      | l1 == l2 = [get (l1 == r1) (n, n - 1), get (l1 == r2) (n - 1, n)]
      | r1 == r2 = [get (r1 == l1) (2, 1), get (r1 == l2) (1, 2)]
      | otherwise = [get True (1, 2), get (l1 == r1) (n, n - 1), get (l1 == r2) (n - 1, n)]
    get b x = if b then Just x else Nothing

import Control.Monad
import Data.Char

printPair :: Int -> Int -> IO ()
printPair x y = putStrLn . unwords $ map show [x, y]

main :: IO ()
main = do
  t <- read <$> getLine
  replicateM_ t $ do
    n <- read <$> getLine
    a <- replicateM n getLine
    let
      ra = reverse $ map reverse a
      pc = (a !! 0) !! 1
      qc = (a !! 1) !! 0
      xc = (ra !! 0) !! 1
      yc = (ra !! 1) !! 0
      [p, q, x, y] = map (\v -> ord v - ord '0') [pc, qc, xc, yc]
      sw = p + q - x - y
      c = 2 - abs sw
    print c
    when (sw >= 0 && p > 0) (printPair 1 2)
    when (sw >= 0 && q > 0) (printPair 2 1)
    when (sw < 0 && x == 0) (printPair n (n-1))
    when (sw < 0 && y == 0) (printPair (n-1) n)


main = interact $ unlines . map p . chunk 3 . drop 1 . lines

chunk n xs = take n xs : if length xs > n then chunk n (drop n xs) else []

f = (map res [0 ..] !!)
    where res 0 = 0
          res 1 = 0
          res x = minimum [f y + 1 | y <- [x `div` 2..x-1], check y (x-y)]

check :: Int -> Int -> Bool
check y d = or [y `div` a == d | a <- reverse [(y `div` (d+1))..y `div` d], a > 0]

p xs =
    let ((n : k : _) : bs : cs : _) = fmap (fmap read . words) xs :: [[Int]]
        costs = [f x | x <- bs]
        maxk = sum costs + 1
        in show $ last $ dpIters n (dpIter costs cs) $ replicate (minimum [maxk, k+1]) 0

dpIters n f val = foldl (\s e -> e s) val [f x | x <- [0..n-1]]

dpIter costs cs i res = let cost = costs !! i
                            score = cs !! i
                        in g cost score res

zipWith' f l1 l2 = [ f e1 e2 | (e1, e2) <- zipWith k l1 l2 ]
            where
                k x y = x `seq` y `seq` (x,y)

g cost score res = take cost res ++ zipWith' (\ x y -> if (y + score) > x then y + score else x) (drop cost res) res

import Data.Array
import Control.Monad (replicateM_, foldM)
import Data.Array.ST
import Control.Monad.ST (ST, runST)
main = read <$> getLine >>= flip replicateM_ (scase $ minOpsGen 1000)
scase costs = rln >>=
              \[n, k] -> rln >>=
              \bs -> rln >>=
              \cs -> print $
                     maxCoins (min k (12*n)) costs (listArray (1, n) bs)
                     (listArray (1, n) cs)
  where rln = map read . words <$> getLine
minOpsGen :: Int -> Array Int Int
minOpsGen n = let m = n
                  aS = newArray (1, n) m  :: ST s (STArray s Int Int)
              in
                runSTArray $
                aS >>=
                \a -> writeArray a 1 0 >>
                      foldM f a [(i, i + i `div` j) | i <- [1..n], j <- [1..i],
                                  i+div i j <= n]
  where f :: STArray s Int Int -> (Int, Int) -> ST s (STArray s Int Int)
        f a (from, to) = readArray a from >>=
                         \af -> readArray a to >>=
                         \at -> if af + 1 < at
                                then writeArray a to (af+1) >> return a
                                else return a
maxCoins :: Int -> Array Int Int -> Array Int Int -> Array Int Int -> Int
maxCoins k costs b c = knapsack01 k (fmap (costs!) b) c
knapsack01 :: Int -> Array Int Int -> Array Int Int -> Int
knapsack01 wt wa va =
  let (1, n) = bounds wa
  in runST $
     (newArray ((0, 0), (n, wt)) 0 :: ST s (STUArray s (Int, Int) Int)) >>=
     \m -> foldM f m (range ((1, 0), (n, wt))) >>= flip readArray (n, wt)
  where f ::STUArray s (Int, Int) Int -> (Int, Int)
          -> ST s (STUArray s (Int, Int) Int)
        f m (i, w) =  readArray m (i-1, w) >>=
                      \mi1w -> ( if (wa!i) > w
                                  then writeArray m (i, w) mi1w
                                  else readArray m (i-1, w - wa!i) >>=
                                       \mi1w1 -> writeArray m (i, w)
                                                 (max mi1w (mi1w1+(va!i)))
                               ) >> return m


{-# OPTIONS_GHC -O2 -optc-O2 #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import Control.Applicative
import Control.Monad
import Control.Monad.State
import Data.Int
import Data.List
import Text.Printf
import qualified Data.ByteString.Lazy.Char8 as L

getCost :: [Int64] -> Int -> Int64
getCost as k = c
    where ! k' = fromIntegral k
          combine a i = a + i * k'
          candidates = take k . sort $ zipWith combine as ([1 ..] :: [Int64])
          ! c = sum candidates

solve :: [Int64] -> Int64 -> (Int, Int64)
solve as s | s >= cmax = (n, cmax)
           | otherwise = go 0 n
    where n = length as
          cmax = getCost as n

          go l r | l + 1 == r = (l, c)
                 | s >= c = go m r
                 | otherwise = go l m
              where m = (l + r) `div` 2
                    c = getCost as m

type Tokenizer = State [L.ByteString]

nextInt :: Tokenizer Int
nextInt = state $ \(s:ss) -> case L.readInt s of
                               Just (x, _) -> (x, ss)
                               Nothing -> error $ "Can't parse Int from: " ++ (L.unpack s)

nextInt64 :: Tokenizer Int64
nextInt64 = fromIntegral <$> nextInt

go :: Tokenizer (Int, Int64)
go = do
  n <- nextInt
  s <- nextInt64
  as <- replicateM n nextInt64
  return $ solve as s

main :: IO ()
main = do
  input <- L.words <$> L.getContents
  let (k, c) = evalState go input
  printf "%d %d\n" k c

{-# LANGUAGE BangPatterns #-}
module Main where
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Control.Applicative
import Data.List
import Data.Int

readInt = maybe undefined (fromIntegral . fst) . B.readInt
readInts = (readInt <$>) . B.words

solve :: Int64 -> Int64 -> [Int64] -> (Int64, Int64)
solve s n as = go 0 (n + 1)
  where
    cost k = sum $ take (fromIntegral k) $ sort $ map (\(i, a) -> a + i * k) $ zip [1..] as
    go !l !r
      | r - l > 1 = if c > s then go l m else go m r
      | otherwise = (l, c)
      where
        m = (l + r) `div` 2
        c = cost m

main = do
  n:s:_ <- readInts <$> B.getLine
  as <- readInts <$> B.getLine
  let (k, t) = solve s n as
  putStr $ show k ++ " " ++ show t

{-# OPTIONS_GHC -O2 -optc-O2 #-}
module Main where

import Control.Applicative
import Control.Monad
import Control.Monad.State
import Data.Int
import Data.List
import Text.Printf
import qualified Data.ByteString.Lazy.Char8 as L

getCost :: [Int64] -> Int -> Int64
getCost as k = c
    where k' = fromIntegral k
          combine a i = a + i * k'
          candidates = take k . sort $ zipWith combine as ([1 ..] :: [Int64])
          c = sum candidates

solve :: [Int64] -> Int64 -> (Int, Int64)
solve as s | s >= cmax = (n, cmax)
           | otherwise = go 0 n
    where n = length as
          cmax = getCost as n

          go l r | l + 1 == r = (l, c)
                 | s >= c = go m r
                 | otherwise = go l m
              where m = (l + r) `div` 2
                    c = getCost as m

type Tokenizer = State [L.ByteString]

nextInt :: Tokenizer Int
nextInt = state $ \(s:ss) -> case L.readInt s of
                               Just (x, _) -> (x, ss)
                               Nothing -> error $ "Can't parse Int from: " ++ (L.unpack s)

nextInt64 :: Tokenizer Int64
nextInt64 = fromIntegral <$> nextInt

go :: Tokenizer (Int, Int64)
go = do
  n <- nextInt
  s <- nextInt64
  as <- replicateM n nextInt64
  return $ solve as s

main :: IO ()
main = do
  input <- L.words <$> L.getContents
  let (k, c) = evalState go input
  printf "%d %d\n" k c

module Main where
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Control.Applicative
import Data.List
import Data.Int

readInt = maybe undefined (fromIntegral . fst) . B.readInt
readInts = (readInt <$>) . B.words

solve :: Int64 -> Int64 -> [Int64] -> (Int64, Int64)
solve s n as = go 0 (n + 1)
  where
    cost k = sum $ take (fromIntegral k) $ sort $ map (\(i, a) -> a + i * k) $ zip [1..] as
    go l r
      | r - l > 1 = if c > s then go l m else go m r
      | otherwise = (l, c)
      where
        m = (l + r) `div` 2
        c = cost m

main = do
  n:s:_ <- readInts <$> B.getLine
  as <- readInts <$> B.getLine
  let (k, t) = solve s n as
  putStr $ show k ++ " " ++ show t

{-# LANGUAGE BangPatterns #-}
module Main where
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Control.Applicative
import Data.List

readInt = maybe undefined fst . B.readInt
readInts = (readInt <$>) . B.words

solve s n as = go 0 (n + 1)
  where
    cost k = sum $ take k $ sort $ map (\(i, a) -> a + i * k) $ zip [1..] as
    go !l !r
      | r - l > 1 = if c > s then go l m else go m r
      | otherwise = (l, c)
      where
        m = (l + r) `div` 2
        c = cost m

main = do
  n:s:_ <- readInts <$> B.getLine
  as <- readInts <$> B.getLine
  let (k, t) = solve s n as
  putStr $ show k ++ " " ++ show t


import Data.Functor
import Data.List (nub, zip4)
import Data.Bits
import Debug.Trace
import Control.Monad.ST

modNum = 1000000007 :: Integer

modIt :: Integer -> Integer
modIt a = mod a modNum

(//) = div
(%%) = mod
(/|) :: Integer -> Integer -> Bool
a /| b = mod b a == 0

(***) :: Integer -> Integer -> Integer
a *** b = modIt $ a * b

(^^^) :: Integer -> Integer -> Integer
a ^^^ 0 = 1
a ^^^ b = cur *** ((a *** a) ^^^ (div b 2))
    where cur = if b .&. 1 == 1 then a else 1

extGCD :: Integer -> Integer -> (Integer, Integer, Integer)
extGCD a 0 = (a, 1, 0)
extGCD a b = (d, ny, nx - (a // b) * ny)
    where (d, nx, ny) = extGCD b (a %% b)

main :: IO ()
main = getInts >>= putStrLn . show . solve . parsePairs . tail where
    getInts = map read <$> words <$> getContents
    parsePairs [] = []
    parsePairs (x:y:rs) = (x,y) : parsePairs rs

---------------------------------------------------------------------
solve :: [Pair] -> Integer
solve (p:[]) = fst p
solve (p:rs) = case sol of Multi (i, _) (_, _) -> answer i
                           Single (i, _) -> answer i
                           All -> answer 0
                           None -> -1
    where sol = foldl intersect All . map projToX $ map (solve0 p) rs
          answer i = (fst p) *** ((snd p) ^^^ i)

-- (a1,b1), (a2,b2) -> (i,j) s.t. a1*b1^i = a2*b2^j
solve0 :: Pair -> Pair -> Solution
solve0 (a1, b1) (a2, b2) = ans
    where primes = nub . concat . map factorize $ [a1, a2, b1, b2]
          [a1', b1', a2', b2'] = map (toVec primes) [a1, b1, a2, b2]
          f' (x1, y1, x2, y2) = f (x1, x2) (y1, y2)
          ans = foldl intersect All . map f' $ zip4 a1' b1' a2' b2'

factorize :: Integer -> [Integer]
factorize 1 = []
factorize n = let xs = filter (/| n) [2 .. floor . sqrt $ fromIntegral n] in
    if xs == [] then [n] else let x = head xs in x:factorize (n // x)

toVec [] n = []
toVec (p:rs) n = getNum p n : toVec rs n where
    getNum p n = if p /| n then 1 + getNum p (n // p) else 0

---------------------------------------------------------------------
-- (a1,a2), (b1,b2) -> (i,j) s.t. a1+b1*i = a2+b2*j
-- a, b -> t=(i,j) s.t. a+bt is on line x=y
f :: Pair -> Pair -> Solution
f (a1, a2) (0, 0) = if a1 == a2 then All else None
f (a1, a2) (0, b2) = let (x, y) = (a1-a2, b2) in
    if mod x y /= 0 || div x y < 0 then None else Multi (0, div x y) (1, 0)
f (a1, a2) (b1, 0) = let (x, y) = (a2-a1, b1) in
    if mod x y /= 0 || div x y < 0 then None else Multi (div x y, 0) (0, 1)
f (a1, a2) (b1, b2) = runST $ do
    (g, i0, j0) <- return $ extGCD b1 b2
    if g /| (a2-a1)
        then do
          d <- return $ (a2 - a1) // g
          (i, j) <- return $ (i0 * d, -j0 * d)
          (di, dj) <- return $ (b2 // g, b1 // g)
          return $ simplify i j di dj
        else return None

---------------------------------------------------------------------
type Pair = (Integer, Integer)

parallel :: Pair -> Pair -> Bool
parallel (x1, y1) (x2, y2) = x1 * y2 == x2 * y1

data Solution = Multi Pair Pair | Single Pair | None | All deriving (Show, Eq)
getSrc (Multi p _) = p
getDir (Multi _ p) = p

projToX :: Solution -> Solution
projToX s = case s of Multi (i, _) (di, _) -> Multi (i, 0) (di, 0)
                      Single (i, _) -> Single (i, 0)
                      None -> None
                      All -> Multi (0, 0) (1, 0)

simplify i0 j0 di dj = Multi (i0'', j0'') (di, dj)
    where
        t1 = max 0 $ max (div (-i0-1) di) (div (-j0-1) dj) + 1
        i0' = i0 + t1 * di
        j0' = j0 + t1 * dj
        t2 = max 0 $ min (div i0 di) (div j0 dj)
        i0'' = i0' - t2 * di
        j0'' = j0' - t2 * dj

contains :: Pair -> Solution -> Bool
contains _ All = True
contains _ None = False
contains p (Single a) = p == a
contains (x, y) (Multi (i, j) (di, dj)) =
    (i<=x && j<=y && parallel (di,dj) (dx,dy) && (v/|u) && (u//v)>=0)
    where (dx, dy) = (x-i, y-j)
          (u, v) = (dx+dy, di+dj)

intersect :: Solution -> Solution -> Solution
intersect None _ = None
intersect _ None = None
intersect a All = a
intersect All a = a
intersect (Single p) a = if contains p a then Single p else None
intersect a (Single p) = if contains p a then Single p else None
intersect m1@(Multi s1 d1) m2@(Multi s2 d2) = if parallel d1 d2 then res1 else res2
    where
        res1 =
            if not (parallel (dx,dy) d1) then None else if tmp == None then None else ans
            where (dx, dy) = (fst s1 - fst s2, snd s1 - snd s2)
                  tmp = if fst d1 > 0 then f (fst s1, fst s2) (fst d1, fst d2)
                                      else f (snd s1, snd s2) (snd d1, snd d2)
                  ((i, _), (di, _)) = (getSrc tmp, getDir tmp)
                  s = (fst s1 + fst d1 * i, snd s1 + snd d1 * i)
                  d = (fst d1 * di, snd d1 * di)
                  ans = Multi s d
        makeLine x1 y1 x2 y2 = (a, b, -(a*x1+b*y1))
            where a = y2 - y1
                  b = x1 - x2
        res2 = if (t/|x0) && (t/|y0) && contains (x,y) m1 && contains (x,y) m2
                 then Single (x, y)
                 else None
            where (a1, b1, c1) = makeLine (fst s1) (snd s1) (fst s1 + fst d1) (snd s1 + snd d1)
                  (a2, b2, c2) = makeLine (fst s2) (snd s2) (fst s2 + fst d2) (snd s2 + snd d2)
                  t = a1*b2-a2*b1
                  x0 = b1*c2-c1*b2
                  y0 = c1*a2-a1*c2
                  (x, y) = (x0//t, y0//t)

import Data.Functor
import Data.List (nub, zip4)
import Data.Bits
import Debug.Trace
import Control.Monad.ST

modNum = 1000000007 :: Integer

modIt :: Integer -> Integer
modIt a = mod a modNum

(//) = div
(%%) = mod
(/|) :: Integer -> Integer -> Bool
a /| b = mod b a == 0

(***) :: Integer -> Integer -> Integer
a *** b = modIt $ a * b

(^^^) :: Integer -> Integer -> Integer
a ^^^ 0 = 1
a ^^^ b = cur *** ((a *** a) ^^^ (div b 2))
    where cur = if b .&. 1 == 1 then a else 1

extGCD :: Integer -> Integer -> (Integer, Integer, Integer)
extGCD a 0 = (a, 1, 0)
extGCD a b = (d, ny, nx - (a // b) * ny)
    where (d, nx, ny) = extGCD b (a %% b)

main :: IO ()
main = getInts >>= putStrLn . show . solve . parsePairs . tail where
    getInts = map read <$> words <$> getContents
    parsePairs [] = []
    parsePairs (x:y:rs) = (x,y) : parsePairs rs

---------------------------------------------------------------------
solve :: [Pair] -> Integer
solve (p:[]) = fst p
solve (p:rs) = case sol of Multi (i, _) (_, _) -> answer i
                           Single (i, _) -> answer i
                           All -> answer 0
                           None -> -1
    where sol = foldl intersect All . map projToX $ map (solve0 p) rs
          answer i = (fst p) *** ((snd p) ^^^ i)

-- (a1,b1), (a2,b2) -> (i,j) s.t. a1*b1^i = a2*b2^j
solve0 :: Pair -> Pair -> Solution
solve0 (a1, b1) (a2, b2) = ans
    where primes = nub . concat . map factorize $ [a1, a2, b1, b2]
          [a1', b1', a2', b2'] = map (toVec primes) [a1, b1, a2, b2]
          f' (x1, y1, x2, y2) = f (x1, x2) (y1, y2)
          ans = foldl intersect All . map f' $ zip4 a1' b1' a2' b2'

factorize :: Integer -> [Integer]
factorize 1 = []
factorize n = let xs = filter (/| n) [2 .. floor . sqrt $ fromIntegral n] in
    if xs == [] then [n] else let x = head xs in x:factorize (n // x)

toVec [] n = []
toVec (p:rs) n = getNum p n : toVec rs n where
    getNum p n = if p /| n then 1 + getNum p (n // p) else 0

---------------------------------------------------------------------
-- (a1,a2), (b1,b2) -> (i,j) s.t. a1+b1*i = a2+b2*j
-- a, b -> t=(i,j) s.t. a+bt is on line x=y
f :: Pair -> Pair -> Solution
f (a1, a2) (0, 0) = if a1 == a2 then All else None

f (a1, a2) (0, b2) = let (x, y) = (a1-a2, b2) in
    if mod x y /= 0 || div x y < 0 then None else Multi (0, div x y) (1, 0)

f (a1, a2) (b1, 0) = let (x, y) = (a2-a1, b1) in
    if mod x y /= 0 || div x y < 0 then None else Multi (div x y, 0) (0, 1)

f (a1, a2) (b1, b2) = let (g, i0, j0) = extGCD b1 b2 in
    if g /| (a2-a1)
        then let d = (a2-a1)//g
                 (i, j, di, dj) = (i0*d, -j0*d, b2//g, b1//g)
             in simplify i j di dj
        else None

---------------------------------------------------------------------
type Pair = (Integer, Integer)

parallel :: Pair -> Pair -> Bool
parallel (x1, y1) (x2, y2) = x1 * y2 == x2 * y1

data Solution = Multi Pair Pair | Single Pair | None | All deriving (Show, Eq)
getMulti (Multi (i,j) (di,dj)) = (i, j, di, dj)

projToX :: Solution -> Solution
projToX s = case s of Multi (i, _) (di, _) -> Multi (i, 0) (di, 0)
                      Single (i, _) -> Single (i, 0)
                      None -> None
                      All -> Multi (0, 0) (1, 0)

simplify i0 j0 di dj = Multi (i0'', j0'') (di, dj)
    where
        t1 = max 0 $ max (div (-i0-1) di) (div (-j0-1) dj) + 1
        i0' = i0 + t1 * di
        j0' = j0 + t1 * dj
        t2 = max 0 $ min (div i0 di) (div j0 dj)
        i0'' = i0' - t2 * di
        j0'' = j0' - t2 * dj

contains :: Pair -> Solution -> Bool
contains _ All = True
contains _ None = False
contains p (Single a) = p == a
contains (x, y) (Multi (i, j) (di, dj)) =
    (i<=x && j<=y && parallel (di,dj) (dx,dy) && (v/|u) && (u//v)>=0)
    where (dx, dy) = (x-i, y-j)
          (u, v) = (dx+dy, di+dj)

intersect :: Solution -> Solution -> Solution
intersect None _ = None
intersect _ None = None
intersect a All = a
intersect All a = a
intersect (Single p) a = if contains p a then Single p else None
intersect a (Single p) = if contains p a then Single p else None
intersect m1@(Multi s1 d1) m2@(Multi s2 d2) = if parallel d1 d2 then res1 else res2
    where
        res1 = let (dx, dy) = (fst s1 - fst s2, snd s1 - snd s2) in
            if not (parallel (dx,dy) d1)
                then None
                else let tmp = if fst d1 > 0 then f (fst s1, fst s2) (fst d1, fst d2)
                                             else f (snd s1, snd s2) (snd d1, snd d2)
                     in if tmp == None
                          then None
                          else let (i, _, di, _) = getMulti tmp
                                   s = (fst s1 + fst d1 * i, snd s1 + snd d1 * i)
                                   d = (fst d1 * di, snd d1 * di)
                               in Multi s d
        makeLine x1 y1 x2 y2 = (a, b, -(a*x1+b*y1))
            where a = y2 - y1
                  b = x1 - x2
        res2 = if (t/|x0) && (t/|y0) && contains (x,y) m1 && contains (x,y) m2
                 then Single (x, y)
                 else None
            where (a1, b1, c1) = makeLine (fst s1) (snd s1) (fst s1 + fst d1) (snd s1 + snd d1)
                  (a2, b2, c2) = makeLine (fst s2) (snd s2) (fst s2 + fst d2) (snd s2 + snd d2)
                  t = a1*b2-a2*b1
                  x0 = b1*c2-c1*b2
                  y0 = c1*a2-a1*c2
                  (x, y) = (x0//t, y0//t)

import Data.Functor
import Data.List (nub, zip4)
import Data.Bits
import Debug.Trace

modNum = 1000000007 :: Integer

modIt :: Integer -> Integer
modIt a = mod a modNum

(//) = div
(%%) = mod
(/|) :: Integer -> Integer -> Bool
a /| b = mod b a == 0

(***) :: Integer -> Integer -> Integer
a *** b = modIt $ a * b

(^^^) :: Integer -> Integer -> Integer
a ^^^ 0 = 1
a ^^^ b = cur *** ((a *** a) ^^^ (div b 2))
    where cur = if b .&. 1 == 1 then a else 1

extGCD :: Integer -> Integer -> (Integer, Integer, Integer)
extGCD a 0 = (a, 1, 0)
extGCD a b = (d, ny, nx - (a // b) * ny)
    where (d, nx, ny) = extGCD b (a %% b)

main :: IO ()
main = getInts >>= putStrLn . show . solve . parsePairs . tail where
    getInts = map read <$> words <$> getContents
    parsePairs [] = []
    parsePairs (x:y:rs) = (x, y) : parsePairs rs
--main = putStrLn . show $ modPow (123::Integer) (321::Integer)
--main = putStrLn . show $ factorize (modNum::Integer)

---------------------------------------------------------------------
solve :: [Pair] -> Integer
solve (p:[]) = fst p
solve (p:rs) = case sol of Multi (i, _) (_, _) -> answer i
                           Single (i, _) -> answer i
                           All -> answer 0
                           None -> -1
    where sol = foldl intersect All . map projToX $ map (solve0 p) rs
          answer i = (fst p) *** ((snd p) ^^^ i)

-- (a1,b1), (a2,b2) -> (i,j) s.t. a1*b1^i = a2*b2^j
solve0 :: Pair -> Pair -> Solution
solve0 (a1, b1) (a2, b2) =
    --trace ("go " ++ show (a1,b1) ++ " " ++ show (a2,b2) ++ " " ++ show ans) $
        ans
    where primes = nub . concat . map factorize $ [a1, a2, b1, b2]
          [a1', b1', a2', b2'] = map (toVec primes) [a1, b1, a2, b2]
          f' (x1, y1, x2, y2) = f (x1, x2) (y1, y2)
          ans = foldl intersect All . map f' $ zip4 a1' b1' a2' b2'

factorize :: Integer -> [Integer]
factorize 1 = []
factorize n = let xs = filter (/| n) [2 .. floor . sqrt $ fromIntegral n] in
    if xs == [] then [n] else let x = head xs in x:factorize (n // x)

toVec [] n = []
toVec (p:rs) n = getNum p n : toVec rs n where
    getNum p n = if p /| n then 1 + getNum p (n // p) else 0

---------------------------------------------------------------------
-- (a1,a2), (b1,b2) -> (i,j) s.t. a1+b1*i = a2+b2*j
-- a, b -> t=(i,j) s.t. a+bt is on line x=y
f :: Pair -> Pair -> Solution
f (a1, a2) (0, 0) = if a1 == a2 then All else None
f (a1, a2) (0, b2) = let (x, y) = (a1-a2, b2) in
    if mod x y /= 0 || div x y < 0 then None else Multi (0, div x y) (1, 0)
f (a1, a2) (b1, 0) = let (x, y) = (a2-a1, b1) in
    if mod x y /= 0 || div x y < 0 then None else Multi (div x y, 0) (0, 1)
f (a1, a2) (b1, b2) =
    --trace ("f " ++ show (g,i0',j0',i0,j0,di,dj) ++ " "++ show (a1,a2) ++ " " ++ show (b1,b2) ++ " " ++ show ans) $
    ans
    where (g, i0', j0'') = extGCD b1 b2
          j0' = -j0''
          d = (a2 - a1) // g
          (i0, j0) = (i0' * d, j0' * d)
          (di, dj) = (b2 // g, b1 // g)
          val = simplify i0 j0 di dj
          ans = if g /| (a2-a1) then val else None

---------------------------------------------------------------------
type Pair = (Integer, Integer)

parallel :: Pair -> Pair -> Bool
parallel (x1, y1) (x2, y2) = x1 * y2 == x2 * y1

data Solution = Multi Pair Pair | Single Pair | None | All deriving (Show, Eq)
getSrc (Multi p _) = p
getDir (Multi _ p) = p

projToX :: Solution -> Solution
projToX s = case s of Multi (i, _) (di, _) -> Multi (i, 0) (di, 0)
                      Single (i, _) -> Single (i, 0)
                      None -> None
                      All -> Multi (0, 0) (1, 0)

simplify i0 j0 di dj = Multi (i0'', j0'') (di, dj)
    where
        t1 = max 0 $ max (div (-i0-1) di) (div (-j0-1) dj) + 1
        i0' = i0 + t1 * di
        j0' = j0 + t1 * dj
        t2 = max 0 $ min (div i0 di) (div j0 dj)
        i0'' = i0' - t2 * di
        j0'' = j0' - t2 * dj

contains :: Pair -> Solution -> Bool
contains _ All = True
contains _ None = False
contains p (Single a) = p == a
contains (x, y) (Multi (i, j) (di, dj)) =
    (i<=x && j<=y && parallel (di,dj) (dx,dy) && (v/|u) && (u//v)>=0)
    where (dx, dy) = (x-i, y-j)
          (u, v) = (dx+dy, di+dj)

intersect :: Solution -> Solution -> Solution
intersect None _ = None
intersect _ None = None
intersect a All = a
intersect All a = a
intersect (Single p) a = if contains p a then Single p else None
intersect a (Single p) = if contains p a then Single p else None
intersect m1@(Multi s1 d1) m2@(Multi s2 d2) = if parallel d1 d2 then res1 else res2
    where
        res1 =
            if not (parallel (dx,dy) d1) then None else if tmp == None then None else ans
            where (dx, dy) = (fst s1 - fst s2, snd s1 - snd s2)
                  tmp = if fst d1 > 0 then f (fst s1, fst s2) (fst d1, fst d2)
                                      else f (snd s1, snd s2) (snd d1, snd d2)
                  ((i, _), (di, _)) = (getSrc tmp, getDir tmp)
                  s = (fst s1 + fst d1 * i, snd s1 + snd d1 * i)
                  d = (fst d1 * di, snd d1 * di)
                  ans = Multi s d
        makeLine x1 y1 x2 y2 = (a, b, -(a*x1+b*y1))
            where a = y2 - y1
                  b = x1 - x2
        res2 =
            --trace ("res2: " ++ show (x,y)) $
            if (t/|x0) && (t/|y0) && contains (x,y) m1 && contains (x,y) m2
                 then Single (x, y)
                 else None
            where (a1, b1, c1) = makeLine (fst s1) (snd s1) (fst s1 + fst d1) (snd s1 + snd d1)
                  (a2, b2, c2) = makeLine (fst s2) (snd s2) (fst s2 + fst d2) (snd s2 + snd d2)
                  t = a1*b2-a2*b1
                  x0 = b1*c2-c1*b2
                  y0 = c1*a2-a1*c2
                  (x, y) = (x0//t, y0//t)

import Data.Functor
import Data.List (nub, zip4)
import Data.Bits
import Debug.Trace
import Control.Monad.ST

modNum = 1000000007 :: Integer

modIt :: Integer -> Integer
modIt a = mod a modNum

(//) = div
(%%) = mod
(/|) :: Integer -> Integer -> Bool
a /| b = mod b a == 0

(***) :: Integer -> Integer -> Integer
a *** b = modIt $ a * b

(^^^) :: Integer -> Integer -> Integer
a ^^^ 0 = 1
a ^^^ b = cur *** ((a *** a) ^^^ (div b 2))
    where cur = if b .&. 1 == 1 then a else 1

extGCD :: Integer -> Integer -> (Integer, Integer, Integer)
extGCD a 0 = (a, 1, 0)
extGCD a b = (d, ny, nx - (a // b) * ny)
    where (d, nx, ny) = extGCD b (a %% b)

main :: IO ()
main = getInts >>= putStrLn . show . solve . parsePairs . tail where
    getInts = map read <$> words <$> getContents
    parsePairs [] = []
    parsePairs (x:y:rs) = (x,y) : parsePairs rs

---------------------------------------------------------------------
solve :: [Pair] -> Integer
solve (p:[]) = fst p
solve (p:rs) = case sol of Multi (i, _) (_, _) -> answer i
                           Single (i, _) -> answer i
                           All -> answer 0
                           None -> -1
    where sol = foldl intersect All . map projToX $ map (solve0 p) rs
          answer i = (fst p) *** ((snd p) ^^^ i)

-- (a1,b1), (a2,b2) -> (i,j) s.t. a1*b1^i = a2*b2^j
solve0 :: Pair -> Pair -> Solution
solve0 (a1, b1) (a2, b2) = ans
    where primes = nub . concat . map factorize $ [a1, a2, b1, b2]
          [a1', b1', a2', b2'] = map (toVec primes) [a1, b1, a2, b2]
          f' (x1, y1, x2, y2) = f (x1, x2) (y1, y2)
          ans = foldl intersect All . map f' $ zip4 a1' b1' a2' b2'

factorize :: Integer -> [Integer]
factorize 1 = []
factorize n = let xs = filter (/| n) [2 .. floor . sqrt $ fromIntegral n] in
    if xs == [] then [n] else let x = head xs in x:factorize (n // x)

toVec [] n = []
toVec (p:rs) n = getNum p n : toVec rs n where
    getNum p n = if p /| n then 1 + getNum p (n // p) else 0

---------------------------------------------------------------------
-- (a1,a2), (b1,b2) -> (i,j) s.t. a1+b1*i = a2+b2*j
-- a, b -> t=(i,j) s.t. a+bt is on line x=y
f :: Pair -> Pair -> Solution
f (a1, a2) (0, 0) = if a1 == a2 then All else None
f (a1, a2) (0, b2) = let (x, y) = (a1-a2, b2) in
    if mod x y /= 0 || div x y < 0 then None else Multi (0, div x y) (1, 0)
f (a1, a2) (b1, 0) = let (x, y) = (a2-a1, b1) in
    if mod x y /= 0 || div x y < 0 then None else Multi (div x y, 0) (0, 1)
f (a1, a2) (b1, b2) =
    if g /| (a2-a1)
        then let d = (a2-a1)//g
                 (i, j, di, dj) = (i0*d, -j0*d, b2//g, b1//g)
             in simplify i j di dj
        else None
    where (g, i0, j0) = extGCD b1 b2

---------------------------------------------------------------------
type Pair = (Integer, Integer)

parallel :: Pair -> Pair -> Bool
parallel (x1, y1) (x2, y2) = x1 * y2 == x2 * y1

data Solution = Multi Pair Pair | Single Pair | None | All deriving (Show, Eq)
getSrc (Multi p _) = p
getDir (Multi _ p) = p

projToX :: Solution -> Solution
projToX s = case s of Multi (i, _) (di, _) -> Multi (i, 0) (di, 0)
                      Single (i, _) -> Single (i, 0)
                      None -> None
                      All -> Multi (0, 0) (1, 0)

simplify i0 j0 di dj = Multi (i0'', j0'') (di, dj)
    where
        t1 = max 0 $ max (div (-i0-1) di) (div (-j0-1) dj) + 1
        i0' = i0 + t1 * di
        j0' = j0 + t1 * dj
        t2 = max 0 $ min (div i0 di) (div j0 dj)
        i0'' = i0' - t2 * di
        j0'' = j0' - t2 * dj

contains :: Pair -> Solution -> Bool
contains _ All = True
contains _ None = False
contains p (Single a) = p == a
contains (x, y) (Multi (i, j) (di, dj)) =
    (i<=x && j<=y && parallel (di,dj) (dx,dy) && (v/|u) && (u//v)>=0)
    where (dx, dy) = (x-i, y-j)
          (u, v) = (dx+dy, di+dj)

intersect :: Solution -> Solution -> Solution
intersect None _ = None
intersect _ None = None
intersect a All = a
intersect All a = a
intersect (Single p) a = if contains p a then Single p else None
intersect a (Single p) = if contains p a then Single p else None
intersect m1@(Multi s1 d1) m2@(Multi s2 d2) = if parallel d1 d2 then res1 else res2
    where
        res1 =
            if not (parallel (dx,dy) d1) then None else if tmp == None then None else ans
            where (dx, dy) = (fst s1 - fst s2, snd s1 - snd s2)
                  tmp = if fst d1 > 0 then f (fst s1, fst s2) (fst d1, fst d2)
                                      else f (snd s1, snd s2) (snd d1, snd d2)
                  ((i, _), (di, _)) = (getSrc tmp, getDir tmp)
                  s = (fst s1 + fst d1 * i, snd s1 + snd d1 * i)
                  d = (fst d1 * di, snd d1 * di)
                  ans = Multi s d
        makeLine x1 y1 x2 y2 = (a, b, -(a*x1+b*y1))
            where a = y2 - y1
                  b = x1 - x2
        res2 = if (t/|x0) && (t/|y0) && contains (x,y) m1 && contains (x,y) m2
                 then Single (x, y)
                 else None
            where (a1, b1, c1) = makeLine (fst s1) (snd s1) (fst s1 + fst d1) (snd s1 + snd d1)
                  (a2, b2, c2) = makeLine (fst s2) (snd s2) (fst s2 + fst d2) (snd s2 + snd d2)
                  t = a1*b2-a2*b1
                  x0 = b1*c2-c1*b2
                  y0 = c1*a2-a1*c2
                  (x, y) = (x0//t, y0//t)

import Data.Functor
import Data.List (nub, zip4)
import Data.Bits

modNum = 1000000007 :: Integer

modIt :: Integer -> Integer
modIt a = mod a modNum

(//) = div
(%%) = mod

(***) :: Integer -> Integer -> Integer
a *** b = modIt $ a * b

(^^^) :: Integer -> Integer -> Integer
a ^^^ 0 = 1
a ^^^ b = cur *** ((a *** a) ^^^ (div b 2))
    where cur = if b .&. 1 == 1 then a else 1

(|||) :: Integer -> Integer -> Bool
a ||| b = mod b a == 0

extGCD :: Integer -> Integer -> (Integer, Integer, Integer)
extGCD a 0 = (a, 1, 0)
extGCD a b = (d, ny, nx - (a // b) * ny)
    where (d, nx, ny) = extGCD b (a %% b)

main :: IO ()
main = getInts >>= putStrLn . show . solve . parsePairs . tail where
    getInts = map read <$> words <$> getContents
    parsePairs [] = []
    parsePairs (x:y:rs) = (x, y) : parsePairs rs
--main = putStrLn . show $ modPow (123::Integer) (321::Integer)
--main = putStrLn . show $ factorize (modNum::Integer)

---------------------------------------------------------------------
solve :: [Pair] -> Integer
solve (p:[]) = modIt $ fst p
solve (p:rs) = case sol of Multi (i, _) (_, _) -> answer i
                           Single (i, _) -> answer i
                           All -> answer 0
                           None -> -1
    where sol = foldl intersect All . map projToX $ map (solve0 p) rs
          answer i = modIt $ fst p * ((snd p) ^^^ i)

-- (a1,b1), (a2,b2) -> (i,j) s.t. a1*b1^i = a2*b2^j
solve0 :: Pair -> Pair -> Solution
solve0 (a1, b1) (a2, b2) = foldl intersect All . map f' $ zip4 a1' b1' a2' b2'
    where primes = nub . concat . map factorize $ [a1, a2, b1, b2]
          [a1', b1', a2', b2'] = map (toVec primes) [a1, b1, a2, b2]
          f' (x1, y1, x2, y2) = f (x1, x2) (y1, y2)

factorize :: Integer -> [Integer]
factorize 1 = []
factorize n = let xs = filter (||| n) [2 .. floor . sqrt $ fromIntegral n] in
    if xs == [] then [n] else let x = head xs in x:factorize (n // x)

toVec [] n = []
toVec (p:rs) n = getNum p n : toVec rs n where
    getNum p n = if p ||| n then 1 + getNum p (n // p) else 0

---------------------------------------------------------------------
-- (a1,a2), (b1,b2) -> (i,j) s.t. a1+b1*i = a2+b2*j
-- a, b -> t=(i,j) s.t. a+bt is on line x=y
f :: Pair -> Pair -> Solution
f (a1, a2) (0, 0) = if a1 == a2 then All else None
f (a1, a2) (0, b2) = let (x, y) = (a1-a2, b2) in
    if mod x y /= 0 || div x y < 0 then None else Multi (0, div x y) (1, 0)
f (a1, a2) (b1, 0) = let (x, y) = (a2-a1, b1) in
    if mod x y /= 0 || div x y < 0 then None else Multi (div x y, 0) (0, 1)
f (a1, a2) (b1, b2) = if g ||| (a2-a1) then val else None
    where (g, i0', j0') = extGCD b1 (-b2)
          d = (a2 - a1) // g
          (i0, j0) = (i0' * d, j0' * d)
          (di, dj) = (b2 // g, b1 // g)
          val = simplify i0 j0 di dj

---------------------------------------------------------------------
type Pair = (Integer, Integer)

parallel :: Pair -> Pair -> Bool
parallel (x1, y1) (x2, y2) = x1 * y2 == x2 * y1

data Solution = Multi Pair Pair | Single Pair | None | All
getSrc (Multi p _) = p
getDir (Multi _ p) = p

projToX :: Solution -> Solution
projToX s = case s of Multi (i, _) (di, _) -> Multi (i, 0) (di, 0)
                      Single (i, _) -> Single (i, 0)
                      None -> None
                      All -> Multi (0, 0) (1, 0)

simplify i0 j0 di dj = Multi (i0'', j0'') (di, dj) -- TODO
    where
        t1 = max 0 $ max (div (-i0-1) di) (div (-j0-1) dj) + 1
        i0' = i0 + t1 * di
        j0' = j0 + t1 * dj
        t2 = max 0 $ min (div i0 di) (div j0 dj)
        i0'' = i0' - t2 * di
        j0'' = j0' - t2 * dj

contains :: Pair -> Solution -> Bool
contains _ All = True
contains _ None = False
contains p (Single a) = p == a
contains (x, y) (Multi (i, j) (di, dj)) =
    (i<=x && j<=y && parallel (di,dj) (dx,dy) && (v|||u) && (u//v)>0)
    where (dx, dy) = (x-i, y-j)
          (u, v) = (dx+dy, di+dj)

intersect :: Solution -> Solution -> Solution
intersect None _ = None
intersect _ None = None
intersect a All = a
intersect All a = a
intersect (Single p) a = if contains p a then Single p else None
intersect a (Single p) = if contains p a then Single p else None
intersect m1@(Multi s1 d1) m2@(Multi s2 d2) = if parallel d1 d2 then res1 else res2
    where
        res1 = if not (parallel (dx,dy) d1) then None else ans
            where (dx, dy) = (fst s1 - fst s2, snd s1 - snd s2)
                  tmp = if fst d1 > 0 then f (fst s1, fst s2) (fst d1, fst d2)
                                      else f (snd s1, snd s2) (snd d1, snd d2)
                  ((i, _), (di, _)) = (getSrc tmp, getDir tmp)
                  s = (fst s1 + fst d1 * i, snd s1 + snd d1 * i)
                  d = (fst d1 * di, snd d1 * di)
                  ans = Multi s d
        makeLine x1 y1 x2 y2 = (a, b, -(a*x1+b*y1))
            where a = y2 - y1
                  b = x1 - x2
        res2 = if (t|||x0) && (t|||y0) && contains (x,y) m1 && contains (x,y) m2
                 then Single (x, y)
                 else None
            where (a1, b1, c1) = makeLine (fst s1) (snd s1) (fst s1 + fst d1) (snd s1 + snd d1)
                  (a2, b2, c2) = makeLine (fst s2) (snd s2) (fst s2 + fst d2) (snd s2 + snd d2)
                  t = a1*b2-a2*b1
                  x0 = b1*c2-c1*b2
                  y0 = c1*a2-a1*c2
                  (x, y) = (x0//t, y0//t)


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

onecase = do
		[s,a,b,c]<-map read <$> words <$> getLine ::IO [Integer]
		let x = div s c
		print $ x + (div x a)*b

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

{-# LANGUAGE Safe #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Monad
import Control.Monad.ST.Safe
import Control.Monad.State
import Control.Applicative
import Control.Arrow
import Data.List
import Data.Array
import Data.Array.IO.Safe
import Data.Array.ST.Safe
import Data.IORef
import Data.STRef
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import Data.Tuple
import Data.Function
import Text.Printf
import Numeric

readIntBS = fst . fromJust . BS.readInt

main = do
  t <- readLn :: IO Int
  replicateM_ t $ do
    [s,a,b,c] <- map read . words <$> getLine :: IO [Integer]
    let n = s `div` c
    print $ n + (n`div`a)*b

f::[String]->[String]
f []=[]
f (e:es)=let (n:a:b:c:[])=map read (words e)::[Integer]
             t1=n `div` c
             t2=(t1 `div` a)*b
         in (show (t1+t2)):f es

main = do
       e<-getLine
       es<-getContents
       mapM_ putStrLn $ f (lines es)

count :: Integer -> Integer -> Integer -> Integer -> Integer
count s a b c = n + b*(n `div` a)
  where n = s `div` c

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

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

readIntegerList :: String -> [Integer]
readIntegerList line = map readInteger $ words line

solve :: IO ()
solve = do
  (s:a:b:c:[]) <- fmap readIntegerList getLine
  putStrLn $ show $ count s a b c

main :: IO ()
main = do
  t <- fmap readInt getLine
  sequence_ $ replicate t solve

import Data.Int
main = interact $ unlines . map show . go . map read . tail . words
go [] = []
go (s:a:b:c:xs) = (paid + paid `div` a * b) : go xs where
  paid = s `div` c :: Int64

process :: Integral a => a -> a -> a -> a -> a
process s a b c = d * (a + b) + (m `div` c)
    where (d,m) = divMod s (a*c)

readInt :: String -> Integer
readInt = read

main :: IO ()
main = do
    t <- fmap readInt getLine
    ns <- fmap (map (map readInt.words).lines) getContents
    mapM_ print $ map (\[s,a,b,c] -> process s a b c) ns

import Control.Monad
import Data.Foldable (traverse_)

solve :: [Integer] -> Integer
solve [s, a, b, c] = (s `div` ac) * (a + b) + ((s `mod` ac) `div` c)
	where ac = a * c

main :: IO ()
main = do
	a <- getLine
	tests <- replicateM (read a) getLine
	traverse_ (putStrLn . show .solve) $ map ((map read) . words) tests

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

onecase = do
		[s,a,b,c]<-map read <$> words <$> getLine ::IO [Integer]
		print $ (div s c) + (div s a)*b

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


module Main where

import Control.Applicative
import Control.Monad
import Control.Monad.State
import Prelude
import qualified Data.ByteString.Lazy.Char8 as L

type Tokenizer = State [L.ByteString]

nextInt :: Tokenizer Int
nextInt = state $ \(s:ss) -> case L.readInt s of
                                   Just (x, _) -> (x, ss)
                                   Nothing -> error $ "Can't parse Int:" ++ (show s)

nextWord :: Tokenizer [Char]
nextWord = state $ \(s:ss) -> (L.unpack s, ss)

solve :: Tokenizer Int
solve = do
    [n, a, b] <- replicateM 3 nextInt
    s <- nextWord
    if s!!(a - 1) == s!!(b - 1) then return 0
    else return 1

main = do
    contents <- L.getContents
    print $ evalState solve (L.words contents)

main :: IO ()
main = do
  s1 <- getLine
  let [n, a, b] = map read $ words s1
  s <- getLine
  let va = s!!(a - 1)
  let vb = s!!(b - 1)
  if va == vb
    then putStrLn "0"
    else putStrLn "1"

#!/usr/bin/env stack
{- stack
  --resolver lts-2.22
  runghc
  --package array
  --package base
  --package bytestring
  --package containers
  --package mtl
  --package parsec
  --package vector
  --
  -hide-all-packages
-}
{-# LANGUAGE BangPatterns, TupleSections, RankNTypes, ScopedTypeVariables #-}
module Main
( main
) where

import           Prelude hiding (interact, lines, unlines, words, unwords,
                                 sequence, foldr)
import           Data.ByteString.Char8 (pack, unpack, ByteString, lines, words,
                                        unlines, unwords, interact, readInt,
                                        readInteger)
import qualified Data.ByteString.Char8 as BS
import           Data.List (foldl', sort, sortBy, group, groupBy, inits, tails)
import qualified Data.List as L
import qualified Data.IntSet as IS
import           Data.IntSet (IntSet)
import qualified Data.IntMap.Strict as IM
import           Data.IntMap.Strict (IntMap)
import qualified Data.Map.Strict as M
import           Data.Map.Strict (Map)
import qualified Data.Set as S
import           Data.Set (Set)
import qualified Data.Array.IArray as A
import           Data.Array.IArray ((!), Array, listArray, array)
import           Data.Maybe (fromJust, isJust, fromMaybe, maybe, mapMaybe,
                             catMaybes)
import           Data.Either (either)
import           Control.Applicative (Applicative, pure,
                                      (<$>), (<*>), liftA2, liftA3)
import           Control.Monad (unless, when, void, filterM, ap)
import           Control.Arrow ((***), (&&&), first, second)
import           Data.Traversable (sequence, sequenceA, traverse,
                                   Traversable)
import           Data.Ord (comparing, Down(..))
import           Data.Function (on)
import           Data.Bits (complement, xor, (.|.), (.&.), testBit, zeroBits,
                            bit, shiftR, shiftL, Bits)
import qualified Data.Bits as B
import           Data.Word (Word32)
import           Control.Monad.State (State, get, put, gets, modify,
                                      evalState, execState, runState)
import           Text.Parsec (char, space, parse, Parsec)
import qualified Text.Parsec as P
import           Data.Tuple (swap)
import           Data.Foldable (Foldable, foldr)
import           Data.Monoid ((<>), Monoid, mappend, mempty)

type N = Int
toNum = toInt

answer :: N -> N -> [Char] -> N
answer i j xs = if xs !! (i-1) == xs !! (j-1)
                  then 0 else 1

handleInput :: ByteString -> ByteString
handleInput = words & drop 1
            & coerceInput answer
            & show & pack
            -- & map (show & pack) & unlines

toInt = readInt & fromJust & fst
toInte = readInteger & fromJust & fst
toX :: Read a => ByteString -> a
toX = unpack & read

coerceInput f (a:b:c:xs) = f (toNum a) (toNum b) (unpack c)
coerceInput _ _ = error "invalid input"

main :: IO ()
main = interact handleInput

-- Util stuff --
(&) :: (a -> b) -> (b -> c) -> a -> c
(&) = flip (.)
infixl 9 &

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

  main :: IO()
  main = do
    [n, a, b] <- getLine >>= return . (map readInt) . words
    xs <- getLine
    let p = xs !! (a - 1)
        q = xs !! (b - 1)
    case p == q of
      True -> print 0
      False -> print 1

module Main where

    main :: IO ()
    main = do
        l <- getLine
        let [_, a, b] = map (\x -> read x :: Int) $ words l
        s <- getLine
        print $ if s !! (a - 1) == s !! (b - 1) then 0 else 1

{-# LANGUAGE FlexibleInstances #-}
module Main (printShit, printShitV, readShit, main, yN, iif) where
import Data.ByteString.Builder
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Maybe

-- Meat
solve :: Int -> Int -> String -> Int
solve a b s = iif 0 1 (s !! a == s !! b)

-- Shit
main :: IO ()
main = do
        [_,a,b]  <- readShit
        s <- readShit
        printShit $ solve (a - 1) (b - 1) s

class Shit a where
    printShit :: a -> IO ()
    printShitV :: a -> IO ()
    readShit :: IO a
    printShitV = printShit

yN :: Bool -> String
yN True = "YES"
yN False = "NO"

iif :: x -> x -> Bool-> x
iif a b c = if c then a else b

instance  Shit Int where
    printShit = print
    readShit = fmap read getLine

instance  Shit [Int] where
    printShit = putStrLn . unwords . fmap show
    printShitV = putStrLn . unlines . fmap show
    readShit = fmap (fmap read . words) getLine

instance  Shit [Integer] where
    printShit = putStrLn . unwords . fmap show
    printShitV = putStrLn . unlines . fmap show
    readShit = fmap (fmap read . words) getLine

instance Shit [[Int]] where
    printShit = printShit . (fmap.fmap)  (toLazyByteString . integerDec .toInteger)
    readShit = fmap (fmap.fmap $ fromInteger.fst.fromJust. BS.readInteger) readShit

instance Shit [[Double]] where
    printShit = printShit . (fmap.fmap) show
    readShit = fmap (fmap.fmap $ read) readShit

instance Shit [[Integer]] where
    printShit  = printShit . (fmap.fmap)  (toLazyByteString . integerDec)
    readShit = fmap (fmap.fmap $ fromInteger.fst.fromJust. BS.readInteger) readShit

instance Shit String where
    printShit = putStrLn
    printShitV = putStrLn
    readShit = getLine

instance Shit [String] where
    printShit = putStrLn. unwords
    printShitV = putStrLn . unlines
    readShit = fmap lines getContents

instance Shit [[String]] where
    printShit = putStrLn . unlines . fmap unwords
    readShit = fmap (fmap (fmap words) lines) getContents

instance Shit [BS.ByteString] where
    printShit = BS.putStrLn. BS.unwords
    printShitV = BS.putStrLn . BS.unlines
    readShit = fmap BS.lines BS.getContents

instance Shit [[BS.ByteString]] where
    printShit = BS.putStrLn . BS.unlines . fmap BS.unwords
    readShit = fmap (fmap (fmap BS.words) BS.lines) BS.getContents

{-# LANGUAGE FlexibleInstances #-}
module Main (printShit, printShitV, readShit, main, yN, iif) where
import Data.ByteString.Builder
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Maybe
import Control.Arrow

-- Meat
solve :: Int -> Int -> String -> Int
solve a b s
    | ours == theirs = 0
    | otherwise = findOurs ours . (reverse *** tail) . splitAt b $ s
        where ours = s !! a
              theirs = s !! b

findOurs :: Char -> (String, String) -> Int
findOurs c ([], y:ys) = if c == y then 1  else 1 + findOurs c ([], ys)
findOurs c (x:xs, []) = if c == x then 1 else 1 + findOurs c (xs, [])
findOurs c (x:xs, y:ys) = if c == y || c == x then 1 else 1 + findOurs c (xs, ys)
findOurs _ ([], []) = error "You suck"

-- Shit
main :: IO ()
main = do
        [_,a,b]  <- readShit
        s <- readShit
        printShit $ solve (a - 1) (b - 1) s

class Shit a where
    printShit :: a -> IO ()
    printShitV :: a -> IO ()
    readShit :: IO a
    printShitV = printShit

yN :: Bool -> String
yN True = "YES"
yN False = "NO"

iif :: Bool -> x -> x -> x
iif True a _ = a
iif _ _ b = b

instance  Shit Int where
    printShit = print
    readShit = fmap read getLine

instance  Shit [Int] where
    printShit = putStrLn . unwords . fmap show
    printShitV = putStrLn . unlines . fmap show
    readShit = fmap (fmap read . words) getLine

instance  Shit [Integer] where
    printShit = putStrLn . unwords . fmap show
    printShitV = putStrLn . unlines . fmap show
    readShit = fmap (fmap read . words) getLine

instance Shit [[Int]] where
    printShit = printShit . (fmap.fmap)  (toLazyByteString . integerDec .toInteger)
    readShit = fmap (fmap.fmap $ fromInteger.fst.fromJust. BS.readInteger) readShit

instance Shit [[Double]] where
    printShit = printShit . (fmap.fmap) show
    readShit = fmap (fmap.fmap $ read) readShit

instance Shit [[Integer]] where
    printShit  = printShit . (fmap.fmap)  (toLazyByteString . integerDec)
    readShit = fmap (fmap.fmap $ fromInteger.fst.fromJust. BS.readInteger) readShit

instance Shit String where
    printShit = putStrLn
    printShitV = putStrLn
    readShit = getLine

instance Shit [String] where
    printShit = putStrLn. unwords
    printShitV = putStrLn . unlines
    readShit = fmap lines getContents

instance Shit [[String]] where
    printShit = putStrLn . unlines . fmap unwords
    readShit = fmap (fmap (fmap words) lines) getContents

instance Shit [BS.ByteString] where
    printShit = BS.putStrLn. BS.unwords
    printShitV = BS.putStrLn . BS.unlines
    readShit = fmap BS.lines BS.getContents

instance Shit [[BS.ByteString]] where
    printShit = BS.putStrLn . BS.unlines . fmap BS.unwords
    readShit = fmap (fmap (fmap BS.words) BS.lines) BS.getContents


solve xs = solve' xs []
  where solve' [] ans = ans
        solve' ('x':'y':xs) ans = solve' xs ans
        solve' ('y':'x':xs) ans = solve' xs ans
        solve' (x:xs) [] = solve' xs [x]
        solve' (x:xs) (y:ys)
          | x == y    = solve' xs (x:y:ys)
          | otherwise = solve' xs ys

main = do xs <- getLine
          putStrLn $ solve xs

-- http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html
-- http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-List.html

import Data.List

getAns :: Int -> Char -> String
getAns 0 _ = []
getAns n c = c : getAns (n - 1) c

main :: IO()
main = do
	str <- getLine
	let xlen = length (filter (== 'x') str)
	let ylen = length (filter (== 'y') str)
	if (xlen > ylen)
		then putStrLn (getAns (xlen - ylen) 'x')
		else putStrLn (getAns (ylen - xlen) 'y')

solve l = replicate x 'x' ++ replicate (-x) 'y'
  where x = length (filter (=='x') l) - length (filter (=='y') l)

main = interact $ solve

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

main :: IO ()
main = do l <- B.getLine
          B.putStrLn $ solve l

solve :: B.ByteString -> B.ByteString
solve l = mkStr (B.count 'x' l,B.count 'y' l)

mkStr (x,y)
    | x > y    = B.replicate (x-y) 'x'
    | otherwise = B.replicate (y-x) 'y'

import Data.List
main = do
    str <- getLine
    let (x, y) = partition (\c -> c == 'x') str
        delta = (length x) - (length y)
    putStrLn $ sq $ show (if (delta > 0)
                        then take delta x
                        else take (abs delta) y )

sq :: String -> String
sq s@[c]                     = s
sq ('"':s)  | last s == '"'  = init s
            | otherwise      = s
sq ('\'':s) | last s == '\'' = init s
            | otherwise      = s
sq s                         = s

solve :: String -> String
solve s
  | x <= y  =  replicate (y-x) 'y'
  | otherwise  =  replicate (x-y) 'x'
  where
    x  =  length $ filter (== 'x') s
    y  =  length $ filter (== 'y') s

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

solve xs = solve' xs []
  where solve' [] ans = reverse ans
        solve' ('x':'y':xs) ans = solve' xs ans
        solve' ('y':'x':xs) ans = solve' xs ans
        solve' (x:xs) [] = solve' xs [x]
        solve' (x:xs) (y:ys)
          | x == y    = solve' xs (x:y:ys)
          | otherwise = solve' xs ys

main = do xs <- getLine
          putStrLn $ solve xs

module Main where

countDiff :: String -> Int
countDiff s = countDiff' s 0
        where
        countDiff' "" d = d
        countDiff' ('x':s) d = countDiff' s (d+1)
        countDiff' ('y':s) d = countDiff' s (d-1)

solve :: String -> String
solve s = if d > 0
          then replicate d 'x'
          else replicate (-d) 'y'
               where
               d = countDiff s

main = getLine >>= (putStrLn . solve)

import qualified Data.ByteString.Char8 as B
main = B.getLine >>= B.putStrLn .solve

solve bs
  | cntx < cnty = B.replicate (cnty-cntx) 'y'
  | otherwise   = B.replicate (cntx-cnty) 'x'
   where
     cntx = B.count 'x' bs
     cnty = B.count 'y' bs

#!/usr/bin/env runghc
main = do
  c <- getContents
  putStrLn . solve . lines $ c

solve (s:ss) = f 0 'x' s
  where
    f 0 a (c:cs) =  f 1 c cs
    f n a []  = replicate n a
    f n a (c:cs) = if c == a then f (n+1) a cs else f (n-1) a cs

main :: IO()
main = do
        l <- getLine
        putStrLn $ func l

func :: String -> String
func l = replicate nc ch
    where
        (nc,ch)=df ( map f ['x','y'])
        f c = length [ x | x <- l, x == c]
        df [nx,ny]
            | nx > ny = ((nx-ny),'x')
            | otherwise = ((ny-nx),'y')

import Data.List
main = interact $ f. map length . group . sort . (++ "xy") where
    f (_:x:y:_)
        | x < y = replicate (y - x) 'y'
        | otherwise = replicate (x - y) 'x'

reduce [] = []
reduce ('y':'x':rest) = reduce rest
reduce ('x':'y':rest) = reduce rest
reduce (x:xs) = x:reduce xs

solve xs = iterate reduce xs !! 250

main = interact solve

import qualified Data.ByteString.Char8 as BS

solve xs = solve' xs []
  where solve' [] ans = ans
        solve' ('x':'y':xs) ans = solve' xs ans
        solve' ('y':'x':xs) ans = solve' xs ans
        solve' (x:xs) [] = solve' xs [x]
        solve' (x:xs) (y:ys)
          | x == y    = solve' xs (x:y:ys)
          | otherwise = solve' xs ys

main = do xs <- fmap BS.unpack BS.getLine
          putStrLn $ solve xs

solve [] = []
solve ('y':'x':rest) = solve rest
solve ('x':'y':rest) = solve rest
solve (x:xs) = x:solve xs

main = interact solve

solve xs = solve' xs []
  where solve' [] ans = reverse ans
        solve' ('x':'y':xs) ans = solve' xs ans
        solve' ('y':'x':xs) ans = solve' xs ans
        solve' (x:xs) [] = solve' xs [x]
        solve' (x:xs) (y:ys)
          | x == y    = solve' xs (x:y:ys)
          | otherwise = solve' xs ys

main = interact solve

#!/usr/bin/env runghc
main = do
  c <- getContents
  putStrLn . solve . lines $ c

solve (s:ss) = f s
  where
    f (a:b:cs) = if a /= b then f cs else a:b:f cs
    f cs = cs