There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {x1, x2, x3, x4} (x1 ≤ x2 ≤ x3 ≤ x4) arithmetic mean is , median is  and range is x4 - x1. The arithmetic mean and median are not necessary integer. It is well-known that if those three numbers are same, boxes will create a "debugging field" and codes in the field will have no bugs.For example, 1, 1, 3, 3 is the example of 4 numbers meeting the condition because their mean, median and range are all equal to 2.Jeff has 4 special boxes of candies. However, something bad has happened! Some of the boxes could have been lost and now there are only n (0 ≤ n ≤ 4) boxes remaining. The i-th remaining box contains ai candies.Now Jeff wants to know: is there a possible way to find the number of candies of the 4 - n missing boxes, meeting the condition above (the mean, median and range are equal)?

The first line of input contains an only integer n (0 ≤ n ≤ 4). The next n lines contain integers ai, denoting the number of candies in the i-th box (1 ≤ ai ≤ 500).

In the first output line, print "YES" if a solution exists, or print "NO" if there is no solution. If a solution exists, you should output 4 - n more lines, each line containing an integer b, denoting the number of candies in a missing box. All your numbers b must satisfy inequality 1 ≤ b ≤ 106. It is guaranteed that if there exists a positive integer solution, you can always find such b's meeting the condition. If there are multiple answers, you are allowed to print any of them. Given numbers ai may follow in any order in the input, not necessary in non-decreasing. ai may have stood at any positions in the original set, not necessary on lowest n first positions.

NoteFor the first sample, the numbers of candies in 4 boxes can be 1, 1, 3, 3. The arithmetic mean, the median and the range of them are all 2.For the second sample, it's impossible to find the missing number of candies.In the third example no box has been lost and numbers satisfy the condition.You may output b in any order.

import Data.List
import Control.Applicative

--Forgive me for such an ugly haskell code

getInt :: IO Int
getInt = readLn

getInts :: Int -> IO [Int]
getInts 0 = return []
getInts n = do
  x <- getInt
  fmap (x:) $ getInts (n-1)

