import qualified Data.ByteString.Char8 as B
import Data.List (sort)
main = B.interact $ solve . map parse . tail . B.lines
parse l = (read' a :: Int,read' b :: Int) where [a,b] = B.words l
solve ps | map snd (sort ps) == sort (map snd ps) = B.pack "Poor Alex"
         | otherwise = B.pack "Happy Alex"
read' bs = i where Just (i,_) = B.readInt bs

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

main= do
	getLine
	s<-transpose. map (map (fst.fromJust.C.readInt)). map C.words . C.lines <$> C.getContents ::IO [[Int]]
	let s1 = map snd $ sort $ zip (head s) (last s)
	putStrLn $ if s1==sort s1 then "Poor Alex" else "Happy Alex"

{-# LANGUAGE FlexibleContexts     #-}
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE OverlappingInstances #-}

module Main where

import           Control.Applicative
import           Control.Monad.State
import qualified Data.ByteString.Lazy.Char8 as B
import           Data.Function
import           Data.List
import           Data.Maybe
import           System.Environment
import           System.IO

type BString = B.ByteString

solve :: [Int] -> [Int] -> String
solve xs ys = get_state $ or $ zipWith (/=) xs ys
    where get_state False = "Poor Alex"
          get_state True  = "Happy Alex"

process :: State Reader String
process = do
    n <- bsGet
    [as, bs] <- transpose <$> replicateM n bsGet
    return $ solve as bs

main :: IO ()
main = do
    args <- getArgs
    reader <- if not (null args) && head args == "MINE"
              then B.lines <$> (openFile "input.txt" ReadMode >>= B.hGetContents)
              else B.lines <$> B.getContents
    say $ evalState process reader

say :: Display a => a -> IO ()
say = putStrLn . display

toNum :: Num a => Bool -> a
toNum False = 0
toNum True  = 1

type Reader = [BString]

class EIO a where
    bsGet :: State Reader a

instance EIO Int where
    bsGet = state $ \(line:rest) -> (fst $ fromJust $ B.readInt line, rest)

instance EIO [Int] where
    bsGet = state $ \(line:rest) -> (map fst . mapMaybe B.readInt . B.words $ line, rest)

instance EIO BString where
    bsGet = state $ \(line:rest) -> (line, rest)

class Show a => Display a where
    display :: a -> String
    display = show

instance Display String where
    display = id

instance Display a => Display [a] where
    display = unwords . map display

instance Display Int
instance Display Double

{-# LANGUAGE FlexibleContexts     #-}
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE OverlappingInstances #-}

module Main where

import           Control.Applicative
import           Control.Monad.State
import qualified Data.ByteString.Lazy.Char8 as B
import           Data.Function
import           Data.List
import           Data.Maybe
import           System.Environment
import           System.IO

type BString = B.ByteString

solve :: [Int] -> [Int] -> String
solve price quality = get_state $ ((==) `on` process) price quality
  where
    process xs = map snd $ sort $ zip xs [1 ..]
    get_state False = "Happy Alex"
    get_state True  = "Poor Alex"

process :: State Reader String
process = do
    n <- bsGet
    [as, bs] <- transpose <$> replicateM n bsGet
    return $ solve as bs

main :: IO ()
main = do
    args <- getArgs
    reader <- if not (null args) && head args == "MINE"
              then B.lines <$> (openFile "input.txt" ReadMode >>= B.hGetContents)
              else B.lines <$> B.getContents
    say $ evalState process reader

say :: Display a => a -> IO ()
say = putStrLn . display

toNum :: Num a => Bool -> a
toNum False = 0
toNum True  = 1

type Reader = [BString]

class EIO a where
    bsGet :: State Reader a

instance EIO Int where
    bsGet = state $ \(line:rest) -> (fst $ fromJust $ B.readInt line, rest)

instance EIO [Int] where
    bsGet = state $ \(line:rest) -> (map fst . mapMaybe B.readInt . B.words $ line, rest)

instance EIO BString where
    bsGet = state $ \(line:rest) -> (line, rest)

class Show a => Display a where
    display :: a -> String
    display = show

instance Display String where
    display = id

instance Display a => Display [a] where
    display = unwords . map display

instance Display Int
instance Display Double

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

solve :: [[Int]] ->  String
solve xs = if sol xs then "Poor Alex" else "Happy Alex"
    where sol = all (>= 0) . (zipWith (-) <$> tail <*> id).fmap (head . tail). sort

-- Shit
main :: IO ()
main = do
        (_: xs) <- readShit
        printShitV [solve xs]

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

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 [[Integer]] where
    printShit  = printShit . (fmap.fmap)  (toLazyByteString . integerDec)
    readShit = fmap (fmap.fmap $ fromInteger.fst.fromJust. BS.readInteger) readShit

instance Shit [String] where
    printShit = putStrLn. unwords
    printShitV = putStrLn . unlines
    readShit = fmap 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) where
import Data.ByteString.Builder
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Maybe
import Data.List
import Control.Applicative
-- Meat

solve :: [[Integer]] ->  String
solve xs = if sol xs then "Poor Alex" else "Happy Alex"
    where sol = all (>= 0) . (zipWith (-) <$> tail <*> id).fmap (head . tail). sort

-- Shit
main :: IO ()
main = do
        (_: xs) <- readShit
        printShitV [solve xs]

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

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 = putStrLn . unlines . fmap (unwords . fmap show)
    readShit = fmap (fmap (fmap read . words) . lines) getContents

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. unwords
    printShitV = putStrLn . unlines
    readShit = fmap 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

import Data.List
import Data.Tree
import Data.Int
import Data.Maybe
import Data.Char
import Data.Functor
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=   readsolveprint
readsolveprint::IO()
readsolveprint = getLine >>= \n -> (solve =<< forM [1..read n] ( \i -> map (fst.fromJust.C.readInteger).C.words<$>C.getLine))
solve xs = let (b1,b2) = break (\a->length a>1) $ groupBy (\[a,b] [c,d] -> d<b) $ sortBy (\[a1,a2] [b1,b2] -> (a1 `compare` b1)) xs in if b2==[] then putStrLn "Poor Alex" else putStrLn "Happy Alex"

import qualified Data.Sequence as Seq
import Data.Foldable
import Control.Monad

getInput :: Int -> IO [String]
getInput n = replicateM n getLine

parse :: [String] -> (Seq.Seq Integer, Seq.Seq Integer)
parse input = (Seq.fromList prices, Seq.fromList qualities)
    where (prices, qualities) = getLists ints ([], [])
          ints = transform input

getLists :: [[Integer]] -> ([Integer], [Integer]) -> ([Integer], [Integer])
getLists [] tuple = tuple
getLists ([x,y]:rest) (prices, qualities) = getLists rest (x:prices, y:qualities)

transform :: [String] -> [[Integer]]
transform [] = []
transform (first:rest) = (map read (words first)) : transform rest

getAnswer :: Seq.Seq Integer -> Seq.Seq Integer -> String
getAnswer prices qualities = if findQaulityLaptop $ toList $ getCounter prices qualities
                             then "Happy Alex"
                             else "Poor Alex"

findQaulityLaptop :: [Integer] -> Bool
findQaulityLaptop [x] = False
findQaulityLaptop (first:second:rest) = if first < second
                                        then findQaulityLaptop (second:rest)
                                        else True

emptySeq :: Integer -> Seq.Seq Integer
emptySeq n = Seq.fromList (take (fromIntegral n) (cycle [0]))

getCounter :: Seq.Seq Integer -> Seq.Seq Integer -> Seq.Seq Integer
getCounter prices qualities = _getCounter prices qualities (emptySeq n)
    where n = fromIntegral $ Seq.length prices

_getCounter :: Seq.Seq Integer -> Seq.Seq Integer -> Seq.Seq Integer -> Seq.Seq Integer
_getCounter prices qualities counter = if prices == Seq.empty
                                       then counter
                                       else _getCounter pricesTail qualitiesTail (Seq.update (fromIntegral index) value counter)
    where pricesTail = Seq.drop 1 prices
          qualitiesTail = Seq.drop 1 qualities
          index = (Seq.index prices 0) - 1
          value = Seq.index qualities 0

unpack :: Maybe Integer -> Integer
unpack Nothing = -1
unpack (Just x) = x

main :: IO ()
main = do
    n <- getLine
    input <- getInput (read n)
    let (prices, qualities) = parse input
    putStrLn $ getAnswer prices qualities

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

process::Int->[[Int]]->String
process n q  | qq == (q!!1) = "Poor Alex"
             | otherwise = "Happy Alex"
  where qq = sort (q!!1)

main=do
    n<-read <$> getLine::IO Int
    q<- transpose <$> sort <$> map(map (fromIntegral. fst.fromJust.C.readInteger)) <$> map C.words <$> C.lines <$> C.getContents::IO [[Int]]
    putStrLn $ process n q

{-# LANGUAGE NPlusKPatterns #-}

module Main where

import Data.List
import Data.Function

main :: IO ()
main = do
    n <- getInt
    n2s <- getInt2s n
    let ls = sort1 n2s
    let answer = check $ map snd ls
    putStrLn $ alex answer

getInt :: IO Int
getInt = fmap read getLine

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

type Int2 = (Int, Int)

getInt2 :: IO Int2
getInt2 = do
    [a, b] <- getInts
    return (a, b)

getInt2s :: Int -> IO [Int2]
getInt2s 0       = return []
getInt2s (n + 1) = do
    n2  <- getInt2
    n2s <- getInt2s n
    return (n2 : n2s)

sort1 :: [Int2] -> [Int2]
sort1 = sortBy (compare `on` fst)

check :: Ord a => [a] -> Bool
check []       = True
check (a : as) = check' a as

check' :: Ord a => a -> [a] -> Bool
check' a0 []       = True
check' a0 (a : as) = a0 <= a && check' a as

alex :: Bool -> String
alex False = "Happy Alex"
alex True = "Poor Alex"

import Data.Function
import Data.List

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

input :: [Int] -> [(Int, Int)]
input []      = []
input (a:b:s) = (a, b):(input s)

solve :: [(Int, Int)] -> Bool
solve p = solve' (sortBy (on compare fst) p)
    where
        solve' :: [(Int, Int)] -> Bool
        solve' []                = False
        solve' [(_, _)]          = False
        solve' ((_, b):(c, d):x) | b > d     = True
                                 | otherwise = solve' ((c, d):x)

output :: Bool -> IO()
output b = putStrLn $ if b then "Happy Alex" else "Poor Alex"

import Data.List
import Data.Function
import Data.Char
import Data.Maybe
import qualified Data.ByteString.Lazy.Char8 as B

main = B.interact $ getAns . tail . map fst . mapMaybe B.readInt . B.words

getAns xs = if (dealArray xs) then B.pack "Happy Alex" else B.pack "Poor Alex"

dealArray :: [Int] -> Bool
dealArray [] = False
dealArray (x:y:xs) = (x /= y) || dealArray xs

import Data.List
import Data.Function
import Data.Char
import Data.Maybe
import qualified Data.ByteString.Lazy.Char8 as B

main = B.interact $ getAns . tail . map fst . mapMaybe B.readInt . B.words

getAns :: [Int] -> B.ByteString
getAns xs = let ar = sort $ dealArray xs;
				br = zipWith (\(_, q1) (_, q2) -> q2 - q1) ar $ tail (cycle ar)
			in if any (<0) $ init br then B.pack "Happy Alex" else B.pack "Poor Alex"

dealArray :: [Int] -> [(Int, Int)]
dealArray [] = []
dealArray (x:y:xs) = (x, y) : dealArray xs

import Data.List
import Data.Function
import Data.Char

main = interact $ getAns . tail . map read . words

getAns :: [Int] -> String
getAns xs = if (dealArray xs) then "Happy Alex" else "Poor Alex"

dealArray :: [Int] -> Bool
dealArray [] = False
dealArray (x:y:xs) = (x /= y) || dealArray xs

import Data.List (sort)
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = B.getContents >>= putStrLn . output . solve . map (map (fst . fromJust . B.readInt) . B.words) . tail . B.lines

solve :: [[Int]] -> Bool
solve = or . (\xs -> zipWith (>) xs (tail xs)) . map (!!1) . sort

output :: Bool -> String
output True = "Happy Alex"
output _ = "Poor Alex"

import Data.List
solve [a,b] = if a==b then "Poor Alex" else "Happy Alex"
main = interact $ solve . transpose . map words. tail . lines

import Data.List
import Data.Function
import Data.Char

main = interact $ getAns . tail . map read . words

getAns :: [Int] -> String
getAns xs = if (any (\(x, y) -> x /= y) $ dealArray xs) then "Happy Alex" else "Poor Alex"

dealArray :: [Int] -> [(Int, Int)]
dealArray [] = []
dealArray (x:y:xs) = (x, y) : dealArray xs

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

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

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

main = do
  n <- readLn
  a <- replicateM n getInts

  let
    b = or $ zipWith (\[a, b] [c, d] -> a < c && b > d) a' (tail a') where a' = sort a

  putStrLn $ if b then "Happy Alex" else "Poor Alex"

main = do
    n <- readLn :: IO Int
    res <- doWork n
    let restr = if res then "Happy" else "Poor"
    putStrLn (restr ++ " Alex")

doWork 0 = return False
doWork n = do
    inp <- getLine
    let (a:b:[]) = map (read::(String->Int)) $ words inp
    if a /= b then return True else doWork $ n-1

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

getSnd :: [(Int, Int)] -> [Int]
getSnd = map snd

solve' :: [(Int, Int)] -> B.ByteString
solve' ys
  | (getSnd $ sort ys) == (sort $ getSnd ys) = B.pack "Poor Alex"
  | otherwise = B.pack "Happy Alex"

main :: IO ()
main = do
  B.interact $ solve' . map parse . tail . B.lines

parse l = (read' a, read' b) where [a, b] = B.words l

read' bs = i where Just (i, _) = B.readInt bs

{-# LANGUAGE FlexibleContexts     #-}
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE OverlappingInstances #-}

module Main where

import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Lazy.Char8 as BS
import           Data.Function
import           Data.List
import           Data.Maybe
import           System.IO

solve :: [Int] -> [Int] -> String
solve price quality = get_state $ ((==) `on` process) price quality
  where
    process xs = map snd $ sort $ zip xs [1 ..]
    get_state False = "Happy Alex"
    get_state True  = "Poor Alex"

main :: IO ()
main = do
    getLine
    [as, bs] <- transpose . map (map fst . mapMaybe BS.readInt . BS.words) . BS.lines <$> BS.getContents
--    [as, bs] <- transpose . scan . BS.unpack <$> BS.getContents
    say $ solve as bs

say :: DS a => a -> IO ()
say = putStrLn . display

get :: DS a => IO a
get = scan <$> getLine

toNum :: Num a => Bool -> a
toNum False = 0
toNum True  = 1

class (Read a, Show a) => DS a where
    display :: a -> String
    scan :: String -> a
    display = show
    scan = read

instance DS String where
    display = id
    scan = id

instance DS [a] => DS [[a]] where
    display = unlines . map display
    scan = map scan . lines

instance DS a => DS [a] where
    display = unwords . map display
    scan = map scan . words

instance DS Int
instance DS Double

import Data.List
import Data.Tree
import Data.Int
import Data.Maybe
import Data.Char
import Data.Functor
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=   readsolveprint
readsolveprint::IO()
readsolveprint = getLine >>= \n -> (solve =<< forM [1..read n] ( \i -> map (fst.fromJust.C.readInteger).C.words<$>C.getLine))
solve xs = let [m11,m12]=maximumBy (\[a1,a2] [b1,b2] -> (a1 `compare` b1) `mappend` (a2 `compare` b2) ) xs
               [m21,m22]=maximumBy (\[a1,a2] [b1,b2] -> (a2 `compare` b2) `mappend` (b1 `compare` a1) ) xs  in if m22>m12 && m21<m11 then putStrLn  "Happy Alex" else putStrLn "Poor Alex"

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

process::Int->[[Int]]->String
process n q  | qq == (q!!1) = "Happy Alex"
             | otherwise = "Poor Alex"
  where qq = sort (q!!1)

main=do
    n<-read <$> getLine::IO Int
    q<- transpose <$> sort <$> map(map (fromIntegral. fst.fromJust.C.readInteger)) <$> map C.words <$> C.lines <$> C.getContents::IO [[Int]]
    putStrLn $ process n q

import Control.Applicative
import Data.List

process q  | x== [] = "NO"
           | otherwise = "YES"
  where x = take 1 [1|[i1,i2]<-q, [j1,j2]<-q , i1<j1, i2>j2]

main=do
    n<-getLine
    q<- map(map read) <$> map words <$> lines <$> getContents::IO [[Int]]
    putStrLn $ process q

main :: IO ()
main = getContents >>= print . solve . map read . words

solve :: [Int] -> Int
solve (_:m:as) = snd $ maximum [ ((a + m - 1) `div` m, i) | (i, a) <- zip [1..] as ]
solve _ = undefined

main :: IO ()
main = getContents >>= putStrLn . output . solve . map (map read . words) . tail . lines

solve :: [[Int]] -> Bool
solve ab = and [ b > b' | [ a, b ] <- ab, [ a', b' ] <- ab, a < a' ]

output :: Bool -> String
output True = "Happy Alex"
output _ = "Poor Alex"

import Data.List
import Data.Ord
import Control.Applicative

sortTuple :: [(Int, Int)] -> [(Int, Int)]
sortTuple = sortBy (comparing fst)

getSnd :: [(Int, Int)] -> [Int]
getSnd = map snd

solve :: [Int] -> String
solve (y:ys:[])
  | y > ys = "Happy Alex"
  | otherwise = "Poor ALex"
solve (y:ys:yss)
  | y > ys = "Happy Alex"
  | otherwise = solve (ys:yss)

main :: IO ()
main = do
  n <- readLn
  getInput n >>= putStrLn . solve . getSnd . sortTuple

getInput :: Int -> IO [(Int, Int)]
getInput 0 = return []
getInput n = do
  liftA2 (:) current next where
    current = getLine >>= return . (\xs -> (head xs, last xs)) . map read . words
    next = getInput (n-1)

import qualified Data.Sequence as Seq
import Data.Foldable

getIntSequence :: IO (Seq.Seq Integer)
getIntSequence = do
    list <- getLine
    return (Seq.fromList $ map read (words list))

getAnswer :: Seq.Seq Integer -> Seq.Seq Integer -> String
getAnswer prices qualities = if findQaulityLaptop $ toList $ getCounter prices qualities
                             then "Happy Alex"
                             else "Poor Alex"

findQaulityLaptop :: [Integer] -> Bool
findQaulityLaptop [x] = False
findQaulityLaptop (first:second:rest) = if first < second
                                        then findQaulityLaptop (second:rest)
                                        else True

emptySeq :: Integer -> Seq.Seq Integer
emptySeq n = Seq.fromList (take (fromIntegral n) (cycle [0]))

getCounter :: Seq.Seq Integer -> Seq.Seq Integer -> Seq.Seq Integer
getCounter prices qualities = _getCounter prices qualities (emptySeq n)
    where n = fromIntegral $ Seq.length prices

_getCounter :: Seq.Seq Integer -> Seq.Seq Integer -> Seq.Seq Integer -> Seq.Seq Integer
_getCounter prices qualities counter = if prices == Seq.empty
                                       then counter
                                       else _getCounter pricesTail qualitiesTail (Seq.update (fromIntegral index) value counter)
    where pricesTail = Seq.drop 1 prices
          qualitiesTail = Seq.drop 1 qualities
          index = (Seq.index prices 0) - 1
          value = Seq.index qualities 0

unpack :: Maybe Integer -> Integer
unpack Nothing = -1
unpack (Just x) = x

main :: IO ()
main = do
    n <- getLine
    prices <- getIntSequence
    qualities <- getIntSequence
    putStrLn $ getAnswer prices qualities

main = do
    n <- readLn :: IO Int
    res <- doWork n
    let restr = if res then "Happy" else "Poor"
    putStrLn (restr ++ " Alex")

doWork 0 = return True
doWork n = do
    inp <- getLine
    let (a:b:[]) = map (read::(String->Int)) $ words inp
    if a == b then return False else doWork $ n-1

{-# LANGUAGE FlexibleContexts     #-}
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE OverlappingInstances #-}

module Main where

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

solve :: [Int] -> [Int] -> String
solve price quality = get_state $ ((==) `on` process) price quality
  where
    process xs = map snd $ sort $ zip xs [1 ..]
    get_state False = "Happy Alex"
    get_state True  = "Poor Alex"

main :: IO ()
main = do
    n <- get
    [as, bs] <- replicateM n get
    say as
    say bs
    say $ solve as bs

say :: DS a => a -> IO ()
say = putStrLn . display

get :: DS a => IO a
get = scan <$> getLine

toNum :: Num a => Bool -> a
toNum False = 0
toNum True  = 1

class (Read a, Show a) => DS a where
    display :: a -> String
    scan :: String -> a
    display = show
    scan = read

instance {-# OVERLAPPING #-} DS String where
    display = id
    scan = id

instance {-# OVERLAPPING #-} DS [a] => DS [[a]] where
    display = unlines . map display
    scan = map scan . lines

instance DS a => DS [a] where
    display = unwords . map display
    scan = map scan . words

instance DS Int
instance DS Double


import Data.List (groupBy, sort)

main = do
	s <- getLine

	let
		ans = h ++ c ++ (reverse h)
			where

				cs = map (\l -> (head l, length l)) . groupBy (==) $ sort s

				es = filter (even . snd) cs
				os = filter (odd . snd) cs

				h = concat . map (\(a, c) -> replicate (c `div` 2) a) $ sort (es ++ os')
					where
						os' = filter (\(_, c) -> c > 0) . concat $ zipWith move os (reverse os)
							where
								move (a1, c1) (a2, c2)
									| a1 < a2 = [(a1, c1 + 1), (a2, c2 - 1)]
									| a1 == a2 = [(a1, c1 - 1)]
									| otherwise = []

				c = if odd l then [fst (os !! (l `div` 2))] else []
					where
						l = length os

	putStrLn ans

import Data.List (groupBy, sort)

main = do
	s <- getLine

	let
		ans = h ++ (if odd (length s) then [fst (os !! (length os `div` 2))] else []) ++ (reverse h)
			where

				cs = map (\l -> (head l, length l)) . groupBy (==) $ sort s

				es = filter (even . snd) cs
				os = filter (odd . snd) cs

				h = concat . map (\(a, c) -> replicate (c `div` 2) a) $ sort (es ++ os')
					where
						os' = filter (\(_, c) -> c > 0) . concat $ zipWith move os (reverse os)
							where
								move (a1, c1) (a2, c2)
									| a1 < a2 = [(a1, c1 + 1), (a2, c2 - 1)]
									| a1 == a2 = [(a1, c1 - 1)]
									| otherwise = []

	putStrLn ans

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

main = do
	str <- filter (not . isSpace) .  BS.unpack <$> BS.getContents
	let	freq :: UArray Char Int
		freq = accumArray (+) 0 ('a', 'z') [(c, 1) | c <- str]
	let toChange = map fst . filter (odd . snd) $ assocs freq;
		len = length toChange;
		new = [(c, 1) | c <- take (len `div` 2) toChange] ++ [(c, -1) | c <- take (len `div` 2) $ reverse toChange]
	let	freq' :: UArray Char Int
		freq' = accumArray (+) 0 ('a', 'z') $ (assocs freq) ++ new
	let newstr = concatMap (\(c, fr) -> replicate (fr `div` 2) c) $ assocs freq'
	putStrLn $ newstr ++ (maybe "" (return . fst) . find (odd . snd) $ assocs freq') ++ (reverse newstr)

import Control.Applicative
import Control.Arrow
import Data.Array.Unboxed
import Data.Char
import Data.Maybe
import Data.Function
import Data.List
import qualified Data.ByteString.Char8 as BS

main = do
	str <- filter (not . isSpace) .  BS.unpack <$> BS.getContents
	let	freq :: UArray Char Int
		freq = accumArray (+) 0 ('a', 'z') [(c, 1) | c <- str]
	let toChange' = filter (odd . snd) $ assocs freq;
		len = length toChange';
		toChange  = if even len then toChange' else delete (toChange' !! ((len `div` 2))) toChange';
		fs = ((++) `on` (replicate (len `div` 2))) (second (+ 1)) (second $ subtract 1);
		new = zipWith ($) fs toChange
	let	freq' :: UArray Char Int
		freq' = accumArray (flip const) 0 ('a', 'z') $ (assocs freq) ++ new
	let newstr = concatMap (\(c, fr) -> replicate (fr `div` 2) c) $ assocs freq'
	putStrLn $ newstr ++ ((if odd len then return $ fst . fromJust . find (odd . snd) $ assocs freq' else "") ++ (reverse newstr))

{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
import Data.Char (ord, chr)
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IM
import Data.Monoid ((<>))
import Data.Functor ((<$>))

changes :: IntMap Int -> IntMap Int -> (IntMap Int, IntMap Int)
changes evens odds
  | IM.size odds <= 1 = (evens, odds)
  | otherwise =
    let
      (min_x, min_c) = IM.findMin odds
      (max_x, max_c) = IM.findMax odds
      odds' = IM.delete max_x (IM.delete min_x odds)
      evens' | max_c > 1 = IM.insert max_x (max_c-1) evens
             | otherwise = evens
      evens'' = IM.insert min_x (min_c+1) evens'
    in
      changes evens'' odds'

makeHalf :: IntMap Int -> ByteString
makeHalf = IM.foldlWithKey' (\bs k x -> bs <> BS.replicate (x`div`2) (chr k)) BS.empty

makePalindrome :: (IntMap Int, IntMap Int) -> ByteString
makePalindrome (evens, odds)
  | IM.null odds = half <> flah
  | otherwise = half <> BS.singleton (chr ox) <> flah
  where
    (ox,oc) = IM.findMax odds
    evens' | IM.null odds = evens
           | oc > 1 = IM.insert ox (oc-1) evens
           | otherwise = evens
    half = makeHalf evens'
    flah = BS.reverse half

main :: IO ()
main = do
  wd <- head . BS.words <$> BS.getLine
  let counts = BS.foldl' (\t c -> IM.insertWith (\_ o -> o+1) (ord c) 1 t) IM.empty wd
  --print counts
  let (evens, odds) = IM.partition even counts
  --print evens
  --print odds
  let eos = changes evens odds
  let p = makePalindrome eos
  BS.putStrLn p

-- C. Make Palindrome

count :: Char -> String -> Int
count = (length .) . filter . (==)

countaz :: String -> [Int]
countaz = flip map ['a'..'z'] . flip count

change :: [Int] -> [Int]
-- change x = change' (length . filter odd $ x) x
change = change' =<< length . filter odd
    where change' :: Int -> [Int] -> [Int]
          change' _ []                = []
          change' k (h:t) | even h    = h : change' k t
                          | otherwise = case k of 0 -> h - 1 : change' 0       t
                                                  1 -> h     : change' 0       t
                                                  _ -> h + 1 : change' (k - 2) t

palindrom :: [Int] -> String
palindrom x = halfString x ++ oddString x ++ (reverse . halfString) x
    where string, halfString, oddString :: [Int] -> String
          string = concat . zipWith (flip replicate) ['a'..'z']
          halfString = string . map (`div` 2)
          oddString = string . map (`mod` 2)

solve :: String -> String
solve = palindrom . change . countaz

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

-- C. Make Palindrome

count :: Char -> String -> Int
count = (length .) . filter . (==)

countaz :: String -> [Int]
countaz = flip map ['a'..'z'] . flip count

change :: [Int] -> [Int]
change x = change' (length (filter odd x)) x
    where change' :: Int -> [Int] -> [Int]
          change' _ []                = []
          change' k (h:t) | even h    = h : change' k t
                          | otherwise = case k of 0 -> h - 1 : change' 0       t
                                                  1 -> h     : change' 0       t
                                                  _ -> h + 1 : change' (k - 2) t

azString :: [Int] -> String
azString = concat . zipWith (flip replicate) ['a'..'z']

palindrom :: [Int] -> String
palindrom x = azString (map (`div` 2) x) ++ azString (map (`mod` 2) x) ++ reverse (azString (map (`div` 2) x))

solve :: String -> String
solve = palindrom . change . countaz

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

--incerc sa portez solutia in haskell
import Data.List
import Data.Tuple
import Control.Monad
f x = ( snd x ) `mod` 2 == 1
g x = ( snd x ) `mod` 2 == 0

repl a b
	| fst a < fst b = [(fst a, snd a + 1), (fst b, snd b - 1)]
	| fst a == fst b = [(fst a, snd a - 1)]
	| otherwise = []

--multumesc stack overflow
repli (a,b) = replicate (b `div` 2) a

main = do
    x <- getLine
    --simuleaza map de frecventa
    let cs = map (\l -> (head l, length l)) . groupBy (\x y -> x == y) $ sortBy (\a b -> compare a b) x
    --let cs = sortBy (\a b -> compare a b) x
    --let cs = groupBy (\x y -> x == y) $ sort [1,2,3,2,1]
    let impare = filter f cs
    --let pare = filter (!f) cs nope nu merge
    let pare = filter g cs
    --indexul la map se face cu !!
    let mid = if odd (length impare) then [fst $ impare !! (length impare `div` 2)] else []
    let invers = reverse impare
    let delete_odds = zipWith repl impare invers
    let delete_zero = filter (\x -> snd x > 0) $ concat delete_odds
    let pare' = pare ++ delete_zero
    let pare_in_ordine = sort pare'
    let first_half = map repli pare_in_ordine
    --print first_half
    --print second_half
    let second_half = map repli $ reverse pare_in_ordine
    --print mid
    let answer = first_half ++ [mid] ++ second_half
    --let final = filter (/='0') . unwords answer
    let final = concat answer
    putStrLn final


main = do
	s <- getLine
	t <- getLine

	let
		answer = if l <= r then r - l else 0
			where
				l = find s t
				r = length t - (find (reverse s) (reverse t)) + 1

				find s t = find' s t 0
					where
						find' "" _ i = i
						find' _ "" i = i
						find' (c:s) (d:t) i =
							if c == d
								then find' s t (i + 1)
								else find' (c:s) t (i + 1)

	print answer

main :: IO()
main = do
    s <- getLine
    t <- getLine
    let f = solve succ 0 s t
        b = solve pred (1+length t) (reverse s) (reverse t)
    if or [b<f,b==0,f==0] then print 0 else print (b-f)
    --print [b,f,length t]

solve _ c [] _ = c
solve _ c _ [] = 0
solve d c (s:ss) (t:ts)
 |s==t = solve d (d c) ss ts
 |otherwise = solve d (d c) (s:ss) ts

import Control.Applicative
import Control.Monad
import Data.Function
import qualified Data.ByteString as B

gao :: B.ByteString -> B.ByteString -> Maybe Int
gao a b
  | B.null a = Just $ B.length b
  | B.null b || B.null b' = Nothing
  | otherwise = gao (B.tail a) (B.tail b')
  where
  b' = B.dropWhile (/= B.head a) b

main :: IO ()
main = do
  a <- chomp <$> B.getLine
  b <- chomp <$> B.getLine
  let n = B.length b
      x = gao a b
      y = (gao `on` B.reverse) a b
  print $ case liftM2 (\i j -> i + j - n) x y of
    Just k | k >= 0 -> k + 1
    _ -> 0
  where
  chomp s
    | B.null s || B.last s /= 13 = s
    | otherwise = B.init s

import Control.Monad
import Data.Function
import qualified Data.ByteString as B

gao :: B.ByteString -> B.ByteString -> Maybe Int
gao a b
  | B.null a = Just $ B.length b
  | B.null b = Nothing
  | otherwise = gao (B.tail a) $ B.tail $ B.dropWhile (/= B.head a) b

main :: IO ()
main = do
  a <- B.getLine
  b <- B.getLine
  let n = B.length b
      x = gao a b
      y = (gao `on` B.reverse) a b
  print $ case liftM2 (\i j -> i + j - n) x y of
    Just k | k >= 0 -> k + 1
    _ -> 0


import Data.List
import Data.Function
r2 = sum . map (^2)
(-.) = zipWith (-)
infixl 6 -.
ort a b = (0==) $ sum $ zipWith (*) a b
applyInv p a = map snd $ sort $ zip p a
solve (a:as) = take 1 [ (a :) $ applyInv p $ vs ++ us
 | p <- permutations [0..6],
   p!!0<p!!1, p!!1<p!!2,
   vs <- mapM permutations $ map (as!!) $ take 3 p,
   let ds = map ((-.) a) vs,
   (1==) $ length $ group $ map r2 ds,
   head vs /= a,
   ort (ds!!0) (ds!!1), ort (ds!!1) (ds!!2), ort (ds!!0) (ds!!2),
   let us = [a -. ds!!0 -. ds!!1, a -. ds!!0 -. ds!!2, a -. ds!!1 -. ds!!2, a -. ds!!0 -. ds!!1 -. ds!!2],
   ((==) `on` map sort) us $ map (as!!) $ drop 3 p
 ]

showA [] = "NO"
showA [ans] = "YES\n" ++ unlines (map (unwords . map show) ans)

main = interact $ showA . solve . map (map read . words) . lines

import Data.List
import Data.Ord
import Data.Int
import Prelude hiding(subtract)

distanceSq (x0, y0, z0) (x1, y1, z1) = (x0 - x1) ^ 2 + (y0 - y1) ^ 2 + (z0 - z1) ^ 2

dot (x0, y0, z0) (x1, y1, z1) = x0 * x1 + y0 * y1 + z0 * z1

subtract (x0, y0, z0) (x1, y1, z1) = (x0 - x1, y0 - y1, z0 - z1)
add (x0, y0, z0) (x1, y1, z1) = (x0 + x1, y0 + y1, z0 + z1)

genCube p va vb vc = map (foldr add p) (subsequences [va,vb,vc])

isCube :: [(Int64, Int64, Int64)] -> Bool
isCube (p : ps) =
  distanceSq p a > 0
  && distanceSq p a == distanceSq p b && distanceSq p c == distanceSq p a
  && dot va vb == 0 && dot vb vc == 0 && dot va vc == 0
  && sort (genCube p va vb vc) == sort (p : ps)
 where
  va = subtract a p
  vb = subtract b p
  vc = subtract c p
  (a : b : c : _) = sortBy (comparing $ distanceSq p) ps

s :: [[Int64]] -> [[[Int64]]]
s (p : ps) = do
  ps' <- mapM permutations ps
  let ps'' = map (\[x,y,z] -> (x,y,z)) (p : ps')
  if isCube ps'' then [p : ps'] else []

p :: [[[Int64]]] -> String
p [] = "NO"
p (s : _) = unlines $ "YES" : map (unwords . map show) s

main = interact $ p . s . map (map read . words) . lines

import Data.List
import GHC.Exts
r2 = sum . map (^2)
(+.) = zipWith (+)
ort a b = (0==) $ sum $ zipWith (*) a b
isCube0 as@(a:b:c:rest) =  r2 a == r2 b && r2 b == r2 c && r2 a > 0 &&
   ort a b && ort a c && ort b c &&
   sort rest == sort [a+.b,a+.c,b+.c,a+.b+.c]
isCube (a:as) = isCube0 $ sortWith r2 $ map (zipWith (-) a) as
solve ::[[Int]]->[[[Int]]]
solve = filter isCube . take (6^7) . mapM permutations

showA [] = "NO"
showA (ans:_) = unlines $ "YES" : map (unwords . map show) ans

main = interact $ showA . solve . map (map read . words) . lines

import Data.List
import Data.Ord
import Data.Int
import Prelude hiding(subtract)

distanceSq (x0, y0, z0) (x1, y1, z1) = (x0 - x1) ^ 2 + (y0 - y1) ^ 2 + (z0 - z1) ^ 2

dot (x0, y0, z0) (x1, y1, z1) = x0 * x1 + y0 * y1 + z0 * z1

subtract (x0, y0, z0) (x1, y1, z1) = (x0 - x1, y0 - y1, z0 - z1)
add (x0, y0, z0) (x1, y1, z1) = (x0 + x1, y0 + y1, z0 + z1)

genCube p va vb vc = map (foldr add p) (subsequences [va,vb,vc])

isCube :: [(Int64, Int64, Int64)] -> Bool
isCube (p : ps)
  | (distanceSq p a == distanceSq p b) && (distanceSq p c == distanceSq p a)
    && (dot va vb == 0) && (dot vb vc == 0) && dot va vc == 0
    =
      sort (genCube p va vb vc) == sort (p : ps)
  | otherwise = False
    where
  va = subtract a p
  vb = subtract b p
  vc = subtract c p
  (a : b : c : _) = sortBy (comparing $ distanceSq p) ps

s :: [[Int64]] -> [[[Int64]]]
s (p : ps) = do
  ps' <- mapM permutations ps
  let ps'' = map (\[x,y,z] -> (x,y,z)) (p : ps')
  if isCube ps'' then [p : ps'] else []

p :: [[[Int64]]] -> String
p [] = "NO"
p (s : _) = unlines $ "YES" : map (unwords . map show) s

main = interact $ p . s . map (map read . words) . lines

import Data.List
import Data.Ord
import Prelude hiding(subtract)

distanceSq (x0, y0, z0) (x1, y1, z1) = (x0 - x1) ^ 2 + (y0 - y1) ^ 2 + (z0 - z1) ^ 2

dot (x0, y0, z0) (x1, y1, z1) = x0 * x1 + y0 * y1 + z0 * z1

subtract (x0, y0, z0) (x1, y1, z1) = (x0 - x1, y0 - y1, z0 - z1)
add (x0, y0, z0) (x1, y1, z1) = (x0 + x1, y0 + y1, z0 + z1)

genCube p va vb vc = map (foldr add p) (subsequences [va,vb,vc])

isCube :: [(Int, Int, Int)] -> Bool
isCube (p : ps)
  | (distanceSq p a == distanceSq p b) && (distanceSq p c == distanceSq p a)
    && (dot va vb == 0) && (dot vb vc == 0) && dot va vc == 0
    =
      sort (genCube p va vb vc) == sort (p : ps)
  | otherwise = False
    where
  va = subtract a p
  vb = subtract b p
  vc = subtract c p
  (a : b : c : _) = sortBy (comparing $ distanceSq p) ps

s :: [[Int]] -> [[[Int]]]
s (p : ps) = do
  ps' <- mapM permutations ps
  let ps'' = map (\[x,y,z] -> (x,y,z)) (p : ps')
  if isCube ps'' then [p : ps'] else []

p :: [[[Int]]] -> String
p [] = "NO"
p (s : _) = unlines $ "YES" : map (unwords . map show) s

main = interact $ p . s . map (map read . words) . lines


import Data.List
import Data.Int
import Data.Char
import Control.Monad
import Data.Bits

readArray :: IO [Int64]
readArray = do
    line <- getLine
    return $ map (read::String->Int64) $ words line

readInt :: IO Int64
readInt = do
    line <- getLine
    return $ (read::String->Int64) $ line

f :: Int64 -> Int64 -> Int64
f curPower xLeft =
  let s = (curPower) * (curPower - 1) `div` 2 in
  if s > xLeft then 0 else 1 + f (curPower * 2) (xLeft - s)

solve :: IO ()
solve = do
    n <- readInt
    print $ f 2 n

main :: IO ()
main = do
    t <- readInt
    forM_ [0..t-1] $ (\i -> solve)

import Control.Monad

size :: Integer -> Integer
size n = div (n * (n+1)) 2

nices :: [Integer]
nices = iterate (\x -> 2*x + 1) 1

solve :: Integer -> Integer
solve = go 0 nices  where
  go k (tar:tars) tot = case  tot - size tar  of
    v | v < 0  -> k
      | True   -> go (k+1) tars v
  go _ _ _ = error "nices is finite???"

main :: IO ()
main = do
  t <- read <$> getLine
  replicateM_ t $ do
    x <- read <$> getLine
    print $ solve x

{- This code was written by
Russell Emerine - linguist,
mathematician, coder,
musician, and metalhead. -}
import Control.Monad

main = getLine >>= flip replicateM_ test . read

test = do
  n <- read <$> getLine
  print $ solve 1 n

solve 100 _ = 0
solve _ 0 = 0
solve p n
  | c <= n = 1 + solve (succ p) (n - c)
  | otherwise = solve (succ p) n
  where
    d = 2 ^ p - 1
    c = (d * (d + 1)) `div` 2

import Control.Monad
main :: IO ()
main = do
  n <- readLn
  replicateM_ n routine

routine :: IO ()
routine = do
  n <- readLn
  print $ solve n

solve :: Integer -> Integer
solve n = (\x -> x-1) $ snd $ head $ filter (\x ->fst x>n) $ zip liste2 [1..]

f :: Integer -> Integer
f n = ((2^n)-1)*(2^(n-1))

liste :: [Integer]
liste = map f [1..]

liste2 :: [Integer]
liste2 = scanl1 (+) liste

{- This code was written by
Russell Emerine - linguist,
mathematician, coder,
musician, and metalhead. -}
import Control.Monad

main = getLine >>= flip replicateM_ test . read

test = do
  n <- read <$> getLine
  print $ solve 100 n

solve 0 _ = 0
solve _ 0 = 0
solve p n
  | c <= n = 1 + solve (pred p) (n - c)
  | otherwise = solve (pred p) n
  where
    d = 2 ^ p - 1
    c = (d * (d + 1)) `div` 2

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

readArray :: IO [Int]
readArray = do
    line <- getLine
    return $ map (read::String->Int) $ words line

readInt :: IO Int
readInt = do
    line <- getLine
    return $ (read::String->Int) $ line

f :: Int -> Int -> Int
f curPower xLeft =
  let s = (curPower) * (curPower - 1) `div` 2 in
  if s > xLeft then 0 else 1 + f (curPower * 2) (xLeft - s)

solve :: IO ()
solve = do
    n <- readInt
    print $ f 2 n

main :: IO ()
main = do
    t <- readInt
    forM_ [0..t-1] $ (\i -> solve)


gcdOfList :: [Int]->Int
gcdOfList x = case x of [] -> 0
                        (x : xs) -> gcd x (gcdOfList xs)

solve :: String->Int->String
solve s n =
  if rem ( (div ma g) - n) 2 == 0 then "Bob" else "Alice"
  where a = map (read :: String->Int) (words s)
        ma = maximum a
        g = gcdOfList a

main = do
  n <- getLine
  s <- getLine
  putStrLn $ solve s ((read :: String->Int)  n)

import Control.Monad

main = do
  n <- liftM read getLine :: IO Int
  xs <- liftM (map read . words) getLine :: IO [Int]
  let moves = maximum xs `div` foldl1 gcd xs - n
  putStrLn (if moves `mod` 2 == 1 then "Alice" else "Bob")

module Main where

import Control.Applicative
import Data.List

data Person = Alice | Bob deriving (Eq, Show)

main = do
    n <- read <$> getLine
    ns <- map read <$> words <$> getLine
    print $ solve' n ns--solve n [] ns

solve' :: Int -> [Int] -> Person
solve' n xs =
    let g = foldl1 (\a b -> gcd a b) xs
    in if odd (maximum (map (`div`g) xs) - n)
       then Alice
       else Bob

solve :: Int -> [Int] -> [Int] -> Person
solve n xs [] = if odd $ (length xs - n)
                then Alice
                else Bob
solve n xs ys =
    let newXs = ys ++ xs
        newYs = (nub $ concat $ map (\y -> nub $ filter (/=0) $ map (\x -> abs (x-y) ) newXs) ys ) \\ newXs
    in  solve n newXs newYs

import Data.List

ans xs= let l=m`div`g-(length xs) in if odd l then "Alice" else "Bob"
    where g=foldl1 gcd xs
          m=maximum xs
main = do
    m<-getLine
    n<-getLine
    let input = map read$ words n
    putStrLn $ ans input

import Control.Monad

main = do
	n <- readLn :: IO Int
	a <- (map read . words) `liftM` getLine :: IO [Int]
	putStrLn$ ["Bob", "Alice"]!!(mod (div (foldr1 max a) (foldr1 gcd a) - n) 2)

{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes #-}

import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace

import Data.List
import Data.Int
import Data.Maybe
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

readInt = B.readInt >>> fmap fst >>> fromMaybe 0
readsInt = map readInt . B.words <$> B.getLine
readLine :: Read a => IO a
readLine = read <$> getLine
readsLine :: Read a => IO [a]
readsLine = map read . words <$> getLine

cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b

swap (a,b) = (b,a)
rect a b = rect2 0 0 a b
rect2 i j a b = ((i,j),(a,b))

itof :: Int -> Double
itof = fromIntegral
casti = fromIntegral

maximize f l = snd $ maximumBy cmpFst [(f x,x) | x <- l]
minimize f l = snd $ minimumBy cmpFst [(f x,x) | x <- l]

infixr 2 <||>
infixr 3 <&&>
p1 <||> p2 = (p1 &&& p2) >>> uncurry (||)
p1 <&&> p2 = (p1 &&& p2) >>> uncurry (&&)

main = do
    n <- readLine
    l <- readsLine
    putStrLn $ if solve n l then "Alice" else "Bob"

solve :: Int -> [Int] -> Bool
solve n l = odd (a - length l)
    where
    d = foldl1 gcd l
    m = maximum l
    a = m `div` d

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

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

solve :: [Int] -> String
solve xs
  | odd (max' `div` gcd' - n)  =  "Alice"
  | otherwise  =  "Bob"
  where
    n  =  length xs
    max'  =  maximum xs
    gcd'  =  foldl1 gcd xs

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

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

main :: IO ()
main = do
  n <- fmap read getLine :: IO Int
  as <- fmap ((fmap read) . words) getLine :: IO [Int]
  let d = foldr1 gcd as
  let r = even $ (div (maximum as) d)-n
  putStr $ if r then "Bob" else "Alice"

module Main where

import Control.Applicative
import Data.List

data Person = Alice | Bob deriving (Eq, Show)

main = do
    n <- read <$> getLine
    ns <- map read <$> words <$> getLine
    print $ solve n ns--solve n [] ns

solve :: Int -> [Int] -> Person
solve n xs =
    let g = foldl1 (\a b -> gcd a b) xs
    in if odd (maximum (map (`div`g) xs) - n)
       then Alice
       else Bob

gcd_ :: Int -> Int -> Int
gcd_ x y = if y == 0 then x else gcd y (x `rem` y)

main = do
  n <- readLn :: IO Int
  line <- getLine
  let
    a = map (read :: String -> Int) $ words line
    d = foldl1 gcd_ a
    m = maximum $ map (\x -> x `div` d) a
    in putStrLn $ if (n - m) `rem` 2 /= 0 then "Alice" else "Bob"

---------------------Import--------------------------- {{{
import Data.List
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Char
import Data.Ratio                                   -- x = 5%6
import Data.Bits                                    -- (.&.), (.|.), shiftL...
import Text.Printf                                  -- printf "%0.6f" (1.0)
import qualified Data.ByteString.Char8 as BS-- }}}

---------------------Input---------------------------- {{{
getInteger = (\(Just (x,_)) -> x). BS.readInteger
getInt = (\(Just (x,_)) -> x). BS.readInt

getIntArray = readIntArray
getIntegerArray = readIntegerArray

readIntArray input =
  case x of
    Just (a, xs) -> a : readIntArray xs
    Nothing -> []
  where
   x = BS.readInt. BS.dropWhile isSpace $ input

readIntegerArray input =
  case x of
    Nothing -> []
    Just (y, ys) -> y : readIntegerArray ys
  where
    x = BS.readInteger. BS.dropWhile isSpace $ input
------------------------------------------------------ }}}

main :: IO ()
main = BS.getContents >>= putStrLn. (["Bob", "Alice"]!!). fromIntegral .(`mod` 2).solve. tail. readIntegerArray
  where
  solve xs = (maximum xs ) `div` g - fromIntegral (length xs)
    where
      g = gcd' xs
      gcd' :: [Integer] -> Integer
      gcd' (a:as) = foldl' (gcd) a as

gcdlist :: [Int] -> Int
gcdlist (x : y : xs) = gcdlist ((gcd x y) : xs)
gcdlist (x : []) = x

main = do
	rawn <- getLine
	rawinput <- getLine
	let n = read rawn :: Int
	let input = map read (words rawinput) :: [Int]
	putStr $ if (odd ((div (maximum input) (gcdlist input)) - n)) then "Alice" else "Bob"

module Main where

import Control.Applicative
import Data.List

data Person = Alice | Bob deriving (Eq, Show)

main = do
    n <- read <$> getLine
    ns <- map read <$> words <$> getLine
    print $ solve' n ns--solve n [] ns

solve' :: Int -> [Int] -> Person
solve' n xs = if odd (maximum xs - n)
              then Alice
              else Bob

solve :: Int -> [Int] -> [Int] -> Person
solve n xs [] = if odd $ (length xs - n)
                then Alice
                else Bob
solve n xs ys =
    let newXs = ys ++ xs
        newYs = (nub $ concat $ map (\y -> nub $ filter (/=0) $ map (\x -> abs (x-y) ) newXs) ys ) \\ newXs
    in  solve n newXs newYs

import Data.List

ans xs= let l=m-(length xs) in if odd l then "Alice" else "Bob"
    where m=maximum xs
main = do
    m<-getLine
    n<-getLine
    let input = map (\x->read x::Int) $ words n
    putStrLn $ ans input

gcdlist :: [Int] -> Int
gcdlist (x : y : xs) = gcdlist ((gcd x y) : xs)
gcdlist (x : []) = x

main = do
	rawn <- getLine
	rawinput <- getLine
	let n = read rawn :: Int
	let input = map read (words rawinput) :: [Int]
	putStr $ if (odd ((div (maximum input) (gcdlist input)) - n)) then "Bob" else "Alice"

import Data.List

getdelts :: [Int] -> [Int]
getdelts a = [abs (x - y) | x <- a, y <- a]

main = do
	n <- getLine
	numbers <- getLine
	putStr $ (if (odd (length $ group $ sort $ getdelts (map read (words numbers) :: [Int]))) then "Bob" else "Alice")

import Data.List

getdelts :: [Int] -> [Int]
getdelts a = [abs (x - y) | x <- a, y <- a, x /= y]

main = do
	n <- getLine
	numbers <- getLine
	putStr $ (if (odd (length $ group $ sort $ getdelts (map read (words numbers) :: [Int]))) then "Alice" else "Bob")


{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Control.Monad.ST.Safe (ST, runST)
import Data.Array.ST.Safe (STUArray)
import Data.Array (array, elems)
import Data.Array.IArray (listArray, (!))
import Data.Array.MArray.Safe (getBounds, readArray, writeArray, newArray)
import Data.Bits
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import Data.List (sort)
import Data.Array.Unboxed (UArray)
import Prelude hiding (words, lines, getLine, getContents)

type Fenwick s = STUArray s Int Int

fenwick l = newArray (0, l-1) 0 :: ST s (Fenwick s)

update f i d = do
  l <- snd <$> getBounds f

  let
    update' i
      | i <= l = do
        readArray f i >>= \v -> writeArray f i (v+d)
        update' (i .|. (i+1))
      | otherwise = return ()

  update' i

query f i = do
  let
    query' (-1) s = return s
    query' i s = do
      v <- readArray f i
      query' ((i .&. (i+1)) - 1) (s + v)

  query' i 0

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

main = do
  [n] <- readInts
  ss <- replicateM n ((\[a, b] -> (a, b)) <$> readInts)

  let
    rs = listArray (1, n) $ sort $ map snd ss :: UArray Int Int
    ss' = sort $ zip ss [1..]

    lookup x = lookup' 1 n
      where
        lookup' l r
          | v == x = m
          | v < x = lookup' (m+1) r
          | otherwise = lookup' l m
          where
            m = (l+r) `div` 2
            v = rs ! m

    cs = runST $ do
      t <- fenwick n

      let
        count [] = return []
        count (((l, r), i):ss) = do
          let j = lookup r
          c <- query t (j-1)
          update t j 1
          cs <- count ss
          return ((i, c):cs)

      count $ reverse ss'

  putStr . unlines . map show . elems $ array (1, n) cs

{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (array, elems)
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import qualified Data.Set as Set
import Data.List (sort)
import Prelude hiding (words, lines, getLine, getContents)
import System.Random

import Control.Monad (when)
import Control.Monad.ST.Safe (ST, runST)
import Data.Array (elems)
import Data.Array.MArray.Safe (getElems, newListArray, readArray, writeArray)
import Data.Array.ST.Safe (STArray, runSTArray)
import Data.STRef (newSTRef, readSTRef, writeSTRef, modifySTRef)
import Data.Ord (comparing)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

qsort gen xs = elems $ runSTArray $ do
    let n = length xs
    a <- newListArray (1, n) xs
    gr <- newSTRef gen

    let sort' l r = when (l < r) $ do
        g <- readSTRef gr
        let (x, g') = randomR (l, r-1) g
        writeSTRef gr g'

        s <- readArray a x

        let loop i j
              | i > j = return (i, j)
              | otherwise = do
                ai <- readArray a i
                aj <- readArray a j
                case () of
                  _ | ai < s -> loop (i+1) j
                    | aj > s -> loop i (j-1)
                    | otherwise -> do
                        writeArray a i aj
                        writeArray a j ai
                        loop (i+1) (j-1)

        (i, j) <- loop l r

        sort' l j
        sort' i r

    sort' 1 n
    return a

data T = T Int Int Int
instance Ord T where (T a _ _) <= (T b _ _) = a >= b
instance Eq T where (T a _ _) == (T b _ _) = a == b

main = do
  [n] <- readInts
  rs <- replicateM n readInts
  gen <- newStdGen

  let
    rs' = qsort gen $ zipWith (\[l, r] i -> T l r i) rs [1..]

    count [] _ = []
    count ((T l r i):rs) set = (i, c):(count rs (r `Set.insert` set))
      where
        c = Set.size . fst $ r `Set.split` set

  putStr . unlines . map show . elems . array (1, n) $ count (rs') Set.empty

{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (array, elems)
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import qualified Data.Set as Set
import Data.List (sort)
import Prelude hiding (words, lines, getLine, getContents)
import System.Random

import Control.Monad (when)
import Control.Monad.ST.Safe (ST, runST)
import Data.Array (elems)
import Data.Array.MArray.Safe (getElems, newListArray, readArray, writeArray)
import Data.Array.ST.Safe (STArray, runSTArray)
import Data.STRef (newSTRef, readSTRef, writeSTRef, modifySTRef)
import Data.Ord (comparing)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

qsort gen xs = elems $ runSTArray $ do
    let n = length xs
    a <- newListArray (1, n) xs
    gr <- newSTRef gen

    let sort' l r = when (l < r) $ do
        g <- readSTRef gr
        let (x, g') = randomR (l, r-1) g
        writeSTRef gr g'

        s <- readArray a x

        let loop i j
              | i > j = return (i, j)
              | otherwise = do
                ai <- readArray a i
                aj <- readArray a j
                case () of
                  _ | ai < s -> loop (i+1) j
                    | aj > s -> loop i (j-1)
                    | otherwise -> do
                        writeArray a i aj
                        writeArray a j ai
                        loop (i+1) (j-1)

        (i, j) <- loop l r

        sort' l j
        sort' i r

    sort' 1 n
    return a

data T = T !Int !Int !Int
instance Ord T where (T a _ _) <= (T b _ _) = a >= b
instance Eq T where (T a _ _) == (T b _ _) = a == b

main = do
  [n] <- readInts
  rs <- replicateM n readInts
  gen <- newStdGen

  let
    rs' = sort $ zipWith (\[l, r] i -> T l r i) rs [1..]

    count [] _ = []
    count ((T l r i):rs) set = (i, c):(count rs (r `Set.insert` set))
      where
        c = Set.size . fst $ r `Set.split` set

  putStr . unlines . map show . elems . array (1, n) $ count (rs') Set.empty

{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (array, elems)
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import qualified Data.Set as Set
import Data.List (sort)
import Prelude hiding (words, lines, getLine, getContents)
import System.Random

import Control.Monad (when)
import Control.Monad.ST.Safe (ST, runST)
import Data.Array (elems)
import Data.Array.MArray.Safe (getElems, newListArray, readArray, writeArray)
import Data.Array.ST.Safe (STArray, runSTArray)
import Data.STRef (newSTRef, readSTRef, writeSTRef, modifySTRef)
import Data.Ord (comparing)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

qsort gen xs = elems $ runSTArray $ do
    let n = length xs
    a <- newListArray (1, n) xs
    gr <- newSTRef gen

    let sort' l r = when (l < r) $ do
        g <- readSTRef gr
        let (x, g') = randomR (l, r-1) g
        writeSTRef gr g'

        s <- readArray a x

        let loop i j
              | i > j = return (i, j)
              | otherwise = do
                ai <- readArray a i
                aj <- readArray a j
                case () of
                  _ | ai < s -> loop (i+1) j
                    | aj > s -> loop i (j-1)
                    | otherwise -> do
                        writeArray a i aj
                        writeArray a j ai
                        loop (i+1) (j-1)

        (i, j) <- loop l r

        sort' l j
        sort' i r

    sort' 1 n
    return a

data T = T !Int !Int !Int
instance Ord T where (T a _ _) <= (T b _ _) = a >= b
instance Eq T where (T a _ _) == (T b _ _) = a == b

main = do
  [n] <- readInts
  rs <- replicateM n readInts
  gen <- newStdGen

  let
    rs' = qsort gen $ zipWith (\[l, r] i -> T l r i) rs [1..]

    count [] _ = []
    count ((T l r i):rs) set = (i, c):(count rs (r `Set.insert` set))
      where
        c = Set.size . fst $ r `Set.split` set

  putStr . unlines . map show . elems . array (1, n) $ count (rs') (Set.empty)

{-# tle 39 #-}
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (array, elems)
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import qualified Data.Set as Set
import Data.List (sort)
import Prelude hiding (words, lines, getLine, getContents)
import System.Random

import Control.Monad (when)
import Control.Monad.ST.Safe (ST, runST)
import Data.Array (elems)
import Data.Array.MArray.Safe (getElems, newListArray, readArray, writeArray)
import Data.Array.ST.Safe (STArray, runSTArray)
import Data.STRef (newSTRef, readSTRef, writeSTRef, modifySTRef)
import Data.Ord (comparing)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

qsort gen xs = elems $ runSTArray $ do
    let n = length xs
    a <- newListArray (1, n) xs
    gr <- newSTRef gen

    let sort' l r = when (l < r) $ do
        s <- readArray a $ (l + r) `div` 2

        let loop i j
              | i > j = return (i, j)
              | otherwise = do
                ai <- readArray a i
                aj <- readArray a j
                case () of
                  _ | ai < s -> loop (i+1) j
                    | aj > s -> loop i (j-1)
                    | otherwise -> do
                        writeArray a i aj
                        writeArray a j ai
                        loop (i+1) (j-1)

        (i, j) <- loop l r

        sort' l j
        sort' i r

    sort' 1 n
    return a

data T = T !Int !Int !Int
instance Ord T where (T a _ _) <= (T b _ _) = a >= b
instance Eq T where (T a _ _) == (T b _ _) = a == b

main = do
  [n] <- readInts
  rs <- replicateM n readInts
  gen <- newStdGen

  let
    rs' = qsort gen $ zipWith (\[l, r] i -> T l r i) rs [1..]

    count [] _ = []
    count ((T l r i):rs) set = (i, c):(count rs (r `Set.insert` set))
      where
        c = Set.size . fst $ r `Set.split` set

  putStr . unlines . map show . elems . array (1, n) $ count (rs') (Set.empty)

{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Control.Monad.ST.Safe (ST, runST)
import Data.Array.ST.Safe (STUArray)
import Data.Array (array, elems)
import Data.Array.IArray (listArray, (!))
import Data.Array.MArray.Safe (getBounds, readArray, writeArray, newArray)
import Data.Bits
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import Data.List (sort)
import Data.Array.Unboxed (UArray)
import Prelude hiding (words, lines, getLine, getContents)

type Fenwick s = STUArray s Int Int

fenwick l = newArray (0, l-1) 0 :: ST s (Fenwick s)

update f i d = do
  l <- snd <$> getBounds f

  mapM (\i -> readArray f i >>= \v -> writeArray f i (v+d)) $
    takeWhile (<= l) $ iterate (\i -> i .|. (i+1)) i

query f i = sum <$> (mapM (readArray f) $ takeWhile (>= 0) $ iterate (\i -> (i .&. (i+1))-1) i)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

main = do
  [n] <- readInts
  ss <- replicateM n ((\[a, b] -> (a, b)) <$> readInts)

  let
    rs = listArray (1, n) $ sort $ map snd ss :: UArray Int Int
    ss' = sort $ zip ss [1..]

    lookup x = lookup' 1 n
      where
        lookup' l r
          | v == x = m
          | v < x = lookup' (m+1) r
          | otherwise = lookup' l m
          where
            m = (l+r) `div` 2
            v = rs ! m

    cs = runST $ do
      t <- fenwick n

      let
        count [] = return []
        count (((l, r), i):ss) = do
          let j = lookup r
          c <- query t (j-1)
          update t j 1
          cs <- count ss
          return ((i, c):cs)

      count $ reverse ss'

  putStr . unlines . map show . elems $ array (1, n) cs

{-# tle 39 #-}
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (array, elems)
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import qualified Data.Set as Set
import Data.List (sort)
import Prelude hiding (words, lines, getLine, getContents)
import System.Random

import Control.Monad (when)
import Control.Monad.ST.Safe (ST, runST)
import Data.Array (elems)
import Data.Array.MArray.Safe (getElems, newListArray, readArray, writeArray)
import Data.Array.ST.Safe (STArray, runSTArray)
import Data.STRef (newSTRef, readSTRef, writeSTRef, modifySTRef)
import Data.Ord (comparing)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

qsort gen xs = elems $ runSTArray $ do
    let n = length xs
    a <- newListArray (1, n) xs
    gr <- newSTRef gen

    let sort' l r = when (l < r) $ do
        s <- readArray a $ (l + r) `div` 2

        let loop i j
              | i > j = return (i, j)
              | otherwise = do
                ai <- readArray a i
                aj <- readArray a j
                case () of
                  _ | ai < s -> loop (i+1) j
                    | aj > s -> loop i (j-1)
                    | otherwise -> do
                        writeArray a i aj
                        writeArray a j ai
                        loop (i+1) (j-1)

        (i, j) <- loop l r

        sort' l j
        sort' i r

    sort' 1 n
    return a

data T = T !Int !Int !Int
instance Ord T where (T a _ _) <= (T b _ _) = a >= b
instance Eq T where (T a _ _) == (T b _ _) = a == b

main = do
  [n] <- readInts
  rs <- replicateM n readInts

  let
    rs' = sort $ zipWith (\[l, r] i -> T l r i) rs [1..]

    count [] _ = []
    count ((T l r i):rs) set = (i, c):(count rs (r `Set.insert` set))
      where
        c = Set.size . fst $ r `Set.split` set

  putStr . unlines . map show . elems . array (1, n) $ count (rs') (Set.empty)

{-# OPTIONS_GHC -O2 #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (array, elems)
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import qualified Data.Set as Set
import Data.List (sort)
import Prelude hiding (words, lines, getLine, getContents)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

main = do
  [n] <- readInts
  rs <- replicateM n ((\[a, b] -> (a, b)) <$> readInts)

  let
    rs' = sort $ zip rs [1..]

    count [] _ = []
    count (((l, r),i):rs) set = (c - 1):(count rs (r `Set.delete` set))
      where
        c = Set.size . fst $ (r+1) `Set.split` set

  putStr . unlines . map show . elems . array (1, n) $ zip [1..] (count rs' (Set.fromList $ map snd rs))

{-# tle 39 #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (array, elems)
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import qualified Data.Set as Set
import Data.List (sortBy)
import Prelude hiding (words, lines, getLine, getContents)
import System.Random

import Control.Monad (when)
import Control.Monad.ST.Safe (ST, runST)
import Data.Array (elems)
import Data.Array.MArray.Safe (getElems, newListArray, readArray, writeArray)
import Data.Array.ST.Safe (STArray, runSTArray)
import Data.STRef (newSTRef, readSTRef, writeSTRef, modifySTRef)
import Data.Ord (comparing)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

qsort gen xs = elems $ runSTArray $ do
    let n = length xs
    a <- newListArray (1, n) xs
    gr <- newSTRef gen

    let sort' l r = when (l < r) $ do
        s <- readArray a $ (l + r) `div` 2

        let loop i j
              | i > j = return (i, j)
              | otherwise = do
                ai <- readArray a i
                aj <- readArray a j
                case () of
                  _ | ai < s -> loop (i+1) j
                    | aj > s -> loop i (j-1)
                    | otherwise -> do
                        writeArray a i aj
                        writeArray a j ai
                        loop (i+1) (j-1)

        (i, j) <- loop l r

        sort' l j
        sort' i r

    sort' 1 n
    return a

main = do
  [n] <- readInts
  rs <- replicateM n ((\[a, b] -> (a, b)) <$> readInts)

  let
    rs' = sortBy (comparing (\a -> - fst (fst a))) $ zip rs [1..]

    count [] _ = []
    count (((l, r),i):rs) set = (i, c):(count rs (r `Set.insert` set))
      where
        c = Set.size . fst $ r `Set.split` set

  putStr . unlines . map show . elems . array (1, n) $ count (reverse rs') (Set.empty)

{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (array, elems)
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import qualified Data.Set as Set
import Data.List (sort)
import Prelude hiding (words, lines, getLine, getContents)
import System.Random

import Control.Monad (when)
import Control.Monad.ST.Safe (ST, runST)
import Data.Array (elems)
import Data.Array.MArray.Safe (getElems, newListArray, readArray, writeArray)
import Data.Array.ST.Safe (STArray, runSTArray)
import Data.STRef (newSTRef, readSTRef, writeSTRef, modifySTRef)
import Data.Ord (comparing)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

qsort gen xs = elems $ runSTArray $ do
    let n = length xs
    a <- newListArray (1, n) xs
    gr <- newSTRef gen

    let sort' l r = when (l < r) $ do
        g <- readSTRef gr
        let (x, g') = randomR (l, r-1) g
        writeSTRef gr g'

        s <- readArray a x

        let loop i j
              | i > j = return (i, j)
              | otherwise = do
                ai <- readArray a i
                aj <- readArray a j
                case () of
                  _ | ai < s -> loop (i+1) j
                    | aj > s -> loop i (j-1)
                    | otherwise -> do
                        writeArray a i aj
                        writeArray a j ai
                        loop (i+1) (j-1)

        (i, j) <- loop l r

        sort' l j
        sort' i r

    sort' 1 n
    return a

data T = T Int Int Int
instance Ord T where (T a _ _) <= (T b _ _) = a >= b
instance Eq T where (T a _ _) == (T b _ _) = a == b

main = do
  [n] <- readInts
  rs <- replicateM n readInts
  gen <- newStdGen

  let
    rs' = sort $ zipWith (\[l, r] i -> (l, r, i)) rs [1..]

    count [] _ = []
    count ((l, r, i):rs) set = (i, c):(count rs (r `Set.insert` set))
      where
        c = Set.size . fst $ r `Set.split` set

  putStr . unlines . map show . elems . array (1, n) $ count (rs') Set.empty

{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (array, elems)
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import qualified Data.Set as Set
import Data.List (sort)
import Prelude hiding (words, lines, getLine, getContents)
import System.Random

import Control.Monad (when)
import Control.Monad.ST.Safe (ST, runST)
import Data.Array (elems)
import Data.Array.MArray.Safe (getElems, newListArray, readArray, writeArray)
import Data.Array.ST.Safe (STArray, runSTArray)
import Data.STRef (newSTRef, readSTRef, writeSTRef, modifySTRef)
import Data.Ord (comparing)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

qsort gen xs = elems $ runSTArray $ do
    let n = length xs
    a <- newListArray (1, n) xs
    gr <- newSTRef gen

    let sort' l r = when (l < r) $ do
        g <- readSTRef gr
        let (x, g') = randomR (l, r-1) g
        writeSTRef gr g'

        s <- readArray a x

        let loop i j
              | i > j = return (i, j)
              | otherwise = do
                ai <- readArray a i
                aj <- readArray a j
                case () of
                  _ | ai < s -> loop (i+1) j
                    | aj > s -> loop i (j-1)
                    | otherwise -> do
                        writeArray a i aj
                        writeArray a j ai
                        loop (i+1) (j-1)

        (i, j) <- loop l r

        sort' l j
        sort' i r

    sort' 1 n
    return a

data T = T Int Int Int
instance Ord T where (T a _ _) <= (T b _ _) = a >= b
instance Eq T where (T a _ _) == (T b _ _) = a == b

main = do
  [n] <- readInts
  rs <- replicateM n readInts
  gen <- newStdGen

  let
    rs' = qsort gen $ zipWith (\[l, r] i -> (l, r, i)) rs [1..]

    count [] _ = []
    count ((l, r, i):rs) set = (i, c):(count rs (r `Set.insert` set))
      where
        c = Set.size . fst $ r `Set.split` set

  putStr . unlines . map show . elems . array (1, n) $ count (rs') Set.empty


import Control.Monad (liftM)
import Data.Char (ord)
import Data.List (nub)
import Data.IntMap (assocs, fromListWith, map)
import qualified Data.IntMap as Map
import Data.Maybe (catMaybes)
import Prelude hiding (reads)

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

solve :: [Int] -> [(Int, Int)]
solve as  =  catMaybes $ Prelude.map liftFromSnd $ assocs $ Map.map getStep intMap
  where
    intMap  =  fromListWith (++) $ zip as $ Prelude.map (\x -> [x]) [1..]
    getStep [_]  =  Just 0
    getStep xs  =  case nub (zipWith (-) xs (tail xs)) of
        [d]  ->  Just d
        _  ->  Nothing

printAns :: [(Int, Int)] -> IO ()
printAns ans  =  do
    print $ length ans
    mapM_ print' ans
  where
    print' (a, b)  =  putStrLn $ concat [show a, " ", show b]

liftFromSnd :: (a, Maybe b) -> Maybe (a, b)
liftFromSnd (a, b)  =  b >>= return . (tuple a)
  where
    tuple a b  =  (a, b)

main :: IO ()
main  =  do
    getLine
    as  <-  reads
    printAns $ solve as

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

main = do
    n <- readLn
    l <- map (fromJust . fmap fst .B.readInt) . B.words <$> B.getLine
    let res = solve n l
    print (length res)
    forM_ res $ \(x,d) -> printf "%d %d\n" x d

solve :: Int -> [Int] -> [(Int,Int)]
solve n l = [ (x,d) | (x,(d,p)) <- M.assocs $ foldl' f M.empty l', d /= -1]
    where
    l' = zip l [1..]
    f m (x,i) | M.notMember x m = M.insert x (0,i) m
              | otherwise =
        case m M.! x of
            (-1,_) -> m
            (0,p)  -> M.insert x (i-p,i) m
            (d,p) | d == i - p -> M.insert x (d,i) m
                  | otherwise  -> M.insert x (-1,i) m

import Data.List
import Text.Printf
import qualified Data.IntMap as M
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Control.Applicative

translate n ([x]) = (n,0)
translate n x = if x==take (length x) [x!!0,x!!1..] then (n, (x!!0 - x!!1)) else (n, -1)

solve :: [Int] -> [(Int, Int)]
solve ls = [(key,d) | (key,d) <- map (\(key, xs) -> (translate key xs)) $ M.assocs ls', d /= -1]
  where
    ls' = M.fromListWith (++) $ zip ls $ map (\a -> [a]) [1..]

main = do
  getLine
  xs <- map (fromJust . fmap fst . B.readInt) . B.words <$> B.getLine
  let ans = solve xs
  print $ length ans
  mapM_ (\(a,b)->printf "%d %d\n" a b) ans

import Data.List
import Text.Printf
import qualified Data.IntMap as M
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Control.Applicative

papa x = x == take (length x) [x!!0,x!!1..]

translate n ([x]) = (n,0)
translate n x = if papa x then (n, (x!!0 - x!!1)) else (n, -1)

solve :: [Int] -> [(Int, Int)]
solve ls = [(key,d) | (key,d) <- map (\(key, xs) -> (translate key xs)) $ M.assocs $ he, d /= -1]
  where
    he = M.fromListWith (++) $ zip ls $ map (\a -> [a]) [1..]

main = do
  getLine
  xs <- map (fromJust . fmap fst .B.readInt) . B.words <$> B.getLine
  let ans = solve xs
  print $ length ans
  mapM_ (\(a,b)->printf "%d %d\n" a b) ans

import Data.List
import Text.Printf
import qualified Data.IntMap as M
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Control.Applicative

translate n ([x]) = (n,0)
translate n x = if x==take (length x) [x!!0,x!!1..] then (n, (x!!0 - x!!1)) else (n, -1)

solve :: [Int] -> [(Int, Int)]
solve ls = filter (\(key,d) -> d /= -1) $ map (\(key, xs) -> (translate key xs)) $ M.assocs ls'
  where
    ls' = M.fromListWith (++) $ zip ls $ map (\a -> [a]) [1..]

main = do
  getLine
  xs <- map (fromJust . fmap fst . B.readInt) . B.words <$> B.getLine
  let ans = solve xs
  print $ length ans
  mapM_ (\(a,b)->printf "%d %d\n" a b) ans

import Data.List
import Text.Printf
import qualified Data.IntMap as M
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Control.Applicative

papa x = x == take (length x) [x!!0,x!!1..]

translate n ([x]) = (n,0)
translate n x = if papa x then (n, (x!!0 - x!!1)) else (n, -1)

solve :: [Int] -> [(Int, Int)]
solve ls = [(key,d) | (key,d) <- map (\(key, xs) -> (translate key xs)) $ M.assocs ls', d /= -1]
  where
    ls' = M.fromListWith (++) $ zip ls $ map (\a -> [a]) [1..]

main = do
  getLine
  xs <- map (fromJust . fmap fst .B.readInt) . B.words <$> B.getLine
  let ans = solve xs
  print $ length ans
  mapM_ (\(a,b)->printf "%d %d\n" a b) ans

import Data.List
import Text.Printf
import qualified Data.IntMap as M
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Control.Applicative

papa x = x == take (length x) [x!!0,x!!1..]

translate n ([x]) = (n,0)
translate n x = if papa x then (n, (x!!1 - x!!0)) else (n, 1)

solve :: [Int] -> [(Int, Int)]
solve ls = ans
  where
    he= M.fromListWith (++) $ zip ls $ map (\a -> [a]) [1..]
    ans = [(key,d) | (key,d) <- map (\(key, xs) -> (translate key xs)) $ M.assocs $ he, d /= 1]

main = do
  getLine
  xs <- map (fromJust . fmap fst .B.readInt) . B.words <$> B.getLine
  --solve xs
  let ans = solve xs
  print $ length ans
  mapM_ (\(a,b)->printf "%d %d\n" a ((-1)*b)) ans

import Data.Array
import Data.List

solve :: [Int] -> [(Int, Int)]
solve x = (unbox . assocs . countDiff) x
        where
            unbox [] = []
            unbox (x:xs) =
                    (case x of
                        (pos, (Just diff, Just last)) ->
                            [(pos, diff)]
                        _ -> []
                    ) ++ unbox xs

countDiff :: [Int] -> Array Int (Maybe Int, Maybe Int)
countDiff list =
        accumArray  updateDiff
                    (Just 0, Nothing)
                    (minimum list, maximum list)
                    (getStartingValues list 0)
            where
                updateDiff (Just 0, Nothing) newVal =
                        (Just 0, Just newVal)

                updateDiff (Just 0, Just lastVal) newVal =
                        (Just (newVal - lastVal), Just newVal)

                updateDiff (diff, _lastVal) newVal =
                        case _lastVal of
                            Just lastVal ->
                                if diff == Just (newVal - lastVal) then
                                    (diff, Just newVal)
                                else
                                    (Nothing, Nothing)

                            Nothing      -> (Nothing, Nothing)

                getStartingValues [] _ = []
                getStartingValues (x:xs) pos =
                        (x, pos) : (getStartingValues xs (pos + 1))

output :: [(Int, Int)] -> String
output list = (show $ length list) ++ "\n" ++ (result list)
        where
            result = unlines . (map (\(a, b) -> (show a) ++ " " ++ (show b))) . sort

main = interact $ output . solve . (map read) . tail . words

import Data.Array
import Data.List

solve :: [Int] -> [(Int, Int)]
solve x = (unbox . assocs . countDiff) x
        where
            unbox [] = []
            unbox (x:xs) =
                    (case x of
                        (pos, (Just diff, Just last)) ->
                            [(pos, diff)]
                        _ -> []
                    ) ++ unbox xs

countDiff :: [Int] -> Array Int (Maybe Int, Maybe Int)
countDiff list =
        accumArray  updateDiff
                    (Just 0, Nothing)
                    (minimum list, maximum list)
                    (reverse $ getStartingValues list 0 [])
            where
                updateDiff (Just 0, Nothing) newVal =
                        (Just 0, Just newVal)

                updateDiff (Just 0, Just lastVal) newVal =
                        (Just (newVal - lastVal), Just newVal)

                updateDiff (diff, _lastVal) newVal =
                        case _lastVal of
                            Just lastVal ->
                                if diff == Just (newVal - lastVal) then
                                    (diff, Just newVal)
                                else
                                    (Nothing, Nothing)

                            Nothing      -> (Nothing, Nothing)

                getStartingValues [] _ acc = acc
                getStartingValues (x:xs) pos acc =
                        getStartingValues xs (pos + 1) ((x, pos) : acc)

output :: [(Int, Int)] -> String
output list = (show $ length list) ++ "\n" ++ (result list)
        where
            result = unlines . (map (\(a, b) -> (show a) ++ " " ++ (show b))) . sort

main = interact $ output . solve . (map read) . tail . words

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

main = do
    n <- readLn
    l <- map (fromJust . fmap fst .B.readInt) . B.words <$> B.getLine
    let res = solve n l
    print (length res)
    forM_ res $ \(x,d) -> printf "%d %d\n" x d

solve :: Int -> [Int] -> [(Int,Int)]
solve n l = [ (x,d) | (x,(d,p)) <- M.assocs $ foldl' f M.empty l', d /= -1]
    where
    l' = zip l [1..]
    f m (x,i) | M.notMember x m = M.insert x (0,i) m
              | otherwise =
        case m M.! x of
            (-1,_) -> m
            (0,p)  -> M.insert x (i-p,i) m
            (d,p) | d == i - p -> M.insert x (d,i) m
                  | otherwise  -> M.insert x (-1,i) m

import Data.List
import Text.Printf
import qualified Data.IntMap as M
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Control.Applicative

papa x = x == take (length x) [x!!0,x!!1..]

translate n ([x]) = (n,0)
translate n x = if papa x then (n, (x!!1 - x!!0)) else (n, -1)

solve :: [Int] -> [(Int, Int)]
solve ls = ans
  where
    he= M.fromListWith (++) $ zip ls $ map (\a -> [a]) [1..]
    ans = [(key,d) | (key,d) <- map (\(key, xs) -> (translate key xs)) $ M.assocs $ he, d /= -1]

main = do
  getLine
  xs <- map (fromJust . fmap fst .B.readInt) . B.words <$> B.getLine
  --solve xs
  let ans = solve xs
  print $ length ans
  mapM_ (\(a,b)->printf "%d %d\n" a ((-1)*b)) ans

import Data.Array
import Data.List

solve :: [Int] -> [(Int, Int)]
solve x = (unbox . assocs . countDiff) x
        where
            unbox [] = []
            unbox (x:xs) =
                    (case x of
                        (pos, (Just diff, Just last)) ->
                            [(pos, diff)]
                        _ -> []
                    ) ++ unbox xs

countDiff :: [Int] -> Array Int (Maybe Int, Maybe Int)
countDiff list =
        accumArray  updateDiff
                    (Just 0, Nothing)
                    (minimum list, maximum list)
                    (getStartingValues list 0 [])
            where
                updateDiff (Just 0, Nothing) newVal =
                        (Just 0, Just newVal)

                updateDiff (Just 0, Just lastVal) newVal =
                        (Just (newVal - lastVal), Just newVal)

                updateDiff (diff, _lastVal) newVal =
                        case _lastVal of
                            Just lastVal ->
                                if diff == Just (newVal - lastVal) then
                                    (diff, Just newVal)
                                else
                                    (Nothing, Nothing)

                            Nothing      -> (Nothing, Nothing)

                getStartingValues [] _ acc = acc
                getStartingValues (x:xs) pos acc =
                        getStartingValues xs (pos + 1) ((x, pos) : acc)

output :: [(Int, Int)] -> String
output list = (show $ length list) ++ "\n" ++ (result list)
        where
            result = unlines . (map (\(a, b) -> (show a) ++ " " ++ (show b))) . sort

main = interact $ output . solve . (map read) . tail . words

import Data.Array
import Data.List

solve :: [Int] -> [(Int, Int)]
solve x = (unbox . assocs . countDiff) x
        where
            unbox [] = []
            unbox (x:xs) =
                    (case x of
                        (pos, (Just diff, Just last)) ->
                            [(pos, diff)]
                        _ -> []
                    ) ++ unbox xs

countDiff :: [Int] -> Array Int (Maybe Int, Maybe Int)
countDiff list =
        accumArray  updateDiff
                    (Just 0, Nothing)
                    (minimum list, maximum list)
                    (getStartingValues list 0)
            where
                updateDiff (Just 0, Nothing) newVal =
                        (Just 0, Just newVal)

                updateDiff (Just 0, Just lastVal) newVal =
                        (Just (newVal - lastVal), Just newVal)

                updateDiff (diff, _lastVal) newVal =
                        case _lastVal of
                            Just lastVal ->
                                if diff == Just (newVal - lastVal) then
                                    (diff, Just newVal)
                                else
                                    (Nothing, Nothing)

                            Nothing      -> (Nothing, Nothing)

                getStartingValues [] _ = []
                getStartingValues (x:xs) pos =
                        (x, pos) : (getStartingValues xs (pos + 1))

output :: [(Int, Int)] -> String
output =
        unlines . (map (\(a, b) -> (show a) ++ " " ++ (show b))) . sort

main = interact $ output . solve . (map read) . tail . words


{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}

import Text.Printf
import System.IO
import Data.List
import Data.Functor
import Data.Bifunctor (bimap)
import Data.Function
import Data.Maybe
import Data.Int
import Data.Bits
import Data.Tree
import Data.Array.Unboxed
import Data.Array.IArray
import Data.Foldable (foldr', foldr1)
import Prelude
import Control.Monad
import Control.Monad.State.Strict
import qualified Data.ByteString.Char8 as B8
import qualified Data.Map.Strict as MapS
import qualified Data.Set as Set

readB8Int :: B8.ByteString -> Int
readB8Int = fst . fromJust . B8.readInt

bitSplit :: Int
bitSplit = 7

generateQuery :: Int -> [Int]
generateQuery 1 = take 100 [0..]
generateQuery 2 = take 100 $ map (* (2 ^ bitSplit)) [1..]

performQuery :: [Int] -> IO Int
performQuery elements = do
    putStrLn $ "? " ++ intercalate " " (map show elements)
    hFlush stdout
    answer <- readB8Int <$> B8.getLine
    return answer

submitAnswer :: Int -> IO ()
submitAnswer answer = do
    printf "! %d\n" answer
    hFlush stdout

main :: IO ()
main = do
    firstAnswer <- performQuery $ generateQuery 1
    secondAnswer <- performQuery $ generateQuery 2
    let queryMask = 2 ^ bitSplit - 1
    let answer = (firstAnswer .&. complement queryMask) .|. (secondAnswer .&. queryMask)
    submitAnswer answer

import Data.List
import Data.Bits
import System.IO

main = do
  hSetBuffering stdout LineBuffering
  let q0 = [1..100] :: [Int]
  putStrLn $ unwords $ "?" : map show q0
  hFlush stdout
  r0 <- readLn
  let q1 = map (*128) q0
  putStrLn $ unwords $ "?" : map show q1
  hFlush stdout
  r1 <- readLn
  let a = r0 `xor` r1
      a0 = a .&. 127
      r = r0 `xor` a0 :: Int
  putStrLn $ "! " ++ show r
  hFlush stdout

{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}

import Text.Printf
import System.IO
import Data.List
import Data.Functor
import Data.Bifunctor (bimap)
import Data.Function
import Data.Maybe
import Data.Int
import Data.Bits
import Data.Tree
import Data.Array.Unboxed
import Data.Array.IArray
import Data.Foldable (foldr', foldr1)
import Prelude
import Control.Monad
import Control.Monad.State.Strict
import qualified Data.ByteString.Char8 as B8
import qualified Data.Map.Strict as MapS
import qualified Data.Set as Set

readB8Int :: B8.ByteString -> Int
readB8Int = fst . fromJust . B8.readInt

bitSplit :: Int
bitSplit = 8

generateQuery :: Int -> [Int]
generateQuery 1 = take 100 [0..]
generateQuery 2 = take 100 $ map (* (2 ^ bitSplit)) [1..]

performQuery :: [Int] -> IO Int
performQuery elements = do
    putStrLn $ "? " ++ intercalate " " (map show elements)
    hFlush stdout
    answer <- readB8Int <$> B8.getLine
    return answer

submitAnswer :: Int -> IO ()
submitAnswer answer = do
    printf "! %d\n" answer
    hFlush stdout

main :: IO ()
main = do
    firstAnswer <- performQuery $ generateQuery 1
    secondAnswer <- performQuery $ generateQuery 2
    let queryMask = 2 ^ bitSplit - 1
    let answer = (firstAnswer .&. complement queryMask) .|. (secondAnswer .&. queryMask)
    submitAnswer answer

import Data.List
import Data.Bits
import System.IO

main = do
  hSetBuffering stdout LineBuffering
  let q0 = [0..99] :: [Int]
  putStrLn $ unwords $ "?" : map show q0
  r0 <- readLn
  let q1 = [128..227] :: [Int]
  putStrLn $ unwords $ "?" : map show q1
  r1 <- readLn
  let a = r0 `xor` r1
      a0 = a .&. 127
      r = r0 `xor` a0 :: Int
  putStrLn $ "! " ++ show r

import Data.List
import Data.Bits
import System.IO

main = do
  hSetBuffering stdout LineBuffering
  let q0 = [0..99] :: [Int]
  putStrLn $ unwords $ "?" : map show q0
  hFlush stdout
  r0 <- readLn
  let q1 = map (*128) q0
  putStrLn $ unwords $ "?" : map show q1
  hFlush stdout
  r1 <- readLn
  let a = r0 `xor` r1
      a0 = a .&. 127
      r = r0 `xor` a0 :: Int
  putStrLn $ "! " ++ show r
  hFlush stdout

import Data.List
import Data.Bits
import System.IO

main = do
  hSetBuffering stdout LineBuffering
  let q0 = [0..99] :: [Int]
  putStrLn $ unwords $ "?" : map show q0
  r0 <- readLn
  let q1 = map (*128) q0
  putStrLn $ unwords $ "?" : map show q1
  r1 <- readLn
  let a = r0 `xor` r1
      a0 = a .&. 127
      r = r0 `xor` a0 :: Int
  putStrLn $ "! " ++ show r


{-# LANGUAGE BangPatterns #-}

import Data.Array.Base
import qualified Data.ByteString.Char8 as B
import Data.List
import Control.Applicative

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

bSearch :: (Int -> Bool) -> Int -> Int -> Int
bSearch p !low !high
  | high<=low = low
  | p mid     = bSearch p mid high
  | otherwise = bSearch p low (mid-1)
   where
     mid = quot (low+high+1) 2

main = B.getContents >>= print.solve.map readInt.B.words

solve :: [Int] -> Integer
solve (n:d:rest) = sum $ map step [0..n-3]
   where
     arr = listArray (0,n-1) rest :: UArray Int Int
     step i = (toInteger $ j-i)*(toInteger $ j-i-1)`div`2
      where
        !aid = unsafeAt arr i + d
        j = bSearch ((<=aid).unsafeAt arr) i (n-1)

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

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

solve :: Int -> Int -> [Int] -> Integer
solve n d xs  =  solve' (1,1)
  where
    a  =  listArray (1, n) xs
    solve' (i, j)
      | j == n  =  f (j - i)
      | otherwise  =  f (j - i) + solve'' (i, j + 1)
    solve'' (i, j)
      | a ! j - a ! i > d  =  solve'' (i + 1, j)
      | otherwise  =  solve' (i, j)
    f :: Int -> Integer
    f n  =  (n' * (n' - 1)) `div` 2
      where
        n'  =  fromIntegral n

main :: IO ()
main  =  do
    [n, d]  <-  reads
    xs  <-  reads
    print $ solve n d xs

main = interact $ show . solve . map read . words
solve :: [Integer] -> Integer
solve (n : d : xs) = f ys ys
    where   ys = zip xs [1..]

            f [] _ = 0
            f ((x, px) : xs) [(y, py)]
                | y - x <= d = choose (py - px) + f xs [(y, py)]
                | otherwise  = f xs [(y, py)]
            f ((x, px) : xs) ((y, py) : (z, pz) : ys)
                | z - x > d  = f xs ((y , py) : (z, pz) : ys) +
                        if y - x <= d then choose (py - px)
                                    else 0
                | otherwise  = f ((x, px) : xs) ((z, pz) : ys)

            choose n
                | n < 2     = 0
                | otherwise = div (n * (n - 1)) 2

main = interact $ show . solve . map read . words
solve :: [Int] -> Int
solve (n : d : xs) = f ys ys
    where   ys = zip xs [1..]

            f [] _ = 0
            f ((x, px) : xs) [(y, py)]
                | y - x <= d = choose (py - px) + f xs [(y, py)]
                | otherwise  = f xs [(y, py)]
            f ((x, px) : xs) ((y, py) : (z, pz) : ys)
                | z - x > d  = f xs ((y , py) : (z, pz) : ys) +
                        if y - x <= d then choose (py - px)
                                    else 0
                | otherwise  = f ((x, px) : xs) ((z, pz) : ys)

            choose n
                | n < 2     = 0
                | otherwise = div (n * (n - 1)) 2

main = interact $ show . solve . map read . words
solve :: [Int] -> Int
solve (n : d : xs) = f ys ys
    where   ys = zip xs [1..]

            f [] _ = 0
            f ((x, px) : xs) [(y, py)]
                | y - x <= d = choose (py - px) + f xs [(y, py)]
                | otherwise  = f xs [(y, py)]
            f ((x, px) : xs) ((y, py) : (z, pz) : ys)
                | z - x > d  = f xs ((z, pz) : ys) +
                        if y - x <= d then choose (py - px)
                                    else 0
                | otherwise  = f ((x, px) : xs) ((z, pz) : ys)

            choose n
                | n < 2     = 0
                | otherwise = div (n * (n - 1)) 2

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

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

solve :: Int -> Int -> [Int] -> Int
solve n d xs  =  solve' (1,1)
  where
    a  =  listArray (1, n) xs
    solve' (i,j)
      | i == n  =  0
      | j == n && a ! j - a ! i <= d  =  f (j - i + 1)
      | j == n  =  solve' (i + 1, j)
      | a ! j - a ! i <= d && a ! (j + 1) - a ! i <= d  =  solve' (i, j+1)
      | a ! j - a ! i <= d  =  f (j - i + 1) + solve' (i + 1, j + 1)
      | otherwise  =  solve' (i + 1, j)
    f n
      | n < 3  =  0
      | otherwise  =  div (n' * (n' - 1) * (n' - 2)) 6
      where
        n'  =  fromIntegral n

main :: IO ()
main  =  do
    [n, d]  <-  reads
    xs  <-  reads
    print $ solve n d xs

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

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

solve :: Int -> Int -> [Int] -> Int
solve n d xs  =  solve' (1,1)
  where
    a  =  listArray (1, n) xs
    solve' (i,j)
      | i == n  =  0
      | j == n && a ! j - a ! i <= d  =  f (j - i + 1)
      | j == n  =  solve' (i + 1, j)
      | a ! j - a ! i <= d && a ! (j + 1) - a ! i <= d  =  solve' (i, j+1)
      | a ! j - a ! i <= d  =  f (j - i + 1) + solve' (i, j + 1)
      | otherwise  =  solve' (i + 1, j)
    f n
      | n < 3  =  0
      | otherwise  =  div (n' * (n' - 1) * (n' - 2)) 6
      where
        n'  =  fromIntegral n

main :: IO ()
main  =  do
    [n, d]  <-  reads
    xs  <-  reads
    print $ solve n d xs


import List
main = interact solve
solve input = output where
  inputs = lines input
  [n,m] = map (read::String->Int) $ words $ head inputs
  scs = [(read y::Int,x)|[x,y] <- map words $ tail inputs]
  output = show $ answer scs
answer :: [(Int,String)] -> Int
answer xs = if c<0 then answer (cas '0' xs) + answer (cas '1' xs) else c
  where c = check xs
cas _ [] = []
cas x ((y,z):xs) = (if head z == x then y-1 else y,tail z):(cas x xs)
check xs
  | x<0 || z>length y = 0
  | null y            = 1
  | otherwise         = -1
  where sxs = sort xs
        (x,y) = head sxs
        (z,_) = last sxs

import Data.List

main = interact $ show . solve.parse.lines

parse = map (\str -> (head (words str), read (last (words str)))) . tail

solve :: [(String, Int)] -> Int
solve xs@(("", _):_)  | all ((==0).snd) xs = 1
                      | otherwise         = 0
solve xs | any ((<0).snd) xs  = 0
         | otherwise          = f '0' + f '1'
         where  match a b  | a == b = 1
                match _ _          = 0
                f c = solve (map (\(s, n) -> (tail s, n - match (head s) c)) xs)