Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.

For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.

NoteLet's consider the test cases of the example:  $$$n=8$$$, $$$k=3$$$:   during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$;  during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$;  during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$;  during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$.   $$$n=6$$$, $$$k=6$$$:   during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$;  during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$;  during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$.   $$$n=7$$$, $$$k=1$$$:   during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$;  during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$;  during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$;  during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$;  during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$;  during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.

import qualified Control.Monad as CM
import qualified Data.List as DL
import Data.Bits
import System.IO

solve :: IO ()
solve = do
  ~[n,k] <- readv :: IO [Int]
  let lk = lgCeil k
  print $  lk + divCeil (n - shiftL 1 lk) k

lg n = fromIntegral $ finiteBitSize n - countLeadingZeros n - 1
lgCeil n = lg n + if popCount n == 1 then 0 else 1
divCeil n d = q + if r==0 then 0 else 1 where (q,r)=divMod n d

printv :: Show a => [a] -> IO ()
printv xs =  putStrLn $ unwords $ fmap show xs

readv :: Read a => IO [a]
readv = fmap read . words <$> getLine

main :: IO ()
main = do
  ~[n] <- readv
  CM.replicateM_ n solve

import qualified Control.Monad as CM
import qualified Data.List as DL
import Data.Bits
import System.IO

solve :: IO ()
solve = do
  ~[n,k] <- readv :: IO [Int]
  print $  lgCeil k + divCeil (n - 2 ^ lgCeil k) k

lg n = fromIntegral $ finiteBitSize n - countLeadingZeros n - 1
lgCeil n = lg n + if popCount n == 1 then 0 else 1
divCeil n d = q + if r==0 then 0 else 1 where (q,r)=divMod n d

printv :: Show a => [a] -> IO ()
printv xs =  putStrLn $ unwords $ fmap show xs

readv :: Read a => IO [a]
readv = fmap read . words <$> getLine

main :: IO ()
main = do
  ~[n] <- readv
  CM.replicateM_ n solve

import Control.Monad
import Data.Int
import Data.List

calc :: Int -> Int -> Int
calc 1 1 = 0
calc n 1 = n-1
calc n k =
  let (ans, cur) = stage1 k 0 1
  in
    if cur < n then ans + ((n - cur + k - 1) `div` k)
    else ans

stage1 :: Int -> Int -> Int -> (Int, Int)
stage1 k it acc | acc >= k = (it, acc)
stage1 k it acc | otherwise =
  stage1 k (it+1) (acc*2)

main = do
  line <- getLine
  let t = read line :: Int
  forM_ [1..t] $ \_ -> do
    line <- getLine
    let [n,k] = map read $ words line :: [Int]
    --print "abc"
    --print $ stage1 k 0 1
    print $ calc n k

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

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

prefMins :: Ord t => (a -> t) -> [a] -> [t]
prefMins f li = tail $ scanl' min (f $ head li) $ map f li

fib n = go n (0,1)
  where
    go !n (!a, !b) | n==0      = a
                   | otherwise = go (n-1) (b, a+b)

gao (n, k) = go (n, k) (0, 1)
  where
    go (!n, !k) (!t, !i) | i >= n = t
                         | i >= k = t + (div (n-i+k-1) (k))
                         | otherwise = go (n, k) (t+1, i*2)

mainFun :: SP Builder
mainFun = do
  ~[t] <- getInts 1
  fmap mconcat $ replicateM t $ do
    ~[n, k] <- getInts 2
    pure $ putInts [gao (n, k)]

type SP = State [P.ByteString]

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

getInts :: Int -> SP [Int]
getInts k = map (fst . fromJust . P.readInt) <$> getNext k

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

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

{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}

import Control.Applicative (liftA2)
import Control.Arrow ((>>>))
import Control.Monad
import Control.Monad.State (State, evalState, get, gets, put)
import qualified Data.ByteString.Lazy.Char8 as C
import Data.Function
import Data.Int
import Data.List
import Data.Maybe

main :: IO ()
main = C.interact $ runScanner (numberOf input) >>> map (solve >>> output) >>> C.unlines

data TC = TC { n :: Integer, k :: Integer }

input :: Scanner TC
input = do
  n <- integer
  k <- integer
  return TC {..}

-- type Output = String

-- output :: Output -> C.ByteString
output = showB

-- solve :: TC -> Output
solve TC {..} = compute 1 (n - 1)
  where
    compute d r
      | r <= 0 = 0
      | d >= k = (r + k - 1) `div` k
      | otherwise = let u = minimum [k, d, r] in 1 + compute (d + u) (r - u)

-------------------------- Template ------------------------------------------
-- Lists
groupOn :: Eq b => (a -> b) -> [a] -> [[a]]
groupOn = groupBy . on (==)

chunksOf :: Int -> [a] -> [[a]]
chunksOf _ [] = []
chunksOf k xs = let (hs, ts) = splitAt k xs in hs : chunksOf k ts

adjacents :: [a] -> [(a, a)]
adjacents xs = zip xs (tail xs)

adjacentsWith :: (a -> a -> b) -> [a] -> [b]
adjacentsWith f xs = zipWith f xs (tail xs)

count :: Eq a => a -> [a] -> Int
count = countBy . (==)

countBy :: (a -> Bool) -> [a] -> Int
countBy p = length . filter p

-- Scanner
type Scanner = State [C.ByteString]

runScanner :: Scanner a -> C.ByteString -> a
runScanner = runScannerWith C.words

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

peek :: Scanner C.ByteString
peek = gets head

bstr :: Scanner C.ByteString
bstr = get >>= \case s : ss -> put ss >> return s

str :: Scanner String
str = C.unpack <$> bstr

readStr :: Read a => Scanner a
readStr = read <$> str

int :: Scanner Int
int = fst . fromJust . C.readInt <$> bstr

integer :: Scanner Integer
integer = readStr

int64 :: Scanner Int64
int64 = readStr

double :: Scanner Double
double = readStr

decimal :: Int -> Scanner Int
decimal p = round . ((10 ^ p) *) <$> double

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

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

till :: (C.ByteString -> Bool) -> Scanner a -> Scanner [a]
till p s = do
  t <- peek
  if p t
    then return []
    else (:) <$> s <*> till p s

times :: Int -> Scanner a -> Scanner [a]
times = replicateM

(><) = times

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

pair :: Scanner a -> Scanner b -> Scanner (a, b)
pair = liftA2 (,)

showB :: Show a => a -> C.ByteString
showB = C.pack . show