check :: [Int] -> Int -> [String]
check xs n | n == 0 = ["YES", "1", "1", "3", "3"]
           | n == 1 = {-d3 = k+(d1+d2)/2 = k+(d1+d2+d3)/4
                        d1+d2 = d3
                        d3 = 2k
                        -}
                      let k = head xs
                          d3 = 2*k
                          d2 = d3
                          d1 = 0
                      in ["YES", show $ k+d1, show $ k+d2, show $ k+d3]
            | n == 4 = let xs' = sort xs
                           mean = if mod (sum xs') 4 /= 0 then Nothing else Just $ div (sum xs') 4
                           median = if mod (xs'!!1 + xs'!!2) 2 /= 0 then Nothing else Just $ div (xs'!!1 + xs'!!2) 2
                           range = xs'!!3 - xs'!!1
                           cmp1 = (==) <$> mean <*> median
                           cmp2 = fmap (== range) mean
                           in case (==) <$> cmp1 <*> cmp2 of
                                Nothing -> ["NO"]
                                Just _ -> ["YES"]
            | n == 3 = let xs' = sort xs
                          in if 3*(head xs') == last xs'
                            then let d3 = 2*(head xs')
                                     d1 = (xs'!!1 - xs'!!0)
                                     d2 = d3-d1
                                  in ["YES", show (head xs' + d2)]
                            else if (xs'!!1 + xs'!!2 - 2*xs'!!0) == 2*(head xs')
                                  then ["YES", show $ 3*(head xs')]
                                  else if mod (last xs') 3 == 0 && check ((div (last xs') 3):xs') 4 /= ["NO"]
                                        then ["YES", show $ div (last xs') 3]
                                        else ["NO"]
            | n == 2 = let xs' = sort xs
                           k1 = head xs'
                           k2 = last xs'
                          in if k2-k1 > 2*k1
                              then ["NO"]
                              else let d1 = k2-k1
                                       d3 = 2*k1
                                       d2 = d3-d1
                                   in ["YES", show $ k1+d2, show $ k1+d3]
            | otherwise = ["Liar."]

solve :: Int -> IO[String]
solve n = do
  xs <- getInts n
  return $ check xs n

main = do
  res <- readLn >>= solve
  mapM_ putStrLn res

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

check l@[_, _, _, _] = m1 == m2 && m2 == m3
  where [a, b, c, d] = sort l
        m1 = a + b + c + d
        m2 = (b + c) * 2
        m3 = (d - a) * 4

solve :: [Integer] -> Maybe [Integer]
solve l@[a, b, c, d] = if check l then Just l else Nothing
solve l@[_, _, _] =
    if s1
      then Just (l ++ [d1])
      else if s2
              then Just (l ++ [d2])
              else if s3
                      then Just (l ++ [d3])
                      else Nothing
  where [a, b, c] = sort l
        d1 = b + c - a
        s1 = d1 >= 1 && d1 <= 1500 && sum l + d1 == (d1 - a) * 4
        d2 = a - b + c
        s2 = d2 >= 1 && d2 <= 1500 && sum l + d2 == (c - a) * 4
        d3 = a + b - c
        s3 = d3 >= 1 && d3 <= 1500 && sum l + d3 == (c - d3) * 4
solve x = foldl1 (<|>) $ solve <$> ((x++) <$> [[i] | i <- [1..1500]])
  where c = if null x then 1 else last x

-- solve :: [Integer] -> Bool
-- solve l@[a, b, c, d] = check l
-- solve x = foldl1 (||) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

main = do
  n <- read <$> getLine
  ls <- replicateM n $ read <$> getLine
  case solve ls of
    Nothing -> putStrLn "NO"
    Just rl -> do putStrLn "YES"
                  forM_ (drop n rl) print

import Data.List
import Control.Applicative

getInt :: IO Int
getInt = readLn

getInts :: Int -> IO [Int]
getInts 0 = return []
getInts n = do
  x <- getInt
  fmap (x:) $ getInts (n-1)

check :: [Int] -> Int -> [String]
check xs n | n == 0 = ["YES", "1", "1", "3", "3"]
           | n == 1 = {-d3 = k+(d1+d2)/2 = k+(d1+d2+d3)/4
                        d1+d2 = d3
                        d3 = 2k
                        -}
                      let k = head xs
                          d3 = 2*k
                          d2 = d3
                          d1 = 0
                      in ["YES", show $ k+d1, show $ k+d2, show $ k+d3]
            | n == 4 = let xs' = sort xs
                           mean = if mod (sum xs') 4 /= 0 then Nothing else Just $ div (sum xs') 4
                           median = if mod (xs'!!1 + xs'!!2) 2 /= 0 then Nothing else Just $ div (xs'!!1 + xs'!!2) 2
                           range = xs'!!3 - xs'!!1
                           cmp1 = (==) <$> mean <*> median
                           cmp2 = fmap (== range) mean
                           in case (==) <$> cmp1 <*> cmp2 of
                                Nothing -> ["NO"]
                                Just _ -> ["YES"]
            | n == 3 = let xs' = sort xs
                  in if mod (sum xs') 3 /= 0
                    then ["No"]
                    else let mean = div (sum xs') 3
                             xs'' = sort (mean:xs')
                             median = if mod (xs''!!1 + xs''!!2) 2 /= 0 then Nothing else Just $ div (xs''!!1 + xs''!!2) 2
                             range = xs''!!3 - xs''!!1
                            in if  (mean == range) && (fmap (==mean) median) == Just True
                                then ["YES", show (4*mean - sum xs')]
                                else ["NO"]
            | n == 2 = let xs' = sort xs
                           k1 = head xs'
                           k2 = last xs'
                          in if k2-k1 > 2*k1
                              then ["NO"]
                              else let d1 = k2-k1
                                       d3 = 2*k1
                                       d2 = d3-d1
                                   in ["YES", show $ k1+d2, show $ k1+d3]
            | otherwise = ["Liar."]

solve :: Int -> IO[String]
solve n = do
  xs <- getInts n
  return $ check xs n

main = do
  res <- readLn >>= solve
  mapM_ putStrLn res

import Data.List

getInt :: IO Int
getInt = readLn

getInts :: Int -> IO [Int]
getInts 0 = return []
getInts n = do
  x <- getInt
  fmap (x:) $ getInts (n-1)

check :: [Int] -> Int -> [String]
check xs n | n == 0 = ["YES", "1", "1", "3", "3"]
           | n == 1 = {-d3 = k+(d1+d2)/2 = k+(d1+d2+d3)/4
                        d1+d2 = d3
                        d3 = 2k
                        -}
                      let k = head xs
                          d3 = 2*k
                          d2 = d3
                          d1 = 0
                      in ["YES", show $ k+d1, show $ k+d2, show $ k+d3]
            | n == 4 = {-let xs' = sort xs
                           mean = if mod (sum xs') 4 /= 0 then Nothing else Just $ div (sum xs') 4
                           median = if mod (xs!!1 + xs!!2) 2 /= 0 then Nothing else Just $ div (xs!!1 + xs!!2) 2
                           range = xs!!3 - xs!!1
                           cmp1 = (==) <$> mean <*> median
                           cmp2 = fmap (== range) mean
                           in case (==) <$> cmp1 <*> cmp2 of
                                Nothing -> ["NO"]
                                Just _ -> ["YES"]-}
                        ["No"] --WTH
            | n == 3 = let xs' = sort xs
                  in if mod (sum xs') 3 /= 0
                    then ["No"]
                    else let mean = div (sum xs') 3
                             xs'' = sort (mean:xs')
                             median = if mod (xs''!!1 + xs''!!2) 2 /= 0 then Nothing else Just $ div (xs''!!1 + xs''!!2) 2
                             range = xs''!!3 - xs''!!1
                            in if  (mean == range) && (fmap (==mean) median) == Just True
                                then ["YES", show (4*mean - sum xs')]
                                else ["NO"]
            | n == 2 = let k1 = head xs
                           k2 = last xs
                          in if k2-k1 > 2*k1
                              then ["NO"]
                              else let d1 = k2-k1
                                       d3 = 2*k1
                                       d2 = d3-d1
                                   in ["YES", show $ k1+d2, show $ k1+d3]
            | otherwise = ["Liar."]

solve :: Int -> IO[String]
solve n = do
  xs <- getInts n
  return $ check xs n

main = do
  res <- readLn >>= solve
  mapM_ putStrLn res

import Data.List
import Control.Applicative

--Forgive me for such an ugly haskell code

getInt :: IO Int
getInt = readLn

getInts :: Int -> IO [Int]
getInts 0 = return []
getInts n = do
  x <- getInt
  fmap (x:) $ getInts (n-1)

check :: [Int] -> Int -> [String]
check xs n | n == 0 = ["YES", "1", "1", "3", "3"]
           | n == 1 = {-d3 = k+(d1+d2)/2 = k+(d1+d2+d3)/4
                        d1+d2 = d3
                        d3 = 2k
                        -}
                      let k = head xs
                          d3 = 2*k
                          d2 = d3
                          d1 = 0
                      in ["YES", show $ k+d1, show $ k+d2, show $ k+d3]
            | n == 4 = let xs' = sort xs
                           mean = if mod (sum xs') 4 /= 0 then Nothing else Just $ div (sum xs') 4
                           median = if mod (xs'!!1 + xs'!!2) 2 /= 0 then Nothing else Just $ div (xs'!!1 + xs'!!2) 2
                           range = xs'!!3 - xs'!!1
                           cmp1 = (==) <$> mean <*> median
                           cmp2 = fmap (== range) mean
                           in case (==) <$> cmp1 <*> cmp2 of
                                Nothing -> ["NO"]
                                Just _ -> ["YES"]
            | n == 3 = let xs' = sort xs
                          in if 3*(head xs') == last xs'
                            then let d3 = 2*(head xs')
                                     d1 = (xs'!!1 - xs'!!0)
                                     d2 = d3-d1
                                  in ["YES", show (head xs' + d2)]
                            else if (xs'!!1 + xs'!!2 - 2*xs'!!0) == 2*(head xs')
                                  then ["YES", show $ 3*(head xs')]
                                  else if mod (last xs') 3 == 0
                                        then ["YES", show $ div (last xs') 3]
                                        else ["NO"]
            | n == 2 = let xs' = sort xs
                           k1 = head xs'
                           k2 = last xs'
                          in if k2-k1 > 2*k1
                              then ["NO"]
                              else let d1 = k2-k1
                                       d3 = 2*k1
                                       d2 = d3-d1
                                   in ["YES", show $ k1+d2, show $ k1+d3]
            | otherwise = ["Liar."]

solve :: Int -> IO[String]
solve n = do
  xs <- getInts n
  return $ check xs n

main = do
  res <- readLn >>= solve
  mapM_ putStrLn res

import Data.List
import Control.Applicative

getInt :: IO Int
getInt = readLn

getInts :: Int -> IO [Int]
getInts 0 = return []
getInts n = do
  x <- getInt
  fmap (x:) $ getInts (n-1)

check :: [Int] -> Int -> [String]
check xs n | n == 0 = ["YES", "1", "1", "3", "3"]
           | n == 1 = {-d3 = k+(d1+d2)/2 = k+(d1+d2+d3)/4
                        d1+d2 = d3
                        d3 = 2k
                        -}
                      let k = head xs
                          d3 = 2*k
                          d2 = d3
                          d1 = 0
                      in ["YES", show $ k+d1, show $ k+d2, show $ k+d3]
            | n == 4 = let xs' = sort xs
                           mean = if mod (sum xs') 4 /= 0 then Nothing else Just $ div (sum xs') 4
                           median = if mod (xs'!!1 + xs'!!2) 2 /= 0 then Nothing else Just $ div (xs'!!1 + xs'!!2) 2
                           range = xs'!!3 - xs'!!1
                           cmp1 = (==) <$> mean <*> median
                           cmp2 = fmap (== range) mean
                           in case (==) <$> cmp1 <*> cmp2 of
                                Nothing -> ["NO"]
                                Just _ -> ["YES"]
            | n == 3 = let xs' = sort xs
                  in if mod (sum xs') 3 /= 0
                    then ["No"]
                    else let mean = div (sum xs') 3
                             xs'' = sort (mean:xs')
                             median = if mod (xs''!!1 + xs''!!2) 2 /= 0 then Nothing else Just $ div (xs''!!1 + xs''!!2) 2
                             range = xs''!!3 - xs''!!1
                            in if  (mean == range) && (fmap (==mean) median) == Just True
                                then ["YES", show (4*mean - sum xs')]
                                else ["NO"]
            | n == 2 = let k1 = head xs
                           k2 = last xs
                          in if k2-k1 > 2*k1
                              then ["NO"]
                              else let d1 = k2-k1
                                       d3 = 2*k1
                                       d2 = d3-d1
                                   in ["YES", show $ k1+d2, show $ k1+d3]
            | otherwise = ["Liar."]

solve :: Int -> IO[String]
solve n = do
  xs <- getInts n
  return $ check xs n

main = do
  res <- readLn >>= solve
  mapM_ putStrLn res

import Data.List
import Control.Applicative

getInt :: IO Int
getInt = readLn

getInts :: Int -> IO [Int]
getInts 0 = return []
getInts n = do
  x <- getInt
  fmap (x:) $ getInts (n-1)

check :: [Int] -> Int -> [String]
check xs n | n == 0 = ["YES", "1", "1", "3", "3"]
           | n == 1 = {-d3 = k+(d1+d2)/2 = k+(d1+d2+d3)/4
                        d1+d2 = d3
                        d3 = 2k
                        -}
                      let k = head xs
                          d3 = 2*k
                          d2 = d3
                          d1 = 0
                      in ["YES", show $ k+d1, show $ k+d2, show $ k+d3]
            | n == 4 = let xs' = sort xs
                           mean = if mod (sum xs') 4 /= 0 then Nothing else Just $ div (sum xs') 4
                           median = if mod (xs'!!1 + xs'!!2) 2 /= 0 then Nothing else Just $ div (xs'!!1 + xs'!!2) 2
                           range = xs'!!3 - xs'!!1
                           cmp1 = (==) <$> mean <*> median
                           cmp2 = fmap (== range) mean
                           in case (==) <$> cmp1 <*> cmp2 of
                                Nothing -> ["NO"]
                                Just _ -> ["YES"]
            | n == 3 = let xs' = sort xs
                  in if mod (sum xs') 3 /= 0
                    then ["NO"]
                    else let mean = div (sum xs') 3
                             xs'' = sort (mean:xs')
                             median = if mod (xs''!!1 + xs''!!2) 2 /= 0 then Nothing else Just $ div (xs''!!1 + xs''!!2) 2
                             range = xs''!!3 - xs''!!1
                            in if  (mean == range) && (fmap (==mean) median) == Just True
                                then ["YES", show (4*mean - sum xs')]
                                else ["NO"]
            | n == 2 = let xs' = sort xs
                           k1 = head xs'
                           k2 = last xs'
                          in if k2-k1 > 2*k1
                              then ["NO"]
                              else let d1 = k2-k1
                                       d3 = 2*k1
                                       d2 = d3-d1
                                   in ["YES", show $ k1+d2, show $ k1+d3]
            | otherwise = ["Liar."]

solve :: Int -> IO[String]
solve n = do
  xs <- getInts n
  return $ check xs n

main = do
  res <- readLn >>= solve
  mapM_ putStrLn res

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

check l@[_, _, _, _] = m1 == m2 && m2 == m3
  where [a, b, c, d] = sort l
        m1 = a + b + c + d
        m2 = (b + c) * 2
        m3 = (d - a) * 4

solve :: [Integer] -> Maybe [Integer]
solve l@[a, b, c, d] = if check l then Just l else Nothing
solve l@[_, _, _] = if d >= 1 && d <= 500 && s then Just (l ++ [d]) else Nothing
  where [a, b, c] = sort l
        d = b + c - a
        s = sum l + d == (d - a) * 4
solve x = foldl1 (<|>) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])
  where c = if null x then 1 else last x

-- solve :: [Integer] -> Bool
-- solve l@[a, b, c, d] = check l
-- solve x = foldl1 (||) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

main = do
  n <- read <$> getLine
  ls <- replicateM n $ read <$> getLine
  case solve ls of
    Nothing -> putStrLn "NO"
    Just rl -> do putStrLn "YES"
                  forM_ (drop n rl) print

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

check l@[_, _, _, _] = m1 == m2 && m2 == m3
  where [a, b, c, d] = sort l
        m1 = a + b + c + d
        m2 = (b + c) * 2
        m3 = (d - a) * 4

solve :: [Integer] -> Maybe [Integer]
solve l@[a, b, c, d] = if check l then Just l else Nothing
solve x = foldl1 (<|>) $ solve <$> ((x++) <$> [[i] | i <- [c..500]])
  where c = if null x then 1 else last x

-- solve :: [Integer] -> Bool
-- solve l@[a, b, c, d] = check l
-- solve x = foldl1 (||) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

main = do
  n <- read <$> getLine
  ls <- replicateM n $ read <$> getLine
  case solve ls of
    Nothing -> putStrLn "NO"
    Just rl -> do putStrLn "YES"
                  forM_ (drop n rl) print

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

check [a, b, c, d] = m1 == m2 && m2 == m3
  where m1 = a + b + c + d
        m2 = (b + c) * 2
        m3 = (d - a) * 4

solve :: [Integer] -> Maybe [Integer]
solve l@[a, b, c, d] = if check l then Just l else Nothing
solve x = foldl1 (<|>) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

-- solve :: [Integer] -> Bool
-- solve l@[a, b, c, d] = check l
-- solve x = foldl1 (||) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

main = do
  n <- read <$> getLine
  ls <- replicateM n $ read <$> getLine
  case solve ls of
    Nothing -> putStrLn "NO"
    Just rl -> do putStrLn "YES"
                  forM_ (drop n rl) print

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

check l@[_, _, _, _] = m1 == m2 && m2 == m3
  where [a, b, c, d] = sort l
        m1 = a + b + c + d
        m2 = (b + c) * 2
        m3 = (d - a) * 4

solve :: [Integer] -> Maybe [Integer]
solve l@[a, b, c, d] = if check l then Just l else Nothing
solve l@[_, _, _] = if d >= c && d <= 500 && s then Just (l ++ [d]) else Nothing
  where [a, b, c] = sort l
        d = b + c - a
        s = sum l + d == (d - a) * 4
solve x = foldl1 (<|>) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])
  where c = if null x then 1 else last x

-- solve :: [Integer] -> Bool
-- solve l@[a, b, c, d] = check l
-- solve x = foldl1 (||) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

main = do
  n <- read <$> getLine
  ls <- replicateM n $ read <$> getLine
  case solve ls of
    Nothing -> putStrLn "NO"
    Just rl -> do putStrLn "YES"
                  forM_ (drop n rl) print

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

check l@[_, _, _, _] = m1 == m2 && m2 == m3
  where [a, b, c, d] = sort l
        m1 = a + b + c + d
        m2 = (b + c) * 2
        m3 = (d - a) * 4

solve :: [Integer] -> Maybe [Integer]
solve l@[a, b, c, d] = if check l then Just l else Nothing
solve l@[_, _, _] =
    if s1
      then Just (l ++ [d1])
      else if s2
              then Just (l ++ [d2])
              else if s3
                      then Just (l ++ [d3])
                      else Nothing
  where [a, b, c] = sort l
        d1 = b + c - a
        s1 = d1 >= 1 && d1 <= 500 && sum l + d1 == (d1 - a) * 4
        d2 = a - b + c
        s2 = d2 >= 1 && d2 <= 500 && sum l + d2 == (c - a) * 4
        d3 = a + b - c
        s3 = d3 >= 1 && d3 <= 500 && sum l + d3 == (c - d3) * 4
solve x = foldl1 (<|>) $ solve <$> ((x++) <$> [[i] | i <- [1..1500]])
  where c = if null x then 1 else last x

-- solve :: [Integer] -> Bool
-- solve l@[a, b, c, d] = check l
-- solve x = foldl1 (||) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

main = do
  n <- read <$> getLine
  ls <- replicateM n $ read <$> getLine
  case solve ls of
    Nothing -> putStrLn "NO"
    Just rl -> do putStrLn "YES"
                  forM_ (drop n rl) print

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

check [a, b, c, d] = m1 == m2 && m2 == m3
  where m1 = a + b + c + d
        m2 = (b + c) * 2
        m3 = (d - a) * 4

-- solve :: [Integer] -> Maybe [Integer]
-- solve l@[a, b, c, d] = if check l then Just l else Nothing
-- solve x = foldl1 (<|>) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

solve :: [Integer] -> Bool
solve l@[a, b, c, d] = check l
solve x = foldl1 (||) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

main = do
  n <- read <$> getLine
  ls <- replicateM n $ read <$> getLine
  print $ solve ls

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

check l@[_, _, _, _] = m1 == m2 && m2 == m3
  where [a, b, c, d] = sort l
        m1 = a + b + c + d
        m2 = (b + c) * 2
        m3 = (d - a) * 4

solve :: [Integer] -> Maybe [Integer]
solve l@[a, b, c, d] = if check l then Just l else Nothing
solve x = foldl1 (<|>) $ solve <$> ((x++) <$> [[i] | i <- [c..500]])
  where c = if null x then 1 else last x

-- solve :: [Integer] -> Bool
-- solve l@[a, b, c, d] = check l
-- solve x = foldl1 (||) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

main = do
  n <- read <$> getLine
  ls <- replicateM n $ read <$> getLine
  case solve ls of
    Nothing -> putStrLn "NO"
    Just rl -> do putStrLn "YES"
                  forM_ (drop 0 rl) print

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

check l@[_, _, _, _] = m1 == m2 && m2 == m3
  where [a, b, c, d] = sort l
        m1 = a + b + c + d
        m2 = (b + c) * 2
        m3 = (d - a) * 4

solve :: [Integer] -> Maybe [Integer]
solve l@[a, b, c, d] = if check l then Just l else Nothing
solve l@[_, _, _] =
    if s1
      then Just (l ++ [d1])
      else if s2
              then Just (l ++ [d2])
              else if s3
                      then Just (l ++ [d3])
                      else Nothing
  where [a, b, c] = sort l
        d1 = b + c - a
        s1 = d1 >= 1 && d1 <= 500 && sum l + d1 == (d1 - a) * 4
        d2 = a - b + c
        s2 = d2 >= 1 && d2 <= 500 && sum l + d2 == (c - a) * 4
        d3 = a + b - c
        s3 = d3 >= 1 && d3 <= 500 && sum l + d3 == (c - d3) * 4
solve x = foldl1 (<|>) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])
  where c = if null x then 1 else last x

-- solve :: [Integer] -> Bool
-- solve l@[a, b, c, d] = check l
-- solve x = foldl1 (||) $ solve <$> ((x++) <$> [[i] | i <- [1..500]])

main = do
  n <- read <$> getLine
  ls <- replicateM n $ read <$> getLine
  case solve ls of
    Nothing -> putStrLn "NO"
    Just rl -> do putStrLn "YES"
                  forM_ (drop n rl) print


You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.

The only line contains three integers l, r and a (0 ≤ l, r, a ≤ 100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.

Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.

NoteIn the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.

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

solve [l,r,a]
    | a + min l r >= max l r = ((l + r + a) `div` 2) * 2
    | otherwise = (min l r + a) * 2

import Data.List

main = do
       e<-getLine
       let (l:r:a:[])=map read (words e)::[Int]
           (c,t1,a1)=if l<r then (l,r-l,a) else (r,l-r,a)
       print $ 2*(c+(min t1 a1)+if a1-t1>=0 then (a1-t1) `div` 2 else 0)

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

solve(l:r:a:_) = maximum [2 * min (l + x) (r + a - x) | x <- [0..a]]

import Control.Monad

teamsize 0 0 a = a-(mod a 2)
teamsize l r 0 = 2 * min l r
teamsize 0 r a = let m = min r a in teamsize 0 (r-m) (a-m) + 2*m
teamsize l r a | l<=r = teamsize 0 (r-l) a + 2*l
               | True = teamsize r l a

main = do
  [l, r, a] <- fmap (map read . words) getContents
  putStrLn . show $ teamsize l r a

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

main = do
		[a,b,c]<-map read <$> words <$> getLine ::IO [Int]
		let s = 2* (min a b)
		let s1 =  (min (abs (a-b)) c)
		let s2 = 2* (div (c-s1) 2)
		print $ s+s1+s1+s2

import Control.Monad

teamsize 0 0 a = a-(mod a 2)
teamsize l r 0 = 0
teamsize 0 r a = let m = min r a in teamsize 0 (r-m) (a-m) + 2*m
teamsize l r a | l<=r = teamsize 0 (r-l) a + 2*l
               | True = teamsize r l a

main = do
  [l, r, a] <- fmap (map read . words) getContents
  putStrLn . show $ teamsize l r a


Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded.For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ways are correct.For given n find out to which integer will Vasya round it.

The first line contains single integer n (0 ≤ n ≤ 109) — number that Vasya has.

Print result of rounding n. Pay attention that in some cases answer isn't unique. In that case print any correct answer.

NoteIn the first example n = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.

main = getLine >>= print . (\n -> let (q, r) = n `quotRem` 10 in (q + fromEnum (r > 5)) * 10) . read

-- Haskell Template
solve :: Int -> Int
solve n = 10 * div (n + 5) 10

main :: IO ()
main = do
  x <- getLine
  let s = solve (read x)
  putStrLn (show s)

main = getLine >>= print . (\n -> round (n / 10) * 10) . read

main = getLine >>= print . (*10) . round . (/10) . read

import Data.List
import qualified Data.Map as Map

main = do
       a<-getLine
       let e=read a::Int
       print $ ((e+5) `div` 10) *10

main = interact $ show . solve . read
solve n = (n + 5) `div` 10 * 10

solve :: Int -> Int
solve n = let
  lastDigit = n `rem` 10
  in
  if lastDigit <= 5 then
    n - lastDigit
  else
    n - lastDigit + 10

main = do
  num <- read <$> getLine
  print $ solve num

getInt :: IO Int
getInt = read `fmap` getLine

solve :: Int -> Int
solve k
    | k `mod` 10 == 0 = k
    | k `mod` 10 <= 5 = k - (k `mod` 10)
    | otherwise = k + 10 - (k `mod` 10)

main :: IO ()
main = do
    n <- getInt
    print (solve n)

{-# OPTIONS_GHC -O3 #-}
{-# LANGUAGE ViewPatterns, ScopedTypeVariables #-}

import qualified Data.ByteString as B (getLine)
import qualified Data.ByteString.Char8 as C (readInt, words, unpack, reverse, dropWhile)
import qualified Data.Maybe as M (fromJust)
import Data.Char as C (isSpace)

readInt = fst . M.fromJust . C.readInt
rstrip = C.reverse . C.dropWhile C.isSpace . C.reverse

main = do
    (map readInt . C.words -> [n]) <- B.getLine
    let x = n `div` 10 * 10
    putStrLn $ show $ if n `mod` 10 > 5 then x + 10 else x

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

main = do
		n<-read <$> getLine ::IO Int
		let s = div n 10
		let m = mod n 10
		print $ (*10) $ s + if m>5 then 1 else 0

process :: Int -> Int
process n = 10 * (round ((fromIntegral n) / 10))

readInt :: String -> Int
readInt = read

main :: IO ()
main = do
    n <- fmap readInt getLine
    print $ process n

main = getLine >>= print . (\n -> n - n `rem` 10) . read

main = getLine >>= print . (\n -> (n `div` 10) * 10) . read


Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Print a single integer, denoting the minimum possible height of the tallest tower.

NoteIn the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.

module Main where

import Control.Monad

solve :: Int -> Int -> Int
solve n m | check 0 = 0
          | otherwise = bsearch 0 (6 * (n + m))
    where check h = credit2 + credit3 <= common
              where common = div h 6
                    only2 = (div h 2) - common
                    only3 = (div h 3) - common
                    credit2 | only2 >= n = 0
                            | otherwise  = n - only2
                    credit3 | only3 >= m = 0
                            | otherwise  = m - only3

          bsearch lo hi | lo + 1 == hi = hi
                        | check mi = bsearch lo mi
                        | otherwise = bsearch mi hi
              where mi = (lo + hi) `div` 2

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

calc::Int->Int->Int
calc = go 0 where
  go acc 1 y | y < 1 = acc + 2
  go acc 2 y | y < 2 = acc + 4
  go acc x 1 | x < 2 = acc + 3
  go acc x 2 | x < 3 = acc + 6
  go acc 3 y | y < 2 = acc + 6
  go acc x y = if x * 2 > y * 3 then go (acc + 6 ) (x - 3) (y - 1) else go (acc + 6 ) (x - 2)( y - 2)

main:: IO ()
main = fmap (map read . words) getLine >>= \[x,y] -> print $ calc x y

calc::Int->Int->Int
calc = go 0 where
  go acc 1 y | y < 1 = acc + 2
  go acc 2 y | y < 2 = acc + 4
  go acc x 1 | x < 2 = acc + 3
  go acc x 2 | x < 3 = acc + 6
  go acc 3 y | y < 2 = acc + 6
  go acc x y = (uncurry .) go (acc + 6) $ if x * 2 > y * 3 then (x - 3,y - 1) else (x - 2 , y - 2)

main:: IO ()
main = fmap (map read . words) getLine >>= \[x,y] -> print $ calc x y


Two best friends Serozha and Gena play a game.Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak = 1. Naturally, the number of piles k should be no less than two.The friends play in turns. The player who cannot make a move loses. Serozha makes the first move. Who will win if both players play in the optimal way?

The single line contains a single integer n (1 ≤ n ≤ 105).

If Serozha wins, print k, which represents the minimal number of piles into which he can split the initial one during the first move in order to win the game. If Gena wins, print "-1" (without the quotes).

{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-}
{-# OPTIONS_GHC -O2 #-}

import Data.List
import Data.Maybe
import Data.Char
import Data.Array.IArray
import Data.Array.Unboxed (UArray)
import Data.Int
import Data.Ratio
import Data.Bits
import Data.Function
import Data.Ord
--import Control.Monad.State
import Control.Monad
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Map (Map)
import qualified Data.Map as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
import Data.Sequence (Seq, (<|), (|>), (><), ViewL(..), ViewR(..))
import qualified Data.Sequence as Seq
import qualified Data.Foldable as F
import Data.Graph

import Debug.Trace

parseInput = do
    n <- readInt
    return n
  where
    readInt = state $ fromJust . BS.readInt . BS.dropWhile isSpace
    readInteger = state $ fromJust . BS.readInteger . BS.dropWhile isSpace
    readString = state $ BS.span (not . isSpace) . BS.dropWhile isSpace
    readLine = state $ BS.span (not . isEoln) . BS.dropWhile isEoln
    isEoln ch = ch == '\r' || ch == '\n'

main = print =<< solve . evalState parseInput <$> BS.getContents

generate :: Int -> [(Int, Int)]
generate sumLimit = concatMap generateGivingNum $ takeWhile (\x -> x * (x + 1) <= sumLimit * 2) [2..]
  where
    generateGivingNum n = [ (fstNum, n)
                          | fstNum <- [1..(sumLimit - sum0) `div` n]
                          , fstNum * n + sum0 <= sumLimit
                          ]
      where
        sum0 = (0 + n - 1) * n `div` 2

solve :: Int -> Int
solve n
    | solveGame n == 0 = -1
    | otherwise        = minimum $ map snd strategiesOkay
  where
    strategiesN = arr ! n
    strategiesOkay = filter ((==0).solveStrategies) strategiesN

    bnds = (1, n)

    arr = accumArray (flip (:)) [] bnds [ (sum, (fstNum, num))
                                        | (fstNum, num) <- generate n
                                        , let sum = (fstNum + fstNum + num - 1) * num `div` 2
                                        ] :: Array Int [(Int,Int)]

    solveGameXor :: Int -> Int
    solveGameXor = (cache!)
      where
        bnds = (0, n)
        cache = listArray bnds $ map go $ range bnds :: Array Int Int

        go 0 = 0
        go x = solveGameXor (x - 1) `xor` solveGame x

    solveGame :: Int -> Int
    solveGame = (cache!)
      where
        bnds = (1, n)
        cache = listArray bnds $ map go $ range bnds :: Array Int Int

        go x
            | null strategies = 0 -- Lose the game
            | otherwise       = mex $ map solveStrategies strategies
          where
            strategies = arr ! x

    solveStrategies :: (Int, Int) -> Int
    solveStrategies (fstNum, num) = solveGameXor (fstNum - 1) `xor` solveGameXor lstNum
      where
        lstNum = fstNum + num - 1

    mex :: [Int] -> Int
    mex xs = fst . head $ filter (\(x,y) -> x /= y) $ zip [0..] (sorted ++ [-1])
      where
        sorted = IntSet.toList $ IntSet.fromList xs

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

class (Monad m) => MonadState s m | m -> s where
	get :: m s
	put :: s -> m ()

modify :: (MonadState s m) => (s -> s) -> m ()
modify f = do
	s <- get
	put (f s)

gets :: (MonadState s m) => (s -> a) -> m a
gets f = do
	s <- get
	return (f s)

newtype State s a = State { runState :: s -> (a, s) }

instance Functor (State s) where
	fmap f m = State $ \s -> let
		(a, s') = runState m s
		in (f a, s')

instance Applicative (State s) where
    pure = return
    (<*>) = ap

instance Monad (State s) where
	return a = State $ \s -> (a, s)
	m >>= k  = State $ \s -> let
		(a, s') = runState m s
		in runState (k a) s'

instance MonadState s (State s) where
	get   = State $ \s -> (s, s)
	put s = State $ \_ -> ((), s)

evalState :: State s a -> s -> a
evalState m s = fst (runState m s)

execState :: State s a -> s -> s
execState m s = snd (runState m s)

mapState :: ((a, s) -> (b, s)) -> State s a -> State s b
mapState f m = State $ f . runState m

withState :: (s -> s) -> State s a -> State s a
withState f m = State $ runState m . f

state = State


You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW".Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).

The first line of the input contains one integer n (2 ≤ n ≤ 100, n is even) — the size of the chessboard.  The second line of the input contains  integer numbers  (1 ≤ pi ≤ n) — initial positions of the pieces. It is guaranteed that all the positions are distinct.

Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.

NoteIn the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.In the second example the possible strategy is to move  in 4 moves, then  in 3 moves,  in 2 moves and  in 1 move.

module Main (main)
    where

import Data.List

readIntegers :: String -> [Int]
readIntegers = map read . words

solve :: [Int] -> Int
solve [] = 1233
solve ar = min (solve' 0 2 ar) (solve' 0 1 ar)

solve' :: Int -> Int -> [Int] -> Int
solve' ans a [x]    = ans + abs (x-a)
solve' ans a (x:xs) = solve' (ans + abs (x-a)) (a + 2) xs

main :: IO ()
main = putStrLn . toStr. solve . sort . readIntegers =<< (getLine >> getLine)
    where toStr = show

import Data.List (sort)

main = do
    xs <- fmap (sort . map read . words) (getLine >> getLine)
    print $ minimum $ map (sum . map abs . zipWith (-) xs) [[1,3..], [2,4..]]

import Data.List
main = interact $ show. go. sort. map read. tail. words
go :: [Int] -> Int
go as = min a b
  where n = 2 * length as
        try = sum. zipWith (\x y -> abs $ x - y) as
        a = try [1, 3 .. n]
        b = try [2, 4 .. n]

import Data.List
main = interact $ show. go. sort. map read. init. words
go :: [Int] -> Int
go as = min a b
  where n = 2 * length as
        try = sum. zipWith (\x y -> abs $ x - y) as
        a = try [1, 3 .. n]
        b = try [2, 4 .. n]


You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard.Initially, you have an empty string. Until you type the whole string, you may perform the following operation:  add a character to the end of the string. Besides, at most once you may perform one additional operation: copy the string and append it to itself.For example, if you have to type string abcabca, you can type it in 7 operations if you type all the characters one by one. However, you can type it in 5 operations if you type the string abc first and then copy it and type the last character.If you have to type string aaaaaaaaa, the best option is to type 4 characters one by one, then copy the string, and then type the remaining character.Print the minimum number of operations you need to type the given string.

The first line of the input containing only one integer number n (1 ≤ n ≤ 100) — the length of the string you have to type. The second line containing the string s consisting of n lowercase Latin letters.

Print one integer number — the minimum number of operations you need to type the given string.

NoteThe first test described in the problem statement.In the second test you can only type all the characters one by one.

module Main where

import Control.Monad
import Control.Applicative

main = do
 n <- (read::String -> Int) <$> getLine
 s <- getLine
 let max_length = maximum $ loop s n
 if max_length /= 0 then print $ n + 1 - max_length else print n

loop::String -> Int -> [Int]
loop x l = do
            end <- [0..l - 1]
            let single = take (end + 1) x
                double = take (end * 2 + 2) x
            if (single ++ single) == double
             then return (end + 1)
             else return 0

{-# LANGUAGE ViewPatterns #-}
module Main where

main = getLine >> getLine >>= (\xs -> let n = length xs in print $ n + (\x -> if x == 0 then 0 else 1 - x) (last (filter (ok xs) [0..n])))
ok xs n | (a, splitAt n -> (b, _)) <- splitAt n xs = a == b

solve :: String -> Int
solve str = min (length str) (1 + length str - copy)
    where copy = maximum $ filter (\x -> take x (drop x str) == take x str) [0..length str `div` 2]

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

import Data.List

main = getLine >> getLine >>= print . solve

solve xs = numOps $ last $ filter check $ inits xs
    where numOps [] = length xs
          numOps s = length xs - (length s `div` 2) + 1

check s = uncurry (==) $ splitAt (length s `div` 2) s

module Main where

maxTrue :: Int -> [Bool] -> Int
maxTrue _ [] = 0
maxTrue init (False:xs) = maxTrue (init + 1) xs
maxTrue init (True:xs) = max init (maxTrue (init + 1) xs)

check :: String -> Int -> Bool
check xs maxRepeatLen = take maxRepeatLen xs == take maxRepeatLen (drop maxRepeatLen xs)

maxCopyLen :: String -> Int
maxCopyLen [] = 0
maxCopyLen [x] = 0
maxCopyLen xs = maxTrue 1 $ map (check xs) [1..length xs `div` 2]

eval :: String -> Int
eval str = min (length str) (length str + 1 - maxCopyLen str)

printRes :: String -> IO ()
printRes = print . eval

main :: IO ()
main = getLine >> getLine >>= printRes

module Main where

import Control.Monad
import Control.Applicative

main = do
 n <- (read::String -> Int) <$> getLine
 s <- getLine
 let max_length = maximum $ loop s n
 if max_length /= 0 then print $ n + 1 - max_length else print n

loop::String -> Int -> [Int]
loop x l = do
            start <- [0..l - 2]
            let partial_x = drop start x
            end <- [start + 1..l - 1]
            let single = take (end - start) partial_x
            let double = take ((end - start) * 2) partial_x
            if (single ++ single) == double
             then return (end - start)
             else return 0

module Main where

import Control.Monad
import Control.Applicative
import qualified Data.Map

main = do
 n <- (read::String -> Int) <$> getLine
 s <- getLine
 let max_length = maximum $ loop s n
 if max_length /= 0 then print $ n + 1 - max_length else print n

loop::String -> Int -> [Int]
loop x l = do
            start <- [0..l - 2]
            let partial_x = drop start x
            end <- [start + 1..l - 1]
            let single = take (end - start) partial_x
            let double = take ((end - start) * 2) partial_x
            if (single ++ single) == double
             then return (end - start)
             else return 0

module Main where

inner :: String -> String -> Int
inner [] _ = 0
inner _ [] = 0
inner (a:[]) (x:xs) = max 1 (inner (a:[x]) xs)
inner (a:as) (x:xs) = if a == x
  then max (inner ((a:as) ++ [x]) xs) (length $ takeWhile (\(c,b) -> c == b) (zip (a:as) (x:xs)))
  else inner ((a:as) ++ [x]) xs

ev :: String -> Int
ev (x:xs) = inner [x] xs

maxCopyLen :: String -> Int
maxCopyLen [] = 0
maxCopyLen [x] = 0
maxCopyLen (x:xs) = max (ev (x:xs)) (maxCopyLen xs)

eval :: String -> Int
eval str = min (length str) (length str + 1 - maxCopyLen str)

printRes :: String -> IO ()
printRes = print . eval

main :: IO ()
main = getLine >> getLine >>= printRes

module Main where

inner :: String -> String -> Int
inner _ [] = 0
inner "" (x:[]) = 0
inner (s:ss) (x:[]) = if s == x
  then 1
  else 0
inner "" (x:xs) = inner [x] xs
inner (a:as) (x:xs) = if a == x
  then max (1 + inner as xs) (inner ((a:as) ++ [x]) xs)
  else (inner ((a:as) ++ [x]) xs)

ev :: String -> Int
ev (x:xs) = inner [x] xs

maxCopyLen :: String -> Int
maxCopyLen [] = 0
maxCopyLen [x] = 0
maxCopyLen (x:xs) = max (ev (x:xs)) (maxCopyLen xs)

eval :: String -> Int
eval str = min (length str) (length str + 1 - maxCopyLen str)

printRes :: String -> IO ()
printRes = print . eval

main :: IO ()
main = getLine >> getLine >>= printRes


Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.

The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points.

Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO».

import List

un = map read . words

isParal [(a,b), (c,d)] = a == c || b == d

isNonnull [a, b] = a /= b

main = do
    s1 <- getLine
    s2 <- getLine
    s3 <- getLine
    s4 <- getLine
    let lines = map (\(a:b:c:d:_) -> sort [(a,b), (c,d)]) $ (map un [s1,s2,s3,s4] :: [[Integer]] )
        points = concat lines
        pointGroups = group $ sort points
        pointCounts = map length pointGroups --must all 2
        numOfPoints = length pointGroups --must be 4
        doubles = group $ sort lines --must be 4
        nonnulls = all (==True) $ map isNonnull lines
        parals = all (==True) $ map isParal lines
        is2d   = 1 < (length $ group $ map fst points) &&
                 1 < (length $ group $ map snd points)
    if (numOfPoints == 4 &&
        all (==2) pointCounts &&
        length doubles == 4 &&
        nonnulls &&
        is2d &&
        parals) then
        putStrLn "YES"
          else
           putStrLn "NO"

import List
import Control.Monad

solve p | sort p == sort q = "YES"
        | otherwise        = "NO"
    where q = nub [[(a,b),(c,d)] | a <- [x0, x1], c <-[a, x1], b <- [y0, y1], d <- [b, y1+0], (a /= c) /= (b /= d)]
          (x0, y0) = minimum $ concat p
          (x1, y1) = maximum $ concat p

main = replicateM 4 (fmap (map read . words) getLine) >>= (
       putStrLn . solve. map (sort.(\[a,b,c,d]->[(a,b),(c,d)])))

import List

un = map read . words

isParal [(a,b), (c,d)] = a == c || b == d

isNonnull [a, b] = a /= b

main = do
    s1 <- getLine
    s2 <- getLine
    s3 <- getLine
    s4 <- getLine
    let lines = map (\(a:b:c:d:_) -> sort [(a,b), (c,d)]) $ (map un [s1,s2,s3,s4] :: [[Int]] )
        points = concat lines
        pointGroups = group $ sort points
        pointCounts = map length pointGroups --must all 2
        numOfPoints = length pointGroups --must be 4
        doubles = group $ sort lines --must be 4
        nonnulls = all (==True) $ map isNonnull lines
        parals = all (==True) $ map isParal lines
    if (numOfPoints == 4 &&
        all (==2) pointCounts &&
        length doubles == 4 &&
        nonnulls &&
        parals) then
        putStrLn "YES"
          else
           putStrLn "NO"

import List

un = map read . words

isParal [(a,b), (c,d)] = a == c || b == d

isNonnull [a, b] = a /= b

main = do
    s1 <- getLine
    s2 <- getLine
    s3 <- getLine
    s4 <- getLine
    let l = map (\(a:b:c:d:_) -> [(a,b), (c,d)]) $ (map un [s1,s2,s3,s4] :: [[Int]] )
        ll = concat l
        points = group $ sort ll
        pointCounts = map length points --must all 2
        numOfPoints = length points --must be 4
        doubles = group $ sort l --must be 4
        nonnulls = all (==True) $ map isNonnull l
        parals = all (==True) $ map isParal l
    if (numOfPoints == 4 &&
        all (==2) pointCounts &&
        length doubles == 4 &&
        nonnulls &&
        parals) then
        putStrLn "YES"
          else
           putStrLn "NO"

import List

un = map read . words

isParal [(a,b), (c,d)] = a == c || b == d

isNonnull [a, b] = a /= b

main = do
    s1 <- getLine
    s2 <- getLine
    s3 <- getLine
    s4 <- getLine
    let l = map (\(a:b:c:d:_) -> [(a,b), (c,d)]) $ (map un [s1,s2,s3,s4] :: [[Int]] )
        ll = concat l
        points = group $ sort ll
        pointCounts = map length points --must all 2
        numOfPoints = length points --must be 4
        doubles = group $ sort l --must be 4
        nonnulls = all (==True) $ map isNonnull l
        parals = all (==True) $ map isParal l
    if (numOfPoints == 4 &&
        all (==2) pointCounts &&
        nonnulls &&
        parals) then
        putStrLn "YES"
          else
           putStrLn "NO"

import List

un = map read . words

isParal [(a,b), (c,d)] = a == c || b == d

isNonnull [a, b] = a /= b

main = do
    s1 <- getLine
    s2 <- getLine
    s3 <- getLine
    s4 <- getLine
    let lines = map (\(a:b:c:d:_) -> sort [(a,b), (c,d)]) $ (map un [s1,s2,s3,s4] :: [[Integer]] )
        points = concat lines
        pointGroups = group $ sort points
        pointCounts = map length pointGroups --must all 2
        numOfPoints = length pointGroups --must be 4
        doubles = group $ sort lines --must be 4
        nonnulls = all (==True) $ map isNonnull lines
        parals = all (==True) $ map isParal lines
    if (numOfPoints == 4 &&
        all (==2) pointCounts &&
        length doubles == 4 &&
        nonnulls &&
        parals) then
        putStrLn "YES"
          else
           putStrLn "NO"


Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n × m chessboard, a very tasty candy and two numbers a and b.Dima put the chessboard in front of Inna and placed the candy in position (i, j) on the board. The boy said he would give the candy if it reaches one of the corner cells of the board. He's got one more condition. There can only be actions of the following types:  move the candy from position (x, y) on the board to position (x - a, y - b);  move the candy from position (x, y) on the board to position (x + a, y - b);  move the candy from position (x, y) on the board to position (x - a, y + b);  move the candy from position (x, y) on the board to position (x + a, y + b). Naturally, Dima doesn't allow to move the candy beyond the chessboard borders.Inna and the pony started shifting the candy around the board. They wonder what is the minimum number of allowed actions that they need to perform to move the candy from the initial position (i, j) to one of the chessboard corners. Help them cope with the task!

The first line of the input contains six integers n, m, i, j, a, b (1 ≤ n, m ≤ 106; 1 ≤ i ≤ n; 1 ≤ j ≤ m; 1 ≤ a, b ≤ 106). You can assume that the chessboard rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. Position (i, j) in the statement is a chessboard cell on the intersection of the i-th row and the j-th column. You can consider that the corners are: (1, m), (n, 1), (n, m), (1, 1).

In a single line print a single integer — the minimum number of moves needed to get the candy. If Inna and the pony cannot get the candy playing by Dima's rules, print on a single line "Poor Inna and pony!" without the quotes.

NoteNote to sample 1:Inna and the pony can move the candy to position (1 + 2, 3 + 2) = (3, 5), from there they can move it to positions (3 - 2, 5 + 2) = (1, 7) and (3 + 2, 5 + 2) = (5, 7). These positions correspond to the corner squares of the chess board. Thus, the answer to the test sample equals two.

import Data.Maybe (maybeToList)

check l r = l `mod` 2 == r `mod` 2

try n m i j a b u v
    | i == u && j == v = Just 0
    | i-a < 1 && i+a > n = Nothing
    | j-b < 1 && j+b > m = Nothing
    | i `mod` a == u `mod` a &&
      j `mod` b == v `mod` b &&
      ma `mod` 2 == mb `mod` 2 = Just $ max ma mb
    | otherwise = Nothing
  where
    ma = abs $ (u-i) `div` a
    mb = abs $ (v-j) `div` b

solve n m i j a b = case concat $ map maybeToList [try n m i j a b x y | x <- [1, n], y <- [1, m]] of
                        [] -> Nothing
                        ls -> Just $ minimum ls

getInts = fmap ((map read) . words) getLine

main = do
    [n, m, i, j, a, b] <- getInts
    case solve n m i j a b of
        Nothing -> putStr "Poor Inna and pony!\n"
        Just ans -> print ans

import Data.Maybe

solve (n:m:i:j:a:b:[]) = catMaybes [try x y | x <- [1, n], y <- [1, m]]
  where
    try u v
        | i == u && j == v         = Just 0
        | i-a < 1 && i+a > n       = Nothing
        | j-b < 1 && j+b > m       = Nothing
        | i `mod` a /= u `mod` a   = Nothing
        | j `mod` b /= v `mod` b   = Nothing
        | ma `mod` 2 /= mb `mod` 2 = Nothing
        | otherwise                = Just $ max ma mb
      where
        ma = abs $ (u-i) `div` a
        mb = abs $ (v-j) `div` b

main = do
    input <- getLine
    case solve $ map read $ words input of
        [] -> putStr "Poor Inna and pony!\n"
        ans -> print $ minimum ans

import Data.Maybe (maybeToList)

solve n m i j a b = case concat $ map maybeToList [try x y | x <- [1, n], y <- [1, m]] of
                        [] -> Nothing
                        ls -> Just $ minimum ls
    where
        try u v
            | i == u && j == v = Just 0
            | i-a < 1 && i+a > n = Nothing
            | j-b < 1 && j+b > m = Nothing
            | i `mod` a == u `mod` a &&
            j `mod` b == v `mod` b &&
            ma `mod` 2 == mb `mod` 2 = Just $ max ma mb
            | otherwise = Nothing
          where
            ma = abs $ (u-i) `div` a
            mb = abs $ (v-j) `div` b

getInts = fmap ((map read) . words) getLine

main = do
    [n, m, i, j, a, b] <- getInts
    case solve n m i j a b of
        Nothing -> putStr "Poor Inna and pony!\n"
        Just ans -> print ans

import Data.Maybe

solve (n:m:i:j:a:b:[]) = catMaybes [try x y | x <- [1, n], y <- [1, m]]
  where
    try u v
        | i == u && j == v         = Just 0
        | i-a < 1 && i+a > n ||
          j-b < 1 && j+b > m ||
          i `mod` a /= u `mod` a ||
          j `mod` b /= v `mod` b ||
          ma `mod` 2 /= mb `mod` 2 = Nothing
        | otherwise                = Just $ max ma mb
      where
        ma = abs $ (u-i) `div` a
        mb = abs $ (v-j) `div` b

main = do
    input <- getLine
    case solve $ map read $ words input of
        [] -> putStr "Poor Inna and pony!\n"
        ans -> print $ minimum ans

import System.IO
import Data.Maybe (maybeToList)

check :: Integer -> Integer -> Bool
check l r = l `mod` 2 == r `mod` 2

try :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Maybe Integer
try n m i j a b u v
    | i == u && j == v = Just 0
    | i-a < 1 && i+a > n = Nothing
    | j-b < 1 && j+b > m = Nothing
    | (i `mod` a == u `mod` a) &&
      (j `mod` b == v `mod` b) &&
      (check ma mb) = Just $ max ma mb
    | otherwise = Nothing
  where
    ma = abs $ (u-i) `div` a
    mb = abs $ (v-j) `div` b

solve :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Maybe Integer
solve n m i j a b = case concat $ map maybeToList [try n m i j a b x y | x <- [1, n], y <- [1, m]] of
                        [] -> Nothing
                        ls -> Just $ minimum ls

main :: IO()
main = do
    [n, m, i, j, a, b] <- fmap ((map read) .words) getLine
    case solve n m i j a b of
        Nothing -> putStr "Poor Inna and pony!\n"
        Just ans -> print ans

import Data.Maybe (maybeToList)

try n m i j a b u v
    | i == u && j == v = Just 0
    | i-a < 1 && i+a > n = Nothing
    | j-b < 1 && j+b > m = Nothing
    | i `mod` a == u `mod` a &&
      j `mod` b == v `mod` b &&
      ma `mod` 2 == mb `mod` 2 = Just $ max ma mb
    | otherwise = Nothing
  where
    ma = abs $ (u-i) `div` a
    mb = abs $ (v-j) `div` b

solve n m i j a b = case concat $ map maybeToList [try n m i j a b x y | x <- [1, n], y <- [1, m]] of
                        [] -> Nothing
                        ls -> Just $ minimum ls

getInts = fmap ((map read) . words) getLine

main = do
    [n, m, i, j, a, b] <- getInts
    case solve n m i j a b of
        Nothing -> putStr "Poor Inna and pony!\n"
        Just ans -> print ans

import Data.Maybe

minimummaybe :: [Maybe Integer] -> Maybe Integer
minimummaybe [] = Nothing
minimummaybe (x : xs) = minmaybe x $ minimummaybe xs
	where
		minmaybe :: Maybe Integer -> Maybe Integer -> Maybe Integer
		minmaybe Nothing Nothing = Nothing
		minmaybe (Just x) Nothing = Just x
		minmaybe Nothing (Just y) = Just y
		minmaybe (Just x) (Just y) = Just (min x y)

steps :: [Integer] -> Maybe Integer
steps (x0 : y0 : x1 : y1 : dx : dy : _)
	| ((mod (abs (x0 - x1)) dx) /= 0) || ((mod (abs (y0 - y1)) dy) /= 0) || (mod ((div (abs (x0 - x1)) dx) + (div (abs (y0 - y1)) dy)) 2 == 1)   = Nothing
	| otherwise                                                    = Just (max ((div (abs (x0 - x1)) dx)) (div (abs (y0 - y1)) dy))

getans :: [Integer] -> String
getans (n : m : i : j : a : b : _)
	| (i == 1 || i == n) && (j == 1 || j == m)        = "0"
	| (i - a < 1 && i + a > n) || (j - b < 1 && j + b > m) ||  minsteps == Nothing                                           = "Poor Inna and pony!"
	| otherwise                                                     = show $ fromJust $ minsteps
	where
		minsteps = minimummaybe [steps [i, j, 1, 1, a, b], steps [i, j, 1, m, a, b], steps [i, j, n, 1, a, b], steps [i, j, n, m, a, b]]

main = do
    input <- getLine
    putStr $ getans (map read (words input) :: [Integer])

import System.IO
import Data.Maybe (maybeToList)

check :: Integer -> Integer -> Bool
check l r = l `mod` 2 == r `mod` 2

try :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Maybe Integer
try i j a b u v
    | (i `mod` a == u `mod` a) &&
      (j `mod` b == v `mod` b) &&
      (check ma mb) = Just $ max ma mb
    | otherwise = Nothing
  where
    ma = abs $ (u-i) `div` a
    mb = abs $ (v-j) `div` b

solve :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Maybe Integer
solve n m i j a b
    | i == a && j == b = Just 0
    | n == 1 || m == 1 = Nothing
    | i-a < 1 && i+a > n = Nothing
    | j-b < 1 && j+b > m = Nothing
    | otherwise = case concat $ map maybeToList [try i j a b x y | x <- [1, n], y <- [1, m]] of
                        [] -> Nothing
                        ls -> Just $ minimum ls

main :: IO()
main = do
    [n, m, i, j, a, b] <- fmap ((map read) .words) getLine
    case solve n m i j a b of
        Nothing -> putStr "Poor Inna and pony!\n"
        Just ans -> print ans

import System.IO
import Data.Maybe (maybeToList)

check :: Integer -> Integer -> Bool
check l r = l `mod` 2 == r `mod` 2

try :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Maybe Integer
try i j a b u v
    | (i `mod` a == u `mod` a) &&
      (j `mod` b == v `mod` b) &&
      (check ma mb) = Just $ max ma mb
    | otherwise = Nothing
  where
    ma = abs $ (u-i) `div` a
    mb = abs $ (v-j) `div` b

solve :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Maybe Integer
solve n m i j a b = case concat $ map maybeToList [try i j a b x y | x <- [1, n], y <- [1, m]] of
                        [] -> Nothing
                        ls -> Just $ minimum ls

main :: IO()
main = do
    [n, m, i, j, a, b] <- fmap ((map read) .words) getLine
    case solve n m i j a b of
        Nothing -> putStr "Poor Inna and pony!\n"
        Just ans -> print ans

import Data.Maybe

minimummaybe :: [Maybe Integer] -> Maybe Integer
minimummaybe [] = Nothing
minimummaybe (x : xs) = minmaybe x $ minimummaybe xs
	where
		minmaybe :: Maybe Integer -> Maybe Integer -> Maybe Integer
		minmaybe Nothing Nothing = Nothing
		minmaybe (Just x) Nothing = Just x
		minmaybe Nothing (Just y) = Just y
		minmaybe (Just x) (Just y) = Just (min x y)

steps :: [Integer] -> Maybe Integer
steps (x0 : y0 : x1 : y1 : dx : dy : _)
	| ((mod (abs (x0 - x1)) dx) /= 0) || ((mod (abs (y0 - y1)) dy) /= 0) || (mod ((div (abs (x0 - x1)) dx) + (div (abs (y0 - y1)) dy)) 2 == 1)   = Nothing
	| otherwise                                                    = Just (max ((div (abs (x0 - x1)) dx)) (div (abs (y0 - y1)) dy))

getans :: [Integer] -> String
getans (n : m : i : j : a : b : _)
	| (i - a < 1 && i + a > n) || (j - b < 1 && j + b > m) ||  minsteps == Nothing                                           = "Poor Inna and pony!"
	| otherwise                                                     = show $ fromJust $ minsteps
	where
		minsteps = minimummaybe [steps [i, j, 1, 1, a, b], steps [i, j, 1, m, a, b], steps [i, j, n, 1, a, b], steps [i, j, n, m, a, b]]

main = do
    input <- getLine
    putStr $ getans (map read (words input) :: [Integer])

import Data.Maybe

minimummaybe :: [Maybe Integer] -> Maybe Integer
minimummaybe [] = Nothing
minimummaybe (x : xs) = minmaybe x $ minimummaybe xs
	where
		minmaybe :: Maybe Integer -> Maybe Integer -> Maybe Integer
		minmaybe Nothing Nothing = Nothing
		minmaybe (Just x) Nothing = Just x
		minmaybe Nothing (Just y) = Just y
		minmaybe (Just x) (Just y) = Just (min x y)

steps :: [Integer] -> Maybe Integer
steps (x0 : y0 : x1 : y1 : dx : dy : _)
	| ((mod (abs (x0 - x1)) dx) /= 0) || ((mod (abs (y0 - y1)) dy) /= 0) || (mod ((div (abs (x0 - x1)) dx) + (div (abs (y0 - y1)) dy)) 2 == 1)   = Nothing
	| otherwise                                                    = Just (max ((div (abs (x0 - x1)) dx)) (div (abs (y0 - y1)) dy))

getans :: [Integer] -> String
getans (n : m : i : j : a : b : _)
	| (i /= n && i /= 1 && i - a < 1 && i + a > n) || (j /= m && j /= 1 && j - b < 1 && j + b > m) ||  minsteps == Nothing                                           = "Poor Inna and pony!"
	| otherwise                                                     = show $ fromJust $ minsteps
	where
		minsteps = minimummaybe [steps [i, j, 1, 1, a, b], steps [i, j, 1, m, a, b], steps [i, j, n, 1, a, b], steps [i, j, n, m, a, b]]

main = do
    input <- getLine
    putStr $ getans (map read (words input) :: [Integer])

import Data.Maybe

minimummaybe :: [Maybe Integer] -> Maybe Integer
minimummaybe [] = Nothing
minimummaybe (x : xs) = minmaybe x $ minimummaybe xs
	where
		minmaybe :: Maybe Integer -> Maybe Integer -> Maybe Integer
		minmaybe Nothing Nothing = Nothing
		minmaybe (Just x) Nothing = Just x
		minmaybe Nothing (Just y) = Just y
		minmaybe (Just x) (Just y) = Just (min x y)

steps :: [Integer] -> Maybe Integer
steps (x0 : y0 : x1 : y1 : dx : dy : _)
	| ((mod (abs (x0 - x1)) dx) /= 0) || ((mod (abs (y0 - y1)) dy) /= 0) || (mod ((div (abs (x0 - x1)) dx) + (div (abs (y0 - y1)) dy)) 2 == 1)   = Nothing
	| otherwise                                                    = Just (max ((div (abs (x0 - x1)) dx)) (div (abs (y0 - y1)) dy))

getans :: [Integer] -> String
getans (n : m : i : j : a : b : _)
	| minsteps == Nothing                                           = "Poor Inna and pony!"
	| otherwise                                                     = show $ fromJust $ minsteps
	where
		minsteps = minimummaybe [steps [i, j, 1, 1, a, b], steps [i, j, 1, m, a, b], steps [i, j, n, 1, a, b], steps [i, j, n, m, a, b]]

main = do
    input <- getLine
    putStr $ getans (map read (words input) :: [Integer])

import Data.Maybe

minimummaybe :: [Maybe Integer] -> Maybe Integer
minimummaybe [] = Nothing
minimummaybe (x : xs) = minmaybe x $ minimummaybe xs
	where
		minmaybe :: Maybe Integer -> Maybe Integer -> Maybe Integer
		minmaybe Nothing Nothing = Nothing
		minmaybe (Just x) Nothing = Just x
		minmaybe Nothing (Just y) = Just y
		minmaybe (Just x) (Just y) = Just (min x y)

steps :: [Integer] -> Maybe Integer
steps (x0 : y0 : x1 : y1 : dx : dy : _)
	| ((mod (abs (x0 - x1)) dx) /= 0) || ((mod (abs (y0 - y1)) dy) /= 0) || ((div (abs (x0 - x1)) dx) /= (div (abs (y0 - y1)) dy))   = Nothing
	| otherwise                                                    = Just ((div (abs (x0 - x1)) dx))

getans :: [Integer] -> String
getans (n : m : i : j : a : b : _)
	| minsteps == Nothing                                           = "Poor Inna and pony!"
	| otherwise                                                     = show $ fromJust $ minsteps
	where
		minsteps = minimummaybe [steps [i, j, 1, 1, a, b], steps [i, j, 1, m, a, b], steps [i, j, n, 1, a, b], steps [i, j, n, m, a, b]]

main = do
    input <- getLine
    putStr $ getans (map read (words input) :: [Integer])

import Data.Maybe

minimummaybe :: [Maybe Int] -> Maybe Int
minimummaybe [] = Nothing
minimummaybe (x : xs) = minmaybe x $ minimummaybe xs
	where
		minmaybe :: Maybe Int -> Maybe Int -> Maybe Int
		minmaybe Nothing Nothing = Nothing
		minmaybe (Just x) Nothing = Just x
		minmaybe Nothing (Just y) = Just y
		minmaybe (Just x) (Just y) = Just (min x y)

steps :: [Int] -> Maybe Int
steps (x0 : y0 : x1 : y1 : dx : dy : _)
	| ((mod (abs (x0 - x1)) dx) /= 0) || ((mod (abs (y0 - y1)) dy) /= 0) || ((div (abs (x0 - x1)) dx) /= (div (abs (y0 - y1)) dy))   = Nothing
	| otherwise                                                    = Just ((div (abs (x0 - x1)) dx))

getans :: [Int] -> String
getans (n : m : i : j : a : b : _)
	| minsteps == Nothing                                           = "Poor Inna and pony!"
	| otherwise                                                     = show $ fromJust $ minsteps
	where
		minsteps = minimummaybe [steps [i, j, 1, 1, a, b], steps [i, j, 1, m, a, b], steps [i, j, n, 1, a, b], steps [i, j, n, m, a, b]]

main = do
    input <- getLine
    putStr $ getans (map read (words input) :: [Int])


Polycarp has $$$n$$$ coins, the value of the $$$i$$$-th coin is $$$a_i$$$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.For example, if Polycarp has got six coins represented as an array $$$a = [1, 2, 4, 3, 3, 2]$$$, he can distribute the coins into two pockets as follows: $$$[1, 2, 3], [2, 3, 4]$$$.Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of coins. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$) — values of coins.

Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.

import Data.List
main=interact$show.maximum.map length.group.sort.map (read::String->Int).tail.words

import System.IO
import Data.List
import Data.Functor

main = do
    line <- getLine
    let n = read line :: Int

    line2 <- getLine
    let mywords = words line2

    let num = read <$> mywords :: [Int]

    let x = [length x | x <- group $ sort num]

    print $ maximum x

-- Codeforces 1003A
import Data.List

maxOccurences :: [Int] -> Int
maxOccurences list = maximum occurences
    where ordered = sort list
          grouped = group ordered
          occurences = map length grouped

main :: IO ()
main = do
    n <- getLine
    input <- getLine
    let numbers = map (read :: String -> Int) (words input)
    let maxOccur = maxOccurences numbers
    print maxOccur

import Data.List
import Data.Function

main = getLine >> getLine >>= print . length . maximumBy (compare `on` length) . group. sort . map (read :: String -> Int) . words

import Data.List

main=do
     e1<-getLine
     es<-getLine
     let xs=map read (words es)::[Int]
     print $ last $ sort $ map length $ group $ sort xs

import Control.Monad
import Data.Map as Map

main = readInput
   >>= putStrLn . show . maxMap . parse . words

readInput :: IO String
readInput = liftM2 go getLine getLine
  where go a b = b

parse :: [String] -> Map String Int
parse strs = fromListWith (+) $ Prelude.map (\s -> (s, 1)) strs

maxMap :: Map String Int -> Int
maxMap xs = Map.foldr max 0 xs

{-# LANGUAGE ScopedTypeVariables #-}

import Prelude
import Data.List
import Text.Printf
import Control.Monad
import Data.Ratio
import Data.Int
import Data.Functor

main :: IO ()
main = do
    (n :: Int) <- read <$> getLine
    (a :: [Int]) <- (map read . words) <$> getLine
    let answer = maximum . map length . group . sort $ a
    printf "%d" answer

{-# LANGUAGE TypeApplications #-}
import Data.List
main = interact $ show . maximum . map length . group . sort . map (read @Int) . tail . words

module Main where

import System.IO

coins :: Eq a => [a] -> Int
coins ns = length (coins' ns)

coins' :: Eq a => [a] -> [[a]]
coins' ns = foldl (flip coins'') [] ns

coins'' :: Eq a => a -> [[a]] -> [[a]]
coins'' a [] = [[a]]
coins'' a (xs:yss) | a `elem` xs = xs : (coins'' a yss)
                   | otherwise   = (a:xs):yss

main :: IO ()
main =
    do
       _ <- readInt
       str <- getLine
       ns <- return (map read $ words str :: [Int])
       putStrLn (show $ coins ns)

  where readInt :: IO Int
        readInt = readLn

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

main = do
		getLine
		n1<- sort <$> map read <$> words <$> getLine ::IO [Int]
		let n=  maximum $ map length $ group n1
		print n

--ghc 7.10

import Data.List(group,sort)

maxOccurrence :: (Ord a) => [a] -> Int
maxOccurrence = maximum . map length . group . sort

main = do
    nStr <- getLine
    aStr <- getLine
    let a = map read . words $ aStr :: [Int]
    print $ maxOccurrence a

import Control.Monad
import Data.List

main = readInput
   >>= putStrLn . show . maxL . (map length) . group . words

readInput :: IO String
readInput = liftM2 go getLine getLine
  where go a b = b

maxL :: Ord a => [a] -> a
maxL (x:xs) = foldr go x xs
  where go a cand
          | a < cand = cand
          | otherwise = a


Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.Your problem is to print the minimum possible length of the sequence of moves after the replacements.

The first line of the input contains one integer n (1 ≤ n ≤ 100) — the length of the sequence. The second line contains the sequence consisting of n characters U and R.

Print the minimum possible length of the sequence of moves after all replacements are done.

NoteIn the first test the shortened sequence of moves may be DUD (its length is 3).In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).

f [] c = c
f ('R':'U':as) c = f as (c+1)
f ('U':'R':as) c = f as (c+1)
f (a:as) c = f as (c+1)

main = do
   getLine
   as <- getLine
   print $ f as 0

main = getContents >>= print . solve . last . lines

solve [] = 0
solve ('R':'U':xs) = 1 + solve xs
solve ('U':'R':xs) = 1 + solve xs
solve (_:xs) = 1 + solve xs

import Data.List

f ::String->Int
f []=0
f (x:[])=1
f ('U':'R':xs)=1+f xs
f ('R':'U':xs)=1+f xs
f (x:xs)=1+f xs

main = do
       e<-getLine
       es<-getLine
       print $ (f es)

module Main where

eval :: String -> Int
eval [] = 0
eval [x] = 1
eval ('U':'R':xs) = 1 + eval xs
eval ('R':'U':xs) = 1 + eval xs
eval (x:xs) = 1 + eval xs

printRes :: String -> IO ()
printRes str = print $ eval str

main :: IO ()
main = getLine >> getLine >>= printRes >>= return

module Main where

import Control.Monad
import Control.Applicative

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

 print . length $ foldl trans [] s

trans::String -> Char -> String
trans ('R':rest) 'U' = 'D':rest
trans ('U':rest) 'R' = 'D':rest
trans rest x = x:rest

{-# LANGUAGE OverloadedStrings #-}

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

process [] = []
process [a] = [a]
process (a:b:c) | a=='R' && b=='U' = 'D' : (process c)
                | a=='U' && b=='R' = 'D' :(process c)
		| otherwise = a: (process (b:c))

main = do
		getLine
		a<-getLine
		print $ length $ process a

reduce :: String -> String
reduce [] = []
reduce [a] = [a]
reduce ('R':'U':xs) = 'D':reduce xs
reduce ('U':'R':xs) = 'D':reduce xs
reduce (x:xs) = x:reduce xs

reduceIter :: String -> String
reduceIter str = let str' = reduce str in if length str' == length str then str else reduce str'

solve :: String -> Int
solve = length . reduceIter

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

{-# LANGUAGE OverloadedStrings #-}

import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.Text as T

main = do
		getLine
		a<-getLine
		print $ T.length $ T.replace "RU" "D" $ T.replace "UR" "D" $ T.pack a

{-# LANGUAGE OverloadedStrings #-}

import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.Text as T

main = do
		getLine
		a<-getLine
		let b=  T.length $ T.replace "RU" "D" $ T.replace "UR" "D" $ T.pack a
		let c=  T.length $ T.replace "UR" "D" $ T.replace "RU" "D" $ T.pack a
		print $ min b c


There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory", they need to choose a group containing exactly t actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a group? Of course, the variants that only differ in the composition of the troupe are considered different.Perform all calculations in the 64-bit type: long long for С/С++, int64 for Delphi and long for Java.

The only line of the input data contains three integers n, m, t (4 ≤ n ≤ 30, 1 ≤ m ≤ 30, 5 ≤ t ≤ n + m).

Find the required number of ways. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

{-
import HUnit

testSimple :: Test
testSimple  =  Test "TestSimple" $
    assertEq 1 (solve 4 1 5)

testInput :: Test
testInput  =  TestList "TestInput"
    [Test "1" $ assertEq 10 (solve 5 2 5),
     Test "2" $ assertEq 3 (solve 4 3 5)]

testReal :: Test
testReal  =  TestList "TestReal"
    [Test "1" $ assertEq 7 (solve 5 2 6)]

test :: IO ()
test  =  mapM_ run [testSimple, testInput, testReal]

--------------------------------------------------------------------------------
-}

reads :: Read a => IO [a]
reads = getLine >>= sequence . map readIO . words

solve :: Integer -> Integer -> Integer -> Integer
solve n m t  =  sum (map (\x -> (c n x) * (c m (t-x))) [x | x <- [4 .. t - 1]])
  where
    c n m  =  div (product [n-m+1 .. n]) (product [1..m])

main :: IO ()
main  =  do
    [n, m, t] <- Main.reads
    print $ solve n m t

--module CC where

combinator x 0 = 1
combinator x y = product [1..x] `div` (product [1..y] * product [1..x-y])

answer :: [Integer] -> Integer
answer [n,m,k] = func k m $ myFilter
                  $ zip [4..n] $ map (n `combinator`) [4..n]
  where
    myFilter xs = filter ((>=k).(+m).fst) xs

func :: Integer -> Integer -> [(Integer,Integer)] -> Integer
func k m xs = sum $ map f xs
  where
    f (x,y) = if k == x then 0 else y *( m `combinator` (k-x))

main = getLine >>= print.answer.map read.take 3.words

import Debug.Trace

main = interact $ show . count . map read . words
	where
		count (n:m:t:_) = foldr sumComb 0 [(x, t-x)| x<-[4..n], 0 < t-x, t-x <= m]
			where
				sumComb (x,y) k = (comb n x) * (comb m y) + k

comb n m = (perm n m) `div` (perm m m)
perm n 0 = 1
perm n m = n * (perm (n-1) (m-1))

main = interact $ show . count . map read . words
	where
		count (n:m:t:_) = sum [(comb n x) * (comb m $ t-x)| x<-[4..n], 0 < t-x, t-x <= m]
		comb n r = product [n-r+1..n] `div` product [1..r]

main = interact $ show . count . map read . words
	where
		count (n:m:t:_) = foldr sumComb 0 [x| x<-[4..n], 0 < t-x, t-x <= m]
			where
				sumComb x k = (comb n x) * (comb m $ t-x) + k
				comb n r = product [n-r+1..n] `div` product [1..r]

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

main = do
  [n,m,t] <- getList
  let list = [c_n_k n x * c_n_k m y | x <- [4..n], y <- [1..m], x+y == t]
  print $ sum list
  where
    getList = fmap (map read . words) getLine :: IO [Integer]
    c_n_k :: Integer -> Integer -> Integer
    c_n_k n k = product [1..n] `div` (product [1..k] * product [1..n-k])

import Data.Int
import Data.Array
main = do
  [n,m,t] <- fmap (map read . words) getLine
  print $ sum [ ncr n n' * ncr m m' | n' <- [4..n], let m' = t - n', m' >= 1, m' <= m ]
ncr :: Int64 -> Int64 -> Int64
ncr = let a = array ((0,0),(30,30))
              [ ((n,m),if m == 0 || m == n
                       then 1
                       else ncr (n-1) (m-1) + ncr (n-1) m)
                | n <- [0..30], m <- [0..30] ]
      in \n m -> a!(n,m)

readInts :: String -> [Integer]
readInts str = map read (words str)

c :: Integer -> Integer -> Integer
c n n' = product [1..n] `div` product [1..n'] `div` product [1..n-n']

main :: IO ()
main = do
  [n, m, t] <- fmap readInts getLine
  let actors = [(n', m') | n'<-[4..n],let m'=t-n', m'>=1]
  print $ sum [ c n n' * c m m' | (n', m')<-actors]

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.Marshal.Alloc
import Debug.Trace
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Unboxed as UB
import Data.Array.ST
import Data.Array
import Data.Char
class IOtyp a where scan' :: String -> a; show' :: a -> String
instance IOtyp Int where scan' = read; show' = show
instance IOtyp Char where scan' (x:_) = x;show' = (:[])
instance IOtyp Float where scan' = read;show' = show
instance IOtyp Double where scan' = read;show' = show
instance IOtyp Integer where scan' = read;show' = show
instance IOtyp String where scan' = id;show' = id
instance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y
instance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z
foreign import ccall "stdio.h puts" c_puts :: CString -> IO ()
scan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'
scans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan
scanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words
scanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist
puts :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}

conb :: Int -> Int -> Integer
conb n m = if m>(n `div` 2)&&(n>m) then conbrec 1 1 (fromIntegral n) (fromIntegral (n-m)) else conbrec 1 1 (fromIntegral n) (fromIntegral m)
    where
      conbrec ans ans2 n m | m==0 = ans `div` ans2
                           | otherwise = conbrec (ans*n) (ans2*m) (n-1) (m-1)

solve :: Integer -> Int -> Int -> Int -> Int -> Integer
solve ans n m act actr | act<4 = ans
                       | otherwise = solve (ans + (conb n act) * (conb m actr)) n m (act-1) (actr + 1)

main = do (n, m, t) <- scan :: IO (Int, Int, Int)
          puts.show $ solve 0 n m (t-1) 1

{-# OPTIONS_GHC -O2 -optc-O2 #-}

-- solution for: http://codeforces.com/problemset/problem/131/C

import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

choose n 0 = 1
choose 0 k = 0
choose n k = toInteger((choose (n-1) (k-1) * n) `div` k)

helper n m t x acc = do
       if (x == t) then acc
                   else helper n m t (x + 1) (acc + (choose n x) * (choose m (t-x)))

solve [n,m,t] = helper n m t 4 0

main =
  do all <- BS.getContents
     let (x, _)  = readMany readInt all
     print (solve x)
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (toInteger(x) : xs, t)
          Nothing     -> ([], s)

fact :: Int -> Integer
fact n = product [1 .. toInteger n]
combo n m = div (fact n) $ (fact m) * (fact (n - m))
solve [n,m,t] = sum $ map ways [4 .. (t - 1)]
    where ways j = (combo m (t - j)) * (combo n j)
main = putStrLn.show.solve.map read.words =<< getLine

main :: IO()
main = interact work

work :: String -> String
work input = show $ solve n m t
    where [n, m, t] = map read . words $ input

factorial :: Integer -> Integer
factorial n = product [1..n]

binom :: Integer -> Integer -> Integer
binom n k
    | n >= k    = factorial n `div` factorial k `div` factorial (n - k)
    | otherwise = 0

solve :: Integer -> Integer -> Integer -> Integer
solve n m t = sum  [binom n i * binom m (t - i) | i <- [4..t - 1]]

comb n 0 = n
comb n m = div numer deno
    where numer = foldl1 (*) [(n-m+1) .. n]
          deno = foldl1 (*) [1..m]
s :: [Integer] -> Integer
s [n, m, t] = sum . map (\(x, y) -> (comb n x) * (comb m y)) $ [(x, t - x) | x <- [4..n], (t - x) <= m, x <= (t - 1)]

main = interact $ show . s . map read . words

import Data.Array
import Data.Function

main = interact solve

solve s =
    show $ c ! (n + m, t) - c ! (n, t) - (sum $ map (\x -> c ! (n, x) * c ! (m, t - x)) [0..3])
    where
        [n, m, t] = map read $ words s
        c = coefArr (n + m, t)

coefArr maxBounds = fix coefArr'
    where
        arrBounds = ((0, 0), maxBounds)
        coefArr' c =
            listArray arrBounds
            [ choose p |
              p <- range arrBounds,
              let choose (n, k) | k == 0    = 1
                                | n < k     = 0
                                | otherwise = c ! (n - 1, k) + c ! (n - 1, k - 1)
            ]

main = do
    [n, m, t] <- fmap (map read . words) getLine
    print $ c (n + m) t - c n t - (sum $ map (\x -> (c n x) * (c m (t - x))) [0..3])
    where
        c n k | n < k     = 0
              | otherwise = product [k + 1..n] `div` product [1..n - k]

import Data.Array (Array, Ix, array, (!), range)
import qualified Data.ByteString.Char8 as BS

memorize :: Ix a => (a -> b) -> (a, a) -> (a -> b)
memorize func rng = let memoArray = array rng [(i, func i) | i <- (range rng)]
                    in (!) memoArray

combination :: (Ix a, Num a, Num b) => (a, a) -> b
combination = memorize cmb ((0, 0), (100, 100))
    where cmb (a, b)
            | b == 0 || a == b = 1
            | otherwise        = combination (a - 1, b - 1) + combination (a - 1, b)

solve :: Int -> Int -> Int -> Integer
solve n m t = sum [ combination (n, i) * combination (m, t - i) |
                    i <- [4..t-1], i <= n, t - i >= 1, t - i <= m ]

main :: IO ()
main = do cs <- BS.getContents
          let ws = BS.words cs
              n  = bReadInt $ ws !! 0
              m  = bReadInt $ ws !! 1
              t  = bReadInt $ ws !! 2
          print $ solve n m t

bReadInt :: BS.ByteString -> Int
bReadInt = toNumber . BS.readInt

bReadInteger :: BS.ByteString -> Integer
bReadInteger = toNumber . BS.readInteger

toNumber :: Num a => Maybe (a, BS.ByteString) -> a
toNumber (Just (x, _)) = x
toNumber Nothing       = 0

-- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-- File Name : 0001A.hs
-- Creation Date : 17-10-2012
-- Last Modified : Fri 19 Oct 2012 07:57:44 PM EEST
-- Created By : Greg Liras <gregliras@gmail.com>
--_._._._._._._._._._._._._._._._._._._._._.

{-# OPTIONS_GHC -O2 -optc-O2 #-}

import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

binom :: (Integral a) => a -> a -> a
--binom n k = product [k+1..n] `div` product [1..n-k]
binom n k = foldl (\z i -> (z * (n-i+1)) `div` i) 1 [1..k]

main :: IO ()
main =
    do
        all <- BS.getContents
        let Just (n, r1)    = readInteger all
        let Just (m, r2)    = readInteger r1
        let Just (t, _)    = readInteger r2
        --print $ (binom n 4) * m * binom (n+m-5) (t-5)

        print $ sum [ (binom m g) * (binom n (t-g)) | g <- [1..min (t-4) m]]
    where
        readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
            Just (x, r) ->  let
                                (xs, t) = readMany readf r
                            in
                                (x : xs, t)
            Nothing     ->  ([], s)

-- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-- File Name : 0001A.hs
-- Creation Date : 17-10-2012
-- Last Modified : Fri 19 Oct 2012 07:55:14 PM EEST
-- Created By : Greg Liras <gregliras@gmail.com>
--_._._._._._._._._._._._._._._._._._._._._.

{-# OPTIONS_GHC -O2 -optc-O2 #-}

import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

binom :: (Integral a) => a -> a -> a
--binom n k = product [k+1..n] `div` product [1..n-k]
binom n k = foldl (\z i -> (z * (n-i+1)) `div` i) 1 [1..k]

main :: IO ()
main =
    do
        all <- BS.getContents
        let Just (n, r1)    = readInteger all
        let Just (m, r2)    = readInteger r1
        let Just (t, _)    = readInteger r2
        print $ (binom n 4) * m * binom (n+m-5) (t-5)

        print $ sum [ (binom m g) * (binom n (t-g)) | g <- [1..min (t-4) m]]
    where
        readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
            Just (x, r) ->  let
                                (xs, t) = readMany readf r
                            in
                                (x : xs, t)
            Nothing     ->  ([], s)

-- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-- File Name : 0001A.hs
-- Creation Date : 17-10-2012
-- Last Modified : Fri 19 Oct 2012 06:44:46 PM EEST
-- Created By : Greg Liras <gregliras@gmail.com>
--_._._._._._._._._._._._._._._._._._._._._.

{-# OPTIONS_GHC -O2 -optc-O2 #-}

import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

binom :: (Integral a) => a -> a -> a
binom n k = product [k+1..n] `div` product [1..n-k]

main :: IO ()
main =
    do
        all <- BS.getContents
        let Just (n, r1)    = readInteger all
        let Just (m, r2)    = readInteger r1
        let Just (t, _)    = readInteger r2
        print $ (binom n 4) * (binom m 1) * (binom (n+m-5) (t-5))
    where
        readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
            Just (x, r) ->  let
                                (xs, t) = readMany readf r
                            in
                                (x : xs, t)
            Nothing     ->  ([], s)

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

main = do
  [n,m,t] <- getList
  let list = [toInteger $ c_n_k n x * c_n_k m y | x <- [4..n], y <- [1..m], x+y == t]
  print $ sum list
  where
    getList = fmap (map read . words) getLine :: IO [Int]
    c_n_k :: Int -> Int -> Int
    c_n_k n k = product [1..n] `div` (product [1..k] * product [1..n-k])

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

main = do
  [n,m,t] <- getList
  let list = [c_n_k n x * c_n_k m y | x <- [4..n], y <- [1..m], x+y == t]
  print $ sum list
  where
    getList = fmap (map read . words) getLine :: IO [Int]
    c_n_k n k = product [1..n] `div` (product [1..k] * product [1..n-k])

{-# OPTIONS_GHC -O2 -optc-O2 #-}

-- solution for: http://codeforces.com/problemset/problem/131/C

import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

choose n 0 = 1
choose 0 k = 0
choose n k = toInteger((choose (n-1) (k-1) * n) `div` k)

solve [n,m,t] = (choose n 4) * (choose m 1) * (choose (n+m-5) (t-5))

main =
  do all <- BS.getContents
     let (x, _)  = readMany readInt all
     print (solve x)
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (toInteger(x) : xs, t)
          Nothing     -> ([], s)

-- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-- File Name : 0001A.hs
-- Creation Date : 17-10-2012
-- Last Modified : Fri 19 Oct 2012 07:28:41 PM EEST
-- Created By : Greg Liras <gregliras@gmail.com>
--_._._._._._._._._._._._._._._._._._._._._.

{-# OPTIONS_GHC -O2 -optc-O2 #-}

import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

binom :: (Integral a) => a -> a -> a
--binom n k = product [k+1..n] `div` product [1..n-k]
binom n k = foldl (\z i -> (z * (n-i+1)) `div` i) 1 [1..k]

main :: IO ()
main =
    do
        all <- BS.getContents
        let Just (n, r1)    = readInteger all
        let Just (m, r2)    = readInteger r1
        let Just (t, _)    = readInteger r2
        print $ (binom n 4) * m * sum (map (\s -> binom (n+m-5) s) [0..(t-5)])
    where
        readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
            Just (x, r) ->  let
                                (xs, t) = readMany readf r
                            in
                                (x : xs, t)
            Nothing     ->  ([], s)

-- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-- File Name : 0001A.hs
-- Creation Date : 17-10-2012
-- Last Modified : Fri 19 Oct 2012 06:45:50 PM EEST
-- Created By : Greg Liras <gregliras@gmail.com>
--_._._._._._._._._._._._._._._._._._._._._.

{-# OPTIONS_GHC -O2 -optc-O2 #-}

import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

binom :: (Integral a) => a -> a -> a
--binom n k = product [k+1..n] `div` product [1..n-k]
binom n k = foldl (\z i -> (z * (n-i+1)) `div` i) 1 [1..k]

main :: IO ()
main =
    do
        all <- BS.getContents
        let Just (n, r1)    = readInteger all
        let Just (m, r2)    = readInteger r1
        let Just (t, _)    = readInteger r2
        print $ (binom n 4) * (binom m 1) * (binom (n+m-5) (t-5))
    where
        readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
            Just (x, r) ->  let
                                (xs, t) = readMany readf r
                            in
                                (x : xs, t)
            Nothing     ->  ([], s)

-- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-- File Name : 0001A.hs
-- Creation Date : 17-10-2012
-- Last Modified : Fri 19 Oct 2012 06:50:39 PM EEST
-- Created By : Greg Liras <gregliras@gmail.com>
--_._._._._._._._._._._._._._._._._._._._._.

{-# OPTIONS_GHC -O2 -optc-O2 #-}

import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

binom :: (Integral a) => a -> a -> a
--binom n k = product [k+1..n] `div` product [1..n-k]
binom n k = foldl (\z i -> (z * (n-i+1)) `div` i) 1 [1..k]

main :: IO ()
main =
    do
        all <- BS.getContents
        let Just (n, r1)    = readInteger all
        let Just (m, r2)    = readInteger r1
        let Just (t, _)    = readInteger r2
        print $ (binom n 4) * m * (binom (n+m-5) (t-5))
    where
        readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
            Just (x, r) ->  let
                                (xs, t) = readMany readf r
                            in
                                (x : xs, t)
            Nothing     ->  ([], s)