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 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)

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)


{-# 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

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 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 -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 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


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           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 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


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

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"

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

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

-- 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

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


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 + 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.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.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


import Control.Monad

toShow [] = ""
toShow (x:xs) = show x ++ " " ++ toShow xs

main :: IO ()
main = do
    ts <- getLine
    replicateM (read ts::Int) $ do
        input <- getLine
        let n = read  input ::Int
        input <- getLine
        let d = map read . words $ input ::[Int]
        let a = scanl1 (+) d
        putStrLn $ if any (\(x,y) -> x>=y && y/=0) $ zip a (tail d) then "-1" else toShow a
    return ()

import Control.Monad (replicateM_)
main = read <$> getLine >>= flip replicateM_ scase
scase = read <$> getLine >>=
        \n -> map read . words <$> getLine >>=
        \ds -> case findA n ds of
                 Just as -> mapM_ (\a -> putStr (show a ++ " ")) as >>
                            putStrLn ""
                 Nothing -> putStrLn "-1"

maxA (d:ds) = scanl (+) d ds

findA :: Int -> [Int] -> Maybe [Int]
findA n ds = let mA = maxA ds in
               if any (\(a, d) -> d <= a && d > 0) (zip mA (tail ds))
               then Nothing
               else Just mA

{-# LANGUAGE ScopedTypeVariables #-}

--import Data.ByteString.Builder.Extra (flush) -- for interactive problems

import Control.Monad
import Control.Monad.Trans.State
import Data.ByteString.Builder
import qualified Data.ByteString.Builder.Prim as Prim
import qualified Data.ByteString.Lazy.Char8 as P
import Data.Maybe
import Debug.Trace
import System.IO (BufferMode (NoBuffering), hSetBuffering, stdout)

mainFun :: SP Builder
mainFun = do
  casnum <- getInt
  ress <- forM [1 .. casnum] $ \_ -> do
    n <- getInt
    d <- replicateM n getInt
    let a = scanl1 (+) d
    let only = all (\(x, y) -> x < y || y == 0) $ zip a (tail d)
    let res = if only then a else [-1]
    pure res
  pure $ foldl1 (<>) $ map putInts ress

type SP = State P.ByteString

type S = StateT P.ByteString

dropSpace :: P.ByteString -> P.ByteString
dropSpace = P.dropWhile (<= ' ') -- not exactly right, but close enough

--getNext :: Monad m => S m P.ByteString
--getNext = state $ P.span (> ' ') . dropSpace

getInt :: Monad m => S m Int
getInt = state $ fromJust . P.readInt . dropSpace

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 inp
  P.putStr $ toLazyByteString outp

--
-- Michael V. Antosha
-- 2022
-- Michael.Antosha@gmail.com
--

{-# language Safe                      #-}
{-# language ImportQualifiedPost       #-}
{-# language NoMonomorphismRestriction #-}

{-# options_ghc -O3                              #-}

{-# options_ghc -Weverything                     #-}
{-# options_ghc -Werror                          #-}

{-# options_ghc -Wno-missing-import-lists        #-}
{-# options_ghc -Wno-missing-local-signatures    #-}

import Prelude               hiding (getLine)
import Control.Arrow
import Control.Monad
import Data.ByteString.Char8 qualified as B
import Data.Char
import Data.List             qualified as L
import Data.Maybe

ri = readInts <$> B.getLine :: IO [Int]
  where
    readInts  = L.unfoldr ((second dropSpace <$>) . B.readInt) . dropSpace
    dropSpace = B.dropWhile isSpace

main :: IO ()
main = do
    [t] <- ri
    tcs <- replicateM t $ do
        [_n] <- ri
        ds   <- ri
        return ds
    mapM_ (putStrLn.showAns.solve) tcs

showAns = maybe "-1" (unwords . map show)

solve (d:ds) = ans
  where
    tt = L.scanl' g (Just d) $ ds
    ans | all isJust tt  = Just (map fromJust tt)
        | otherwise      = Nothing

    g Nothing  _ = Nothing
    g (Just a) b = f a b

    f prevA currD | length cands == 1  = Just (head cands)
                  | otherwise          = Nothing
      where
        cands = L.nub . filter (>=0) $ [prevA + currD, prevA - currD]
solve _ = error "Empty input?"

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

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

main :: IO ()
main = C.interact $ runScanner (numberOf input) >>> map solve >>> zip [1 ..] >>> map (uncurry output) >>> C.unlines

type TC = [Int]

type Output = Maybe [Int]

input :: Scanner TC
input = numberOf int

solve :: TC -> Output
solve ds = guard (zip as (tail ds) >$> filter (snd >>> (/= 0)) >>> all (uncurry (<))) >> return as
  where
    as = scanl1 (+) ds

output :: Int -> Output -> C.ByteString
output _ = fmap (map show >>> unwords) >>> fromMaybe "-1" >>> C.pack

-------------------------- Template ------------------------------------------
-- Debug
debug :: Show a => a -> a

#ifdef ONLINE_JUDGE
debug = id
#else
debug a = trace (show a) a
#endif

-- helpers
(>$>) = flip ($)

infixl 0 >$>

-- 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


{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -cpp #-}
{-# OPTIONS_GHC -funbox-strict-fields -fexcess-precision -monly-3-regs #-}
{-# LANGUAGE OverloadedStrings #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Ord
import qualified Data.IntMap as Map
import qualified Data.IntSet as Set
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  let readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
  n : _ <- readInts
  let check acc _ = do
        x : y : _ <- readInts
        let acc'  = Map.insertWith (Set.union) y (Set.singleton x) acc
            acc'' = Map.insertWith (Set.union) x (Set.singleton y) acc'
        return acc''
  pathes <- foldM check Map.empty [1 .. n]
  let Just (start, _) = find ((== 1) . Set.size . snd)
        $ Map.toList pathes
      search (mp, i)
        | i < 0       = Nothing
        | Map.null mp = Just (show i, (mp, -1))
        | otherwise   = do
            let s     = mp Map.! i
                j : _ = Set.toList s
                s'    = mp Map.! j
                t     = Set.delete j s
                t'    = Set.delete i s'
                mp'  = if Set.null t
                         then Map.delete i mp
                         else Map.insert i t  mp
                mp'' = if Set.null t'
                         then Map.delete j mp'
                         else Map.insert j t' mp'
            Just (show i, (mp'', j))
      answer = unfoldr search (pathes, start)
  putStrLn $ intercalate " " answer

import Data.List
import qualified Data.IntMap as IM
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Maybe(fromJust)
import GHC.Exts(groupWith)

main = do
  (s:ss) <- fmap (BS.lines) BS.getContents
  let n = readInt s
      input = map(map readInt . BS.words) . take n $ ss
      list = map (\ [x,y] -> (x,y)) input ++
             map (\ [x,y] -> (y,x)) input
      joinedList = map merge . groupWith fst $ list
       where merge l = (fst (head l), map snd l)

      allVertices = map head . group . sort . concat $ input
      [start,end] = map fst . filter ((<2) . length . snd) $ joinedList
      joinedMap = IM.fromList joinedList
      ans = takeWhile(/=end) . map fst $ iterate step (start, -1)
      step (u, prev) = let
        Just adj = IM.lookup u joinedMap
        [v] = adj \\ [prev]
        in (v,u)

  putStrLn . unwords . map show $ ans ++ [end]

readInt = fst . fromJust . BS.readInt

{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math #-}
{-# OPTIONS_GHC -funbox-strict-fields -fexcess-precision #-}
{-# LANGUAGE OverloadedStrings #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Ord
import qualified Data.IntMap as Map
import qualified Data.IntSet as Set
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  let readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
  n : _ <- readInts
  let check acc _ = do
        x : y : _ <- readInts
        let acc'  = Map.insertWith (Set.union) y (Set.singleton x) acc
            acc'' = Map.insertWith (Set.union) x (Set.singleton y) acc'
        return acc''
  pathes <- foldM check Map.empty [1 .. n]
  let Just (start, _) = find ((== 1) . Set.size . snd)
        $ Map.toList pathes
      search (mp, i)
        | i < 0       = Nothing
        | Map.null mp = Just (show i, (mp, -1))
        | otherwise   = do
            let s     = mp Map.! i
                j : _ = Set.toList s
                s'    = mp Map.! j
                t     = Set.delete j s
                t'    = Set.delete i s'
                mp'  = if Set.null t
                         then Map.delete i mp
                         else Map.insert i t  mp
                mp'' = if Set.null t'
                         then Map.delete j mp'
                         else Map.insert j t' mp'
            Just (show i, (mp'', j))
      answer = unfoldr search (pathes, start)
  putStrLn $ intercalate " " answer

import Data.List
import qualified Data.IntMap as IM
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Maybe(fromJust)
import GHC.Exts(groupWith)

main = do
  (s:ss) <- fmap (BS.lines) BS.getContents
  let n = readInt s
      input = map(map readInt . BS.words) . take n $ ss
      list = map (\ [x,y] -> (x,y)) input ++
             map (\ [x,y] -> (y,x)) input
      joinedList = map merge . groupWith fst $ list
       where merge l = (fst (head l), map snd l)

      allVertices = map head . group . sort . concat $ input
      [start,end] = map fst . filter ((<2) . length . snd) $ joinedList
      joinedMap = IM.fromList joinedList
      ans = takeWhile(/=end) . map fst $ iterate step (start, -1)
      step (u, prev) = let
        Just adj = IM.lookup u joinedMap
        [v] = adj \\ [prev]
        in (v,u)

  print . IM.toList $ joinedMap
  putStrLn . unwords . map show $ ans ++ [end]

readInt = fst . fromJust . BS.readInt


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

main :: IO ()
main = do
	content <- getContents
	let
		[s, a, b, c] = map (\x -> read x :: Double). concat. map words. lines $ content
		x = max 0 (a*s/ (b + a + c))
		y = max 0 (b*s / (a+b+c))
		z = max 0 ( s - x - y)
	putStrLn $ (show x) ++ " " ++ (show y) ++ " " ++ (show z)

solve :: String -> String -> [Double]
solve str1 str2 =
    let
        s = a + b + c
        s0 = (read str1)::Double
        [a, b, c] = map (\x -> (read x)::Double) (words str2)
    in
        if s == 0 then [0, 0, 0]
        else [a*s0/s, b*s0/s, c*s0/s]

join delim [] = []
join delim (x:xs) = x ++ delim ++ join delim xs

main =
    do
        str1 <- getLine
        str2 <- getLine
        putStrLn $ join " " (map show (solve str1 str2))

main = getContents >>= putStrLn. unwords. map show. (\(s:as) -> let ss = s/sum as in if sum as == 0 then replicate 3 0 else map (*ss) as). map read. concat. map words. lines

main = getContents >>= putStrLn. unwords. map show. (\(s:as) -> let ss = s/(sum as) in if sum as == 0 then replicate 3 0 else map (*ss) as). map read. words

import Monad (liftM)

solve :: Fractional d => d -> d -> d -> d -> (d, d, d)
solve a b c s
  | a + b + c == 0  =  (0, 0, 0)
  | otherwise  =  (a*s / abc, b*s / abc, c*s / abc)
  where
    abc  =  a + b + c

main :: IO ()
main  =  do
    s  <-  readLn
    [a,b,c]  <-  liftM (map read . words) getLine
    let (x,y,z)  =  solve a b c s
    putStrLn $ concat [show x, " ", show y, " ", show z]

import Control.Applicative
import Text.Printf

main = do
  s <- readLn :: IO Double
  [a,b,c] <- map read.words <$> getLine
  if all(0==)[a,b,c]
     then putStrLn "0 0 0"
     else printf "%f %f %f\n" (s*a/(a+b+c)) (s*b/(a+b+c)) (s*c/(a+b+c))

s :: [Integer] -> [Double]
s [s,0,0,0] = [fromIntegral s,0,0.0]
s [s,a,b,c] = [fromIntegral s * fromIntegral a / ss, fromIntegral s * fromIntegral b / ss, fromIntegral s * fromIntegral c / ss] where
 ss = fromIntegral (a + b + c)
main = interact $ unwords . map show . s . map read . words

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

main :: IO ()
main = do
	content <- getContents
	let
		[s, a, b, c] = map (\x -> read x :: Double). concat. map words. lines $ content
		x = a*s/ (b + a + c)
		y = b*s / (a+b+c)
		z = s - x - y
	putStrLn $ (show x) ++ " " ++ (show y) ++ " " ++ (show z)