{-# LANGUAGE BangPatterns #-}

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

main :: IO ()
main = do
  [t] <- readInts
  replicateM_ t $ do
    [n, k] <- readIntegers
    print $ solve n k 1

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

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

solve n k a
  | a >= n = 0
  | a >= k = (n - a - 1) `div` k + 1
  | otherwise = 1 + (solve n k $ 2 * a)

import Control.Monad
import Data.Int
import Data.List

isqrt :: Int -> Int
isqrt = ceiling . sqrt . fromIntegral

calc :: Int -> Int -> Int
calc 1 1 = 0
calc n 1 = n-1

-- 1. max k <= k : k*(k+1) <= n
calc n k =
  let k2 = ((isqrt (8*n+1)) - 1) `div` 2
      k3 = min k k2
      r = max 0 $ n-((k3*(k3+1)) `div` 2)
      m = r `mod` k
      add = if m > 0 then 1 else 0
  in
    k3 + (r `div` k) + add

main = do
  line <- getLine
  let t = read line :: Int
  forM_ [1..t] $ \_ -> do
    line <- getLine
    let [n,k] = map read $ words line :: [Int]
    --print "123"
    --print $ ((isqrt (8*2+1)) - 1) `div` 2
    --print $ max 0 $ (n-((2*(2+1)) `div` 2))
    print $ calc n k

import Control.Monad
import Data.Int
import Data.List

isqrt :: Int -> Int
isqrt = floor . sqrt . fromIntegral

calc :: Int -> Int -> Int
calc 1 1 = 0
calc n 1 = n-1

-- 1. max k <= k : k*(k+1) <= n
calc n k =
  let k2 = ((isqrt (4*n+1)) - 1) `div` 2
      k3 = min k k2
      r = n-k3
      m = r `mod` k
      add = if m > 0 then 1 else 0
  in
    k3 + (r `div` k) + add

main = do
  line <- getLine
  let t = read line :: Int
  forM_ [1..t] $ \_ -> do
    line <- getLine
    let [n,k] = map read $ words line :: [Int]
    print $ calc n k


The Beroil corporation structure is hierarchical, that is it can be represented as a tree. Let's examine the presentation of this structure as follows:  employee ::= name. | name:employee1,employee2, ... ,employeek.  name ::= name of an employee That is, the description of each employee consists of his name, a colon (:), the descriptions of all his subordinates separated by commas, and, finally, a dot. If an employee has no subordinates, then the colon is not present in his description.For example, line MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY... is the correct way of recording the structure of a corporation where the director MIKE has subordinates MAX, ARTEM and DMITRY. ARTEM has a subordinate whose name is MIKE, just as the name of his boss and two subordinates of DMITRY are called DMITRY, just like himself.In the Beroil corporation every employee can only correspond with his subordinates, at that the subordinates are not necessarily direct. Let's call an uncomfortable situation the situation when a person whose name is s writes a letter to another person whose name is also s. In the example given above are two such pairs: a pair involving MIKE, and two pairs for DMITRY (a pair for each of his subordinates).Your task is by the given structure of the corporation to find the number of uncomfortable pairs in it.

The first and single line contains the corporation structure which is a string of length from 1 to 1000 characters. It is guaranteed that the description is correct. Every name is a string consisting of capital Latin letters from 1 to 10 symbols in length.

Print a single number — the number of uncomfortable situations in the company.

import qualified Char as Char

data Token = Id String | Comma | Dot | Colon
data Tree = Node String [Tree]

tokenize [] = []
tokenize (':':xs) = Colon   : tokenize xs
tokenize (',':xs) = Comma   : tokenize xs
tokenize ('.':xs) = Dot     : tokenize xs
tokenize string   = Id name : tokenize rest
    where (name, rest) = span Char.isAlpha string

get_employee (Id x : Dot : xs) = ((Node x []), xs)
get_employee (Id x : Colon : xs) = ((Node x children), rest)
    where (children, rest) = get_children [] xs
          get_children children (Dot:xs) = (children, xs)
          get_children children (Comma:xs) = get_children (child:children) rest
              where (child, rest) = get_employee xs
          get_children children xs = get_children (child:children) rest
              where (child, rest) = get_employee xs

parse string = fst (get_employee (tokenize string))

tree_check boss (Node name children) = conflict + sum (map (tree_check boss) children)
    where conflict = if name == boss then 1 else 0

traverse (Node name children) = this_conflicts + next_conflicts
    where this_conflicts = sum (map (tree_check name) children)
          next_conflicts = sum (map traverse children)

main :: IO ()
main = do
    seq <- getLine
    print (traverse (parse seq))

import Data.Char

data Node = Node String [Node] deriving Show

parseChildren (c:s) | c == ':' || c == ',' = (c1:cs, s'')
                    | otherwise = ([], s)
  where
    (c1, s') = parseEmp s
    (cs, s'') = parseChildren s'

parseEmp s = (Node name ch, s'')
  where
    (name, s') = span isAlpha s
    (ch, s'') = parseChildren s'

visit (Node name children) = ((sum cnts) + c', name:names')
  where
    (cnts, names) = unzip$ map visit children
    names' = concat names
    c' = length$ filter (==name) names'

main = getLine >>= (putStrLn.show.fst.visit.fst.parseEmp)

module Main where

import Control.Monad
import Data.List
import Debug.Trace

readI :: String -> Int
readI = read

readL :: String -> [Int]
readL = (map read) . words

main = do
    s <- getLine
    print $ solve s

solve s = parser s [] 0 where
    -- TODO: remove tracer
    --parser s  acc count | trace (show s ++ " " ++ show acc ++ " " ++ show count) False = undefined
    parser "" _   count = count
    parser s  acc count = if isAlpha hs
        then parser ost (name:acc) count
        else case hs of
            ':' -> parser (tail s) acc count
            ',' -> parser (tail s) acc count
            '.' -> parser (tail s) tacc (count+sovp)
        where
            hs = head s
            sp = span isAlpha s
            name = fst sp
            ost = snd sp

            tacc = tail acc
            hacc = head acc
            sovp = foldl (\c s -> if s == hacc then (c+1) else c) 0 tacc

isAlpha c = c >= 'A' && c <= 'Z'

import qualified Data.List as List
import qualified Data.Map as Map
import Data.Char

data Tree = Tree String [Tree] deriving Show  -- name, employee

solve :: Tree -> Integer
solve (Tree name chn) = a + b
  where fastSum = List.foldl' (+) 0

        a = fastSum $ map (f name) chn
        b = fastSum $ map solve chn

        f name (Tree name' chn) =
          (fastSum $ map (f name) chn) +
          if name == name' then 1 else 0

parse :: String -> Tree
parse ss = snd $ f ss
  where f ss =
          case span isAlpha ss of
            (name, ':':rs) -> let (qs, ts) = g rs
                              in (qs, Tree name ts)
            (name, '.':rs) -> (rs, Tree name [])
            _              -> undefined
        g ss = g' ss []
          where g' ss acc =
                  case f ss of
                    (',':qs, t) -> g' qs (t:acc)
                    ('.':qs, t) -> (qs, t:acc)
                    _           -> undefined

main = interact (show.solve.parse)

import Prelude
import Data.Char
import Data.List
import Data.Functor

main = interact q

q = func

func::String->String
func = show . solve

fileInteract func inf ouf = do file <- readFile inf
                               writeFile ouf (func file)

toInt::String->Int
toInt = read

asInteger::String->Integer
asInteger = read

toString::Int->String
toString = show

reverseTuple::(a,b)->(b,a)
reverseTuple (a,b) = (b,a)

isVailed::String->Bool
isVailed "" = False
isVailed "0" = True
isVailed ('0':_) = False
isVailed _ = True

data Emp = Emp(String, [Emp])
         deriving (Show)

name::String->(String, String)
name = span isLetter

employee::String->(Emp, String)
employee str = (Emp (n, es), r')
    where
      (n, r) = name str
      (es,r')= case r !! 0 of
                 ':' -> emps (tail r)
                 _   -> ([], tail r)
      emps ('.':xs) = ([], xs)
      emps (',':xs) = emps xs
      emps xs = (emp:er, r')
          where
            (emp, right) = employee xs
            (er , r')    = emps right

solve::String->Int
solve = s' [""] . fst . employee

s'::[String]->Emp->Int
s' pnames (Emp (name, other)) = c + count [name] pnames
    where
      c = sum $ map (s' (name:pnames))  other
      count l1 (x:xs) | x `elem` l1 = count l1 xs + 1
                      | otherwise   = count l1 xs
      count l1 _                    = 0

import Data.List

processEmployee :: String -> [String] -> (Int, String)
processEmployee s names =
  let name = takeWhile (\c -> c /= ':' && c /= '.') s
      rest = drop (length name) s
      s' = if head rest == ':'
              then tail rest
              else rest
      (count, s'') = process s' (name:names)
  in (count + length (findIndices (==name) names), s'')

process [] _ = (0, [])
process ('.':rest) _ = (0, rest)
process s names =
  let (count, s') = processEmployee s names
      (c, s'') = process (tail s') names
  in if head s' == ','
        then (count + c, s'')
        else (count, tail s')

main = do s <- getLine
          let (c, _) = processEmployee s []
          print c

import qualified Data.List as List
import qualified Data.Map as Map
import Data.Char

data Tree = Tree String [Tree]  -- name, employee

solve tree = solve' tree Map.empty
  where solve' (Tree name []) m =
          List.foldl' (+) 0 $ map (\(_, y) -> y * (y - 1) `div` 2) $ Map.toList m'
            where m' = Map.insertWith (+) name 1 m
        solve' (Tree name children) m =
          List.foldl' (+) 0 $ map (\x -> solve' x m') children
            where m' = Map.insertWith (+) name 1 m

parse ss = snd $ f ss
  where f ss =
          case span isAlpha ss of
            (name, ':':rs) -> let (qs, ts) = g rs
                              in (qs, Tree name ts)
            (name, '.':rs) -> (rs, Tree name [])
            _              -> undefined
        g ss = g' ss []
          where g' ss acc =
                  case f ss of
                    (',':qs, t) -> g' qs (t:acc)
                    ('.':qs, t) -> (qs, t:acc)

main = interact (show.solve.parse)


You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?

The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.

If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.

NoteIn the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.

import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Array
import Data.List
import Data.Int
import Control.Monad

getInt = read `fmap` getLine :: IO Int
getInt64s = (map parseInt64 . BS8.words) `fmap` BS8.getLine :: IO [Int64]
parseInt64 = fromIntegral . fst . fromJust . BS8.readInt

type Point = (Int64,Int64)
type Line = (Point,Point)

contains :: Line -> Point -> Bool
contains ((x1,y1),(x2,y2)) (x,y) = (y-y2)*(x2-x1) == (y2-y1)*(x-x2)

main = do
    n <- getInt
    ps <- replicateM n $ do
        [x, y] <- getInt64s
        return (x,y)
    if length ps <= 4
    then putStrLn "YES"
    else do
        let pivots = take 3 ps
        let answers = map (solve ps) pivots
        if any id answers
        then putStrLn "YES"
        else putStrLn "NO"

solve :: [Point] -> Point -> Bool
solve ps p = case findColinear p ps of
    Nothing -> False
    Just q -> do
        let lineA = (p, q)
        let notOnLineA = filter (not . (contains lineA)) ps
        if length notOnLineA <= 2
        then True
        else do
            let lineB = (head notOnLineA, head (tail notOnLineA))
            let notOnLineB = filter (not . (contains lineB)) notOnLineA
            if length notOnLineB == 0
            then True
            else False

-- if there are 2 colinear points with p in ps, return any one
findColinear :: Point -> [Point] -> Maybe Point
findColinear p ps = f ps M.empty where
    f [] _ = Nothing
    f (q:qs) tanDB
        | M.member t tanDB = Just q
        | otherwise = f qs (M.insert t q tanDB)
        where t = tangent p q

tangent :: Point -> Point -> (Int64,Int64)
tangent (x1,y1) (x2,y2)
    | dx' == 0 && dy' == 0 = (0,0)
    | dx <= 0 && dy <= 0 = (-dx,-dy)
    | otherwise = (dx,dy)
    where
        dx' = (x2 - x1)
        dy' = (y2 - y1)
        g = gcd dx' dy'
        dx = dx' `div` g
        dy = dy' `div` g

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

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

main :: IO ()
main = do
    n <- readLn :: IO Int
    ps <- unfoldr(runStateT $ mkPoint <$> parseInt <*> parseInt) <$> B.getContents
    putStrLn.bool"NO""YES" $ solve ps

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT $ B.readInt . B.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = (,) <$> parseInt <*> parseInt

solve :: [Point] -> Bool
solve ps = case convexHull ps of
    [_] -> True
    [_, _] -> True
    [x, y, z] -> or
        [ validate3 (x, y) ps
        , validate3 (y, z) ps
        , validate3 (z, x) ps
        ]
    [x, y, z, w] -> or
        [ validate4 (x, y) (z, w) ps
        , validate4 (x, z) (y, w) ps
        , validate4 (x, w) (y, z) ps
        ]
    _ -> False

validate3 :: Seg -> [Point] -> Bool
validate3 seg ps = case convexHull $ filter (not.onLine seg) ps of
    [_]    -> True
    [_, _] -> True
    _      -> False

validate4 :: Seg -> Seg -> [Point] -> Bool
validate4 seg0 seg1 ps = all (\o -> onLine seg0 o || onLine seg1 o) ps

onLine :: Seg -> Point -> Bool
onLine (P px py, P qx qy) (P ox oy) = (qx - px) * (py - oy) == (qy - py) * (px - ox)

data Point = P !Integer !Integer deriving (Eq, Ord)

mkPoint :: Int -> Int -> Point
mkPoint x y = P (fromIntegral x) (fromIntegral y)

type Seg = (Point, Point)
type Polygon = [Point]
type Convex = [Point]

instance Show Point where
  show (P x y) = show (x, y)

instance Num Point where
  (P x0 y0) + (P x1 y1) = P (x0 + x1) (y0 + y1)
  (P x0 y0) - (P x1 y1) = P (x0 - x1) (y0 - y1)
  (P x0 y0) * (P x1 y1) = P (x0 * x1 - y0 * y1) (x0 * y1 + x1 * y0)
  negate (P x y) = P (negate x) (negate y)
  abs _ = undefined
  signum _ = undefined
  fromInteger n = P n 0

infixr 7 *:
(*:) :: Integer -> Point -> Point
(*:) !k (P x y) = P (k * x) (k * y)
{-# INLINE (*:) #-}

dot :: Point -> Point -> Integer
dot (P x0 y0) (P x1 y1) = x0 * x1 + y0 * y1
{-# INLINE dot #-}

cross :: Point -> Point -> Integer
cross (P x0 y0) (P x1 y1) = x0 * y1 - y0 * x1
{-# INLINE cross #-}

--        v
--       /  <==> area o u v > 0
--  o---u
area :: Point -> Point -> Point -> Integer
area o u v = (u - o) `cross` (v - o)
{-# INLINE area #-}

--        v
--       /  <==> compCCW o u v == LT
--  o---u
compCCW :: Point -> Point -> Point -> Ordering
compCCW o u v = compare 0 $ area o u v
{-# INLINE compCCW #-}

compCW :: Point -> Point -> Point -> Ordering
compCW o u v = compCCW o v u
{-# INLINE compCW #-}

onSeg :: Point -> Seg -> Bool
onSeg p (q0, q1) = (q0 - p) `cross` (q1 - p) == 0
                 && (q0 - p) `dot` (q1 - p) < 0
{-# INLINE onSeg #-}

segIntersect :: Seg -> Seg -> Bool
segIntersect (p0, p1) (q0, q1) = area p0 q0 q1 * area p1 q0 q1 < 0
                               && area q0 p0 p1 * area q1 p0 p1 < 0
{-# INLINE segIntersect #-}

convexHull :: [Point] -> Convex
convexHull ps = reverse.go [v0] $ sortBy (compCCW v0) sorted
   where
     !(v0:sorted) = sort ps
     go (p:q:conv) (r:rs) = case compCCW q p r of
        LT -> go (r:p:q:conv) rs
        GT -> go (q:conv) (r:rs)
        EQ | (q - p) `dot` (r - p) < 0 -> go (r:q:conv) rs -- q--p--r
           | otherwise             -> go (p:q:conv) rs -- q--r--p
     go [p] (r:rs) = go [r ,p] rs
     go conv [] = conv

{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

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

main :: IO ()
main = do
    n <- readLn :: IO Int
    ps <- L.unfoldr(runStateT $ mkPoint <$> parseInt <*> parseInt) <$> B.getContents
    putStrLn.bool"NO""YES" $ solve ps

mkPoint :: Int -> Int -> Vec2 Int64
mkPoint x y = V2 (fromIntegral x) (fromIntegral y)

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT $ B.readInt . B.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = (,) <$> parseInt <*> parseInt

solve :: [Point] -> Bool
solve ps = case convexHull ps of
    [_] -> True
    [_, _] -> True
    [x, y, z] -> or
        [ validate3 (x, y) ps
        , validate3 (y, z) ps
        , validate3 (z, x) ps
        ]
    [x, y, z, w] -> or
        [ validate4 (x, y) (z, w) ps
        , validate4 (x, z) (y, w) ps
        , validate4 (x, w) (y, z) ps
        ]
    _ -> False

validate3 :: Seg -> [Point] -> Bool
validate3 seg ps = case convexHull $ filter (not.flip onLine seg) ps of
    [_]    -> True
    [_, _] -> True
    _      -> False

validate4 :: Seg -> Seg -> [Point] -> Bool
validate4 seg0 seg1 ps = all (\o -> onLine o seg0 || onLine o seg1) ps

data Vec2 a = V2 !a !a deriving (Eq, Ord)

instance Show a => Show (Vec2 a) where
    show (V2 x y) = show [x, y]

instance Functor Vec2 where
    fmap f (V2 x y) = V2 (f x) (f y)

instance (Num a) => Num (Vec2 a) where
    (V2 x0 y0) + (V2 x1 y1) = V2 (x0 + x1) (y0 + y1)
    (V2 x0 y0) - (V2 x1 y1) = V2 (x0 - x1) (y0 - y1)
    (V2 x0 y0) * (V2 x1 y1) = V2 (x0 * x1 - y0 * y1) (x0 * y1 + x1 * y0)
    negate = fmap negate
    abs = fmap abs
    signum = fmap signum
    fromInteger n = V2 (fromInteger n) 0

instance (Fractional a) => Fractional (Vec2 a) where
    v0@(V2 x0 y0) / v1@(V2 x1 y1) = recip rr *: V2 x y
      where
        !rr = sqrMagnitude v1
        !x = v0 `dot` v1
        !y = v1 `cross` v0
    fromRational q = V2 (fromRational q) 0

infixr 7 *:
(*:) :: Num a => a -> Vec2 a -> Vec2 a
(*:) k = fmap (k*)
{-# INLINE (*:) #-}

dot :: Num a => Vec2 a -> Vec2 a -> a
dot (V2 x0 y0) (V2 x1 y1) = x0 * x1 + y0 * y1
{-# INLINE dot #-}

cross :: Num a => Vec2 a -> Vec2 a -> a
cross (V2 x0 y0) (V2 x1 y1) = x0 * y1 - y0 * x1
{-# INLINE cross #-}

magnitude :: Floating a => Vec2 a -> a
magnitude = sqrt . sqrMagnitude
{-# INLINE magnitude #-}

sqrMagnitude :: Num a => Vec2 a -> a
sqrMagnitude v = v `dot` v
{-# INLINE sqrMagnitude #-}

normalize :: Floating a => Vec2 a -> Vec2 a
normalize v = recip (magnitude v) *: v
{-# INLINE normalize #-}

type K = Int64
type Point = Vec2 K

type Seg = (Point, Point)
type Polygon = [Point]

--        v
--       /  <==> area o u v > 0
--  o---u
area :: Point -> Point -> Point -> K
area o u v = (u - o) `cross` (v - o)
{-# INLINE area #-}

--        v
--       /  <==> compCCW o u v == LT
--  o---u
compCCW :: Point -> Point -> Point -> Ordering
compCCW o u v = compare 0 $ area o u v
{-# INLINE compCCW #-}

compCW :: Point -> Point -> Point -> Ordering
compCW o = flip (compCCW o)
{-# INLINE compCW #-}

onSeg :: Point -> Seg -> Bool
onSeg p (u, v) = (u - p) `cross` (v - p) == 0
                 && (u - p) `dot` (v - p) < 0
{-# INLINE onSeg #-}

onLine :: Point -> Seg -> Bool
onLine p (u, v) = area p u v == 0
{-# INLINE onLine #-}

hasIntersect :: Seg -> Seg -> Bool
hasIntersect (p0, p1) (q0, q1) = area p0 q0 q1 * area p1 q0 q1 < 0
                               && area q0 p0 p1 * area q1 p0 p1 < 0
{-# INLINE hasIntersect #-}

type Convex = [Point]

convexHull :: [Point] -> Convex
convexHull [] = []
convexHull ps = reverse . go [leftest] $ L.sortBy (compCCW leftest) sorted
   where
     !(leftest:sorted) = L.sort ps
     go (p:q:conv) (r:rs) = case compCCW q p r of
        LT -> go (r:p:q:conv) rs
        GT -> go (q:conv) (r:rs)
        EQ | (q - p) `dot` (r - p) < 0 -> go (r:q:conv) rs -- q--p--r
           | otherwise                 -> go (p:q:conv) rs -- q--r--p
     go [p] (r:rs) = go [r, p] rs
     go conv [] = conv
     go [] (r:rs) = undefined

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

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

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

main :: IO ()
main = do
    n <- readLn :: IO Int
    ps <- parse.map readInteger.B.words <$> B.getContents
    putStrLn.bool"NO""YES" $ solve ps

solve :: [Point] -> Bool
solve ps = case convexHull ps of
    [_] -> True
    [_, _] -> True
    [x, y, z] -> or
        [ validate3 (x, y) ps
        , validate3 (y, z) ps
        , validate3 (z, x) ps
        ]
    [x, y, z, w] -> or
        [ validate4 (x, y) (z, w) ps
        , validate4 (x, z) (y, w) ps
        , validate4 (x, w) (y, z) ps
        ]
    _ -> False

validate3 :: Seg -> [Point] -> Bool
validate3 seg ps = case convexHull $ filter (not.onLine seg) ps of
    [_]    -> True
    [_, _] -> True
    _      -> False

validate4 :: Seg -> Seg -> [Point] -> Bool
validate4 seg0 seg1 ps = all (\o -> onLine seg0 o || onLine seg1 o) ps

onLine :: Seg -> Point -> Bool
onLine (p, q) o = dot (p - o) (q - o) * dot (p - o) (q - o) == dot (p - o) (p - o) * dot (q - o) (q - o)

parse :: [Integer] -> [Point]
parse (x:y:xys) = P x y : parse xys
parse _         = []

data Point = P !Integer !Integer deriving (Eq, Ord)
type Seg = (Point, Point)
type Polygon = [Point]
type Convex = [Point]

instance Show Point where
  show (P x y) = show (x,y)

instance Num Point where
  (P x0 y0) + (P x1 y1) = P (x0 + x1) (y0 + y1)
  (P x0 y0) - (P x1 y1) = P (x0 - x1) (y0 - y1)
  (P x0 y0) * (P x1 y1) = P (x0 * x1 - y0 * y1) (x0 * y1 + x1 * y0)
  negate (P x y) = P (negate x) (negate y)
  abs _ = undefined
  signum _ = undefined
  fromInteger n = P n 0

infixr 7 *:
(*:) :: Integer -> Point -> Point
(*:) !k (P x y) = P (k * x) (k * y)
{-# INLINE (*:) #-}

dot :: Point -> Point -> Integer
dot (P x0 y0) (P x1 y1) = x0 * x1 + y0 * y1
{-# INLINE dot #-}

cross :: Point -> Point -> Integer
cross (P x0 y0) (P x1 y1) = x0 * y1 - y0 * x1
{-# INLINE cross #-}

--        v
--       /  <==> area o u v > 0
--  o---u
area :: Point -> Point -> Point -> Integer
area o u v = (u - o) `cross` (v - o)
{-# INLINE area #-}

--        v
--       /  <==> compCCW o u v == LT
--  o---u
compCCW :: Point -> Point -> Point -> Ordering
compCCW o u v = compare 0 $ area o u v
{-# INLINE compCCW #-}

compCW :: Point -> Point -> Point -> Ordering
compCW o u v = compCCW o v u
{-# INLINE compCW #-}

onSeg :: Point -> Seg -> Bool
onSeg p (q0, q1) = (q0 - p) `cross` (q1 - p) == 0
                 && (q0 - p) `dot` (q1 - p) < 0
{-# INLINE onSeg #-}

segIntersect :: Seg -> Seg -> Bool
segIntersect (p0, p1) (q0, q1) = (area p0 q0 q1) * (area p1 q0 q1) < 0
                               && (area q0 p0 p1) * (area q1 p0 p1) < 0
{-# INLINE segIntersect #-}

convexHull :: [Point] -> Convex
convexHull ps = reverse.go [v0] $ sortBy (compCCW v0) sorted
   where
     !(v0:sorted) = sort ps
     go (p:q:conv) (r:rs) = case compCCW q p r of
        LT -> go (r:p:q:conv) rs
        GT -> go (q:conv) (r:rs)
        EQ | (q-p) `dot` (r-p) < 0 -> go (r:q:conv) rs -- q--p--r
           | otherwise             -> go (p:q:conv) rs -- q--r--p
     go [p] (r:rs) = go [r,p] rs
     go conv [] = conv

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

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

main :: IO ()
main = do
    n <- readLn :: IO Int
    ps <- unfoldr(runStateT $ mkPoint <$> parseInt <*> parseInt) <$> B.getContents
    putStrLn.bool"NO""YES" $ solve ps

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT $ B.readInt . B.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = (,) <$> parseInt <*> parseInt

solve :: [Point] -> Bool
solve ps = case convexHull ps of
    [_] -> True
    [_, _] -> True
    [x, y, z] -> or
        [ validate3 (x, y) ps
        , validate3 (y, z) ps
        , validate3 (z, x) ps
        ]
    [x, y, z, w] -> or
        [ validate4 (x, y) (z, w) ps
        , validate4 (x, z) (y, w) ps
        , validate4 (x, w) (y, z) ps
        ]
    _ -> False

validate3 :: Seg -> [Point] -> Bool
validate3 seg ps = case convexHull $ filter (not.onLine seg) ps of
    [_]    -> True
    [_, _] -> True
    _      -> False

validate4 :: Seg -> Seg -> [Point] -> Bool
validate4 seg0 seg1 ps = all (\o -> onLine seg0 o || onLine seg1 o) ps

onLine :: Seg -> Point -> Bool
onLine (p, q) o = dot (p - o) (q - o) * dot (p - o) (q - o) == dot (p - o) (p - o) * dot (q - o) (q - o)

parse :: [Integer] -> [Point]
parse (x:y:xys) = P x y : parse xys
parse _         = []

data Point = P !Integer !Integer deriving (Eq, Ord)

mkPoint :: Int -> Int -> Point
mkPoint x y = P (fromIntegral x) (fromIntegral y)

type Seg = (Point, Point)
type Polygon = [Point]
type Convex = [Point]

instance Show Point where
  show (P x y) = show (x,y)

instance Num Point where
  (P x0 y0) + (P x1 y1) = P (x0 + x1) (y0 + y1)
  (P x0 y0) - (P x1 y1) = P (x0 - x1) (y0 - y1)
  (P x0 y0) * (P x1 y1) = P (x0 * x1 - y0 * y1) (x0 * y1 + x1 * y0)
  negate (P x y) = P (negate x) (negate y)
  abs _ = undefined
  signum _ = undefined
  fromInteger n = P n 0

infixr 7 *:
(*:) :: Integer -> Point -> Point
(*:) !k (P x y) = P (k * x) (k * y)
{-# INLINE (*:) #-}

dot :: Point -> Point -> Integer
dot (P x0 y0) (P x1 y1) = x0 * x1 + y0 * y1
{-# INLINE dot #-}

cross :: Point -> Point -> Integer
cross (P x0 y0) (P x1 y1) = x0 * y1 - y0 * x1
{-# INLINE cross #-}

--        v
--       /  <==> area o u v > 0
--  o---u
area :: Point -> Point -> Point -> Integer
area o u v = (u - o) `cross` (v - o)
{-# INLINE area #-}

--        v
--       /  <==> compCCW o u v == LT
--  o---u
compCCW :: Point -> Point -> Point -> Ordering
compCCW o u v = compare 0 $ area o u v
{-# INLINE compCCW #-}

compCW :: Point -> Point -> Point -> Ordering
compCW o u v = compCCW o v u
{-# INLINE compCW #-}

onSeg :: Point -> Seg -> Bool
onSeg p (q0, q1) = (q0 - p) `cross` (q1 - p) == 0
                 && (q0 - p) `dot` (q1 - p) < 0
{-# INLINE onSeg #-}

segIntersect :: Seg -> Seg -> Bool
segIntersect (p0, p1) (q0, q1) = (area p0 q0 q1) * (area p1 q0 q1) < 0
                               && (area q0 p0 p1) * (area q1 p0 p1) < 0
{-# INLINE segIntersect #-}

convexHull :: [Point] -> Convex
convexHull ps = reverse.go [v0] $ sortBy (compCCW v0) sorted
   where
     !(v0:sorted) = sort ps
     go (p:q:conv) (r:rs) = case compCCW q p r of
        LT -> go (r:p:q:conv) rs
        GT -> go (q:conv) (r:rs)
        EQ | (q-p) `dot` (r-p) < 0 -> go (r:q:conv) rs -- q--p--r
           | otherwise             -> go (p:q:conv) rs -- q--r--p
     go [p] (r:rs) = go [r,p] rs
     go conv [] = conv

{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

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

main :: IO ()
main = do
    n <- readLn :: IO Int
    ps <- unfoldr(runStateT $ mkPoint <$> parseInt <*> parseInt) <$> B.getContents
    putStrLn.bool"NO""YES" $ solve ps

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT $ B.readInt . B.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = (,) <$> parseInt <*> parseInt

solve :: [Point] -> Bool
solve ps = case convexHull ps of
    [_] -> True
    [_, _] -> True
    [x, y, z] -> or
        [ validate3 (x, y) ps
        , validate3 (y, z) ps
        , validate3 (z, x) ps
        ]
    [x, y, z, w] -> or
        [ validate4 (x, y) (z, w) ps
        , validate4 (x, z) (y, w) ps
        , validate4 (x, w) (y, z) ps
        ]
    _ -> False

validate3 :: Seg -> [Point] -> Bool
validate3 seg ps = case convexHull $ filter (not.onLine seg) ps of
    [_]    -> True
    [_, _] -> True
    _      -> False

validate4 :: Seg -> Seg -> [Point] -> Bool
validate4 seg0 seg1 ps = all (\o -> onLine seg0 o || onLine seg1 o) ps

onLine :: Seg -> Point -> Bool
onLine (P px py, P qx qy) (P ox oy) = (qx - px) * (py - oy) == (qy - py) * (px - ox)

data Point = P !Integer !Integer deriving (Eq, Ord)

mkPoint :: Int -> Int -> Point
mkPoint x y = P (fromIntegral x) (fromIntegral y)

type Seg = (Point, Point)
type Polygon = [Point]
type Convex = [Point]

instance Show Point where
  show (P x y) = show (x, y)

instance Num Point where
  (P x0 y0) + (P x1 y1) = P (x0 + x1) (y0 + y1)
  (P x0 y0) - (P x1 y1) = P (x0 - x1) (y0 - y1)
  (P x0 y0) * (P x1 y1) = P (x0 * x1 - y0 * y1) (x0 * y1 + x1 * y0)
  negate (P x y) = P (negate x) (negate y)
  abs _ = undefined
  signum _ = undefined
  fromInteger n = P n 0

infixr 7 *:
(*:) :: Integer -> Point -> Point
(*:) !k (P x y) = P (k * x) (k * y)
{-# INLINE (*:) #-}

dot :: Point -> Point -> Integer
dot (P x0 y0) (P x1 y1) = x0 * x1 + y0 * y1
{-# INLINE dot #-}

cross :: Point -> Point -> Integer
cross (P x0 y0) (P x1 y1) = x0 * y1 - y0 * x1
{-# INLINE cross #-}

--        v
--       /  <==> area o u v > 0
--  o---u
area :: Point -> Point -> Point -> Integer
area o u v = (u - o) `cross` (v - o)
{-# INLINE area #-}

--        v
--       /  <==> compCCW o u v == LT
--  o---u
compCCW :: Point -> Point -> Point -> Ordering
compCCW o = \u v -> compare 0 $ area o u v
{-# INLINE compCCW #-}

compCW :: Point -> Point -> Point -> Ordering
compCW o u v = compCCW o v u
{-# INLINE compCW #-}

onSeg :: Point -> Seg -> Bool
onSeg p (q0, q1) = (q0 - p) `cross` (q1 - p) == 0
                 && (q0 - p) `dot` (q1 - p) < 0
{-# INLINE onSeg #-}

segIntersect :: Seg -> Seg -> Bool
segIntersect (p0, p1) (q0, q1) = area p0 q0 q1 * area p1 q0 q1 < 0
                               && area q0 p0 p1 * area q1 p0 p1 < 0
{-# INLINE segIntersect #-}

convexHull :: [Point] -> Convex
convexHull ps = reverse.go [v0] $ sortBy (compCCW v0) sorted
   where
     !(v0:sorted) = sort ps
     go (p:q:conv) (r:rs) = case compCCW q p r of
        LT -> go (r:p:q:conv) rs
        GT -> go (q:conv) (r:rs)
        EQ | (q - p) `dot` (r - p) < 0 -> go (r:q:conv) rs -- q--p--r
           | otherwise             -> go (p:q:conv) rs -- q--r--p
     go [p] (r:rs) = go [r ,p] rs
     go conv [] = conv

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

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

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

main :: IO ()
main = do
    n <- readLn :: IO Int
    ps <- parse.unfoldr(B.readInteger.B.dropWhile isSpace) <$> B.getContents
    putStrLn.bool"NO""YES" $ solve ps

solve :: [Point] -> Bool
solve ps = case convexHull ps of
    [_] -> True
    [_, _] -> True
    [x, y, z] -> or
        [ validate3 (x, y) ps
        , validate3 (y, z) ps
        , validate3 (z, x) ps
        ]
    [x, y, z, w] -> or
        [ validate4 (x, y) (z, w) ps
        , validate4 (x, z) (y, w) ps
        , validate4 (x, w) (y, z) ps
        ]
    _ -> False

validate3 :: Seg -> [Point] -> Bool
validate3 seg ps = case convexHull $ filter (not.onLine seg) ps of
    [_]    -> True
    [_, _] -> True
    _      -> False

validate4 :: Seg -> Seg -> [Point] -> Bool
validate4 seg0 seg1 ps = all (\o -> onLine seg0 o || onLine seg1 o) ps

onLine :: Seg -> Point -> Bool
onLine (p, q) o = dot (p - o) (q - o) * dot (p - o) (q - o) == dot (p - o) (p - o) * dot (q - o) (q - o)

parse :: [Integer] -> [Point]
parse (x:y:xys) = P x y : parse xys
parse _         = []

data Point = P !Integer !Integer deriving (Eq, Ord)
type Seg = (Point, Point)
type Polygon = [Point]
type Convex = [Point]

instance Show Point where
  show (P x y) = show (x,y)

instance Num Point where
  (P x0 y0) + (P x1 y1) = P (x0 + x1) (y0 + y1)
  (P x0 y0) - (P x1 y1) = P (x0 - x1) (y0 - y1)
  (P x0 y0) * (P x1 y1) = P (x0 * x1 - y0 * y1) (x0 * y1 + x1 * y0)
  negate (P x y) = P (negate x) (negate y)
  abs _ = undefined
  signum _ = undefined
  fromInteger n = P n 0

infixr 7 *:
(*:) :: Integer -> Point -> Point
(*:) !k (P x y) = P (k * x) (k * y)
{-# INLINE (*:) #-}

dot :: Point -> Point -> Integer
dot (P x0 y0) (P x1 y1) = x0 * x1 + y0 * y1
{-# INLINE dot #-}

cross :: Point -> Point -> Integer
cross (P x0 y0) (P x1 y1) = x0 * y1 - y0 * x1
{-# INLINE cross #-}

--        v
--       /  <==> area o u v > 0
--  o---u
area :: Point -> Point -> Point -> Integer
area o u v = (u - o) `cross` (v - o)
{-# INLINE area #-}

--        v
--       /  <==> compCCW o u v == LT
--  o---u
compCCW :: Point -> Point -> Point -> Ordering
compCCW o u v = compare 0 $ area o u v
{-# INLINE compCCW #-}

compCW :: Point -> Point -> Point -> Ordering
compCW o u v = compCCW o v u
{-# INLINE compCW #-}

onSeg :: Point -> Seg -> Bool
onSeg p (q0, q1) = (q0 - p) `cross` (q1 - p) == 0
                 && (q0 - p) `dot` (q1 - p) < 0
{-# INLINE onSeg #-}

segIntersect :: Seg -> Seg -> Bool
segIntersect (p0, p1) (q0, q1) = (area p0 q0 q1) * (area p1 q0 q1) < 0
                               && (area q0 p0 p1) * (area q1 p0 p1) < 0
{-# INLINE segIntersect #-}

convexHull :: [Point] -> Convex
convexHull ps = reverse.go [v0] $ sortBy (compCCW v0) sorted
   where
     !(v0:sorted) = sort ps
     go (p:q:conv) (r:rs) = case compCCW q p r of
        LT -> go (r:p:q:conv) rs
        GT -> go (q:conv) (r:rs)
        EQ | (q-p) `dot` (r-p) < 0 -> go (r:q:conv) rs -- q--p--r
           | otherwise             -> go (p:q:conv) rs -- q--r--p
     go [p] (r:rs) = go [r,p] rs
     go conv [] = conv

import Control.Applicative
import Control.Monad
import Data.Char
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8

construct :: BS.ByteString -> [Integer]
construct str
    | BS.null str = []
    | isSpace (BS8.head str) = construct (BS8.tail str)
    | otherwise = let Just (i, other) = BS8.readInteger str in i : construct other

getInts :: IO [Integer]
getInts = construct <$> BS.getLine

type Point = (Integer, Integer)

line :: Point -> Point -> Point -> Bool
line (x1,y1) (x2,y2) (x3,y3) = dx1 * dy2 == dx2 * dy1
    where dx1 = x2 - x1
          dy1 = y2 - y1
          dx2 = x3 - x2
          dy2 = y3 - y2

can :: [Point] -> [Point] -> [Point] -> Bool
can _ _ [] = True
can (ga:gb:gs) [] (p:ps) = if line ga gb p then can (p:ga:gb:gs) [] ps else can (ga:gb:gs) [p] ps
can (ga:gb:gs) [sa] (p:ps) = if line ga gb p then can (p:ga:gb:gs) [sa] ps else can (ga:gb:gs) [p,sa] ps
can (ga:gb:gs) (sa:sb:ss) (p:ps)
    | line ga gb p = can (p:ga:gb:gs) (sa:sb:ss) ps
    | line sa sb p = can (ga:gb:gs) (p:sa:sb:ss) ps
    | otherwise = False

solve :: [Point] -> String
solve xs
    | can [p0, p1] [] (drop 2 xs) || can [p0, p2] [p1] (drop 3 xs) || can [p1, p2] [p0] (drop 3 xs)  = "YES"
    | otherwise = "NO"
    where p0 = xs !! 0
          p1 = xs !! 1
          p2 = xs !! 2

main = do
    [n] <- getInts
    points <- replicateM (fromIntegral n) (getInts >>= \[a,b] -> pure (a,b))
    putStrLn $ solve points

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

getInt = read `fmap` getLine :: IO Int
getInts = (map parseInt . BS8.words) `fmap` BS8.getLine
parseInt = fst . fromJust . BS8.readInt

type Point = [Int]
type Line = (Point,Point)

contains :: Line -> Point -> Bool
contains ([x1,y1],[x2,y2]) [x,y] = (y-y2)*(x2-x1) == (y2-y1)*(x-x2)

main = do
    n <- getInt
    pointList <- replicateM n getInts
    let points = listArray (1,n) pointList
    if n <= 4
    then putStrLn "YES"
    else do
        let lineA = (points ! 1, points ! 2)
        let notOnA = filter (not . (contains lineA)) (elems points)
        if length notOnA <= 2
        then putStrLn "YES"
        else do
            let lineB = (head notOnA, (head . tail) notOnA)
            let notOnB = filter (not . (contains lineB)) notOnA
            if length notOnB == 0
            then putStrLn "YES"
            else do
                let lineC = (points ! 1, head notOnA)
                let notOnC = filter (not . (contains lineC)) (elems points)
                if length notOnC <= 2
                then putStrLn "YES"
                else do
                    let lineD = (head notOnC, (head . tail) notOnC)
                    let notOnD = filter (not . (contains lineD)) notOnC
                    if length notOnD == 0
                    then putStrLn "YES"
                    else putStrLn "NO"

import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Array
import Data.List
import Control.Monad

getInt = read `fmap` getLine :: IO Int
getInts = (map parseInt . BS8.words) `fmap` BS8.getLine
parseInt = fst . fromJust . BS8.readInt

type Point = (Int,Int)
type Line = (Point,Point)

contains :: Line -> Point -> Bool
contains ((x1,y1),(x2,y2)) (x,y) = (y-y2)*(x2-x1) == (y2-y1)*(x-x2)

main = do
    n <- getInt
    ps <- replicateM n $ do
        [x, y] <- getInts
        return (x,y)
    if length ps <= 4
    then putStrLn "YES"
    else do
        let pivots = take 3 ps
        if any id (map (solve ps) pivots)
        then putStrLn "YES"
        else putStrLn "NO"

solve :: [Point] -> Point -> Bool
solve ps p = case findColinear p ps of
    Nothing -> False
    Just q -> do
        let lineA = (p, q)
        let notOnLineA = filter (not . (contains lineA)) ps
        if length notOnLineA <= 2
        then True
        else do
            let lineB = (head notOnLineA, head (tail notOnLineA))
            let notOnLineB = filter (not . (contains lineB)) notOnLineA
            if length notOnLineB == 0
            then True
            else False

-- if there are 2 colinear points with p in ps, return any one
findColinear :: Point -> [Point] -> Maybe Point
findColinear p ps = f ps M.empty where
    f [] _ = Nothing
    f (q:qs) tanDB
        | M.member t tanDB = Just q
        | otherwise = f qs (M.insert t q tanDB)
        where t = tangent p q

tangent :: Point -> Point -> (Int,Int)
tangent (x1,y1) (x2,y2)
    | dx' == 0 && dy' == 0 = (0,0)
    | dx < 0 && dy < 0 = (-dx,-dy)
    | otherwise = (dx,dy)
    where
        dx' = (x2 - x1)
        dy' = (y2 - y1)
        g = gcd dx' dy'
        dx = dx' `div` g
        dy = dy' `div` g

import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import Data.Maybe
import Data.Array
import Data.List
import Control.Monad
import qualified Data.Map.Strict as M

getInt = read `fmap` getLine :: IO Int
getInts = (map parseInt . BS8.words) `fmap` BS8.getLine
parseInt = fst . fromJust . BS8.readInt

type Point = (Int,Int)
type Line = (Point,Point)

contains :: Line -> Point -> Bool
contains ((x1,y1),(x2,y2)) (x,y) = (y-y2)*(x2-x1) == (y2-y1)*(x-x2)

main = do
    n <- getInt
    ps <- replicateM n $ do
        [x, y] <- getInts
        return (x,y)
    if length ps <= 4
    then putStrLn "YES"
    else do
        let p = head ps
        case findColinear p (tail ps) of
            Nothing -> putStrLn "NO"
            Just q -> do
                let lineA = (p, q)
                let notOnLineA = filter (not . (contains lineA)) ps
                if length notOnLineA <= 2
                then putStrLn "YES"
                else do
                    let lineB = (head notOnLineA, head (tail notOnLineA))
                    let notOnLineB = filter (not . (contains lineB)) notOnLineA
                    if length notOnLineB == 0
                    then putStrLn "YES"
                    else putStrLn "NO"

-- if there are 2 colinear points with p in ps, return any one
findColinear :: Point -> [Point] -> Maybe Point
findColinear p ps = f ps M.empty where
    f [] _ = Nothing
    f (q:qs) tanDB
        | M.member t tanDB = Just q
        | otherwise = f qs (M.insert t q tanDB)
        where t = tangent p q

tangent :: Point -> Point -> (Int,Int)
tangent (x1,y1) (x2,y2)
    | dx < 0 && dy < 0 = (-dx,-dy)
    | otherwise = (dx,dy)
    where
        dx' = (x2 - x1)
        dy' = (y2 - y1)
        g = gcd dx' dy'
        dx = dx' `div` g
        dy = dy' `div` g

import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Array
import Data.List
import Control.Monad

getInt = read `fmap` getLine :: IO Int
getInts = (map parseInt . BS8.words) `fmap` BS8.getLine
parseInt = fst . fromJust . BS8.readInt

type Point = (Int,Int)
type Line = (Point,Point)

contains :: Line -> Point -> Bool
--contains ((x1,y1),(x2,y2)) (x,y) = (y-y2)*(x2-x1) == (y2-y1)*(x-x2)
contains ((x1,y1),(x2,y2)) (x,y)
    | y1 == y2 = y == y1
    | x1 == x2 = x == x1
    | otherwise = (y-y2)*(x2-x1) == (y2-y1)*(x-x2)

main = do
    n <- getInt
    ps <- replicateM n $ do
        [x, y] <- getInts
        return (x,y)
    if length ps <= 4
    then putStrLn "YES"
    else do
        let pivots = take 3 ps
        let answers = map (solve ps) pivots
        if any id answers
        then putStrLn "YES"
        else putStrLn "NO"

solve :: [Point] -> Point -> Bool
solve ps p = case findColinear p ps of
    Nothing -> False
    Just q -> do
        let lineA = (p, q)
        let notOnLineA = filter (not . (contains lineA)) ps
        if length notOnLineA <= 2
        then True
        else do
            let lineB = (head notOnLineA, head (tail notOnLineA))
            let notOnLineB = filter (not . (contains lineB)) notOnLineA
            if length notOnLineB == 0
            then True
            else False

-- if there are 2 colinear points with p in ps, return any one
findColinear :: Point -> [Point] -> Maybe Point
findColinear p ps = f ps M.empty where
    f [] _ = Nothing
    f (q:qs) tanDB
        | M.member t tanDB = Just q
        | otherwise = f qs (M.insert t q tanDB)
        where t = tangent p q

tangent :: Point -> Point -> (Int,Int)
tangent (x1,y1) (x2,y2)
    | dx' == 0 && dy' == 0 = (0,0)
    | dx <= 0 && dy <= 0 = (-dx,-dy)
    | otherwise = (dx,dy)
    where
        dx' = (x2 - x1)
        dy' = (y2 - y1)
        g = gcd dx' dy'
        dx = dx' `div` g
        dy = dy' `div` g

import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Array
import Data.List
import Control.Monad

getInt = read `fmap` getLine :: IO Int
getInts = (map parseInt . BS8.words) `fmap` BS8.getLine
parseInt = fst . fromJust . BS8.readInt

type Point = (Int,Int)
type Line = (Point,Point)

contains :: Line -> Point -> Bool
contains ((x1,y1),(x2,y2)) (x,y) = (y-y2)*(x2-x1) == (y2-y1)*(x-x2)

main = do
    n <- getInt
    ps <- replicateM n $ do
        [x, y] <- getInts
        return (x,y)
    if length ps <= 4
    then putStrLn "YES"
    else do
        let pivots = take 3 ps
        if any id (map (solve ps) pivots)
        then putStrLn "YES"
        else putStrLn "NO"

solve :: [Point] -> Point -> Bool
solve ps p = case findColinear p ps of
    Nothing -> False
    Just q -> do
        let lineA = (p, q)
        let notOnLineA = filter (not . (contains lineA)) ps
        if length notOnLineA <= 2
        then True
        else do
            let lineB = (head notOnLineA, head (tail notOnLineA))
            let notOnLineB = filter (not . (contains lineB)) notOnLineA
            if length notOnLineB == 0
            then True
            else False

-- if there are 2 colinear points with p in ps, return any one
findColinear :: Point -> [Point] -> Maybe Point
findColinear p ps = f ps M.empty where
    f [] _ = Nothing
    f (q:qs) tanDB
        | M.member t tanDB = Just q
        | otherwise = f qs (M.insert t q tanDB)
        where t = tangent p q

tangent :: Point -> Point -> (Int,Int)
tangent (x1,y1) (x2,y2)
    | dx' == 0 && dy' == 0 = (0,0)
    | dx <= 0 && dy <= 0 = (-dx,-dy)
    | otherwise = (dx,dy)
    where
        dx' = (x2 - x1)
        dy' = (y2 - y1)
        g = gcd dx' dy'
        dx = dx' `div` g
        dy = dy' `div` g

import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Array
import Data.List
import Control.Monad

getInt = read `fmap` getLine :: IO Int
getInts = (map parseInt . BS8.words) `fmap` BS8.getLine
parseInt = fst . fromJust . BS8.readInt

type Point = (Int,Int)
type Line = (Point,Point)

contains :: Line -> Point -> Bool
contains ((x1,y1),(x2,y2)) (x,y) = (y-y2)*(x2-x1) == (y2-y1)*(x-x2)

main = do
    n <- getInt
    ps <- replicateM n $ do
        [x, y] <- getInts
        return (x,y)
    if length ps <= 4
    then putStrLn "YES"
    else do
        let pivots = take 3 ps
        let answers = map (solve ps) pivots
        if any id answers
        then putStrLn "YES"
        else putStrLn "NO"

solve :: [Point] -> Point -> Bool
solve ps p = case findColinear p ps of
    Nothing -> False
    Just q -> do
        let lineA = (p, q)
        let notOnLineA = filter (not . (contains lineA)) ps
        if length notOnLineA <= 2
        then True
        else do
            let lineB = (head notOnLineA, head (tail notOnLineA))
            let notOnLineB = filter (not . (contains lineB)) notOnLineA
            if length notOnLineB == 0
            then True
            else False

-- if there are 2 colinear points with p in ps, return any one
findColinear :: Point -> [Point] -> Maybe Point
findColinear p ps = f ps M.empty where
    f [] _ = Nothing
    f (q:qs) tanDB
        | M.member t tanDB = Just q
        | otherwise = f qs (M.insert t q tanDB)
        where t = tangent p q

tangent :: Point -> Point -> (Int,Int)
tangent (x1,y1) (x2,y2)
    | dx' == 0 && dy' == 0 = (0,0)
    | dx <= 0 && dy <= 0 = (-dx,-dy)
    | otherwise = (dx,dy)
    where
        dx' = (x2 - x1)
        dy' = (y2 - y1)
        g = gcd dx' dy'
        dx = dx' `div` g
        dy = dy' `div` g

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

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

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

main :: IO ()
main = do
    n <- readLn :: IO Int
    ps <- parse.map readInteger.B.words <$> B.getContents
    putStrLn.bool"NO""YES" $ solve ps

solve :: [Point] -> Bool
solve ps = case convexHull ps of
    [_] -> True
    [_, _] -> True
    [x, y, z] -> or
        [ validate3 (x, y) ps
        , validate3 (y, z) ps
        , validate3 (z, x) ps
        ]
    [x,y,z,w] -> or
        [ validate4 (x, y) (z, w) ps
        , validate4 (x, z) (y, w) ps
        , validate4 (x, w) (y, z) ps
        ]
    _ -> False

validate3 :: Seg -> [Point] -> Bool
validate3 seg ps = case convexHull $ filter (\o -> not $ onLine seg o) ps of
    [_]    -> True
    [_, _] -> True
    _      -> False

validate4 :: Seg -> Seg -> [Point] -> Bool
validate4 seg0 seg1 ps = all (\o -> onLine seg0 o || onLine seg1 o) ps

onLine :: Seg -> Point -> Bool
onLine (p, q) o = dot (p - o) (q - o) * dot (p - o) (q - o) == dot (p - o) (p - o) * dot (q - o) (q - o)

parse :: [Integer] -> [Point]
parse (x:y:xys) = P x y : parse xys
parse _         = []

data Point = P !Integer !Integer deriving (Eq, Ord)
type Seg = (Point, Point)
type Polygon = [Point]
type Convex = [Point]

instance Show Point where
  show (P x y) = show (x,y)

instance Num Point where
  (P x0 y0) + (P x1 y1) = P (x0 + x1) (y0 + y1)
  (P x0 y0) - (P x1 y1) = P (x0 - x1) (y0 - y1)
  (P x0 y0) * (P x1 y1) = P (x0 * x1 - y0 * y1) (x0 * y1 + x1 * y0)
  negate (P x y) = P (negate x) (negate y)
  abs _ = undefined
  signum _ = undefined
  fromInteger n = P n 0

infixr 7 *:
(*:) :: Integer -> Point -> Point
(*:) !k (P x y) = P (k * x) (k * y)
{-# INLINE (*:) #-}

dot :: Point -> Point -> Integer
dot (P x0 y0) (P x1 y1) = x0 * x1 + y0 * y1
{-# INLINE dot #-}

cross :: Point -> Point -> Integer
cross (P x0 y0) (P x1 y1) = x0 * y1 - y0 * x1
{-# INLINE cross #-}

--        v
--       /  <==> area o u v > 0
--  o---u
area :: Point -> Point -> Point -> Integer
area o u v = (u - o) `cross` (v - o)
{-# INLINE area #-}

--        v
--       /  <==> compCCW o u v == LT
--  o---u
compCCW :: Point -> Point -> Point -> Ordering
compCCW o u v = compare 0 $ area o u v
{-# INLINE compCCW #-}

compCW :: Point -> Point -> Point -> Ordering
compCW o u v = compCCW o v u
{-# INLINE compCW #-}

onSeg :: Point -> Seg -> Bool
onSeg p (q0, q1) = (q0 - p) `cross` (q1 - p) == 0
                 && (q0 - p) `dot` (q1 - p) < 0
{-# INLINE onSeg #-}

segIntersect :: Seg -> Seg -> Bool
segIntersect (p0, p1) (q0, q1) = (area p0 q0 q1) * (area p1 q0 q1) < 0
                               && (area q0 p0 p1) * (area q1 p0 p1) < 0
{-# INLINE segIntersect #-}

convexHull :: [Point] -> Convex
convexHull ps = reverse.go [v0].sortBy (compCCW v0) $ filter (/=v0) ps
   where
     !v0 = minimum ps
     go (p:q:conv) (r:rs) = case compCCW q p r of
        LT -> go (r:p:q:conv) rs
        GT -> go (q:conv) (r:rs)
        EQ | (q-p) `dot` (r-p) < 0 -> go (r:q:conv) rs -- q--p--r
           | otherwise             -> go (p:q:conv) rs -- q--r--p
     go [p] (r:rs) = go [r,p] rs
     go conv [] = conv

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

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

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

main :: IO ()
main = do
    n <- readLn :: IO Int
    ps <- parse.map readInteger.B.words <$> B.getContents
    putStrLn.bool"NO""YES" $ solve ps

solve :: [Point] -> Bool
solve ps = case convexHull ps of
    [_] -> True
    [_, _] -> True
    [x, y, z] -> or
        [ validate3 (x, y) ps
        , validate3 (y, z) ps
        , validate3 (z, x) ps
        ]
    [x, y, z, w] -> or
        [ validate4 (x, y) (z, w) ps
        , validate4 (x, z) (y, w) ps
        , validate4 (x, w) (y, z) ps
        ]
    _ -> False

validate3 :: Seg -> [Point] -> Bool
validate3 seg ps = case convexHull $ filter (not.onLine seg) ps of
    [_]    -> True
    [_, _] -> True
    _      -> False

validate4 :: Seg -> Seg -> [Point] -> Bool
validate4 seg0 seg1 ps = all (\o -> onLine seg0 o || onLine seg1 o) ps

onLine :: Seg -> Point -> Bool
onLine (p, q) o = dot (p - o) (q - o) * dot (p - o) (q - o) == dot (p - o) (p - o) * dot (q - o) (q - o)

parse :: [Integer] -> [Point]
parse (x:y:xys) = P x y : parse xys
parse _         = []

data Point = P !Integer !Integer deriving (Eq, Ord)
type Seg = (Point, Point)
type Polygon = [Point]
type Convex = [Point]

instance Show Point where
  show (P x y) = show (x,y)

instance Num Point where
  (P x0 y0) + (P x1 y1) = P (x0 + x1) (y0 + y1)
  (P x0 y0) - (P x1 y1) = P (x0 - x1) (y0 - y1)
  (P x0 y0) * (P x1 y1) = P (x0 * x1 - y0 * y1) (x0 * y1 + x1 * y0)
  negate (P x y) = P (negate x) (negate y)
  abs _ = undefined
  signum _ = undefined
  fromInteger n = P n 0

infixr 7 *:
(*:) :: Integer -> Point -> Point
(*:) !k (P x y) = P (k * x) (k * y)
{-# INLINE (*:) #-}

dot :: Point -> Point -> Integer
dot (P x0 y0) (P x1 y1) = x0 * x1 + y0 * y1
{-# INLINE dot #-}

cross :: Point -> Point -> Integer
cross (P x0 y0) (P x1 y1) = x0 * y1 - y0 * x1
{-# INLINE cross #-}

--        v
--       /  <==> area o u v > 0
--  o---u
area :: Point -> Point -> Point -> Integer
area o u v = (u - o) `cross` (v - o)
{-# INLINE area #-}

--        v
--       /  <==> compCCW o u v == LT
--  o---u
compCCW :: Point -> Point -> Point -> Ordering
compCCW o u v = case compare 0 $ area o u v of
    EQ -> compare (dot (u-o)(u-o))(dot(v-o)(v-o))
    x->x
{-# INLINE compCCW #-}

compCW :: Point -> Point -> Point -> Ordering
compCW o u v = compCCW o v u
{-# INLINE compCW #-}

onSeg :: Point -> Seg -> Bool
onSeg p (q0, q1) = (q0 - p) `cross` (q1 - p) == 0
                 && (q0 - p) `dot` (q1 - p) < 0
{-# INLINE onSeg #-}

segIntersect :: Seg -> Seg -> Bool
segIntersect (p0, p1) (q0, q1) = (area p0 q0 q1) * (area p1 q0 q1) < 0
                               && (area q0 p0 p1) * (area q1 p0 p1) < 0
{-# INLINE segIntersect #-}

convexHull :: [Point] -> Convex
convexHull ps = reverse.go [v0].sortBy (compCCW v0) $ filter (/=v0) ps
   where
     !v0 = minimum ps
     go (p:q:conv) (r:rs) = case compCCW q p r of
        LT -> go (r:p:q:conv) rs
        GT -> go (q:conv) (r:rs)
        EQ | (q-p) `dot` (r-p) < 0 -> go (r:q:conv) rs -- q--p--r
           | otherwise             -> go (p:q:conv) rs -- q--r--p
     go [p] (r:rs) = go [r,p] rs
     go conv [] = conv

import Control.Applicative
import Control.Monad
import Data.Char
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8

construct :: BS.ByteString -> [Int]
construct str
    | BS.null str = []
    | isSpace (BS8.head str) = construct (BS8.tail str)
    | otherwise = let Just (i, other) = BS8.readInt str in i : construct other

getInts :: IO [Int]
getInts = construct <$> BS.getLine

type Point = (Int, Int)

line :: Point -> Point -> Point -> Bool
line (x1,y1) (x2,y2) (x3,y3) = dx1 * dy2 == dx2 * dy1
    where dx1 = x2 - x1
          dy1 = y2 - y1
          dx2 = x3 - x2
          dy2 = y3 - y2

can :: [Point] -> [Point] -> [Point] -> Bool
can _ _ [] = True
can (ga:gb:gs) [] (p:ps) = if line ga gb p then can (p:ga:gb:gs) [] ps else can (ga:gb:gs) [p] ps
can (ga:gb:gs) [sa] (p:ps) = if line ga gb p then can (p:ga:gb:gs) [sa] ps else can (ga:gb:gs) [p,sa] ps
can (ga:gb:gs) (sa:sb:ss) (p:ps)
    | line ga gb p = can (p:ga:gb:gs) (sa:sb:ss) ps
    | line sa sb p = can (ga:gb:gs) (p:sa:sb:ss) ps
    | otherwise = False

solve :: [Point] -> String
solve xs
    | can [p0, p1] [] (drop 2 xs) || can [p0, p2] [p1] (drop 3 xs) || can [p1, p2] [p0] (drop 3 xs)  = "success"
    | otherwise = "failure"
    where p0 = xs !! 0
          p1 = xs !! 1
          p2 = xs !! 2

main = do
    [n] <- getInts
    points <- replicateM n (getInts >>= \[a,b] -> pure (a,b))
    putStrLn $ solve points

import Control.Applicative
import Control.Monad
import Data.Char
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8

construct :: BS.ByteString -> [Int]
construct str
    | BS.null str = []
    | isSpace (BS8.head str) = construct (BS8.tail str)
    | otherwise = let Just (i, other) = BS8.readInt str in i : construct other

getInts :: IO [Int]
getInts = construct <$> BS.getLine

type Point = (Int, Int)

line :: Point -> Point -> Point -> Bool
line (x1,y1) (x2,y2) (x3,y3) = dx1 * dy2 == dx2 * dy1
    where dx1 = x2 - x1
          dy1 = y2 - y1
          dx2 = x3 - x2
          dy2 = y3 - y2

can :: [Point] -> [Point] -> [Point] -> Bool
can _ _ [] = True
can (ga:gb:gs) [] (p:ps) = if line ga gb p then can (p:ga:gb:gs) [] ps else can (ga:gb:gs) [p] ps
can (ga:gb:gs) [sa] (p:ps) = if line ga gb p then can (p:ga:gb:gs) [sa] ps else can (ga:gb:gs) [p,sa] ps
can (ga:gb:gs) (sa:sb:ss) (p:ps)
    | line ga gb p = can (p:ga:gb:gs) (sa:sb:ss) ps
    | line sa sb p = can (ga:gb:gs) (p:sa:sb:ss) ps
    | otherwise = False

solve :: [Point] -> String
solve xs
    | can [p0, p1] [] (drop 2 xs) || can [p0, p2] [p1] (drop 3 xs) || can [p1, p2] [p0] (drop 3 xs)  = "YES"
    | otherwise = "NO"
    where p0 = xs !! 0
          p1 = xs !! 1
          p2 = xs !! 2

main = do
    [n] <- getInts
    points <- replicateM n (getInts >>= \[a,b] -> pure (a,b))
    putStrLn $ solve points


Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.

The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.

Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li < ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.

NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.

import           Control.Applicative
import           Control.Monad
import           Data.List
import qualified Data.Map            as Map
import qualified Data.Set            as Set
import           Data.Tree

smallToFront _ 0 = []
smallToFront x n = (x + n - 1, x + n) : (smallToFront x (n - 1))

selectSort _ (_:[]) = []
selectSort n xs = (smallToFront n minPos) ++ (selectSort (n + 1) ys)
  where
    minPos = minIndex xs
    minIndex l = snd $ minimum $ zip l [0..]
    (initArray, restArray) = genericSplitAt minPos xs
    ys = case restArray of
           [] -> initArray
           _ -> initArray ++ (tail restArray)

printPair (a, b) = putStrLn $ show (a + 1) ++ " " ++ show (b + 1)

main = do
  _ <- getLine
  nums <- fmap (map (read :: String -> Int) . words) getLine
  let ans = selectSort 0 nums
  mapM_ printPair ans

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

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

main = do
  _ <- getLine
  inp <- fmap (map read . words) getLine
  mapM_ g $ solve 0 inp

g :: (Int, Int) -> IO ()
g (a, b) = putStrLn $ show (a + 1) ++ " " ++ show (b + 1)

solve' :: Int -> [Int] -> IO ()
solve' x y = mapM_ g $ solve x y

solve :: Int -> [Int] -> [(Int, Int)]
solve _ [] = []
solve v xs = ops ++ solve (v+1) xs'
    where
      ops = fmap f ops'
      ops' = zip [ind-1, ind-2 .. 0] [ind, ind-1..0]
      f (x, y) = (x + v, y + v)
      (sm, ind) = minimum $ zip xs [0..]
      (initial, _:rest) = splitAt ind xs
      xs' = initial ++ rest

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

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

main = do
  _ <- getLine
  inp <- fmap (map read . words) getLine
  mapM_ g $ solve 0 inp

g :: (Int, Int) -> IO ()
g (a, b) = putStrLn $ show (a + 1) ++ " " ++ show (b + 1)

solve' :: Int -> [Int] -> IO ()
solve' x y = mapM_ g $ solve x y

solve :: Int -> [Int] -> [(Int, Int)]
solve _ [] = []
solve i l = smallestToFront ++ rest
    where
      smallestToFront = zip [(minInd + i - 1), minInd + i - 2 .. i] [(minInd + i), minInd+i - 1 ..]
      rest = solve (i+1) restOfArray
      restOfArray = initialArray ++ restArray
      (initialArray, _:restArray) = splitAt minInd l
      minInd = snd . minimum $ zip l [0..]

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

sort' x = bsort (map( (\[x,y]->(x,y)) . map (read :: String -> Int) . words ) $ lines $ f x ) x

bsort [] ls = ls
bsort ((x,y):zs) ls =
    let (a,b) = splitAt (pred x)  ls
        (c,d) = splitAt (succ $ y-x) b
    in bsort zs $ a ++  swap c ++  d
    where
        swap [] = []
        swap (a:b:cs) = b : a : swap cs

minWithIndex [] a _ = a
minWithIndex (a:as) mm@(m,j) i =
    if a<m
        then minWithIndex as (a,i) (i+1)
        else minWithIndex as mm (i+1)

f x = f' x 1
    where
    f' [] _ = ""
    f' [x] _ = ""
    f' x i =
        let (m,j) = minWithIndex x (10^9+1,0) i in
        if j>i
            then
                let k = [j,j-1..i]
                    l = unlines $ map (\(a,b) -> show b ++ " " ++ show a) $ zip k $ tail k
                in l ++ f' (m `delete` x) (i+1)
            else f' (m `delete` x) (i+1)

int = fst .fromJust  .B.readInt
ints = map int . B.words <$> B.getLine
_' = B.getLine

main = _' >> ints >>= putStrLn . f

import Data.List

findMinPos :: [Integer] -> Int
findMinPos xs = (\(Just x) -> x) $ elemIndex (minimum xs) xs

getSwaps :: Int -> Int -> [(Int, Int)]
getSwaps _ 0 = []
getSwaps x n = (x + n - 1, x + n) : (getSwaps x (n - 1))

getAllSwaps :: Int -> [Integer] -> [(Int, Int)]
getAllSwaps _ (x:[]) = []
getAllSwaps n xs = (getSwaps n minPos) ++ (getAllSwaps (n + 1) ys)
                where minPos = findMinPos xs
                      (a, b) = genericSplitAt minPos xs
                      ys = case b of [] -> a
                                     _ -> a ++ (tail b)

getIntList :: [String] -> [Integer]
getIntList [] = []
getIntList (x:xs) = (read x :: Integer) : (getIntList xs)

putAllPairs :: [(Int, Int)] -> IO ()
putAllPairs [] = return ()
putAllPairs ((x,y):xs) = do
                        putStrLn $ show x ++ " " ++ show y
                        putAllPairs xs

main = do
        x <- getLine
        let n = read x :: Int
        hwords <- getLine
        let hs = getIntList . words $ hwords
            as = getAllSwaps 1 hs
        putAllPairs as
        return ()

import Data.List

findMinPos :: [Integer] -> Int
findMinPos xs = (\(Just x) -> x) $ elemIndex (minimum xs) xs

getSwaps :: Int -> Int -> [(Int, Int)]
getSwaps _ 0 = []
getSwaps x n = (x + n - 1, x + n) : (getSwaps x (n - 1))

getAllSwaps :: Int -> [Integer] -> [(Int, Int)]
getAllSwaps _ (x:[]) = []
getAllSwaps n xs = (getSwaps n minPos) ++ (getAllSwaps (n + 1) ys)
                where minPos = findMinPos xs
                      (a, b) = genericSplitAt minPos xs
                      ys = case b of [] -> a
                                     _ -> a ++ (tail b)
putAllPairs :: [(Int, Int)] -> IO ()
putAllPairs [] = return ()
putAllPairs ((x,y):xs) = do
                        putStrLn $ show x ++ " " ++ show y
                        putAllPairs xs

main = do
        x <- getLine
        let n = read x :: Int
        hwords <- getLine
        let hs = map (read::String->Integer) . words $ hwords
            as = getAllSwaps 1 hs
        putAllPairs as

import Control.Monad.State

main = do
    n <- readLn
    hs <- return . map read . words =<< getLine
    let	loop xns st = let
	    (v,s)   = (`runState` st) $ process $ zip [1..n] xns
	    cs	    = compress s
	  in if sorted v
	     then return cs
	     else loop v cs
	  where
	    sorted [n] = True
	    sorted (n1:tl@(n2:rest))| n1<=n2    =  sorted tl
				    | otherwise = False
    mapM_ print' =<< return . reverse =<< loop hs []
      where
	print' (a,b) = do
	    putStr . show $ a
	    putChar ' '
	    print b

process::[(Int,Int)] -> State [(Int,Int)] [Int]
process [] = return []
process [(ix,v)] = return [v]
process ((ix1,v1):tl@((ix2,v2):rest))
  | v1 <= v2	= return . (v1:) =<< process tl
  | otherwise	= do	modify ((ix1,ix2):)
			return . (v2:) . (v1:) =<< process rest

compress = foldr push []
    where
	push p [] = [p]
	push p@(ix3, ix4) stack@((ix1,ix2):ps) =
	    if ix2+1==ix3 then (ix1,ix4):ps else p:stack

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

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

main = do
  _ <- getLine
  inp <- fmap (map read . words) getLine
  print $ solve 0 inp

solve :: Int -> [Int] -> [(Int, Int)]
solve _ [] = []
solve v xs = ops ++ solve (v+1) xs'
    where
      ops = fmap f ops'
      ops' = zip [0..] [1..ind]
      f (x, y) = (x + v, y + v)
      (sm, ind) = minimum $ zip xs [0..]
      (initial, _:rest) = splitAt ind xs
      xs' = initial ++ rest

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

sort' x = bsort (map( (\[x,y]->(x,y)) . map (read :: String -> Int) . words ) $ lines $ f x ) x

bsort [] ls = ls
bsort ((x,y):zs) ls =
    let (a,b) = splitAt (pred $ min x y)  ls
        (c,d) = splitAt (succ $ abs $ y-x) b
    in bsort zs $ a ++  swap c ++  d
    where
        swap [] = []
        swap (a:b:cs) = b : a : swap cs

minWithIndex [] a _ = a
minWithIndex (a:as) mm@(m,j) i =
    if a<m
        then minWithIndex as (a,i) (i+1)
        else minWithIndex as mm (i+1)

f x = f' x 1
    where
    f' [] _ = ""
    f' [x] _ = ""
    f' x i =
        let (m,j) = minWithIndex x (10^9+1,0) i in
        if j>i
            then
                let k = [j,j-1..i]
                    l = unlines $ map (\(a,b) -> show a ++ " " ++ show b) $ zip k $ tail k
                in l ++ f' (m `delete` x) (i+1)
            else f' (m `delete` x) (i+1)

int = fst .fromJust  .B.readInt
ints = map int . B.words <$> B.getLine
_' = B.getLine

main = _' >> ints >>= putStrLn . f


Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each individual letter all its positions in the string are written out in the increasing order. This results in 26 lists of numbers; some of them can be empty. A string is considered lucky if and only if in each list the absolute difference of any two adjacent numbers is a lucky number. For example, let's consider string "zbcdzefdzc". The lists of positions of equal letters are: b: 2 c: 3, 10 d: 4, 8 e: 6 f: 7 z: 1, 5, 9 Lists of positions of letters a, g, h, ..., y are empty.This string is lucky as all differences are lucky numbers. For letters z: 5 - 1 = 4, 9 - 5 = 4, for letters c: 10 - 3 = 7, for letters d: 8 - 4 = 4. Note that if some letter occurs only once in a string, it doesn't influence the string's luckiness after building the lists of positions of equal letters. The string where all the letters are distinct is considered lucky.Find the lexicographically minimal lucky string whose length equals n.

The single line contains a positive integer n (1 ≤ n ≤ 105) — the length of the sought string.

Print on the single line the lexicographically minimal lucky string whose length equals n.

NoteThe lexical comparison of strings is performed by the < operator in modern programming languages. String a is lexicographically less than string b if exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj.

-- Codeforces Beta Round 84 (Div. 2 Only) - Problem B: Lucky String (https://codeforces.com/problemset/problem/110/B)
import Data.List

solve n = take n $ intercalate "" $ replicate n "abcd"

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

module Main where

import Control.Monad

main = do
    n <- read `liftM` getLine
    putStrLn $ take n $ cycle "abcd"

import Control.Monad

main = do n <- liftM read getLine
          putStrLn . take n . cycle $ "abcd"

main = getLine >>= (\n -> (putStrLn . take n . concat . repeat) "abcd") . read

import Data.List
main = readLn >>=
       (\n -> putStrLn $
              take n (cycle "abcd"))

{-# OPTIONS_GHC -O2 -XNoMonomorphismRestriction #-}
{-# LANGUAGE BangPatterns #-}
{-(c) gorlum0 [at] gmail.com-}
import Control.Monad (forM_)

lucky = cycle "abcd"

main = do
    ls <- lines `fmap` getContents
    let ns = map read ls
    forM_ [take n lucky | n <- ns] $
        putStrLn

solve :: Int -> String
solve n = take n (cycle "abcd")

main :: IO ()
main = do
    readLn >>= putStrLn . solve

main = interact $ (\n -> take n $ cycle "abcd").read

luckies = 4 : 7 : concatMap (\l -> [10*l + 4, 10*l + 7]) luckies
main = do
  n <- readLn
  putStrLn $ concat (replicate (n `div` 4) "abcd") ++
             take (n `mod` 4) "abcd"

main = interact (f . read)
f n = take n $ cycle "abcd"

solve :: Int -> String
solve = (`take` (cycle "abcd"))

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

main = do n<-getLine
          (putStrLn.take (read n::Int).cycle) "abcd"

calc :: Int -> String
calc n = take n $ cycle "abcd"

main = do s <- getLine
          putStrLn $ calc $ read s

solve :: Int -> String
solve n = take n (cycle "abcd")

main :: IO ()
main = do
    readLn >>= print . solve

solve :: Int -> String
solve = (`take` (cycle "abcd"))

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


This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?Polycarp can throw his fire ball into an archer if the latter is already killed.

The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.

In the first line print t — the required minimum amount of fire balls. In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.

module Main where

import qualified Data.ByteString.Char8 as BS
import Data.Maybe(fromJust)
import Data.Array.Unboxed
import Data.Array.ST.Safe

import Control.Monad.ST
import Data.Bool (bool)
import Data.List (minimumBy)
import Data.Ord (comparing)

main :: IO ()
main = do
    [n, a, b] <- ints
    hp <- listArray (1, n) <$> ints
    let (k, hs) = solve a b hp
    print k
    putStrLn (unwords $ map show hs)

solve :: Int -> Int -> UArray Int Int -> (Int, [Int])
solve a b hp = runST $ do
    dp <- newArray ((0, 0, 0, 0), (n, hm, hm, hm)) inf
    res <- fill dp sp
    fdp <- freeze dp
    pure (res, collect fdp sp)
  where
    n = snd $ bounds hp
    hm = 1 + maximum (elems hp)
    sp = (n, 0, 0, 0)
    hitRange = (2, n - 1)
    targets n = filter (inRange hitRange) [n - 1, n , n + 1]
    inf = (maxBound :: Int) `div` 2
    fill :: STUArray s QInt Int -> QInt -> ST s Int
    fill dp i@(k, x, y, z) =
      k < 1 ? pure 0 $
      testM (< inf) (readArray dp i) $
      applyM (writeArray dp i) $
      (hp ! k) - (x + z) * b - y * a < 0 ? fill dp (k - 1, 0, x, y) $
      (1 + ) . minimum <$> mapM (fill dp . hit i) (targets k)
    collect :: UArray QInt Int -> QInt -> [Int]
    collect dp i@(k, x, y, z) =
      k < 1 ? [] $
      (hp ! k) - (x + z) * b - y * a < 0 ? collect dp (k - 1, 0, x, y) $
      let (t, h) = bestHit dp i in t:collect dp h
    bestHit dp i@(k, _, _, _) = minimumBy (comparing (\(_, h) -> dp ! h)) $ zipMap (hit i) (targets k)

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

type QInt = (Int, Int, Int, Int)

hit :: QInt -> Int ->  QInt
hit (n, x, y, z) k
  | k == n     = (n, x, y + 1, z)
  | k == n + 1 = (n, x, y, z + 1)
  | k == n - 1 = (n, x + 1, y, z)
  | otherwise  = (n, x, y, z)

(?) :: Bool -> a -> a -> a
(?) True  x _ = x
(?) False _ y = y
infixr 1 ?

testM :: Monad m => (a -> Bool) -> m a -> m a -> m a
testM f a b = f <$> a >>= bool b a

applyM :: Monad m => (a -> m ()) -> m a -> m a
applyM f a = a >>= f >> a

zipMap :: (a -> b) -> [a] -> [(a, b)]
zipMap f = map (\a -> (a, f a))

module Main where

import qualified Data.ByteString.Char8 as BS
import Data.Maybe(fromJust)
import Data.Array.Unboxed
import Data.Array.ST.Safe

import Control.Monad.ST
import Data.Bool (bool)
import Data.List (minimumBy)
import Data.Ord (comparing)

main :: IO ()
main = do
    [n, a, b] <- ints
    hp <- listArray (1, n) <$> ints
    let (k, hs) = solve a b hp
    print k
    putStrLn (unwords $ map show hs)

solve :: Int -> Int -> UArray Int Int -> (Int, [Int])
solve a b hp = runST $ do
    dp <- newArray ((0, 0, 0, 0), (n, hm, hm, hm)) inf
    res <- fill dp sp
    fdp <- freeze dp
    pure (res, collect fdp sp)
  where
    n = snd $ bounds hp
    hm = 1 + maximum (elems hp)
    sp = (n, 0, 0, 0)
    hitRange = (2, n - 1)
    targets n = filter (inRange hitRange) [n - 1, n , n + 1]
    inf = (maxBound :: Int) `div` 2
    fill :: STUArray s QInt Int -> QInt -> ST s Int
    fill dp i@(k, x, y, z) =
      k < 1 ? pure 0 $
      testM (< inf) (readArray dp i) $
      applyM (writeArray dp i) $
      (hp ! k) - (x + z) * b - y * a < 0 ? fill dp (k - 1, 0, x, y) $
      (1 + ) . minimum <$> mapM (fill dp . hit i) (targets k)
    collect :: UArray QInt Int -> QInt -> [Int]
    collect dp i@(k, x, y, z) =
      k < 1 ? [] $
      (hp ! k) - (x + z) * b - y * a < 0 ? collect dp (k - 1, 0, x, y) $
      t:collect dp (hit i t) where t = minimumBy (comparing $ (dp !) . hit i) (targets k)

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

type QInt = (Int, Int, Int, Int)

hit :: QInt -> Int ->  QInt
hit (n, x, y, z) k
  | k == n     = (n, x, y + 1, z)
  | k == n + 1 = (n, x, y, z + 1)
  | k == n - 1 = (n, x + 1, y, z)
  | otherwise  = (n, x, y, z)

(?) :: Bool -> a -> a -> a
(?) True  x _ = x
(?) False _ y = y
infixr 1 ?

testM :: Monad m => (a -> Bool) -> m a -> m a -> m a
testM f a b = f <$> a >>= bool b a

applyM :: Monad m => (a -> m ()) -> m a -> m a
applyM f a = a >>= f >> a

zipMap :: (a -> b) -> [a] -> [(a, b)]
zipMap f = map (\a -> (a, f a))

module Main where

import qualified Data.ByteString.Char8 as BS
import Data.Maybe(fromJust)
import Data.Array.Unboxed
import Data.Array.ST.Safe

import Control.Monad.ST
import Data.Bool (bool)
import Data.List (minimumBy)
import Data.Ord (comparing)

main :: IO ()
main = do
    [n, a, b] <- ints
    hp <- listArray (1, n) <$> ints
    let (k, hs) = solve a b hp
    print k
    putStrLn (unwords $ map show hs)

solve :: Int -> Int -> UArray Int Int -> (Int, [Int])
solve a b hp = runST $ do
    dp <- newArray ((0, 0, 0, 0), (n, hm, hm, hm)) inf
    res <- fill dp sp
    fdp <- freeze dp
    pure (res + s, replicate s (n - 1) ++ collect fdp sp)
  where
    n = snd $ bounds hp
    hm = 1 + maximum (elems hp)
    s = (hp ! n + 1) `updiv` b
    sp = (n - 1, 0, s, 0)
    hitRange = (2, n - 1)
    targets n = filter (inRange hitRange) [n - 1, n , n + 1]
    inf = (maxBound :: Int) `div` 2
    fill :: STUArray s QInt Int -> QInt -> ST s Int
    fill dp i@(k, x, y, z) =
      k < 1 ? pure 0 $
      testM (< inf) (readArray dp i) $
      applyM (writeArray dp i) $
      (hp ! k) - (x + z) * b - y * a < 0 ? fill dp (k - 1, 0, x, y) $
      (1 + ) . minimum <$> mapM (fill dp . hit i) (targets k)
    collect :: UArray QInt Int -> QInt -> [Int]
    collect dp i@(k, x, y, z) =
      k < 1 ? [] $
      (hp ! k) - (x + z) * b - y * a < 0 ? collect dp (k - 1, 0, x, y) $
      let (t, h) = bestHit dp i in t:collect dp h
    bestHit dp i@(k, _, _, _) = minimumBy (comparing (\(_, h) -> dp ! h)) $ zipMap (hit i) (targets k)

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

type QInt = (Int, Int, Int, Int)

hit :: QInt -> Int ->  QInt
hit (n, x, y, z) k
  | k == n     = (n, x, y + 1, z)
  | k == n + 1 = (n, x, y, z + 1)
  | k == n - 1 = (n, x + 1, y, z)
  | otherwise  = (n, x, y, z)

(?) :: Bool -> a -> a -> a
(?) True  x _ = x
(?) False _ y = y
infixr 1 ?

testM :: Monad m => (a -> Bool) -> m a -> m a -> m a
testM f a b = f <$> a >>= bool b a

applyM :: Monad m => (a -> m ()) -> m a -> m a
applyM f a = a >>= f >> a

zipMap :: (a -> b) -> [a] -> [(a, b)]
zipMap f = map (\a -> (a, f a))

updiv :: Int -> Int -> Int
updiv a b = (a + b - 1) `div` b

module Main where

import qualified Data.ByteString.Char8 as BS
import Data.Maybe(fromJust)
import Data.Array.Unboxed
import Data.Array.ST.Safe

import Control.Monad.ST
import Data.Functor (($>))
import Data.Bool (bool)
import Data.List (minimumBy)
import Data.Ord (comparing)

main :: IO ()
main = do
    [n, a, b] <- ints
    hp <- listArray (1, n) <$> ints
    let (k, hs) = solve a b hp
    print k
    putStrLn (unwords $ map show hs)

solve :: Int -> Int -> UArray Int Int -> (Int, [Int])
solve a b hp = runST $ do
    dp <- newArray ((0, 0, 0, 0), (n, hm, hm, hm)) (-1)
    res <- fill dp sp
    fdp <- freeze dp
    return (res + s, replicate s (n - 1) ++ collect fdp sp)
  where
    n = snd $ bounds hp
    hm = 1 + maximum (elems hp)
    s = (hp ! n + 1) `div` b
    sp = (n - 1, 0, s, 0)
    hitRange = (2, n - 1)
    targets n = filter (inRange hitRange) [n - 1, n , n + 1]
    inf = (maxBound :: Int) `div` 2
    fill :: STUArray s QInt Int -> QInt -> ST s Int
    fill dp i@(k, x, y, z) =
      k < 1 ? pure 0 $
      testM (>= 0) (readArray dp i) $
      (hp ! k) - (x + z) * b - y * a < 0 ? fill dp (k - 1, 0, x, y) $
      minimum <$> mapM (fill dp . hit i) (targets k) >>= \res ->
      applyM (writeArray dp i) (res + 1)
    collect :: UArray QInt Int -> QInt -> [Int]
    collect dp i@(k, x, y, z) =
      k < 1 ? [] $
      (hp ! k) - (x + z) * b - y * a < 0 ? collect dp (k - 1, 0, x, y) $
      let (t, h) = bestHit dp i in t:collect dp h
    bestHit dp i@(k, _, _, _) = minimumBy (comparing (\(_, h) -> dp ! h)) $ zipMap (hit i) (targets k)

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

type QInt = (Int, Int, Int, Int)

hit :: QInt -> Int ->  QInt
hit (n, x, y, z) k
  | k == n     = (n, x, y + 1, z)
  | k == n + 1 = (n, x, y, z + 1)
  | k == n - 1 = (n, x + 1, y, z)
  | otherwise  = (n, x, y, z)

(?) :: Bool -> a -> a -> a
(?) True  x _ = x
(?) False _ y = y
infixr 1 ?

testM :: Monad m => (a -> Bool) -> m a -> m a -> m a
testM f a b = f <$> a >>= bool b a

applyM :: Monad m => (a -> m ()) -> a -> m a
applyM f a = f a $> a

zipMap :: (a -> b) -> [a] -> [(a, b)]
zipMap f = map (\a -> (a, f a))

module Main where

import qualified Data.ByteString.Char8 as BS
import Data.Maybe(fromJust)
import Data.Array.Unboxed
import Data.Array.ST.Safe

import Control.Monad.ST
import Data.Functor (($>))
import Data.Bool (bool)
import Data.List (minimumBy)
import Data.Ord (comparing)

main :: IO ()
main = do
    [n, a, b] <- ints
    hp <- listArray (1, n) <$> ints
    let (k, hs) = solve a b hp
    print k
    putStrLn (unwords $ map show hs)

solve :: Int -> Int -> UArray Int Int -> (Int, [Int])
solve a b hp = runST $ do
    dp <- newArray ((0, 0, 0, 0), (n, hm, hm, hm)) (-1)
    res <- fill dp sp
    fdp <- freeze dp
    return (res + s, replicate s (n - 1) ++ collect fdp sp)
  where
    n = snd $ bounds hp
    hm = 1 + maximum (elems hp)
    s = (hp ! n + 1) `updiv` b
    sp = (n - 1, 0, s, 0)
    hitRange = (2, n - 1)
    targets n = filter (inRange hitRange) [n - 1, n , n + 1]
    inf = (maxBound :: Int) `div` 2
    fill :: STUArray s QInt Int -> QInt -> ST s Int
    fill dp i@(k, x, y, z) =
      k < 1 ? pure 0 $
      testM (>= 0) (readArray dp i) $
      (hp ! k) - (x + z) * b - y * a < 0 ? fill dp (k - 1, 0, x, y) $
      minimum <$> mapM (fill dp . hit i) (targets k) >>= \res ->
      applyM (writeArray dp i) (res + 1)
    collect :: UArray QInt Int -> QInt -> [Int]
    collect dp i@(k, x, y, z) =
      k < 1 ? [] $
      (hp ! k) - (x + z) * b - y * a < 0 ? collect dp (k - 1, 0, x, y) $
      let (t, h) = bestHit dp i in t:collect dp h
    bestHit dp i@(k, _, _, _) = minimumBy (comparing (\(_, h) -> dp ! h)) $ zipMap (hit i) (targets k)

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

type QInt = (Int, Int, Int, Int)

hit :: QInt -> Int ->  QInt
hit (n, x, y, z) k
  | k == n     = (n, x, y + 1, z)
  | k == n + 1 = (n, x, y, z + 1)
  | k == n - 1 = (n, x + 1, y, z)
  | otherwise  = (n, x, y, z)

(?) :: Bool -> a -> a -> a
(?) True  x _ = x
(?) False _ y = y
infixr 1 ?

testM :: Monad m => (a -> Bool) -> m a -> m a -> m a
testM f a b = f <$> a >>= bool b a

applyM :: Monad m => (a -> m ()) -> a -> m a
applyM f a = f a $> a

zipMap :: (a -> b) -> [a] -> [(a, b)]
zipMap f = map (\a -> (a, f a))

updiv :: Int -> Int -> Int
updiv a b = (a + b - 1) `div` b