{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

class Printable a where
  format :: a -> String

instance Printable Int where
  format = show

instance Printable Integer where
  format = show

instance Printable Double where
  format = show

instance Printable Float where
  format = show

instance Printable Char where
  format = show

instance Printable String where
  format x = x

instance Printable Bool where
  format = show

put :: Printable a => a -> IO ()
put = putStr . format

putLn :: Printable a => a -> IO ()
putLn = putStrLn . format

putList :: Printable a => [a] -> IO ()
putList [a] = put a
putList (a:as) = do
  put a
  putStr " "
  putList as

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
  [d] <- readInt
  print $ f d

f 25 = "Christmas"
f 24 = "Christmas Eve"
f 23 = "Christmas Eve Eve"
f 22 = "Christmas Eve Eve Eve"


import Control.Applicative

main :: IO ()
main = do
    n <- readLn
    putStrLn $ solve n

solve :: Int -> String
solve n | 25 == n = "Christmas"
        | 24 == n = "Christmas Eve"
        | 23 == n = "Christmas Eve Eve"
        | 22 == n = "Christmas Eve Eve Eve"

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 100 points

Problem Statement

In some other world, today is December D-th.

Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.

Constraints

22 \leq D \leq 25

D is an integer.

Input

Input is given from Standard Input in the following format:

D

Output

Print the specified string (case-sensitive).

Sample Input 1

25

Sample Output 1

Christmas

Sample Input 2

22

Sample Output 2

Christmas Eve Eve Eve

Be sure to print spaces between the words.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


main = do
    n <- readLn :: IO Int
    putStrLn $ "Christmas " ++ unwords ["Eve " | x <- [n..24]]


chris::String->String
chris d = case d of
    "22" -> "Christmas Eve Eve Eve"
    "23" -> "Christmas Eve Eve"
    "24" -> "Christmas Eve"
    "25" -> "Christmas"

main::IO ()
main = do
    d <- getLine
    putStrLn $ chris d


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

main :: IO ()
main = do
  d <- readLn
  putStrLn $ solve d

solve :: Int -> String
solve d = "Christmas" ++ concat (replicate (25 - d) " Eve")


main = do
    d <- readLn
    putStrLn $ concat $ "Christmas" : replicate (25 - d) " Eve"


abc115a :: Int -> String
abc115a 25 = "Christmas"
abc115a 24 = "Christmas Eve"
abc115a 23 = "Christmas Eve Eve"
abc115a 22 = "Christmas Eve Eve Eve"

main :: IO ()
main = do
  d <- getLine
  putStrLn (abc115a (read d))


stoi str = read str :: Int
main = getLine >>= putStrLn . solve . stoi

solve  num =
    case num of
     25  -> "Christmas"
     24  -> "Christmas Eve"
     23  -> "Christmas Eve Eve"
     22  -> "Christmas Eve Eve Eve"
     otherwise -> "WTF"


repeat' :: Int -> [a] -> [a]
repeat' 0 _ = []
repeat' n l = l ++ repeat' (n-1) l

main :: IO()
main = do
    n <- readLn :: IO Int
    print $ "Christmas" ++ (repeat' (25 - n) " Eve")


main = putStrLn . solve . read =<< getLine

solve n = "Christmas" ++ (concat . take (25 - n) . repeat) " Eve"


main = do
  d <- readLn
  putStrLn $ "Christmas" ++ (concat (replicate (25 - d) " Eve"))


main :: IO ()
main = do
  d <- readLn
  putStrLn $ solve d

solve :: Int -> String
solve 22 = "Christmas Eve Eve Eve"
solve 23 = "Christmas Eve Eve"
solve 24 = "Christmas Eve"
solve 25 = "Christmas"


main=readLn>>=putStr.("Christmas"++).concat.flip replicate " Eve".(25-)


readInt :: String -> Int
readInt = read

main = do
    s <- readInt<$>getLine
    putStr $ solve s

solve :: Int -> String
solve 25 = "Christmas"
solve 24 = "Christmas Eve"
solve 23 = "Christmas Eve Eve"
solve 22 = "Christmas Eve Eve Eve"


conv :: Integral a => a -> String
conv 25 = "Christmas"
conv 24 = "Christmas Eve"
conv 23 = "Christmas Eve Eve"
conv 22 = "Christmas Eve Eve Eve"
conv _ = ""

main :: IO ()
main = do
    d <- readLn :: IO Int
    putStrLn $ conv d


main :: IO ()
main = do
  d <- readLn
  putStrLn $ case d of
    25 -> "Christmas"
    24 -> "Christmas Eve"
    23 -> "Christmas Eve Eve"
    22 -> "Christmas Eve Eve Eve"


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

toTriple :: B.ByteString -> (Int, Int, Int)
toTriple bs =
    let
        Just (a, bs') = B.readInt bs
        Just (b, bs'') = B.readInt $ B.dropWhile isSpace bs'
        Just (c, _) = B.readInt $ B.dropWhile isSpace bs''
    in
        (a, b, c)

f :: (Int, Int, Int) -> (Int, Int) -> Int
f (x,y,h) (cx,cy) = (abs $ cx - x) + (abs $ cy - y) + h

main = do
    n <- readLn :: IO Int
    xyh <- replicateM n (toTriple <$> B.getLine) :: IO [(Int, Int, Int)]
    forM_ [0..100] $ \i ->
        forM_ [0..100] $ \j -> do
            let xs = filter (/=0) $ map (flip f (i,j)) xyh
            unless (null xs) $ do
                let k = head xs
                let res = and $ map (\(x,y,h) -> (max (k-(abs$i-x)-(abs$j-y)) 0) == h) xyh
                when res $ do
                    putStr $ show i ++ " "
                    putStr $ show j ++ " "
                    putStrLn $ show k

Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

N is an integer between 1 and 100 (inclusive).

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.


main=do
 getLine
 xyh<-map(map read.words).lines<$>getContents
 let[sx,sy,sh]=head$filter((>0).(!!2))xyh
 putStrLn$unwords$map show$head[[x,y,h]|x<-[0..100],y<-[0..100],let h=sh+(abs$sx-x)+(abs$sy-y),ok x y h xyh]
ok sx sy sh[]=True
ok sx sy sh([x,y,h]:xyh)
 |max(h-(abs$sx-x)-(abs$sy-y))0==sh=ok sx sy sh xyh
 |otherwise=False


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

type Information = (Int,Int,Int)

main = do
  n <- readLn
  infos <- replicateM n $ (\[a,b,c]->(a,b,c)).map read.words<$>getLine
  putStr $ (\(a,b,c) -> unwords$map show [a,b,c]) $ solve infos

solve :: [Information] -> Information
solve infos = fromJust $ find isAns candidates where
  candidates = [(x,y,ih+abs(x-ix)+abs(y-iy))|x<-[0..100],y<-[0..100]]
  info@(ix,iy,ih) = fromJust $ find (\(_,_,h)->h/=0) infos
  isAns (cx,cy,ch) = all eval infos where
    eval (x,y,h) = h == max (ch-abs(x-cx)-abs(y-cy)) 0


{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

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

main = do
	n <- readInt
	[ xs, ys, hs ] <- transpose <$> replicateM n readInts
	let
		( x, y, h ) = head $ do
			cx <- [ 0 .. 100 ]
			cy <- [ 0 .. 100 ]
			let
				ch = head [ h + abs ( cx - x ) + abs ( cy - y ) | ( x, y, h ) <- zip3 xs ys hs, 0 < h ]
			if all ( check ( cx, cy,  ch ) ) ( zip3 xs ys hs )
				then return ( cx, cy, ch )
				else []
	printf "%d %d %d\n" x y h

check ( cx, cy, ch ) ( x, y, h ) = max 0 ( ch - abs ( cx - x ) - abs ( cy - y ) ) == h


import Data.List
import Text.Printf
nextPyramid (x,y) = if y+1<101 then (x,y+1) else if x+1<101 then (x+1,0) else (-1,-1)
listToTuple [x,y,z] = (x,y,z)

check::(Integer,Integer)->[(Integer,Integer,Integer)]->Integer->Integer
check (x,y) (d:ds) h
    | h==0      = check (x,y) ds (abs (a-x) + abs (b-y) + c)
    | c==tmp    = if ds==[] then h else check (x,y) ds h
    | otherwise = -1
    where
        (a,b,c) = d
        tmp     = max (h - abs (a-x) - abs (b-y)) 0

solve (x,y) tbl
    | ans == -1 = solve (nextPyramid (x,y)) tbl
    | otherwise = (x,y,ans)
    where
        ans     = check (x,y) tbl 0

main::IO()
main=do
    getLine
    tbl <- map (listToTuple.map read.words) . lines <$> getContents :: IO [(Integer,Integer,Integer)]
    let (x,y,h) = solve (0,0) (sortBy (\(a0,a1,a2) (b0,b1,b2) -> compare b2 a2) tbl)
    printf "%d %d %d\n" x y h


import Data.List
import Text.Printf
getInt = do
    t <- getLine
    return (read t::Integer)

getInts = do
    x <- getLine
    let y = map (read::String->Integer) (words x)
    return y

getData 1 = do
    [x,y,h] <- getInts
    return [(x,y,h)]

getData n = do
    [x,y,h] <- getInts
    z <- getData (n-1)
    let rt = [(x,y,h)] ++ z
    return rt

nextPyramid (x,y) = if y+1<101 then (x,y+1) else if x+1<101 then (x+1,0) else (-1,-1)

check::(Integer,Integer)->[(Integer,Integer,Integer)]->Integer->Integer
check (x,y) (d:ds) h
    | ds==[] && (h==(abs (a-x) + abs (b-y) + c) || c==0) = h
    | h==0 && c/=0 = check (x,y) ds (abs (a-x) + abs (b-y) + c)
    | h/=0 && abs (a-x) + abs (b-y) + c > h = -1
    | h==(abs (a-x) + abs (b-y) + c) || c==0 = check (x,y) ds h
    | otherwise = -1
    where
        (a,b,c) = d

solve (-1,-1) tbl = (-1,-1,-1)
solve (x,y) tbl
    | ans == (0-1) = solve (nextPyramid (x,y)) tbl
    | otherwise = (x,y,ans)
    where
        ans = check (x,y) tbl 0

main::IO()
main=do
    n <- getInt
    tbl <- getData n
    let (x,y,h) = solve (0,0) tbl
    printf "%d %d %d\n" x y h


import Data.List
import Text.Printf
getInt = do
    t <- getLine
    return (read t::Integer)

getInts = do
    x <- getLine
    let y = map (read::String->Integer) (words x)
    return y

getData 1 = do
    [x,y,h] <- getInts
    return [(x,y,h)]

getData n = do
    [x,y,h] <- getInts
    z <- getData (n-1)
    let rt = [(x,y,h)] ++ z
    return rt

nextPyramid (x,y) = if y+1<101 then (x,y+1) else if x+1<101 then (x+1,0) else (-1,-1)

check::(Integer,Integer)->[(Integer,Integer,Integer)]->Integer->Integer
check (x,y) (d:ds) h
    | ds==[] = h
    | h==0 && c==0 = check (x,y) ds h
    | h==0 = check (x,y) ds (abs (a-x) + abs (b-y) + c)
    | h==(abs (a-x) + abs (b-y) + c) = check (x,y) ds h
    | otherwise = -1
    where
        (a,b,c) = d

solve (x,y) tbl
    | ans == (0-1) = solve (nextPyramid (x,y)) tbl
    | otherwise = (x,y,ans)
    where
        ans = check (x,y) tbl 0

main::IO()
main=do
    n <- getInt
    tbl <- getData n
    let (x,y,h) = solve (0,0) tbl
    printf "%d %d %d\n" x y h


{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V

getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]

type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)

mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
fi = fromInteger
fig = fromIntegral
rf = realToFrac

(.<.) f g -- combination
    | f < g = 0
    | g < 1 || f < 1 = 1
    | True = foldr1 (*) (take g [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)

unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x

zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros

i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)

mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a

countIf f = length . filter f

--
--
--
enumAll :: (Int, Int) -> Int -> [((Int, Int), Int)]
enumAll (x, y) h = [((a, b), c) | a <- [0..100], b <- [0..100], c <- [h + abs (x - a) + abs (y - b)], c >= 0]

main = do
  time <- getI
  points <- map (\[x,y,z] -> ((x, y), z)) <$> replicateM time getIs
  let candidates = uncurry enumAll $ head points
      inputs = if length points > 1 then map isCorrect $ tail points else []
      ans = head $ foldr (\f x -> filter f x) candidates inputs
  putStrLn $ format ans
  where
    isCorrect ((a, b), c) ((x, y), z) = z - c == dist || c == 0 && z < dist
      where dist = abs (a - x) + abs (b - y)
    format ((a, b), c) = show a ++ " " ++ show b ++ " " ++ show c


{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V

getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]

type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)

mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
fi = fromInteger
fig = fromIntegral
rf = realToFrac

(.<.) f g -- combination
    | f < g = 0
    | g < 1 || f < 1 = 1
    | True = foldr1 (*) (take g [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)

unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x

zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros

i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)

mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a

countIf f = length . filter f

--
--
--
enumAll :: (Int, Int) -> Int -> [((Int, Int), Int)]
enumAll (x, y) h = [((a, b), c) | a <- [0..100], b <- [0..100], c <- [h + abs (x - a) + abs (y - b)]]

main = do
  time <- getI
  points <- map (\[x,y,z] -> ((x, y), z)) <$> replicateM time getIs
  let candidates = uncurry enumAll $ head points
      inputs = map isCorrect $ init points
      ans = head $ foldr (\f x -> filter f x) candidates inputs
  putStrLn $ format ans
  where
    isCorrect ((a, b), c) ((x, y), z) = z - c == abs (a - x) + abs (b - y)
    format ((a, b), c) = show a ++ " " ++ show b ++ " " ++ show c


import Control.Monad
import Text.Printf

height :: Int -> Int -> [[Int]] -> Int
height cx cy ps = if (all (\[x, y, h] -> h == (max 0 ch - (abs (cx - x)) - (abs (cy - y)))) ps) then ch else 0
  where
    [x0, y0, h0]:_ = filter (\[x, y, h] -> h > 0) ps
    ch = h0 + (abs (cx - x0)) + (abs (cy - y0))

solve :: [[Int]] -> (Int, Int, Int)
solve ps = t
  where
    t:_ = filter (\(x, y, h) -> h > 0) [(cx, cy, height cx cy ps) | cx <- [0 .. 100], cy <- [0 .. 100]]

main :: IO ()
main = do
  n <- readLn :: IO Int
  ps <- replicateM n $ (map (\s -> read s :: Int)) . words <$> getLine
  let (cx, cy, ch) = solve ps in
    printf "%d %d %d\n" cx cy ch


import Control.Monad (replicateM)

type Pos = (Int, Int)
type Height = Int

diff :: Pos -> Pos -> Height
diff (x1, y1) (x2, y2) = abs (x1 - x2) + abs (y1 - y2)

veridation :: Pos -> Height -> Pos -> Height -> Bool
veridation x h c ch = h == max 0 (ch - diff c x)

candidates :: Pos -> Height -> [(Pos, Height)]
candidates x h = map (\p -> (p, h + d p)) [(x', y') | x' <- [0..100], y' <- [0..100]]
  where d = diff x

takeSample :: [(Pos, Height)] -> (Pos, Height)
takeSample = head . filter (\(_, h) -> 0 < h)

parse :: IO (Pos, Height)
parse = do
  [x, y, h] <- map read . words <$> getLine
  return ((x, y), h)

fil' :: (Pos, Height) -> [(Pos, Height)] -> [(Pos, Height)]
fil' (x,h) cs = filter (uncurry (veridation x h)) cs

fil :: [(Pos, Height)] -> [(Pos, Height)] -> [(Pos, Height)]
fil ss cs = foldr fil' cs ss

main = do
  n <- read <$> getLine :: IO Int
  samples <- replicateM n parse
  let (sx, sh) = takeSample samples
      cs = candidates sx sh
      ((x,y), h) = head $ fil samples cs
  putStrLn $ show x ++ ' ' : show y ++ ' ' : show h


import Data.List

judge :: (Int, Int) -> Int -> (Int, Int) -> Int -> Bool
judge (cx, cy) h' (x, y) h
 | tmp1 <= 0  = (h == 0)
 | otherwise  = (max tmp2 0 == h)
 where tmp1 = h' - abs (x-cx)
       tmp2 = tmp1 - abs (y-cy)

main = do
  xyhs <- map (map read.words).lines <$> (getLine >> getContents)
  let pyrs = [((cx, cy), h') | h' <- [1..], cx <- [0..100], cy <- [0..100]]
      Just ((ax, ay), ah) = find (\(c, h') -> and $ map (\(x:y:h:_) -> judge c h' (x, y) h) xyhs) pyrs
  putStrLn $ unwords $ map show [ax, ay, ah]


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

main = do
    n<-readLn::IO Int
    (xyhs, xyzs)<-partition (\(_:_:h:_)->h>0) <$> replicateM n (map read.words<$>getLine) ::IO ([[Int]],[[Int]])
    let Just (Just h,(x,y)) = find (chkz xyzs) $ map (f xyhs) [(cx,cy)|cx<-[0..100],cy<-[0..100]]
    putStrLn $ unwords $ map show [x,y,h]
--
f xyhs (cx,cy) = (chk $ map (g cx cy) xyhs, (cx,cy))
g cx cy (x:y:h:_) = h+ abs(x-cx)+ abs(y-cy)

chk [h] = Just h
chk (a:b:hs)
    | a==b = chk (b:hs)
    | otherwise = Nothing
--
chkz _ (Nothing, _) = False
chkz xyzs (Just h,(x,y)) = all (\(u:v:_) -> (h-abs(u-x)-abs(v-y)) <=0) xyzs


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

main = do
    n<-readLn::IO Int
    xyhs <- replicateM n (map read.words<$>getLine) ::IO [[Int]]
    let Just (_,(x,y,h)) = find (\(f,_)->f) $ map (f xyhs) [(cx,cy)|cx<-[0..100],cy<-[0..100]]
    putStrLn $ unwords $ map show [x,y,h]
--
f xyhs (cx,cy) = (all (g cx cy ch) xyhs, (cx,cy,ch))
    where
        Just(tx:ty:th:_) = find (\(_:_:h:_)->h>0) xyhs
        ch = th + abs(cx-tx) + abs(cy-ty)

g cx cy ch (x:y:h:_)
    | max (ch-abs(cx-x)-abs(cy-y)) 0 == h = True
    | otherwise = False


-- ABC112 C - Pyramid
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn
  am <- replicateM n $ map read . words <$> getLine :: IO [[Int]]
  putStrLn . unwords . map show $ solve am

solve :: [[Int]] -> [Int]
solve am = head . filter isOk $ [[x,y,centerH (x,y)] | x <- [0..100], y <- [0..100]]
  where
    isOk (cx:cy:ch:_) = all (\(x:y:h:_) -> height ch (x,y) (cx,cy) == h) am
    highest = last $ sortBy (\a b -> compare (a!!2) (b!!2)) am
    centerH = calcBackHeight highest

type Position = (Int, Int)
height :: Int -> Position -> Position -> Int
height h (x, y) (cx, cy) = max (h - (abs (x - cx)) - (abs (y - cy))) 0
calcBackHeight :: [Int] -> Position -> Int
calcBackHeight a (cx, cy) = h + (abs (x - cx)) + (abs (y - cy))
  where
    x = a !! 0
    y = a !! 1
    h = a !! 2


import Control.Monad

main :: IO ()
main = do
  n <- readLn
  xyhs <- replicateM n $ map read . words <$> getLine
  let [xt, yt, ht] = head [ [x, y, h] | [x, y, h] <- xyhs, h > 0 ]
  putStrLn $ unwords $ map show $ solve xt yt ht xyhs

solve :: Int -> Int -> Int -> [[Int]] -> [Int]
solve xt yt ht xyhs =
  let
    (cx, cy) = head $ foldl (step xt yt ht) ((,) <$> [0 .. 100] <*> [0 .. 100]) xyhs
  in
    [cx, cy, ht + abs (xt - cx) + abs (yt - cy)]

step :: Int -> Int -> Int -> [(Int, Int)] -> [Int] -> [(Int, Int)]
step xt yt ht cxys [x, y, h] =
  [ (cx, cy)
  | (cx, cy) <- cxys
  , let ch = ht + abs (xt - cx) + abs (yt - cy)
  , h == (ch - abs (x - cx) - abs (y - cy)) `max` 0
  ]


{-# LANGUAGE BangPatterns #-}

import Control.Monad

main :: IO ()
main = do
  n <- readLn
  xyhs <- replicateM n $ map read . words <$> getLine
  putStrLn $ unwords $ map show $ solve xyhs

solve :: [[Int]] -> [Int]
solve xyhs = go acc0 xyhs
  where
    acc0 = [ [cx, cy, ch] | cx <- [0 .. 100], cy <- [0 .. 100], ch <- [ch0 - 200 .. ch0 + 200] ]
    ch0 = head $ map last xyhs

    go !acc [] = head acc
    go !acc (xyh:xyhs) = go (step xyh acc) xyhs

    step [x, y, h] acc = filter (\[cx, cy, ch] -> h == max (ch - abs (x - cx) - abs (y - cy)) 0) acc


import Control.Monad

main :: IO ()
main = do
  n <- readLn
  xs <- replicateM n $ do
          [x,y,h] <- getInts
          return (x,y,h)
  let x = head $ dropWhile (\(_,_,h) -> h < 1) xs
  putStrLn $ format $ solve x xs

getInts :: IO [Int]
getInts = map read . words <$> getLine

format :: (Int,Int,Int) -> String
format (x,y,h) = unwords $ map show [x,y,h]

solve :: (Int,Int,Int) -> [(Int,Int,Int)] -> (Int,Int,Int)
solve x xs = head [c | x0 <- [0..100], y0 <- [0..100], let c = (x0,y0,calcH x x0 y0), check xs c]

calcH :: (Int,Int,Int) -> Int -> Int -> Int
calcH (x1,y1,h1) x0 y0 = h1 + abs (x1-x0) + abs (y1-y0)

check :: [(Int,Int,Int)] -> (Int,Int,Int) -> Bool
check xs (x0,y0,h0) = all valid xs
  where
    valid (x1,y1,h1) = h1 == max 0 (h0 - abs (x0-x1) - abs (y0-y1))


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

query :: [(Int,Int,Int)] -> [(Int,Int,Int)]
query cs =
  foldl' (flip $ \(x,y,h) ->
             filter $ if h > 0
                      then (\(cx,cy,ch) -> ch == h + abs (x-cx) + abs (y-cy))
                      else (\(cx,cy,ch) -> ch <= abs (x-cx) + abs (y-cy)))
  [(cx,cy,h0 + abs (x0-cx) + abs (y0-cy)) | cx <- [0..100], cy <- [0..100]]
  cs'
  where
    (cs0,(x0,y0,h0):cs1) = span (\(_,_,h) -> h <= 0) cs
    cs' = cs0 ++ cs1

main :: IO ()
main = do
  n <- getLine
  cs <- map ((\(a:b:c:_)->(a,b,c))
              . unfoldr (B.readInt . B.dropWhile (== ' ')))
         . B.lines <$> B.getContents
  let (cx,cy,ch):_ = query cs
  putStrLn $ show cx ++ ' ' : show cy ++ ' ' : show ch


import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe (catMaybes)
import Text.Printf(printf)
import Control.Exception (assert)

dst :: (Int, Int) -> (Int, Int) -> Int
dst (x1, y1) (x2, y2) = abs (x2 - x1) + abs (y2 - y1)

f1 :: (Int, Int) -> ((Int, Int), Int) -> Int
f1 (cx, cy) ((x, y), h) = dst (x, y) (cx, cy) + h

f2 :: (Int, Int) -> [((Int, Int), Int)] -> Maybe ((Int, Int), Int)
f2 cs xss = if length (group ys) == 1 then Just (cs, head ys) else Nothing
 where
    ys = fmap (f1 cs) xss

main :: IO ()
main = do
    n <- readLn :: IO Int
    xss <- replicateM n $ do
        [x, y, h] <- fmap read . words <$> getLine :: IO [Int]
        return ((x, y), h)
    let cs = [(x, y) | x <- [0 .. 100], y <- [0 .. 100]]
    let ms = catMaybes $ fmap (flip f2 xss) cs
    assert (not $ null ms) (return ())
    let ((cx, cy), h) = head ms
    printf "%d %d %d\n" cx cy h


import Data.List
main = do
    [a,b,c] <- words <$> getLine
    let s = (sort [a,b,c])!!0
    let m = (sort [a,b,c])!!1
    let l = (sort [a,b,c])!!2
    print $ read(concat [l,m]) + read s

Score : 100 points

Problem Statement

You have decided to give an allowance to your child depending on the outcome of the game that he will play now.

The game is played as follows:

There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it.

The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)

Then, the amount of the allowance will be equal to the resulting value of the formula.

Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

Constraints

All values in input are integers.

1 \leq A, B, C \leq 9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the maximum possible amount of the allowance.

Sample Input 1

1 5 2

Sample Output 1

53

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.

Sample Input 2

9 9 9

Sample Output 2

108

Sample Input 3

6 6 7

Sample Output 3

82


{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

class Printable a where
  format :: a -> String

instance Printable Int where
  format = show

instance Printable Integer where
  format = show

instance Printable Double where
  format = show

instance Printable Float where
  format = show

instance Printable Char where
  format = show

instance Printable String where
  format x = x

instance Printable Bool where
  format = show

put :: Printable a => a -> IO ()
put = putStr . format

putLn :: Printable a => a -> IO ()
putLn = putStrLn . format

putList :: Printable a => [a] -> IO ()
putList [a] = put a
putList (a:as) = do
  put a
  putStr " "
  putList as

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
  [a, b, c] <- sortOn Down <$> readInt
  put $ a * 10 + b + c


import Control.Applicative
import Data.List

main :: IO ()
main = do
    ns <- map read . words <$> getLine
    putStrLn $ show (solve (sort ns))

solve :: [Int] -> Int
solve (n:ns) = n + (head ns + (last ns) * 10)


main=do
 [a,b,c]<-map read.words<$>getLine
 print(a+b+c+(max(max a b)c)*9)


import Data.List(sort)
main = do
    a <- map read . words <$> getLine :: IO [Int]
    print $ read (f2 a) + last (f a)
        where f = reverse . sort
              f2 a = let (b:c:_) = init (f a) in show b ++ show c


main=interact$show.f.map read.words;f l=sum l+9*maximum l


import Data.List
main = do
  a <- map read . words <$> getLine
  let b = reverse $ sort a
  print $ 10 * head b + sum (tail b)


main :: IO ()
main = do
    ls <- fmap (map read . words) getLine :: IO [Int]
    print $ sum ls + 9 * maximum ls


main=interact $ show.f.map read.words
f x = 9 * (maximum x) + (sum x)


import Data.List
main = do
    [a,b,c]<-sort.map read.words<$>getLine::IO [Int]
    print $ c*10+a+b


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

toInt :: (String -> Int)
toInt x = read x ::Int

getInts = do
  x <- getLine
  let y = (map$toInt)$words x
  return y

getStr = do
  x <- getLine
  let y = words x
  return y

main :: IO ()
main = do
  x <- getInts
  let a = sort x
  let b = splitAt 1 a
  let f = fst b
  let s = snd b
  print $ (foldl (+) 0 $ map (\x -> snd x * 10^(fst x)) $ zip [0..((length s)-1)] s) + head f


import Data.List

readInt :: String -> Int
readInt = read

main = do
    s <- sort.map readInt.words<$>getContents
    print $ solve s

solve :: [Int] -> Int
solve [a,b,c] = a + b + 10*c


import Data.List

solve a b c =
  let [x,y,z] = sort [a,b,c]
  in 10*z+y+x

main = do
  cont <- getContents
  let [a,b,c] = map read $ words cont
      n = solve a b c
  putStrLn $ show n


{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

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

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)
listToTuple5 [a,b,c,d,e] = (a,b,c,d,e)

readIntBS = fst . fromJust . BS.readInt

for = flip map

infixr 1 ?
(?) :: Bool -> (a,a) -> a
(?) b t = (if b then fst else snd) t

main :: IO ()
main = do
  [a,b,c] <- sort . map read . words <$> getLine
  print $ c*10+b+a


import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [_,_,x,y] <- map (read::String->Int) . words <$> getLine
  xmax <- maximum . map (read::String->Int) . words <$> getLine
  ymin <- minimum . map (read::String->Int) . words <$> getLine
  putStrLn $ war [z|z<-[x..y], xmax<z, z<=ymin]

war l
  |length l/=0 = "No War"
  |otherwise   = "War"

Score : 200 points

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.

One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.

If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

X < Z \leq Y

x_1, x_2, ..., x_N < Z

y_1, y_2, ..., y_M \geq Z

Determine if war will break out.

Constraints

All values in input are integers.

1 \leq N, M \leq 100

-100 \leq X < Y \leq 100

-100 \leq x_i, y_i \leq 100

x_1, x_2, ..., x_N \neq X

x_i are all different.

y_1, y_2, ..., y_M \neq Y

y_i are all different.

Input

Input is given from Standard Input in the following format:

N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

Output

If war will break out, print War; otherwise, print No War.

Sample Input 1

3 2 10 20
8 15 13
16 22

Sample Output 1

No War

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.

X = 10 < 16 \leq 20 = Y

8, 15, 13 < 16

16, 22 \geq 16

Sample Input 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

Sample Output 2

War

Sample Input 3

5 3 6 8
-10 3 1 5 -100
100 6 14

Sample Output 3

War


main = do
  [n, m, _X, _Y] <- map read . words <$> getLine :: IO [Int]
  x <- map read . words <$> getLine :: IO [Int]
  y <- map read . words <$> getLine :: IO [Int]
  putStrLn $ if maximum (_X:x) < minimum (_Y:y) then "No War" else "War"


main :: IO()
main = do
    [_,_,x,y] <- map read . words <$> getLine
    xls <- map read . words <$> getLine
    yls <- map read . words <$> getLine
    putStrLn $ if (judge x y xls yls) then "War" else "No War"

--戦争起こるならTrue 起こらないならFalse
judge :: Int -> Int -> [Int] -> [Int] -> Bool
judge x y xls yls
    | xmax >= ymin			= True
    | ymin <= x				= True
    | xmax >= y				= True
    | otherwise				= False
    where xmax = maximum xls
          ymin = minimum yls


main=do
 [n,m,x,y]<-map read.words<$>getLine
 a<-map read.words<$>getLine
 b<-map read.words<$>getLine
 putStrLn$(if null [k|k<-[x+1,x+2..y],maximum a < k, minimum b >= k] then [] else "No ")++"War"


main :: IO ()
main = do
    [_, _, x, y] <- fmap (map read . words) getLine :: IO [Int]
    xs           <- fmap (map read . words) getLine :: IO [Int]
    ys           <- fmap (map read . words) getLine :: IO [Int]
    putStrLn $ if maximum (x : xs) < minimum (y : ys) then "No War" else "War"


parseLine :: IO [Int]
parseLine = map read . words <$> getLine

main = do
  [n, m, x, y] <- parseLine
  xs <- parseLine
  ys <- parseLine

  if (maximum (x:xs)) < (minimum (y:ys))
    then putStrLn "No War"
    else putStrLn "War"


module Main where

import           Control.Monad
import           Data.List

readInt :: String -> Int
readInt = read

main :: IO()
main = do
  [n,m,x,y] <- map readInt . words <$> getLine
  xs <- map readInt . words <$> getLine
  ys <- map readInt . words <$> getLine
  if solve x y xs ys
    then putStrLn "No War"
    else putStrLn "War"

solve :: Int -> Int -> [Int] -> [Int] -> Bool
solve x y xs ys =
  let
    overXtoY = [x+1..y]
    maxXs = maximum xs
    minYs = minimum ys
  in
    any (\z -> z > maxXs && z <= minYs) overXtoY


main = do
    [n, m, lx, ly] <- map read . words <$> getLine :: IO [Int]
    xs             <- map read . words <$> getLine :: IO [Int]
    ys             <- map read . words <$> getLine :: IO [Int]
    let maxX = maximum xs
    let minY = minimum ys
    if (lx < ly && maxX < minY && maxX < ly && lx < minY)
        then print "No War"
        else print "War"


import Data.List

main = do
  [_,_,x,y] <- map read . words <$> getLine
  xs  <- sort . (:) x . map read . words <$> getLine :: IO [Int]
  ys  <- sort . (:) y . map read . words <$> getLine :: IO [Int]
  putStrLn $ if last xs < head ys then "No War" else "War"


main :: IO ()
main = do
  (n:m:x:y:_) <- fmap (map read . words) getLine :: IO [Int]
  xs <- fmap (map read . words) getLine :: IO [Int]
  ys <- fmap (map read . words) getLine :: IO [Int]
  putStrLn $ if war (x:xs) (y:ys)
             then "War"
             else "No War"

war :: [Int] -> [Int] -> Bool
war xs ys = (maximum xs) >= (minimum ys)


main :: IO ()
main = do
    [n, m, x, y] <- readInts
    xs           <- readInts
    ys           <- readInts
    putStrLn $ if solve n m x y xs ys then "No War" else "War"

solve :: Int -> Int -> Int -> Int -> [Int] -> [Int] -> Bool
solve n m x y xs ys = any (\z -> maximum xs < z && minimum ys >= z) [x + 1 .. y]

readInts :: IO [Int]
readInts = map read . words <$> getLine


main = do
    [a,b] <- map read . words <$> getLine
    putStrLn $ if a/=2 && b/=2 then "Yes" else "No"

Score : 100 points

Problem Statement

You are given integers A and B, each between 1 and 3 (inclusive).

Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number.

Constraints

All values in input are integers.

1 \leq A, B \leq 3

Input

Input is given from Standard Input in the following format:

A B

Output

If there is an integer C between 1 and 3 that satisfies the condition, print Yes; otherwise, print No.

Sample Input 1

3 1

Sample Output 1

Yes

Let C = 3. Then, A \times B \times C = 3 \times 1 \times 3 = 9, which is an odd number.

Sample Input 2

1 2

Sample Output 2

No

Sample Input 3

2 2

Sample Output 3

No


import Data.List
main = do
    [a,b] <- map read . words <$> getLine
    putStrLn $ if a/=2 && b/=2 then "Yes" else "No"


import Control.Applicative
import Data.List

main :: IO ()
main = do
    [a, b] <- map read . words <$> getLine
    putStrLn $ (if a == 2 || b == 2 then "No" else "Yes")


import Data.List
import Data.Bits
import Data.List.Split

main = do
  [a,b] <- map read . words <$> getLine::IO [Int]
  putStrLn $ if odd (a * b) then "Yes" else "No"


bta True = "Yes"
bta False = "No"

main = do
  ab <- product . map read . words <$> getLine
  putStrLn . bta . odd $ ab


main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  putStrLn $ if odd $ a * b then "Yes" else "No"


{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V

getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]

type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)

mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
fi = fromInteger
fig = fromIntegral
rf = realToFrac

(.<.) f g -- combination
    | f < g = 0
    | g < 1 || f < 1 = 1
    | True = foldr1 (*) (take g [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)

unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x

zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros

i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)

mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a

countIf f = length . filter f

--
--
--

main = do
  a <- getIs
  putStrLn $ bool "Yes" "No" (any (\x -> mod x 2 == 0) a)


import Control.Applicative

main = do
    [a,b] <- map read . words <$> getLine
    putStrLn $ if (mod (a*b) 2) == 0 then "No" else "Yes"


main :: IO ()
main =
    (map read).words <$> getLine >>=
        putStrLn.(\[a,b] -> if(a/=2 && b/=2) then "Yes" else "No")


main :: IO ()
main = do
  [a, b] <- map (read :: String -> Int) . words <$> getLine
  if even (a * b)
    then putStrLn "No"
    else putStrLn "Yes"


main :: IO ()
main = do
    ab <- getLine
    let list = words ab
    let list2 = map read list :: [Int]
    -- putStrLn $ unwords $ map show list2
    solve list2

solve :: [Int] -> IO ()
solve listt
    | ( mod ( listt !! 0 ) 2 == 1 ) && ( mod ( listt !! 1 ) 2 == 1 ) = putStrLn "Yes"
    | otherwise = putStrLn "No"


import Control.Applicative

main :: IO ()
main = do
  [a,b] <- map read . words <$> getLine :: IO [Int]
  putStrLn $ if odd $ a*b then "Yes" else "No"


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

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

readInt = ( readLn :: IO Int )
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

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

main = readInts	>>= putStrLn . which "Yes" "No" . all odd


main = do
    [a,b] <- ((fmap read . words) <$> getLine)
    if a == 2 || b== 2 then putStrLn "No"
                       else putStrLn "Yes"


import Data.List
import Control.Monad

main = do
    n <- readLn :: IO Int
    ws <- lines <$> getContents
    let p1 = and $ zipWith check ws (tail ws)
    let p2 = (== length ws) . length . group $ sort ws
    putStrLn $ if p1 && p2 then "Yes" else "No"

check w1 w2 = l == h
    where l = last w1
          h = head w2

Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

In the first turn, a player announces any one word.

In the subsequent turns, a player announces a word that satisfies the following conditions:

That word is not announced before.

The first character of that word is the same as the last character of the last word announced.

In this game, he is practicing to announce as many words as possible in ten seconds.

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

Constraints

N is an integer satisfying 2 \leq N \leq 100.

W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

As hoge is announced multiple times, the rules of shiritori was not observed.

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No


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

readInt = fst . fromJust . BS.readInt
readString = map BS.unpack . BS.words

getInt = readInt <$> BS.getLine
getNString n = map readString <$> replicateM n BS.getLine

check :: [String] -> [String] -> Char -> String
check _ [] c = "Yes"
check ds (w : ws) c
  | w `elem` ds = "No"
  | c == head w = check (w : ds) ws (last w)
  | otherwise = "No"

main = do
  n <- getInt
  ws <- getNString n
  let ws' = map head ws
  putStrLn $ check [head ws'] (tail ws') (last (head ws'))


--{-# LANGUAGE BangPatterns #-}
--{-# LANGUAGE ScopedTypeVariables #-}
--{-# LANGUAGE FlexibleContexts #-}
--{-# LANGUAGE ViewPatterns #-}
--{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BC
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ord
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Debug.Trace
-- import qualified Data.Vector.Algorithms.Merge as VAM
-- import qualified Data.Heap as HP
-- import Numeric.Extra
-- import Data.Tuple.Extra
-- import Data.List.Extra

--------------------------------------------------------------------------
solve [] _ = True
solve (xs:xss) (ys:yss) = (head xs == last ys) && (notElem xs (ys:yss)) && (solve xss (xs:ys:yss))

main = do
    n <- int
    xss <- replicateM n $ str >>= return
    yesnoL $ solve (tail xss) [head xss]
--------------------------------------------------------------------------

-- Input Util
int :: IO Int
int = BC.getLine >>= return . bsToInt

double :: IO Double
double = BC.getLine >>= return . bsToDouble

str :: IO String
str = getLine

strBS :: IO BC.ByteString
strBS = BC.getLine

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

bsToDouble :: BC.ByteString -> Double
bsToDouble = read . BC.unpack

parseInt :: BC.ByteString -> Maybe (Int, BC.ByteString)
parseInt = BC.readInt . BC.dropWhile isSpace

sLineToIntL :: IO [Int]
sLineToIntL = strBS >>= return . map bsToInt . BC.words

sLineToDoubleL :: IO [Double]
sLineToDoubleL = strBS >>= return . map bsToDouble . BC.words

sLineToIntV :: Int -> IO (VU.Vector Int)
sLineToIntV n = strBS >>= return . VU.unfoldrN n parseInt

sLineToDoubleV :: IO (VU.Vector Double)
sLineToDoubleV = strBS >>= return . VU.fromList . map bsToDouble . BC.words

mLinesToIntL :: Int -> IO [Int]
mLinesToIntL n = replicateM n (strBS >>= return . bsToInt)

mLinesToDoubleL :: Int -> IO [Double]
mLinesToDoubleL n = replicateM n (strBS >>= return . bsToDouble)

mLinesToIntV :: Int -> IO (VU.Vector Int)
mLinesToIntV n = VU.replicateM n (strBS >>= return . bsToInt)

mLinesToDoubleV :: Int -> IO (VU.Vector Double)
mLinesToDoubleV n = VU.replicateM n (strBS >>= return . bsToDouble)

mLinesToTupleL :: Int -> IO [(Int, Int)]
mLinesToTupleL n = replicateM n (strBS >>= return . (\[a,b] -> (a,b)) . map bsToInt . BC.words)

mLinesToTripleL :: Int -> IO [(Int, Int, Int)]
mLinesToTripleL n = replicateM n (strBS >>= return . (\[a,b,c] -> (a,b,c)) . map bsToInt . BC.words)

mLinesToTupleV :: Int -> IO (VU.Vector (Int, Int))
mLinesToTupleV n = VU.replicateM n $ do
    bs <- strBS
    let
        Just (a, bs') = parseInt bs
        Just (b, _) = parseInt bs'
    return (a,b)

mLinesToTripleV :: Int -> IO (VU.Vector (Int, Int, Int))
mLinesToTripleV n = VU.replicateM n $ do
    bs <- strBS
    let
        Just (a, bs') = parseInt bs
        Just (b, bs'') = parseInt bs'
        Just (c, _) = parseInt bs''
    return (a,b,c)

-- output
yesnoL :: Bool -> IO ()
yesnoL cond
    | cond = putStrLn "Yes"
    | otherwise = putStrLn "No"

yesnoU :: Bool -> IO ()
yesnoU cond
    | cond = putStrLn "YES"
    | otherwise = putStrLn "NO"

-- others
strToChr :: String -> Char
strToChr [x] = x

chrToStr :: Char -> String
chrToStr x = [x]

m1 :: Int -> Int
m1 x = subtract 1 x

toDouble :: Int -> Double
toDouble x = fromIntegral x

toInt :: Double -> Int
toInt x = floor x


main=interact$t.s[].tail.words
s _(b:[])=False
s [](a:b)=s[a]b
s x(a:b:c)=last a/=head b||elem b x||s(b:x)(b:c)
t True="No"
t _="Yes"


import           Control.Monad
import           Data.List

main :: IO ()
main = do
    n  <- fmap read getLine :: IO Int
    ws <- replicateM n getLine :: IO [String]
    putStrLn $ if iscont ws && not (isdup ws) then "Yes" else "No"

iscont :: [String] -> Bool
iscont ws = all (\(v, w) -> last v == head w) $ zip (init ws) (tail ws)

isdup :: [String] -> Bool
isdup ws = length ws /= length (nub ws)


import Control.Monad

main = do
  n <- liftM read $ getLine
  ls <- forM [1..n] (\ _ -> getLine)
  putStrLn $ abc109b ls

abc109b ls
  | noDupe ls && connected ls = "Yes"
  | True = "No"

noDupe [] = True
noDupe (x:xs) = null bs && noDupe as && noDupe cs
  where
    (as,bs,cs) = part3 x xs

part3 _ [] = ([],[],[])
part3 p (x:xs) =
  case compare p x of
    LT -> (x:as,bs,cs)
    EQ -> (as,x:bs,cs)
    GT -> (as,bs,x:cs)
  where
    (as,bs,cs) = part3 p xs

connected [] = True
connected xs = and $ zipWith (==) (map last xs) (map head $ tail xs)


module Main where

import           Data.List

main :: IO ()
main = do
    n    <- readLn :: IO Int
    list <- (sequence . take n . repeat) getLine
    putStr
        $ if (length . nub) list
             == length list
             && (siritori ((head . head) list) list)
          then
              "Yes"
          else
              "No"
    return ()

siritori :: Char -> [String] -> Bool
siritori _    []       = True
siritori next (x : xs) = head x == next && siritori (last x) xs


import Control.Monad (replicateM)
main :: IO ()
main = do
    n <- readLn
    ws <- replicateM n getLine
    case nodup ws of
        True -> putStrLn "Yes"
        False -> putStrLn "No"

nodup (a:[]) = False
nodup (a:b:c) = (last a) == (head b) && (notElem a (b:c)) && nodup (b:c)


import Data.List
import Data.Function

main = readLn >>= sequence . ($ getLine) . replicate >>=
  putStrLn . ($ "No") . ($ "Yes") . if' . test

if' p x y = if p then x else y

test :: [String] -> Bool
test xs = valid && unique where
  valid   = and . zipWith ((==) `on` head) xs .
            map reverse . tail $ xs
  unique  = all (== 1) . map length . group . sort $ xs


import Control.Monad

main :: IO()
main = do
    n <- readLn
    list <- replicateM n getLine
    {-replicateM n getLine←これ使うline送ってもらったしdiscodeにも書いてあるからそれ参考に頑張れ！-}
    --let list = scan n
    if loop list  == False
        then putStrLn "No"
        else ( if (siritori list n ) > 0 then putStrLn "No" else putStrLn "Yes" )

{-
scan :: String -> IO [String]
scan 0 = return []
scan n = do
    w <- getLine
    l <- scan $ n-1
    return w:l
-}

loop :: (Eq a) => [a] -> Bool
loop (x:xs) = elemm x xs

elemm :: (Eq a) => a -> [a] -> Bool
elemm a [] = False
elemm a (x:xs)
    | ( x == a ) = True
    | otherwise = elemm a xs

siritori :: [String] -> Int -> Int
siritori list n
    | ( n == 1 ) = 0
    | last (list !! (n-1)) == head (list !! n) = 0 + (siritori list (n-1))
    | otherwise = 1 + (siritori list (n-1))


import Control.Monad

solver::[String]->Char->[String]->Bool
solver _ _ [] = True
solver says l (x:xs) = if (head x) == l && not (elem x says) then solver (x:says) (last x) xs else False

main::IO()
main=do
  nc<-getLine
  let n = read nc ::Int
  dat<-mapM (\_-> getLine ) [1..n]
  putStr (if solver [(head dat)] (last (head dat)) (tail dat) then "Yes\n" else "No\n")


{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Control.Monad.Primitive
import Control.Applicative
import Control.Arrow
import Data.List
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import qualified Data.Sequence as Sq
import Data.Tuple
import Data.Function
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)
listToTuple5 [a,b,c,d,e] = (a,b,c,d,e)

readIntBS = fst . fromJust . BS.readInt

for = flip map

infixr 1 ?
(?) :: Bool -> (a,a) -> a
(?) b t = (if b then fst else snd) t

main :: IO ()
main = do
  n <- readLn :: IO Int
  ws <- lines <$> getContents

  putStrLn $ if func ws && (length . nub) ws == length ws then "Yes" else "No"

func (x:[]) = True
func (x:y:xs) = if last x == head y then func (y:xs) else False


import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  li <- BS.getLine
  let [n,x] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  li <- BS.getLine
  let xs = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let ans = compute n x xs
  print ans

compute :: Int -> Int -> [Int] -> Int
compute n x xs = w
  where
    xs1 = sort (x:xs)
    w = foldl1' gcd $ zipWith subtract xs1 (tail xs1)

Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999


import Control.Monad
import Control.Monad.ST
import qualified Data.Array as A
import qualified Data.Array.ST as ST
import qualified Data.Array.Unboxed as AU
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.Int
import qualified Data.IntMap as IM
import Data.List
import qualified Data.Map as M
import Data.Maybe
import Data.Ord
import qualified Data.Set as S
import Data.Time
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
  [n, x] <- readInt
  xs <- readInt
  print $ solve x xs

solve x xs = ans
  where
    distances = map (\x' -> abs (x' - x)) xs
    ans = foldl1 gcd distances


{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

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

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ n, x ] <- readInts
	xs <- map ( abs . subtract x ) <$> readInts
	print $ foldl1 gcd xs


main = do
  [n,x] <- map read. words <$> getLine::IO[Int]
  xn <- map read . words <$> getLine::IO[Int]
  print $ abs $ foldl1 gcd $ map (\y -> y-x) xn


import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

main = do
    [n,x] <- map read . words <$> getLine
    xs <- sort . (x:) . VU.toList . VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine :: IO [Int]
    let xs' = map snd $ drop 2 $ scanl' (\(prev, _) x -> (x, abs $ prev - x)) (0, 0) xs :: [Int]
    print $ foldl1' gcd xs'


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

main :: IO ()
main = do
    [n,x0] <- map read . words <$> getLine :: IO [Int]
    x <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    let xs = sort (x0:x)
    print . foldr1 gcd . tail $ zipWith (-) xs (0:xs)


{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import           Unsafe.Coerce

main :: IO ()
main = do
    [n, x] <- map read.words <$> getLine :: IO [Int]
    xs <- U.unfoldrN n (C.readInt.C.dropWhile isSpace) <$> C.getLine
    print $ solve x xs

solve :: Int -> U.Vector Int -> Int
solve x xs = U.foldl gcd 0 $ U.map (subtract x) xs

-------------------------------------------------------------------------------
type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)


import Data.List(sort)

main = do
    [n, x] <- map read . words <$> getLine
    y <- map (read :: String -> Integer) . words <$> getLine
    putStrLn $ show $ foldr1 gcd (sort $ x:y)


import Control.Applicative

main = do
    [n,x] <- map read . words <$> getLine
    xlist <- map read . words <$> getLine
    print $ solve x xlist

solve :: Integer -> [Integer] -> Integer
solve x list = foldl (\acc elem -> gcd acc (elem - x)) (head list - x) (tail list)


module Main where

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

main :: IO ()
main = do
    [_, x] <- fmap read . words <$> getLine :: IO [Int]
    xs <- fmap read . words <$> getLine :: IO [Int]
    let ys = sort (x:xs)
    let d = minimum $ fmap (\(a,b) -> b-a) $ zip ys (tail ys)
    let f d = let r = (head ys) `mod` d
              in all (== r) (fmap (`mod` d) ys)
    let ans = head $ filter f [d, d-1 .. 1]
    print ans


import Data.List
factor 1 = [1]
factor x = reverse $sort $nub $1:inFactor [] [1] 2 x
 where
  inFactor fadd all begin x
   | x == begin       = fadd++(x:map (*begin) all)
   | mod x begin == 0 = let bye = begin:map (*begin) all in inFactor (fadd++bye)  bye begin (div x begin)
   | otherwise        = inFactor fadd all (begin+1) x
-- factor x = x:[y|y<-[div x 2,div x 2 -1..1],mod x y == 0]

check [1] _ = 1
check (x:xs) list = if null (filter ((0/=) . flip mod x) list) then x else check xs list

main = do
 [n,x] <- map read . words <$> getLine :: IO [Int]
 xs <- map read. words <$> getLine
 let list = map (flip(-)(minimum (x:xs))) $ sort (x:xs)
 print $ check (factor (head $ tail list)) $ drop 2 list


main = do
  [n, x] <- map read . words <$> getLine
  s <- map (subtract x . read) . words <$> getLine
  print $ foldl1 gcd s


main = read . last . words <$> getLine >>= \x -> foldr1 gcd . map (subtract x . read) . words <$> getLine >>= print


main :: IO ()
main = do
  [_, x] <- map read . words <$> getLine
  xs <- map read . words<$> getLine
  print $ solve x xs

solve :: Int -> [Int] -> Int
solve x = foldl1 gcd . map (abs . subtract x)


main = do
    [_,x] <- ((fmap read . words) <$> getLine) :: IO [Int]
    xs <- (fmap (abs . subtract x . read) . words) <$> getLine
    print $ gcdL xs

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


import Data.List

main = do
 x <- read.last.words <$> getLine
 xs <- map read.words <$> getLine
 let xs' = sort (x:xs) :: [Int]
 print $ minimum $ zipWith (\x y -> y - x) xs' (tail xs')


readInt :: String -> Int
readInt = read

main = do
    s <- map readInt.tail.words<$>getContents
    print $ solve s

solve s = foldr gcd v (convert s)
 where
  v = head (convert s)

convert [] = []
convert [a] = []
convert (a:b:x) = [abs(a-b)] ++ convert (b:x)


main = do
 x <- read.last.words <$> getLine
 xs <- map read.words <$> getLine
 let xs' = (x:xs) :: [Int]
 print $ minimum [x2 - x1 | x1 <- xs', x2 <- xs', x1 < x2]


import Data.List

main = do
  [n,x] <- map read . words <$> getLine
  xs <- sort . (x :) . map read . words <$> getLine
  print $ foldl1' gcd (zipWith (flip (-)) xs (tail xs))


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

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

readInt = ( readLn :: IO Int )
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

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

main = do
	[ n, x ] <- readInts
	xs <- sort . ( x : ) <$> readInts
	print $ ( \l -> if length l == 1 then head l else foldl1 gcd l ) $ differences xs

differences [_] = []
differences ( a : rest@( b : xs ) ) = ( b - a ) : differences rest


solver::[Int]->Int->Int
solver coords init_pos = let d = (map (\x -> abs (init_pos - x)) coords) in
                         foldl gcd (head d) (tail d)

main::IO()
main=do
  nxc<-getLine
  let n:x:[]= map read (words nxc)::[Int]
  d<-getLine
  let dat = map read (words d) ::[Int]
  print (solver dat x)


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

main = do
    (n:x:_)<-map read.words<$>getLine::IO[Int]
    xs<-sort.(x:).unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
    print $ gcds $ dff [] xs
--
dff ac [_] = ac
dff ac (x:y:r) = dff ((y-x):ac) (y:r)
--
gcds [x] = x
gcds (a:ys) = gcd a $ gcds ys


main = do
    [d,n] <- map read . words <$> getLine :: IO [Int]
    print $ if n == 100 then 101 * (100^d) else n * (100^d)

Score: 200 points

Problem Statement

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.

As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

Find the N-th smallest integer that would make Ringo happy.

Constraints

D is 0, 1 or 2.

N is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

D N

Output

Print the N-th smallest integer that can be divided by 100 exactly D times.

Sample Input 1

0 5

Sample Output 1

5

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...

Thus, the 5-th smallest integer that would make Ringo happy is 5.

Sample Input 2

1 11

Sample Output 2

1100

The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \ 000, 1 \ 100, ...

Thus, the integer we are seeking is 1 \ 100.

Sample Input 3

2 85

Sample Output 3

850000

The integers that can be divided by 100 exactly twice are as follows: 10 \ 000, 20 \ 000, 30 \ 000, ...

Thus, the integer we are seeking is 850 \ 000.


main = do
    [d,n] <- map read . words <$> getLine :: IO [Int]
    print $ n * (100^d)


{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

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

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ d, n ] <- readInts
	let
		n' = if n == 100 then 101 else n
	print $ n' * ( 100 ^ d )


{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

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

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ d, n ] <- readInts
	print $ if d == 0 && n == 100
		then 101
		else n * ( 100 ^ d )


{-# LANGUAGE CPP #-}

module Main where

import qualified Data.Vector.Unboxed as V
import qualified Data.Map.Strict as M
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Char
import qualified Data.List as L

dump :: (Show a) => a -> IO ()

#if __GLASGOW_HASKELL__ >= 800
dump x = print x
#else
dump _ = pure ()
#endif

-- "101010" -> [1,0,1,0,1,0]
readToList :: String -> [ Int ]
readToList [] = []
readToList (x : xs) = read [ x ] : readToList xs

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

-- "10 10 10" -> [10, 10, 10]
getList :: IO [ Int ]
getList = (fmap (read . BS.unpack) . BS.words) <$> BS.getLine

-- "10 10 10" -> [10, 10, 10]
getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readmat :: Int -> IO [ [ Int ] ]
readmat rows = replicateM rows getList

newtype UF a = UF (M.Map a a)
    deriving ( Show ) -- Map node parent

makeuf :: Int -> UF Int
makeuf n = let m = M.fromList $ zip [ 0 .. n ] [ 0 .. n ] in UF m

unionUF :: ( Eq a, Ord a ) => a -> a -> UF a -> UF a
unionUF l r uf @ (UF m) = let lp = findUF l uf
                              rp = findUF r uf in if lp == rp then uf
    else if size l uf < size r uf then UF $ M.update (const $ Just rp) lp m
        else UF $ M.update (const $ Just lp) rp m

findUF :: ( Eq a, Ord a ) => a -> UF a -> a
findUF x uf @ (UF m) = let px = m M.! x in if px == x then px else findUF px uf -- TODO 貼り直し

size :: ( Eq a, Ord a ) => a -> UF a -> Int
size x (UF m) = M.size $ M.filter (\par -> par == x) m

genbit :: Int -> [ [ Int ] ]
genbit 0 = []
genbit 1 = [ [ 0 ], [ 1 ] ]
genbit len = do
    x <- [ 0, 1 ]
    map (x :) $ genbit (len - 1)

base :: Int
base = 10 ^ 9 + 7

forn :: ( Num a, Enum a, Monad m ) => a -> (a -> m b) -> m [ b ]
forn x = forM [ 0 .. (x - 1) ]

count :: (Eq a) => a -> [ a ] -> Int
count y = length . filter (== y)

main :: IO ()
main = do
    [ d, n ] <- getList
    if n /= 100 then print $ 100 ^ d * n else print $ 100 ^ d * (n + 1)


main :: IO ()
main = do
    [d,n] <- map read . words <$> getLine :: IO [Int]
    print $ if d == 0
       then [i | i <- [1..], (i `mod` 100) /= 0] !! n-1
       else 100^d * n


main :: IO ()
main = do
    [d,n] <- map read . words <$> getLine :: IO [Integer]
    print $ (100^d) * n


main :: IO ()
main = do
    [d,n] <- map read . words <$> getLine :: IO [Int]
    print $ [ i * (100^d) | i <- [1..] ] !! (n-1)


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

solve :: Int -> Int -> Int
solve d n = 100^d * n


module Main where

import Data.List.Split

algorithm :: Int -> Int ->  Int
algorithm d n = (n-((n-1) `div` 99))*100^d

process :: [String] -> String
process ls = case  splitOn " " $ head ls of
  [x, y] -> show $ algorithm (read x) (read y)
  _ -> "Wrong input"

main :: IO ()
main = do
  input <- getContents
  putStrLn $ process (lines input)


import Data.List

solve :: Int -> Int -> Int
solve d n = head $ drop (n - 1) $ filter (\x -> x `mod` 100^(d + 1) /= 0) [100^d, 100^d*2..]

main :: IO ()
main = do
  [d, n] <- map read . words <$> getLine
  print $ solve d n


import Data.Char

main = do
    [d, n] <- map read . words <$> getLine
    putStrLn $ show $ ans d n

ans 0 n = last . take n $ filter (\x -> x `mod` 100 /= 0) [1..]
ans 1 n = last . take n $ filter (\x -> x `mod` 100 == 0 && x `mod` 10000 /= 0) [1..]
ans 2 n = last . take n $ filter (\x -> x `mod` 10000 == 0 && x `mod` 1000000 /= 0) [1..]


import Data.Char

main = do
    [d, n] <- words <$> getLine
    putStrLn $ ans (read d) n

ans d n = n ++ (take (2 * d) $ repeat '0')


import Control.Monad
import Control.Applicative

solver :: [Int] -> Int
solver [d, n]
    | d == 0 && n == 100 = 101
    | d == 0             = n
    | n == 100           = (n+1) * (100^d)
    | otherwise          = n * (100^d)

main :: IO ()
main = getLine >>= print . solver . (map read) . words


import Control.Monad
import Control.Applicative

solver :: [Int] -> Int
solver [d, n]
    | d == 0    = n
    | otherwise = n * (100^d)

main :: IO ()
main = getLine >>= print . solver . (map read) . words


main :: IO ()
main = do
  [d, n] <- map read . words <$> getLine
  print $ solve d n

solve :: Int -> Int -> Int
solve d n = length [ i | i <- [1..n], i `mod` 100 > 0 ] * 100 ^ d


import Control.Applicative

main :: IO ()
main = getLine >>= putStrLn . solve . map read . words

solve :: [Int] -> String
solve [a,100] = show (100 ^ a * 101)
solve [a,b] = show (100 ^ a * b)


main :: IO ()
main = do
  [d, n] <- map read . words <$> getLine
  print $ solve d n 0

solve :: Int -> Int -> Int -> Int
solve d 0 x = x
solve d n x
  | x `mod` 10000 == 0 = solve d n (x+100)
  | otherwise = solve d (n-1) x


main :: IO ()
main = do
  [d, n] <- map read . words <$> getLine
  print $ solve d n

solve :: Int -> Int -> Int
solve d n = n * 100 ^ d


main = do
  [d, n] <- map read . words <$> getLine :: IO [Int]
  print $ (100^d)*n + (if n==100 then
                         if d==0 then 1
                         else if d==1 then 100
                         else 10000
                       else 0)


solve 0 100 = 101
solve 0 a = a
solve 1 100 = 10100
solve 1 a = a * 100
solve 2 100 = 1010000
solve 2 a = a * 10000

main = do
  conts <- getContents
  let [a,b] = map read $ words conts
      answer = solve a b
  putStrLn $ show answer


solve 0 a = a
solve 1 a = a * 100
solve 2 a = a * 10000

main = do
  conts <- getContents
  let [a,b] = map read $ words conts
      answer = solve a b
  putStrLn $ show answer


main = do
    [d,n] <- (fmap read . words) <$> getLine
    if n == 100
        then putStrLn $ show $ 100^d*(n+1)
        else putStrLn $ show $ 100^d*n


import Data.List

main :: IO()
main = do
  [d, n] <- map read . words <$> getLine :: IO([Int])
  print $ solve d n

solve d 100 = solve d 101
solve d n = [100^d * a | a <- [1..101]] !! (n - 1)


import Control.Applicative ((<$>))

main :: IO ()
main = solve <$> map read <$> words <$> getLine >>= print

solve :: [Int] -> Int
solve [d, n] | d == 0 = ls !! (n-1)
             | d == 1 = map (*100) ls !! (n-1)
             | otherwise = map (*10000) ls !! (n-1)
  where ls = [1 .. 99] ++ [101]


f d n | d == 0 = n
      | d == 1 = 100 * n
      | d == 2 = 10000* n

main = do
    [d, n] <- map read . words <$> getLine
    print $ f d n


main = do
  [d, n] <- map read . words <$> getLine :: IO [Int]
  print $ (100^d)*n


import Control.Applicative

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

solve :: Int -> Int -> Int
solve d n | d == 0 = (filter (\x-> mod x 100 /= 0) [1..]) !! (n-1)
          | d == 1 = (filter (\x-> mod x 100 /= 0) [1..]) !! (n-1) * 100
          | d == 2 = (filter (\x-> mod x 100 /= 0) [1..]) !! (n-1) * 10000


Score : 200 points

Problem Statement

You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?

Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Constraints

0 \leq A, B, C \leq 50

A + B + C \geq 1

50 \leq X \leq 20 000

A, B and C are integers.

X is a multiple of 50.

Input

Input is given from Standard Input in the following format:

A
B
C
X

Output

Print the number of ways to select coins.

Sample Input 1

2
2
2
100

Sample Output 1

2

There are two ways to satisfy the condition:

Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.

Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.

Sample Input 2

5
1
0
150

Sample Output 2

0

Note that the total must be exactly X yen.

Sample Input 3

30
40
50
6000

Sample Output 3

213


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

readInt = fst . fromJust . BS.readInt

getInt = readInt <$> BS.getLine

divide :: Int -> Int -> Int -> Int -> Int
divide (-1) b c x = 0
divide a b c x = count + divide (a -1) b c x
  where
    remain = x - 500 * a
    count =
      if remain <= 100 * b + 50 * c
        then divideBc b c remain
        else 0

divideBc :: Int -> Int -> Int -> Int
divideBc (-1) c x = 0
divideBc b c x = count + divideBc (b -1) c x
  where
    remain = x - 100 * b
    count =
      if remain >= 0 then do
        let divided = remain `div` 50
        if divided <= c
          then 1
          else 0
      else 0

main = do
  a <- getInt
  b <- getInt
  c <- getInt
  x <- getInt
  print $ divide a b c x


--{-# LANGUAGE BangPatterns #-}
--{-# LANGUAGE ScopedTypeVariables #-}
--{-# LANGUAGE FlexibleContexts #-}
--{-# LANGUAGE ViewPatterns #-}
--{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BC
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ord
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Debug.Trace
-- import qualified Data.Vector.Algorithms.Merge as VAM
-- import qualified Data.Heap as HP
-- import Numeric.Extra
-- import Data.Tuple.Extra
-- import Data.List.Extra

--------------------------------------------------------------------------
main = do
    a <- int
    b <- int
    c <- int
    x <- int
    print $ length [() | i<-[0..a],j<-[0..b],k<-[0..c],(i*500+j*100+k*50) == x]
--------------------------------------------------------------------------

-- Input Util
int :: IO Int
int = readLn

double :: IO Double
double = readLn

str :: IO String
str = getLine

strBS :: IO BC.ByteString
strBS = BC.getLine

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

bsToDouble :: BC.ByteString -> Double
bsToDouble = read . BC.unpack

parseInt :: BC.ByteString -> Maybe (Int, BC.ByteString)
parseInt = BC.readInt . BC.dropWhile isSpace

sLineToIntL :: IO [Int]
sLineToIntL = strBS >>= return . map bsToInt . BC.words

sLineToDoubleL :: IO [Double]
sLineToDoubleL = strBS >>= return . map bsToDouble . BC.words

sLineToIntV :: Int -> IO (VU.Vector Int)
sLineToIntV n = strBS >>= return . VU.unfoldrN n parseInt

sLineToDoubleV :: IO (VU.Vector Double)
sLineToDoubleV = strBS >>= return . VU.fromList . map bsToDouble . BC.words

mLinesToIntL :: Int -> IO [Int]
mLinesToIntL n = replicateM n (strBS >>= return . bsToInt)

mLinesToDoubleL :: Int -> IO [Double]
mLinesToDoubleL n = replicateM n (strBS >>= return . bsToDouble)

mLinesToIntV :: Int -> IO (VU.Vector Int)
mLinesToIntV n = VU.replicateM n (strBS >>= return . bsToInt)

mLinesToDoubleV :: Int -> IO (VU.Vector Double)
mLinesToDoubleV n = VU.replicateM n (strBS >>= return . bsToDouble)

mLinesToTupleL :: Int -> IO [(Int, Int)]
mLinesToTupleL n = replicateM n (strBS >>= return . (\[a,b] -> (a,b)) . map bsToInt . BC.words)

mLinesToTripleL :: Int -> IO [(Int, Int, Int)]
mLinesToTripleL n = replicateM n (strBS >>= return . (\[a,b,c] -> (a,b,c)) . map bsToInt . BC.words)

mLinesToTupleV :: Int -> IO (VU.Vector (Int, Int))
mLinesToTupleV n = VU.replicateM n $ do
    bs <- strBS
    let
        Just (a, bs') = parseInt bs
        Just (b, _) = parseInt bs'
    return (a,b)

mLinesToTripleV :: Int -> IO (VU.Vector (Int, Int, Int))
mLinesToTripleV n = VU.replicateM n $ do
    bs <- strBS
    let
        Just (a, bs') = parseInt bs
        Just (b, bs'') = parseInt bs'
        Just (c, _) = parseInt bs''
    return (a,b,c)

-- output
yesnoL :: Bool -> IO ()
yesnoL cond
    | cond = putStrLn "Yes"
    | otherwise = putStrLn "No"

yesnoU :: Bool -> IO ()
yesnoU cond
    | cond = putStrLn "YES"
    | otherwise = putStrLn "NO"

-- others
strToChr :: String -> Char
strToChr [x] = x

chrToStr :: Char -> String
chrToStr x = [x]

m1 :: Int -> Int
m1 x = subtract 1 x

toDouble :: Int -> Double
toDouble x = fromIntegral x

toInt :: Double -> Int
toInt x = floor x


main :: IO ()
main = do
    a <- readLn
    b <- readLn
    c <- readLn
    x <- readLn :: IO Int
    let combinations = [i * 500 + j * 100 + k * 50 | i <- [0..a], j <- [0..b], k <- [0..c]]
    print . length $ filter (== x) combinations


main = do
  a <- readLn
  b <- readLn
  c <- readLn
  x <- readLn
  let ans = [na * 500 + nb * 100 + nc * 50 | na <- [0 .. a], nb <- [0 .. b], nc <- [0 .. c]]
  print $ length $ filter (==x) ans


main :: IO ()
main = do
    [a,b,c,x] <- map read . words <$> getContents
    print $ calc a b c x

calc :: Int -> Int -> Int -> Int -> Int
calc a b c x = length $ pairs a b c x

pairs :: Int -> Int -> Int -> Int -> [(Int,Int,Int)]
pairs a b c x = [(na,nb,nc) | na <- [0..a]
                            , nb <- [0..b]
                            , nc <- [0..c]
                            , exact na nb nc x]

exact :: Int -> Int -> Int -> Int -> Bool
exact a b c x = 500 * a + 100 * b + 50 * c == x


main :: IO ()
main = do
  a <- readLn :: IO Int
  b <- readLn :: IO Int
  c <- readLn :: IO Int
  x <- readLn :: IO Int
  print $ sum $ solve a b c x

solve a b c x = do
  i <- [0 .. a]
  j <- [0 .. b]
  k <- [0 .. c]
  if 500 * i + 100 * j + 50 * k == x
    then return 1
    else return 0


solve a b c x = do
  d <- [0..a]
  e <- [0..b]
  f <- [0..c]
  if 500*d+100*e+50*f==x
    then return x
    else []

main = do
  a <- readLn
  b <- readLn
  c <- readLn
  x <- readLn
  putStrLn $ show $ length $ solve a b c x


realize50::Int->Int->Int
realize50 lim50 n = if mod n 50 == 0 && div n 50 <= lim50 then 1 else 0

realize100::Int->Int->Int->Int
realize100 lim50 lim100 n = sum [realize50 lim50 (n-(100*i))|i<-[0..min lim100 (div n 100)]]

realize500::Int->Int->Int->Int->Int
realize500 lim50 lim100 lim500 n = sum [realize100 lim50 lim100 (n-(500*i))|i<-[0..min lim500 (div n 500)]]

main::IO()
main=do
  ac<-getLine
  bc<-getLine
  cc<-getLine
  xc<-getLine
  let a:b:c:x:[]=map read [ac,bc,cc,xc]::[Int]
  print (realize500 c b a x)


import Control.Applicative
import Data.Char

toInt :: String -> Integer
toInt str =
    let skipSpace :: String -> String
        skipSpace "" = ""
        skipSpace (' ':xs) = skipSpace xs
        skipSpace x = x
        toDigit :: String -> Integer
        toDigit "" = 0 :: Integer
        toDigit (x:xs)
            | isDigit x = (fromIntegral $ digitToInt x) + (toDigit xs) * 10 :: Integer
        in toDigit $ skipSpace $ reverse $ skipSpace str

main = do
    a <- mod <$> (toInt <$> getLine) <*> return 500
    b <- toInt <$> getLine
    putStrLn $ if (a <= b) then "Yes" else "No"


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

solve (a:b:c:x:_) = length [(i, j, k) | i <- [0..a], j <- [0..b], k <- [0..c], 500 * i + 100 * j + 50 * k == x]


import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- 整数の入力
    a <- readLn
    b <- readLn
    c <- readLn
    p <- readLn
    -- 出力
    putStrLn $ show $ length [1 | x <- [0..a], y <- [0..b], z <- [0..c], 50*x+100*b+500*c == p]


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

main :: IO ()
main = do
  [a, b, c, x] <- map (fst . fromJust . B.readInt) . B.words <$> B.getContents
  print $ length $ filter (== x) $ total <$> [0..a] <*> [0..b] <*> [0..c]
    where total u v w = 500*u + 100*v + 50*w


main :: IO()
main = do
    a <- readLn
    b <- readLn
    c <- readLn
    x <- readLn
    print $ length [[d,e,f] | d <- [0..a], e <- [0..b], f <- [0..c], 500*d+100*e+50*f==x]


main = do
    [a,b] <- map read . words <$> getLine
    putStrLn $ if (a*b) `mod` 2 == 0 then "Even" else "Odd"

Score : 100 points

Problem Statement

AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

Constraints

1 ≤ a,b ≤ 10000

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the product is odd, print Odd; if it is even, print Even.

Sample Input 1

3 4

Sample Output 1

Even

As 3 × 4 = 12 is even, print Even.

Sample Input 2

1 21

Sample Output 2

Odd

As 1 × 21 = 21 is odd, print Odd.


main = do
     [a, b] <- map read . words <$> getLine
     if odd (a * b)
     	then print "Odd"
     	else print "Even"


main :: IO ()
main = do
    [a, b] <- map read . words <$> getLine
    if even (a * b)
      then print "Even"
      else print "Odd"


main :: IO ()
main = do
	[a, b] <- map read . words <$> getLine
        if even (a * b)
          then print "Even"
          else print "Odd"


{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

main = do
  [a, b] <- readInt
  if even (a * b)
    then putStrLn "Even"
    else putStrLn "Odd"


{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Maybe as Maybe
import qualified Data.Char as Char

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

main :: IO ()
main = do
    input <- getInput
    B.putStrLn (solve input)

getInput :: IO (Int, Int)
getInput =
    let
        parser = (,) <$> parseInt <*> parseInt
    in
        runParser parser <$> B.getContents

solve :: (Int, Int) -> B.ByteString
solve (a, b) =
    if a * b `mod` 2 == 0 then
        "Even"
    else
        "Odd"

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

newtype Parser a =
    Parser (B.ByteString -> (a, B.ByteString))

instance Functor Parser where
    fmap f (Parser parser) =
        Parser $ \input ->
            let (v, remainder) = parser input in
                (f v, remainder)

instance Applicative Parser where
    pure v =
        Parser $ \input ->
            (v, input)

    (Parser parser1) <*> (Parser parser2) =
        Parser $ \input ->
            let
                (f, remainder1) = parser1 input
                (v, remainder2) = parser2 remainder1
            in
                (f v, remainder2)

consumeSpace :: Parser ()
consumeSpace =
    Parser $ \input ->
        ((), B.dropWhile Char.isSpace input)

lexeme :: Parser a -> Parser a
lexeme parser =
    consumeSpace *> parser

parseInt_ :: Parser Int
parseInt_ =
    Parser $ \input ->
        Maybe.fromJust (B.readInt input)

parseInt :: Parser Int
parseInt =
    lexeme parseInt_

runParser :: Parser a -> B.ByteString -> a
runParser (Parser parser) input =
    fst $ parser input

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


module Main where

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

strToIntList :: String -> [Int]
strToIntList = map toInt . words

getIntList :: IO [Int]
getIntList = getLine >>= return . strToIntList

main :: IO ()
main = do
  ab <- getIntList
  putStrLn $ if all odd ab then "Odd" else "Even"


import Data.Bool

f = ((bool "Even" "Odd" .) . (((==1).) . ((`mod` 2).).(*)))

main = do
  [a, b] <- (map read . words) <$> getLine
  putStrLn $ f a b


main::IO ()
main = do
    [a,b] <- map read . words <$> getLine
    putStrLn $ if odd (a*b) then "Odd" else "Even"


-- modules to import --
import Data.ByteString.Char8
import Data.Maybe
import Prelude

-- functions for this task --

read_Integer     = Prelude.fst . Data.Maybe.fromJust . Data.ByteString.Char8.readInteger
read_ListInteger = Prelude.map read_Integer . Data.ByteString.Char8.words

get_Integer     = read_Integer     <$> Data.ByteString.Char8.getLine
get_ListInteger = read_ListInteger <$> Data.ByteString.Char8.getLine

task_A :: [Integer] -> ByteString
task_A [a, b] = Data.ByteString.Char8.pack $ if (Prelude.even $ a * b) then "Even" else "Odd"

-- main process is below --

main :: IO ()
main = do

        -- STEP.01
        -- read out the given string
        [a, b] <- get_ListInteger

        -- STEP.02
        -- output the answer of this task
        Data.ByteString.Char8.putStrLn $ task_A $ [a, b]

-- End of this source code --


-- modules to import --
import Data.ByteString.Char8
import Data.Maybe
import Prelude

-- functions for this task --

read_Integer     = Prelude.fst . Data.Maybe.fromJust . Data.ByteString.Char8.readInteger
read_ListInteger = Prelude.map read_Integer . Data.ByteString.Char8.words

get_Integer     = read_Integer     <$> Data.ByteString.Char8.getLine
get_ListInteger = read_ListInteger <$> Data.ByteString.Char8.getLine

isMultiple :: Integer -> Integer -> Bool
isMultiple target base
        | mod target base == 0 = True
        | otherwise            = False

isEven :: Integer -> Bool
isEven target = isMultiple target 2

task_A :: [Integer] -> ByteString
task_A [a, b]
        | isEven (a * b) == True = Data.ByteString.Char8.pack $ "Even"
        | otherwise              = Data.ByteString.Char8.pack $ "Odd"

-- main process is below --

main :: IO ()
main = do

        -- STEP.01
        -- read out the given string
        [a, b] <- get_ListInteger

        -- STEP.02
        -- output the answer of this task
        Data.ByteString.Char8.putStrLn $ task_A $ [a, b]

-- End of this source code --


import qualified Data.ByteString.Char8 as BS
main = do
  [Just (a,_), Just (b,_)] <- map BS.readInt . BS.words <$> BS.getLine
  if even (a * b)
    then putStrLn "Even"
    else putStrLn "Odd"


main :: IO()
main = do
    [a,b] <- map read . words <$> getLine
    putStrLn $ if (mod (a * b) 2 == 0) then "Even" else "Odd"


import Data.Bool
main = interact $  bool "Odd" "Even" . even . product . map read . words


module Main where

import Control.Applicative

evenOrOdd :: Integer -> Integer -> Bool
evenOrOdd a b = even (a * b)

main :: IO ()
main = do
    [a,b] <- map read . words <$> getLine
    if evenOrOdd a b then
        putStrLn "even"
    else
        putStrLn "odd"


main = do
  [a,b] <- map read . words <$> getLine
  putStrLn $ if(a*b) `mod` 2 == 0 then "Even" else "Odd"


main = do
    [a,b] <- map read.words<$>getLine :: IO [Int]
    putStrLn $ if even (a*b) then "Even" else "Odd"


import Control.Monad
import Text.Printf
import Control.Applicative

main :: IO()
main = do
    [a, b] <- map read.words <$> getLine
    printf "%s" $ if even (a * b) then "Even" else "Odd"


main :: IO ()
main = do
  ab <- getLine
  let [a, b] = map read $ words ab
  putStrLn $ if odd (a * b) then "Odd" else "Even"


main = getLine >>= putStrLn.solve.map read.words
solve [a,b] | even (a * b) = "Even"
    | otherwise = "Odd"


main = do
  n <- (map read . words) <$> getLine
  let m = foldl (*) 1 n
  if mod m 2 == 0
    then putStrLn $ "Even"
    else putStrLn $ "Odd"


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

main = do
     xs <- map (read :: String -> Int) . words <$> getLine
     print $ if even (xs !! 0 * xs !! 1) then "Even" else "Odd"


main :: IO ()
main = do
  [n,yy] <- map read . words <$> getLine :: IO [Int]
  putStrLn . f $ [[x,y,z] | z <- [0..n]
                       , y <- [0..(n-z)]
                       , let x = n-z-y, 10000*x + 5000*y + 1000*z == yy]

f :: [[Int]] -> String
f [] = "-1 -1 -1"
f list = unwords . map show $ head list

Score : 300 points

Problem Statement

The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.

According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Constraints

1 ≤ N ≤ 2000

1000 ≤ Y ≤ 2 × 10^7

N is an integer.

Y is a multiple of 1000.

Input

Input is given from Standard Input in the following format:

N Y

Output

If the total value of N bills cannot be Y yen, print -1 -1 -1.

If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed.

Sample Input 1

9 45000

Sample Output 1

4 0 5

If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0 is also correct.

Sample Input 2

20 196000

Sample Output 2

-1 -1 -1

When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.

Sample Input 3

1000 1234000

Sample Output 3

14 27 959

There are also many other possibilities.

Sample Input 4

2000 20000000

Sample Output 4

2000 0 0


main :: IO ()
main = do
    [count, amount] <- map read . words <$> getLine
    let cases = execOtoshidama count amount
    if null cases
        then putStrLn "-1 -1 -1"
        else putStrLn $ unwords $ map show $ head cases

execOtoshidama :: Int -> Int -> [[Int]]
execOtoshidama num amount =
            [[x, y, z] |
                  x <- [0 .. num], y <- [0 .. num - x], let z = num - x - y
                , x * 10000 + y * 5000 + z * 1000 == amount]


main :: IO ()
main = do
    [count, amount] <- map read . words <$> getLine
    let cases = execOtoshidama count amount
    let (x, y, z) = head cases
    if not (null cases)
        then putStrLn $ mconcat [show x," ",show y," ", show z]
        else putStrLn "-1 -1 -1"

execOtoshidama :: Int -> Int -> [(Int, Int, Int)]
execOtoshidama num amount =
        let abc = [(a, b, c) | a <- [0 .. num], b <- [0 .. num], c <- [0 .. num], a + b + c == num]
        in  filter (\(a, b, c) ->
                a * 1000 + b * 5000 + c * 10000 == amount
            ) abc