import Data.Int

getInt64 = read `fmap` getLine :: IO Int64
isqrt :: Int64 -> Int64
isqrt = floor . sqrt . fromIntegral
isSquare x = y * y == x where y = isqrt x

main = do
    n <- getInt64
    solve n

solve n = do
    if n <= 2
    then print (-1)
    else if odd n
    then do
        let n2 = n*n
        let a = n2 `div` 2
        let b = a + 1
        putStrLn $ show a ++ " " ++ show b
    else do
        let n2 = (n `div` 2)^2
        let a = n2 - 1
        let b = n2 + 1
        putStrLn $ show a ++ " " ++ show b

module Main where
  import Data.List
  import Control.Monad
  import Data.Array

  ($!$) :: Int -> () -> Int
  ($!$) 0 _ = 1
  ($!$) n _ = (n - 1) * (n $!$ ())

  toArray :: [a] -> Array Int a
  toArray xs =
    let ls = length xs - 1
        in array (0, ls) $ zip [0..ls] xs

  readInteger :: String -> Integer
  readInteger s = read s :: Integer

  readMultilineInput :: Int -> (String -> IO a) -> IO [a]
  readMultilineInput n transformer = replicateM n (getLine >>= transformer)

  pythagorasOf :: Integer -> Maybe (Integer, Integer)
  pythagorasOf x
    | x == 1 = Nothing
    | x == 2 = Nothing
    | x == 3 = Just (4, 5)
    | x == 4 = Just (3, 5)
    | x `mod` 2 == 1 =
      let y = x `div` 2
          y1 = (y * x) + y
          in return (y1, y1 + 1)
    | otherwise = do
      (a, b) <- pythagorasOf (x `div` 2)
      return (a * 2, b * 2)

  strify :: Maybe (Integer, Integer) -> String
  strify Nothing = "-1"
  strify (Just (x, y)) = show x ++ " " ++ show y

  main :: IO()
  main = do
    x <- getLine >>= return . readInteger
    putStrLn $ strify$ pythagorasOf x

module Main where

import Control.Monad
import Prelude
import Text.Printf

solve :: Integer -> (Integer, Integer)
solve n | n <= 2    = (-1, -1)
        | odd n     = ((x + 1) `div` 2, (x + 1) `div` 2 - 1)
        | otherwise = ((x `div` 4) + 1, (x `div` 4) - 1)
        where x = n * n

main = do
    n <- liftM read getLine
    let (a, b) = solve n
    if a < 0 then printf "%d\n" a
    else printf "%d %d\n" a b

process :: String -> String
process str =
  let n = read str
      r = if even n then n - 2 else n - 1
      s = if even n then 2 else 1
      t = div (r*r) (2*s)
  in
    if n < 3
    then "-1"
    else show (r + t) ++ " " ++ show (r + s + t)

main :: IO ()
main = interact process

main = interact $ printRes . sol . read
    where
    printRes [] = "-1"
    printRes [a, b] = show a ++ " " ++ show b

sol :: Integer -> [Integer]
sol 1 = []
sol 4 = [3, 5]
sol n
    | n `mod` 2 == 0 = map (*2) $ sol (n `div` 2)
    | otherwise = [2*k*k + 2*k, 2*k*k + 2*k + 1]
    where
    k = (n-1) `div` 2

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

readIntList = fmap ((map fn) . B.words) B.getLine :: IO [Int64]
 where fn x = let Just (y,_) = B.readInt x in fromIntegral y

search :: Int64 -> Int64 -> Int64 -> Int64
search x l h = if l>=h then -1
                else if diff == x then m
                else if diff<x then search x (m+1) h else search x l m
                    where m = (l+h) `div` 2
                          diff = (m+1)^2 - m^2

pfactor 6 _ = 3
pfactor n [] = if n `rem` 2 == 0 then n `div` 2 else n
pfactor n (i:is)
 |n `rem` i == 0 = i
 |otherwise = pfactor n is

main = do
    [n] <- readIntList
    if n <= 2 then print (-1)
    else do
        if n `rem` 4 == 0 then do
            let x = n `div` 4
            putStrLn . unwords . map show $ [3*x,5*x]
        else do
            let a = pfactor n [3,5..(round . sqrt . fromIntegral $ n)]
                mult = n `div` a
                b = search (a^2) 1 (round (1e18)+10)
            if (b+1)^2 - b^2 /= a^2 then error "Fail" else putStrLn . unwords . map show $ [b*mult,(b+1)*mult]

-- 30 ms
import Data.Int
import Data.List
{-# OPTIONS_GHC -O #-}
import Control.Monad
import qualified Data.ByteString.Char8 as B

readIntList = fmap ((map fn) . B.words) B.getLine :: IO [Int64]
 where fn x = let Just (y,_) = B.readInt x in fromIntegral y

search x l h = if l>=h then -1
                else if diff == x then m
                else if diff<x then search x (m+1) h else search x l m
                    where m = (l+h) `div` 2
                          diff = (m+1)^2 - m^2

pfactor 6 _ = 3
pfactor n [] = if n `rem` 2 == 0 then n `div` 2 else n
pfactor n (i:is)
 |n `rem` i == 0 = i
 |otherwise = pfactor n is

main = do
    [n] <- readIntList
    if n <= 2 then print (-1)
    else do
        if n `rem` 4 == 0 then do
            let x = n `div` 4
            putStrLn . unwords . map show $ [3*x,5*x]
        else do
            let a = pfactor n [3,5..(round . sqrt . fromIntegral $ n)]
                mult = n `div` a
                b = search (a^2) 1 (round (1e18)+10)
            if (b+1)^2 - b^2 /= a^2 then error "Fail" else putStrLn . unwords . map show $ [b*mult,(b+1)*mult]

main = interact $ g.f
f x = read x :: Integer
g x
  | y < 5 = "-1"
  | y `rem` 4 /= 0 = (show a) ++ " " ++ (show (a+1))
  | otherwise = (show (b-1)) ++ " " ++ (show (b+1))
  where a = y `div` 2
        b = y `div` 4
        y = x*x

{-# OPTIONS_GHC -O2 #-}
import Data.Int (Int64)
import Data.List (genericLength)

main = do
  a <- readLn :: IO Integer

  let
    (b, c) = if even a then (a^2`div`4 - 1, a^2`div`4 + 1) else ((a^2-1) `div`2, (a^2+1)`div`2)

  if a == 1 || a == 2
     then print $ -1
     else putStrLn $ show b ++ " " ++ show c

main = getLine >>= putStrLn . f . read

f n
	| n <= 2 = "-1"
	| otherwise = show a ++ " " ++ show b
		where
			p = if n `mod` 2 == 0 then 2 else 1
			q = if n `mod` 2 == 0 then n ^ 2 `div` 2 else n ^ 2
			a = (q - p) `div` 2
			b = (q + p) `div` 2

{-# LANGUAGE TypeApplications #-}

main :: IO ()
main = do
  n <- read @ Integer <$> getLine
  let (m, k) = solve n
  putStrLn $ if n < 3 then "-1" else show m ++ " " ++ show k

solve :: Integer -> (Integer, Integer)
solve n | odd n = let root1 = (n - 1) `div` 2
                      root2 = succ root1
                  in (2 * root1 * root2, root1 * root1 + root2 * root2)
solve n | even n = let root = n `div` 2
                   in (root * root - 1, root * root + 1)

main = interact $ unwords . map show . solve . read
solve n | n <= 2 = [-1]
        | odd n  = [(n^2+1) `div` 2, (n^2-1) `div` 2]
        | even n = [n^2 `div` 4 + 1, n^2 `div` 4 - 1]

module Main where
  import Data.List
  import Control.Monad
  import Data.Array

  toArray :: [a] -> Array Int a
  toArray xs =
    let ls = length xs - 1
        in array (0, ls) $ zip [0..ls] xs

  readInteger :: String -> Integer
  readInteger s = read s :: Integer

  readMultilineInput :: Int -> (String -> IO a) -> IO [a]
  readMultilineInput n transformer = replicateM n (getLine >>= transformer)

  pythagorasOf :: Integer -> Maybe (Integer, Integer)
  pythagorasOf x
    | x == 1 = Nothing
    | x == 2 = Nothing
    | x == 4 = Just (3, 5)
    | x `mod` 4 == 0 =
      let y = (x `div` 4) -1
          y1 = (y * x) + (x - 1)
          in return (y1, y1 + 2)
    | x `mod` 4 == 2 = do
       (a, b) <- pythagorasOf (x `div` 2)
       return (a * 2, b * 2)
    | x `mod` 2 == 1 =
      let y = x `div` 2
          y1 = (y * x) + y
          in return (y1, y1 + 1)

  strify :: Maybe (Integer, Integer) -> String
  strify Nothing = "-1"
  strify (Just (x, y)) = show x ++ " " ++ show y

  main :: IO()
  main = do
    x <- getLine >>= return . readInteger
    putStrLn $ strify$ pythagorasOf x

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

readIntList = fmap ((map fn) . B.words) B.getLine :: IO [Int64]
 where fn x = let Just (y,_) = B.readInt x in fromIntegral y

search :: Int64 -> Int64 -> Int64 -> Int64
search x l h = if l>=h then -1
                else if diff == x then m
                else if diff<x then search x (m+1) h else search x l m
                    where m = (l+h) `div` 2
                          diff = (m+1)^2 - m^2

pfactor 6 _ = 3
pfactor n [] = n
pfactor n (i:is)
 |n `rem` i == 0 = i
 |otherwise = pfactor n is

main = do
    [n] <- readIntList
    if n <= 2 then print (-1)
    else do
        if n `rem` 4 == 0 then do
            let x = n `div` 4
            putStrLn . unwords . map show $ [3*x,5*x]
        else do
            let a = pfactor n [3,5..(round . sqrt . fromIntegral $ n)]
                mult = n `div` a
                b = search (a^2) 1 (round (1e18))
            putStrLn . unwords . map show $ [b*mult,(b+1)*mult]

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

readIntList = fmap ((map fn) . B.words) B.getLine :: IO [Int64]
 where fn x = let Just (y,_) = B.readInt x in fromIntegral y

search :: Int64 -> Int64 -> Int64 -> Int64
search x l h = if l>=h then -1
                else if diff == x then m
                else if diff<x then search x (m+1) h else search x l m
                    where m = (l+h) `div` 2
                          diff = (m+1)^2 - m^2

pfactor n [] = n
pfactor n (i:is)
 |n `rem` i == 0 = i
 |otherwise = pfactor n is

main = do
    [n] <- readIntList
    if n <= 2 then print (-1)
    else do
        if n `rem` 4 == 0 then do
            let x = n `div` 4
            putStrLn . unwords . map show $ [3*x,5*x]
        else do
            let a = pfactor n [3,5..(round . sqrt . fromIntegral $ n)]
                mult = n `div` a
                b = search (a^2) 1 (round (1e18))
            putStrLn . unwords . map show $ [b*mult,(b+1)*mult]

main = interact $ g.f
f x = read x :: Int
g x
  | x <= 2 = "-1"
  | odd x = (show j) ++ " " ++ (show (floor (sqrt (fromIntegral i))))
  | otherwise = (show a) ++ " " ++ (show (a+2))
  where j = ((x^2 + 1) `div` 2)
        i = j^2 - x^2
        a = (x `div` 2)^2 -1

main = interact $ g.f
f x = read x :: Int
g x
  | x <= 2 = "-1"
  | odd x = (show j) ++ " " ++ (show (floor (sqrt (fromIntegral i))))
  | otherwise = (show a) ++ " " ++ (show (floor (sqrt (fromIntegral b))))
  where j = ((x^2 + 1) `div` 2)
        i = j^2 - x^2
        a = (x `div` 2)^2 -1
        b = a + 2

main = interact $ g.f
f x = read x :: Int
g x
  | x <= 2 = "-1"
  | odd x = (show j) ++ " " ++ (show (floor (sqrt (fromIntegral i))))
  | otherwise = (show a) ++ " " ++ (show (floor (sqrt (fromIntegral b))))
  where j = ((x^2 + 1) `div` 2)
        i = j^2 - x^2
        a = ((x^2 + 4) `div` 4)
        b = a^2 - x^2

main = interact $ g.f
f x = read x :: Integer
g x
  | x <= 2 = "-1"
  | odd x = (show (floor (sqrt (fromIntegral j)))) ++ " " ++ (show (floor (sqrt (fromIntegral i))))
  | otherwise = (show (floor (sqrt (fromIntegral a)))) ++ " " ++ (show (floor (sqrt (fromIntegral b))))
  where j = ((x^2 + 1) `div` 2)^2
        i = j - x^2
        a = ((x^2 + 4) `div` 4)^2
        b = a - x^2

main = interact $ h.f
f x = read x :: Integer
h x
  | x <= 2 = "-1"
  | odd x = (show j) ++ " " ++ (show (floor (sqrt (fromIntegral i))))
  | otherwise = (show a) ++ " " ++ (show (floor (sqrt (fromIntegral b))))
  where j = ((x^2 + 1) `div` 2)
        i = j^2 - x^2
        a = ((x^2 + 4) `div` 4)
        b = a^2 - x^2

main = interact $ g.f
f x = read x :: Integer
g x
  | x <= 2 = "-1"
  | odd x = (show j) ++ " " ++ (show (floor (sqrt (fromIntegral i))))
  | otherwise = (show a) ++ " " ++ (show (a+2))
  where j = ((x^2 + 1) `div` 2)
        i = j^2 - x^2
        a = (x `div` 2)^2 -1

{-# OPTIONS_GHC -O2 #-}
import Data.Int (Int64)
import Data.List (genericLength)

main = do
  a <- readLn :: IO Integer

  let
    k = (head $ dropWhile even $ iterate (`div` 2) a) `div` 2
    m = 2*2 ^ (genericLength $ takeWhile even $ iterate (`div` 2) a)
    (b, c) = (m*k^2 + m*k + (m`div`2), m*k^2 + m*k)

  if a == 1 || a == 2
     then print $ -1
     else if a == 4
       then putStrLn "3 5"
       else putStrLn $ show b ++ " " ++ show c

{-# OPTIONS_GHC -O2 #-}
import Data.Int (Int64)
import Data.List (genericLength)

main = do
  a <- readLn :: IO Int64

  let
    k = (head $ dropWhile even $ iterate (`div` 2) a) `div` 2
    m = 2*2 ^ (genericLength $ takeWhile even $ iterate (`div` 2) a)
    (b, c) = (m*k^2 + m*k + (m`div`2), m*k^2 + m*k)

  if a == 1 || a == 2
     then print $ -1
     else if a == 4
       then putStrLn "3 5"
       else putStrLn $ show b ++ " " ++ show c

{-# LANGUAGE TypeApplications #-}

main :: IO ()
main = do
  n <- read @ Integer <$> getLine
  let (m, k) = solve n
  putStrLn $ if n == 1 then "-1" else show m ++ " " ++ show k

solve :: Integer -> (Integer, Integer)
solve n | odd n = let root1 = (n - 1) `div` 2
                      root2 = succ root1
                  in (2 * root1 * root2, root1 * root1 + root2 * root2)
solve n | even n = let root = n `div` 2
                   in (root * root - 1, root * root + 1)

module Main where
  import Data.List
  import Control.Monad
  import Data.Array

  toArray :: [a] -> Array Int a
  toArray xs =
    let ls = length xs - 1
        in array (0, ls) $ zip [0..ls] xs

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

  readMultilineInput :: Int -> (String -> IO a) -> IO [a]
  readMultilineInput n transformer = replicateM n (getLine >>= transformer)

  data Coordinat = Coordinat { x :: Int, y :: Int } deriving (Show, Eq)
  data Taxi = Taxi { coordinat :: Coordinat, speed :: Int } deriving (Show, Eq)

  mkTaxi :: String -> Taxi
  mkTaxi s =
    let [xi, yi, vi] = map readInt $ words s
        in Taxi (Coordinat xi yi) vi

  mkCoordinat :: [Int] -> Coordinat
  mkCoordinat [x,y] = Coordinat x y

  distance :: Floating a => Coordinat -> Coordinat -> a
  distance (Coordinat p q) (Coordinat x y) =
    let dx = fromIntegral $ p - x
        dy = fromIntegral $ q - y
        in (sqrt $ dx * dx + dy * dy)

  timeToArrive :: Floating a => Coordinat -> Taxi -> a
  timeToArrive co1@(Coordinat _ _) (Taxi co2@(Coordinat _ _) v) = (distance co1 co2) / (fromIntegral v)

  pythagorasOf :: Int -> Maybe (Int, Int)
  pythagorasOf x
    | x == 1 = Nothing
    | x == 2 = Nothing
    | x == 4 = Just (3, 5)
    | x `mod` 4 == 0 =
      let y = (x `div` 4) -1
          y1 = (y * x) + (x - 1)
          in return (y1, y1 + 2)
    | x `mod` 4 == 2 = do
       (a, b) <- pythagorasOf (x `div` 2)
       return (a * 2, b * 2)
    | x `mod` 2 == 1 =
      let y = x `div` 2
          y1 = (y * x) + y
          in return (y1, y1 + 1)

  strify :: Maybe (Int, Int) -> String
  strify Nothing = "-1"
  strify (Just (x, y)) = show x ++ " " ++ show y

  main :: IO()
  main = do
    x <- getLine >>= return . readInt
    putStrLn $ strify$ pythagorasOf x

    -- [x,y] <- getLine >>= return . (map readInt) . words
    -- n <- getLine >>= return . readInt
    -- taxis <- readMultilineInput n $ return . mkTaxi
    -- putStrLn $ show $ minimum $ map (timeToArrive (Coordinat x y)) taxis

module Main where

import Control.Monad
import Prelude
import Text.Printf

solve :: Int -> (Int, Int)
solve n | n <= 2    = (-1, -1)
        | odd n     = ((x + 1) `div` 2, (x + 1) `div` 2 - 1)
        | otherwise = ((x `div` 4) + 1, (x `div` 4) - 1)
        where x = n * n

main = do
    n <- liftM read getLine
    let (a, b) = solve n
    if a < 0 then printf "%d\n" a
    else printf "%d %d\n" a b

main = interact $ printRes . sol . read
    where
    printRes [] = "-1"
    printRes [a, b] = show a ++ " " ++ show b

sol :: Integer -> [Integer]
sol n
    | n == 1 = []
    | n `mod` 2 == 0 = map (*2) $ sol (n `div` 2)
    | otherwise = [2*k*k + 2*k, 2*k*k + 2*k + 1]
    where
    k = (n-1) `div` 2


import Control.Monad

main :: IO ()
main = do
  t <- readLn
  replicateM_ t routine

routine :: IO ()
routine = do
  n <- readLn
  print $ (n `div` 2)

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

main=interact$unlines.map(show.(`div`2).read).tail.words

main = interact $ unlines . map (show . (flip div 2) . read) . tail . words

cardProd :: [a] -> [b] -> [(a,b)]
cardProd xs ys = [(x,y) | x<-xs, y<-ys]

solve :: Integer -> Integer
--solve n = foldr max 0 . map ( uncurry gcd) . filter (\(a,b)-> a<b) . cardProd [1..n] $ [1..n]
solve n = div n 2

parse :: String -> Integer
parse = read . head . words

solveCase :: Int -> IO()
solveCase 0 = return ()
solveCase t = do
  test <- getLine
  putStrLn . show . solve . parse  $ test
  solveCase (t-1)

getInt :: IO Int
getInt = fmap read getLine

main :: IO()
main = do
  n <- getInt
  solveCase n

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

process a = div a 2

main = do
		n<-read <$> getLine ::IO Int
		a<- map read <$> replicateM n getLine ::IO [Int]
		mapM_ print $ map  process a


import qualified Data.Map.Strict as M
import Control.Arrow
import Data.List

factorsK :: Int -> Int -> [(Int, Int)]
factorsK k = filter ((/=0) . snd) . map (head &&& (`mod` k) . length) . group . go [] 2
  where
    go a c n
      | c * c > n = if n /= 1 then n:a else a
      | n `rem` c == 0 = go (c:a) c (n `div` c)
      | otherwise = go a (c + 1) n

folder k (hist, cnt) n = (M.insertWith (+) fcs 1 hist, cnt + M.findWithDefault 0 fi hist)
  where fcs = factorsK k n
        fi = filter ((/=0) . snd) $ map (\(f, c) -> (f, k - c)) fcs

rl = map read . words <$> getLine

main = do
  [_, k] <- rl
  inp <- rl

  print $ snd $ foldl' (folder k) (M.empty, 0) inp

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IM
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
-- import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
{-
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
-}
import Control.Monad
import Control.Monad.ST
import Control.Monad.ST.Lazy (strictToLazyST, lazyToStrictST)
import qualified Control.Monad.ST.Lazy as STL
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import Data.Word
import Data.STRef
import Data.IORef
import Data.Function
import System.IO
import System.Exit
import Data.Char
import Data.Semigroup
import Data.Monoid

aMax = 100000 :: Int

aMax64 = fromIntegral aMax :: Int64

main :: IO ()
main = do
  [n,k] <- map readInt . words <$> getLine
  as <- unfoldr (runStateT rIntS) <$> BS.getLine
  print $ query k as

maxPowerable :: UArray Int Int64
maxPowerable = A.array (1,100)
  $ [(1,100000),(2,316),(3,46),(4,17),(5,10),(6,6),(7,5),(8,4),(9,3),(10,3)]
  ++ map (,2) [11..16]
  ++ map (,1) [17..100]

corrPair :: Int -> Int -> Maybe (Int,Int)
corrPair k v_ = (\(x,y) -> (fromIntegral x, fromIntegral y))
  <$> foldM (\ (!red,!compl) (!p,!e) -> do
                let eRed = e `rem` k
                    eRev | eRed == 0 = 0
                         | otherwise = k-eRed
                guard $ eRev == 0 || p <= maxPowerable A.! eRev
                let !redNew   = red * p ^ eRed
                    !complNew = compl * p ^ eRev
                guard $ complNew <= aMax64
                return (redNew,complNew))
               (1::Int64,1::Int64)
               (primeDecp v)
   where v = fromIntegral v_

data DictElement
  = DE {-# UNPACK #-} !Int64 {-# UNPACK #-} !Int64
  | Same {-# UNPACK #-} !Int64

instance Semigroup DictElement where
  DE cntThis1 cntCompl1 <> DE cntThis2 cntCompl2
    = DE (cntThis1+cntThis2) (cntCompl1+cntCompl2)
  Same l0 <> Same l1 = Same (l0+l1)
  _ <> _ = undefined

query :: Int -> [Int] -> Int64
query k as = sum $ map match $ IM.elems dict
  where
    match (DE x y) = x*y
    match (Same x) = (x*x-x) `shiftR` 1
    dict
      = foldl'
        (\ !dict !a ->
           maybe dict
           (\(!red,!compl) ->
              case compare red compl of
                EQ -> IM.insertWith (<>) red (Same 1) dict
                LT -> IM.insertWith (<>) red (DE 1 0) dict
                GT -> IM.insertWith (<>) compl (DE 0 1) dict)
           $ corrPair k a)
        IM.empty
        as

#define IL(f) {-# INLINE f #-}; f

rInt :: StateT BSL.ByteString Maybe Int
IL(rInt) = StateT $ BSL.readInt . BSL.dropWhile (<'!')
rIntS :: StateT BS.ByteString Maybe Int
IL(rIntS) = StateT $ BS.readInt . BS.dropWhile (<'!')

primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,
          71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,
          151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,
          233,239,241,251,257,263,269,271,277,281,283,293,307,311,313]

primeDecp :: (Integral i, FiniteBits i) => i -> [(i,Int)]
primeDecp !n = (\f -> f (:)[]) $ \cons nil ->
  let !expt2 = countTrailingZeros n
      nDiv2 = n `unsafeShiftR` expt2
      start a | a > 1 = go (tail primes) a
              | otherwise = nil
      {-# INLINE start #-}
      go (!p:ps) !a | r == 0    = goExpt p ps q 1
                    | q > p     = go ps a
                    | otherwise = cons (a,1) nil
        where (!q,!r) = a `quotRem` p
      go [] !a | a == 1    = nil
               | otherwise = cons (a,1) nil
      goExpt !p ps 1 !j = cons (p,j) nil
      goExpt !p ps !a !j
        | r == 0    = goExpt p ps q (j+1)
        | otherwise = cons (p,j) $ if q > p then go ps a
                                            else cons (a,1) nil
        where (!q,!r) = a `quotRem` p
  in if expt2 /= 0 then cons (2,expt2) $ start nDiv2 else start n

-- unlessM, whenM :: (Monad m) => m Bool -> m () -> m ()
IL(whenM) = (. flip when) . (>>=)
IL(unlessM) = (. flip unless) . (>>=)

IL(wrA) = A.writeArray
IL(rdA) = A.readArray
IL(mdA) = \arr f !i -> do
  ai <- rdA arr i
  let fai = f ai
  wrA arr i fai
  return (ai,fai)
{-# INLINE mdA' #-}
mdA' = \arr f !i -> do
  !ai <- rdA arr i
  let !fai = f ai
  wrA arr i fai
  return (ai,fai)
IL(swapA) = \arr !i !j -> do
  ai <- rdA arr i
  wrA arr i =<< rdA arr j
  wrA arr j ai

#define D(f,r,d)\
  IL(f) :: Integral a=>a->d; f=fromIntegral;\
  IL(r) :: String->d; r=read
#define C(f,r,g,h,d) D(f,r,d);\
  g,h :: RealFrac a=>a->d; IL(g)=floor; IL(h)=ceiling
C(_toInteger_,readInteger,floorInteger,ceilInteger,Integer)
C(toInt,readInt,floorInt,ceilInt,Int)
C(toI8,readI8,floorI8,ceilI8,Int8)
C(toI16,readI16,floorI16,ceilI16,Int16)
C(toI32,readI32,floorI32,ceilI32,Int32)
C(toI64,readI64,floorI64,ceilI64,Int64)
C(toWord,readWord,floorWord,ceilWord,Word)
C(toW8,readW8,floorW8,ceilW8,Word8)
C(toW16,readW16,floorW16,ceilW16,Word16)
C(toW32,readW32,floorW32,ceilW32,Word32)
C(toW64,readW64,floorW64,ceilW64,Word64)
D(toDouble,readDouble,Double)
D(toFloat,readFloat,Float)
#undef D
#undef C

#define N(f,g,h,a,m)\
  IL(f) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> e -> m (a i e);\
  f=A.newArray;\
  IL(g) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> m (a i e);\
  g=A.newArray_;\
  IL(h) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> [e] -> m (a i e);\
  h=A.newListArray
#define C(a,m)
N(newIOA,newIOA_,newIOAL,IOArray,IO)
N(newSTA,newSTA_,newSTAL,STArray s,ST s)
#undef C
#define C(a,m) MArray (a) e (m),
N(newIOUA,newIOUA_,newIOUAL,IOUArray,IO)
N(newSTUA,newSTUA_,newSTUAL,STUArray s,ST s)
#undef C
#undef N

#undef IL

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IM
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
-- import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
{-
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
-}
import Control.Monad
import Control.Monad.ST
import Control.Monad.ST.Lazy (strictToLazyST, lazyToStrictST)
import qualified Control.Monad.ST.Lazy as STL
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import Data.Word
import Data.STRef
import Data.IORef
import Data.Function
import System.IO
import System.Exit
import Data.Char
import Data.Semigroup
import Data.Monoid

aMax = 100000 :: Int

aMax64 = fromIntegral aMax :: Int64

main :: IO ()
main = do
  [n,k] <- map readInt . words <$> getLine
  as <- unfoldr (runStateT rIntS) <$> BS.getLine
  print $ query k as

maxPowerable :: UArray Int Int64
maxPowerable = A.array (1,100)
  $ [(1,100000),(2,316),(3,46),(4,17),(5,10),(6,6),(7,5),(8,4),(9,3),(10,3)]
  ++ map (,2) [11..16]
  ++ map (,1) [17..100]

corrPair :: Int -> Int -> Maybe (Int,Int)
corrPair k v_ = (\(x,y) -> (fromIntegral x, fromIntegral y))
  <$> foldM (\ (!red,!compl) (!p,!e) -> do
                let eRed = e `rem` k
                    eRev | eRed == 0 = 0
                         | otherwise = k-eRed
                guard $ eRev == 0 || p <= maxPowerable A.! eRev
                let !redNew   = red * p ^ eRed
                    !complNew = compl * p ^ eRev
                guard $ complNew <= aMax64
                return (redNew,complNew))
               (1::Int64,1::Int64)
               (primeDecp v)
   where v = fromIntegral v_

data DictElement
  = DE {-# UNPACK #-} !Int64 {-# UNPACK #-} !Int64
  | Same {-# UNPACK #-} !Int64

instance Semigroup DictElement where
  DE cntThis1 cntCompl1 <> DE cntThis2 cntCompl2
    = DE (cntThis1+cntThis2) (cntCompl1+cntCompl2)
  Same l0 <> Same l1 = Same (l0+l1)
  _ <> _ = undefined

query :: Int -> [Int] -> Int64
query k as
  | k >= 34 = let x = fromIntegral $ length $ elemIndices 1 $ as :: Int64
              in shiftR (x*(x-1)) 1
  | otherwise = sum $ map match $ IM.elems dict
  where
    match (DE x y) = x*y
    match (Same x) = x * (x-1) `shiftR` 1
    dict
      = foldl'
        (\ !dict !a ->
           maybe dict
           (\(!red,!compl) ->
              case compare red compl of
                EQ -> IM.insertWith (<>) red (Same 1) dict
                LT -> IM.insertWith (<>) red (DE 1 0) dict
                GT -> IM.insertWith (<>) compl (DE 0 1) dict)
           $ corrPair k a)
        IM.empty
        as

#define IL(f) {-# INLINE f #-}; f

rInt :: StateT BSL.ByteString Maybe Int
IL(rInt) = StateT $ BSL.readInt . BSL.dropWhile (<'!')
rIntS :: StateT BS.ByteString Maybe Int
IL(rIntS) = StateT $ BS.readInt . BS.dropWhile (<'!')

primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,
          71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,
          151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,
          233,239,241,251,257,263,269,271,277,281,283,293,307,311,313]

primeDecp :: (Integral i, FiniteBits i) => i -> [(i,Int)]
primeDecp !n = (\f -> f (:)[]) $ \cons nil ->
  let !expt2 = countTrailingZeros n
      nDiv2 = n `unsafeShiftR` expt2
      start a | a > 1 = go (tail primes) a
              | otherwise = nil
      {-# INLINE start #-}
      go (!p:ps) !a | r == 0    = goExpt p ps q 1
                    | q > p     = go ps a
                    | otherwise = cons (a,1) nil
        where (!q,!r) = a `quotRem` p
      goExpt !p ps 1 !j = cons (p,j) nil
      goExpt !p ps !a !j
        | r == 0    = goExpt p ps q (j+1)
        | otherwise = cons (p,j) $ if q > p then go ps a
                                            else cons (a,1) nil
        where (!q,!r) = a `quotRem` p
  in if expt2 /= 0 then cons (2,expt2) $ start nDiv2 else start n

-- unlessM, whenM :: (Monad m) => m Bool -> m () -> m ()
IL(whenM) = (. flip when) . (>>=)
IL(unlessM) = (. flip unless) . (>>=)

IL(wrA) = A.writeArray
IL(rdA) = A.readArray
IL(mdA) = \arr f !i -> do
  ai <- rdA arr i
  let fai = f ai
  wrA arr i fai
  return (ai,fai)
{-# INLINE mdA' #-}
mdA' = \arr f !i -> do
  !ai <- rdA arr i
  let !fai = f ai
  wrA arr i fai
  return (ai,fai)
IL(swapA) = \arr !i !j -> do
  ai <- rdA arr i
  wrA arr i =<< rdA arr j
  wrA arr j ai

#define D(f,r,d)\
  IL(f) :: Integral a=>a->d; f=fromIntegral;\
  IL(r) :: String->d; r=read
#define C(f,r,g,h,d) D(f,r,d);\
  g,h :: RealFrac a=>a->d; IL(g)=floor; IL(h)=ceiling
C(_toInteger_,readInteger,floorInteger,ceilInteger,Integer)
C(toInt,readInt,floorInt,ceilInt,Int)
C(toI8,readI8,floorI8,ceilI8,Int8)
C(toI16,readI16,floorI16,ceilI16,Int16)
C(toI32,readI32,floorI32,ceilI32,Int32)
C(toI64,readI64,floorI64,ceilI64,Int64)
C(toWord,readWord,floorWord,ceilWord,Word)
C(toW8,readW8,floorW8,ceilW8,Word8)
C(toW16,readW16,floorW16,ceilW16,Word16)
C(toW32,readW32,floorW32,ceilW32,Word32)
C(toW64,readW64,floorW64,ceilW64,Word64)
D(toDouble,readDouble,Double)
D(toFloat,readFloat,Float)
#undef D
#undef C

#define N(f,g,h,a,m)\
  IL(f) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> e -> m (a i e);\
  f=A.newArray;\
  IL(g) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> m (a i e);\
  g=A.newArray_;\
  IL(h) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> [e] -> m (a i e);\
  h=A.newListArray
#define C(a,m)
N(newIOA,newIOA_,newIOAL,IOArray,IO)
N(newSTA,newSTA_,newSTAL,STArray s,ST s)
#undef C
#define C(a,m) MArray (a) e (m),
N(newIOUA,newIOUA_,newIOUAL,IOUArray,IO)
N(newSTUA,newSTUA_,newSTUAL,STUArray s,ST s)
#undef C
#undef N

#undef IL

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IM
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
-- import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
{-
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
-}
import Control.Monad
import Control.Monad.ST
import Control.Monad.ST.Lazy (strictToLazyST, lazyToStrictST)
import qualified Control.Monad.ST.Lazy as STL
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import Data.Word
import Data.STRef
import Data.IORef
import Data.Function
import System.IO
import System.Exit
import Data.Char
import Data.Semigroup
import Data.Monoid

aMax = 100000 :: Int

aMax64 = fromIntegral aMax :: Int64

main :: IO ()
main = do
  [n,k] <- map readInt . words <$> getLine
  as <- unfoldr (runStateT rIntS) <$> BS.getLine
  print $ query k as

maxPowerable :: UArray Int Int64
maxPowerable = A.array (1,100)
  $ [(1,100000),(2,316),(3,46),(4,17),(5,10),(6,6),(7,5),(8,4),(9,3),(10,3)]
  ++ map (,2) [11..16]
  ++ map (,1) [17..100]

corrPair :: Int -> Int -> Maybe (Int,Int)
corrPair k v_ = (\(x,y) -> (fromIntegral x, fromIntegral y))
  <$> foldM (\ (!red,!compl) (!p,!e) -> do
                let eRed = e `rem` k
                    eRev | eRed == 0 = 0
                         | otherwise = k-eRed
                guard $ eRev == 0 || p <= maxPowerable A.! eRev
                let !redNew   = red * p ^ eRed
                    !complNew = compl * p ^ eRev
                guard $ complNew <= aMax64
                return (redNew,complNew))
               (1::Int64,1::Int64)
               (primeDecp v)
   where v = fromIntegral v_

data DictElement
  = DE {-# UNPACK #-} !Int64 {-# UNPACK #-} !Int64
  | Same {-# UNPACK #-} !Int64

instance Semigroup DictElement where
  DE cntThis1 cntCompl1 <> DE cntThis2 cntCompl2
    = DE (cntThis1+cntThis2) (cntCompl1+cntCompl2)
  Same l0 <> Same l1 = Same (l0+l1)
  _ <> _ = undefined

query :: Int -> [Int] -> Int64
query k as = sum $ map match $ IM.elems dict
  where
    match (DE x y) = x*y
    match (Same x) = x * (x-1) `shiftR` 1
    dict
      = foldl'
        (\ !dict !a ->
           maybe dict
           (\(!red,!compl) ->
              case compare red compl of
                EQ -> IM.insertWith (<>) red (Same 1) dict
                LT -> IM.insertWith (<>) red (DE 1 0) dict
                GT -> IM.insertWith (<>) compl (DE 0 1) dict)
           $ corrPair k a)
        IM.empty
        as

#define IL(f) {-# INLINE f #-}; f

rInt :: StateT BSL.ByteString Maybe Int
IL(rInt) = StateT $ BSL.readInt . BSL.dropWhile (<'!')
rIntS :: StateT BS.ByteString Maybe Int
IL(rIntS) = StateT $ BS.readInt . BS.dropWhile (<'!')

primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,
          71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,
          151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,
          233,239,241,251,257,263,269,271,277,281,283,293,307,311,313]

primeDecp :: (Integral i, FiniteBits i) => i -> [(i,Int)]
primeDecp !n = (\f -> f (:)[]) $ \cons nil ->
  let !expt2 = countTrailingZeros n
      nDiv2 = n `unsafeShiftR` expt2
      start a | a > 1 = go (tail primes) a
              | otherwise = nil
      {-# INLINE start #-}
      go (!p:ps) !a | r == 0    = goExpt p ps q 1
                    | q > p     = go ps a
                    | otherwise = cons (a,1) nil
        where (!q,!r) = a `quotRem` p
      goExpt !p ps 1 !j = cons (p,j) nil
      goExpt !p ps !a !j
        | r == 0    = goExpt p ps q (j+1)
        | otherwise = cons (p,j) $ if q > p then go ps a
                                            else cons (a,1) nil
        where (!q,!r) = a `quotRem` p
  in if expt2 /= 0 then cons (2,expt2) $ start nDiv2 else start n

-- unlessM, whenM :: (Monad m) => m Bool -> m () -> m ()
IL(whenM) = (. flip when) . (>>=)
IL(unlessM) = (. flip unless) . (>>=)

IL(wrA) = A.writeArray
IL(rdA) = A.readArray
IL(mdA) = \arr f !i -> do
  ai <- rdA arr i
  let fai = f ai
  wrA arr i fai
  return (ai,fai)
{-# INLINE mdA' #-}
mdA' = \arr f !i -> do
  !ai <- rdA arr i
  let !fai = f ai
  wrA arr i fai
  return (ai,fai)
IL(swapA) = \arr !i !j -> do
  ai <- rdA arr i
  wrA arr i =<< rdA arr j
  wrA arr j ai

#define D(f,r,d)\
  IL(f) :: Integral a=>a->d; f=fromIntegral;\
  IL(r) :: String->d; r=read
#define C(f,r,g,h,d) D(f,r,d);\
  g,h :: RealFrac a=>a->d; IL(g)=floor; IL(h)=ceiling
C(_toInteger_,readInteger,floorInteger,ceilInteger,Integer)
C(toInt,readInt,floorInt,ceilInt,Int)
C(toI8,readI8,floorI8,ceilI8,Int8)
C(toI16,readI16,floorI16,ceilI16,Int16)
C(toI32,readI32,floorI32,ceilI32,Int32)
C(toI64,readI64,floorI64,ceilI64,Int64)
C(toWord,readWord,floorWord,ceilWord,Word)
C(toW8,readW8,floorW8,ceilW8,Word8)
C(toW16,readW16,floorW16,ceilW16,Word16)
C(toW32,readW32,floorW32,ceilW32,Word32)
C(toW64,readW64,floorW64,ceilW64,Word64)
D(toDouble,readDouble,Double)
D(toFloat,readFloat,Float)
#undef D
#undef C

#define N(f,g,h,a,m)\
  IL(f) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> e -> m (a i e);\
  f=A.newArray;\
  IL(g) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> m (a i e);\
  g=A.newArray_;\
  IL(h) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> [e] -> m (a i e);\
  h=A.newListArray
#define C(a,m)
N(newIOA,newIOA_,newIOAL,IOArray,IO)
N(newSTA,newSTA_,newSTAL,STArray s,ST s)
#undef C
#define C(a,m) MArray (a) e (m),
N(newIOUA,newIOUA_,newIOUAL,IOUArray,IO)
N(newSTUA,newSTUA_,newSTUAL,STUArray s,ST s)
#undef C
#undef N

#undef IL


{- written by MarekCerny.com -}
{-# LANGUAGE ViewPatterns, PatternSynonyms  #-}
{-# LANGUAGE TupleSections                  #-}
{-# LANGUAGE UnicodeSyntax                  #-}
{-# LANGUAGE LambdaCase, MultiWayIf         #-}
import Data.Tuple
import Data.Bits
import Data.Maybe
import Data.Function
import Data.List
import Control.Exception
import qualified Data.HashMap.Strict as M
import Data.Sequence (Seq, (|>), (<|), (><))
import qualified Data.Sequence as S

main = interact $ unlines . sol . allInt . lines

sol :: [[Int]] -> [String]
sol [_,xs] = let
    m = minimum xs
    in
     wrap.show $ minimum $ diffs $ map fst $ filter ((m==).snd) $ zip [0..] xs

diffs [_] = []
diffs []  = []
diffs (x:y:xs) = abs (x-y) : diffs (y:xs)

--------------------------------------------------------------------------------
groupOn :: Int -> [a] -> [[a]]
groupOn _ [] = []
groupOn n xs = let (sts, nds) = splitAt n xs in sts : groupOn n nds

fromBool :: Num a => Bool -> a
fromBool b = if b then 1 else 0

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

swrt :: Ord a => (a, a) -> (a, a)
swrt (a, b) | compare b a == LT = (b, a) | otherwise = (a, b)

wrap :: a -> [a]
wrap x = [x]

toSnd :: a->b-> (a,b)
toSnd x y = (x,y)

toFst :: b->a-> (a,b)
toFst y x = (x,y)

addCnt :: [String] -> [String]
addCnt ls = (show $ length ls) : ls

toBitMap :: Int -> [(Int, Bool)]
toBitMap = toBitMap' 31
  where
    toBitMap' (-1) _ = []
    toBitMap' n v = (n, v .&. (1`shiftL`n) > 0) : toBitMap' (n-1) v
--------------------------------------------------------------------------------
pattern Empty   <- (S.viewl -> S.EmptyL)
pattern x :< xs <- (S.viewl -> x S.:< xs)
pattern xs :> x <- (S.viewr -> xs S.:> x)
--------------------------------------------------------------------------------

module Main where

import Control.Applicative
import Control.Monad

minIndices :: [Int] -> [Int]
minIndices xs = map fst . filter isMin $ zip [1 ..] xs
    where minx = minimum xs
          isMin (_, x) = x == minx

diffs :: [Int] -> [Int]
diffs xs = zipWith (-) (tail xs) (init xs)

solve :: [Int] -> Int
solve = minimum . diffs . minIndices

test0 = [3, 3] :: [Int]
test1 = [5, 6, 5] :: [Int]
test2 = [2, 1, 3, 5, 4, 1, 2, 3, 1] :: [Int]

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

import Data.List
import Data.Function
main = getLine >> getLine >>= print . minimum . (\xs@(_:xs') -> zipWith (\a b -> abs $ a - b) xs xs') . map snd . head . groupBy ((==) `on` fst) . sort . flip zip [(0 :: Int)..] . map (read :: String -> Int) . words

-- Codeforces 911A

{-# OPTIONS_GHC -O0 #-}
{-# OPTIONS_GHC -optc-O0 #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-}

import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as BC
import Data.List
import Data.Maybe

main :: IO ()
main = do
    (n:ns) <- (map (fst . fromJust . BC.readInt) . BC.words) <$> BC.getContents :: IO [Int]
    let a = minimum ns
        indices = elemIndices a ns
        diff = zipWith (-) (tail indices) indices
        ans = minimum diff
    print ans

import Data.List

main = do
    _ <- getLine
    inputLines <- fmap words getLine
    let intList = map read inputLines :: [Int]
    print $ distance $ elemIndices (minimum intList) intList

distance [] = maxBound
distance [_] = maxBound
distance (x:y:xs)
    | (abs (x - y)) > (distance $ y:xs) = distance $ y:xs
    | otherwise = abs (x - y)

import Control.Applicative
import Control.Arrow
import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.Maybe

main = sol <$> (C.getLine *> get) >>= print

get = fmap fst . mapMaybe C.readInt . C.words <$> C.getLine

sol =  mds . fmap fst . mis
    where
    mds = minimum . uncurry (zipWith (-)) <<< tail &&& id
    mis = (\m -> filter ((m==) . snd)) <$> minimum <*> zip ([0..]::[Int])

import Control.Applicative
import Control.Monad
import qualified Data.Map.Strict as M
import qualified Data.ByteString.Char8 as C
import Data.Maybe

main = sol <$> (C.getLine *> get) >>= print

get = fmap fst . mapMaybe C.readInt . C.words <$> C.getLine

sol as = minimum $ minimum <$> ds
    where
    mp = M.filter ((>1) . length) . M.fromListWith (++) $ zipWith (\a i -> (a,[i])) as [0..]
    ds = (\bs -> zipWith (-) bs (tail bs)) . snd <$> M.toList mp


import Control.Monad (liftM, replicateM)
import Data.Char (ord)
import Data.List (intercalate)

solve :: [Int] -> [Int]
solve [n, k]
  | 3 * k > n  =  [-1]
  | otherwise  =  take n (k : [1..k-1] ++ cycle [1..k])

main :: IO ()
main  =  reads >>= prints . solve

  where

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

    readPair :: Num a => IO (a, a)
    readPair  =  do
        [a, b]  <-  reads
        return (a, b)

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

main = interact (unwords . map show . (\[n, k] -> ans k n) . map read . words)

ans :: Int -> Int -> [Int]
ans k n = if 3*k > n then [-1] else gen k
  where
    gen 3 = [3, 3, 2, 3, 2, 1, 1, 2, 1] ++ replicate (n - 3*k) 1
    gen 2 = [2, 2, 1, 2, 1, 1]          ++ replicate (n - 3*k) 1
    gen x = [x, x, x-1, x, x-1, x-1]    ++ gen (x-2)

{-# OPTIONS_GHC -O2 #-}
main=interact$unwords.map show.f.map read.words
f[n,k]
  | n `div` k < 3 = [-1]
  | even k = take n $ cycle ([1..k] ++ [k,k-1..1])
  | otherwise = (take (n-1) $ k:k:cycle ([1..k-1] ++ [k-1,k-2..1]))++[k]


import Data.List
main=print.g.f.reverse.sort.map read.tail.words=<<getContents
f(x:y:zs)|x-y>1=f(y:zs)|0<1=y:f zs;f _=[]
g(x:y:zs)=x*y+g zs;g _=0

import Data.List (group, sort)
import Data.Int (Int64)
import Data.Bits ((.&.))
import Control.Applicative ((<$>), liftA)
import Data.ByteString (ByteString)
import Control.Monad (replicateM, sequence)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C8

press :: [(Int64, Int)] -> [(Int64, Int64)]
press ((l, n):(l', n'):rest)
    | l == l' + 1 && n .&. 1 == 1 = (l, n'' - 1):press ((l', n' + 1):rest)
    | otherwise = (l, n''): press ((l', n'):rest)
    where n'' = fromIntegral n :: Int64
press [(l, n)] = [(l, fromIntegral n)]

area :: Int64 -> [(Int64, Int64)] -> Int64
area acc [] = acc
area acc ((l, n):rest)
    | 3 < n = area (acc + (n `div` 4) * l * l) ((l, n `mod` 4):rest)
area acc ((l, n):(l', n'):rest)
    | 1 < n = area (acc + l * l') ((l', n' - 2):rest)
area acc (_:rest) = area acc rest

parse :: ByteString -> Maybe [Int64]
parse = sequence . fmap readInt64 . C8.words
    where
    readInt64 :: ByteString -> Maybe Int64
    readInt64 = liftA (fromIntegral . fst) . C8.readInt

main = B.getLine >> parse <$> B.getLine >>= \(Just a) ->
    print . area 0 . filter ((1 < ) . snd) .  press .
    fmap (\l -> (head l, length l)) . group . reverse . sort $ a

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

maximizePairs :: [Int] -> [Int]
maximizePairs = snd . foldr step ((0 :: Int, 0 :: Int), []) . group . sort
    where
        step xs ((lastVal, cnt), list)
            | length xs `mod` 2 == 0 || lastVal /= h + 1 || cnt == 0 =
                let add = if lastVal == h + 1 then cnt else 0
                in
                    ((h, max add (length xs `mod` 2)), replicate pairs h ++ list)
            | otherwise =
                ((h, 0), replicate (pairs + 1) h ++ list)
            where
                pairs = length xs `div` 2
                h = head xs

groupPairs :: [Int] -> Int64
groupPairs [] = 0
groupPairs [x] = 0
groupPairs (x:y:xys) = fromIntegral x * fromIntegral y + groupPairs xys

readIntList :: IO [Int]
readIntList = do
    _ <- B.getLine
    line <- B.getLine
    let res = map (fst . fromJust . B.readInt) $ B.words line
    return res

main = do
    a <- readIntList
    print $ groupPairs . reverse . maximizePairs $ a

import Control.Monad
import Data.List

trimSticks :: [Integer] -> [Integer]
trimSticks [] = []
trimSticks [_] = []
trimSticks (x:y:rest)
  | x - y < 2 = (y:trimSticks rest)
  | otherwise  = trimSticks (y:rest)

prepare :: [Integer] -> [Integer]
prepare ls =
  let sls = reverse . sort $ ls
  in trimSticks sls

maxArea :: [Integer] -> Integer
maxArea [] = 0
maxArea [_] = 0
maxArea (x:y:rest) = x * y + maxArea rest

main :: IO ()
main = do
  n <- readLn
  ls <- liftM (map read . take n . words) $ getLine
  putStrLn . show . maxArea . prepare $ ls

import Data.List

main = print . g . f . reverse . sort . map read . tail . words =<< getContents

f (x:y:zs)
  | x - y <= 1 = y : f zs
  | otherwise = f (y:zs)
f _ = []

g (x:y:zs) = x*y + g zs
g _ = 0

import Data.List (sortBy)

main :: IO ()
main = getContents >>= print . solve . sortBy (flip compare) . map read . tail . words

solve :: [Integer] -> Integer
solve (a:b:c:d:xs) | a <= b + 1 && c <= d + 1 = b * d + solve xs
                   | a <= b + 1 = solve (a:b:d:xs)
                   | otherwise = solve (b:c:d:xs)
solve _ = 0

import Data.List (sortBy, unfoldr)

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

solve :: [Integer] -> Integer
solve = sum . map product . splitN 2 . go . sortBy (flip compare)
  where go (a:yss@(b:ys)) | b `elem` [ a, a - 1 ] = b : go ys
                          | otherwise = go yss
        go _ = [0, 0]

splitN :: Int -> [a] -> [[a]]
splitN n = takeWhile (not . null) . unfoldr (Just . splitAt n)

import Data.List (sortBy, unfoldr)

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

solve :: [Integer] -> Integer
solve = sum . map product . splitN 2 . go . sortBy (flip compare)
  where go (a:yss@(b:ys)) | a == b = a : go ys
                          | a == b + 1 = b : go ys
                          | otherwise = go yss
        go _ = [0, 0]

splitN :: Int -> [a] -> [[a]]
splitN n = takeWhile (not . null) . unfoldr (Just . splitAt n)

import Data.List (sortBy, unfoldr)

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

solve :: [Integer] -> Integer
solve = sum . map product . filter ((==2) . length) . splitN 2 . go . sortBy (flip compare)
  where go (a:yss@(b:ys)) | a == b = a : go ys
                          | a == b + 1 = b : go ys
                          | otherwise = go yss
        go _ = [0, 0]

splitN :: Int -> [a] -> [[a]]
splitN n = takeWhile (not . null) . unfoldr (Just . splitAt n)

{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns, TupleSections, OverloadedStrings #-}
import Control.Applicative
import Control.Exception hiding (mask)
import Control.Monad hiding (foldM, foldM_)
import Control.Monad.ST
import Data.Array.Base hiding (readArray, writeArray)
import Data.Array.ST (runSTUArray, runSTArray)
import Data.Bits
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.Function
import Data.Int
import Data.List
import qualified Data.Map as M
import qualified Data.IntMap as IM
import qualified Data.Set as S
import qualified Data.IntSet as IS
import Data.STRef
import GHC.Arr (Array, STArray, Ix(..))
import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  xs <- sortBy (flip compare).map (fromIntegral.readInt).B.words <$> B.getLine
  print $ solve xs

solve :: [Integer] -> Integer
solve xs = go 0 xs
   where
     go !res (x:y:z:w:xs)
       | x == y || x - 1 == y = if z == w || z - 1 == w
                                then go (res + y * w) xs
                                else go res (x:y:w:xs)
       | otherwise = go res (y:z:w:xs)
     go res _ = res

------------------------------------------------------------------------------
bool :: a -> a -> Bool -> a
bool t f b=if b then t else f
readInt :: B.ByteString -> Int
readInt bs=case B.readInt bs of{Just(n,_)->n;_->error$"readInt error : bs = "++show bs;}
rep, rev :: Monad m => Int -> (Int -> m ()) -> m ()
rep n f=foldr((>>).f)(return())[0..n-1]
rev n f=foldr((>>).f.negate)(return())[1-n..0]
for :: Monad m => Int -> Int -> (Int -> m ()) -> m ()
for a b f=foldr((>>).f)(return())[a..b]
{-# INLINE rep #-}
{-# INLINE rev #-}
{-# INLINE for #-}
foldM :: (Monad m) => a -> [b] -> (a -> b -> m a) -> m a
foldM a xs f=foldr((>=>).flip f)return xs$a
{-# INLINE foldM #-}
unsafeModify :: (MArray a e m, Ix i) => a i e -> Int -> (e -> e) -> m ()
unsafeModify a i f=unsafeRead a i>>=unsafeWrite a i.f
{-# INLINE unsafeModify #-}
(!) :: (IArray a e, Ix i) => a i e -> i -> e
(!) a i=unsafeAt a$unsafeIndex(bounds a)i
{-# INLINE (!) #-}
readArray :: (MArray a e m, Ix i) => a i e -> i -> m e
readArray a i=do lr<-getBounds a;unsafeRead a$unsafeIndex lr i
{-# INLINE readArray #-}
writeArray :: (MArray a e m, Ix i) => a i e -> i -> e -> m ()
writeArray a i e=do lr<-getBounds a;unsafeWrite a(unsafeIndex lr i)e
{-# INLINE writeArray #-}
modifyArray :: (MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m ()
modifyArray a i f=do lr<-getBounds a;unsafeModify a(unsafeIndex lr i)f
{-# INLINE modifyArray #-}

import Data.List (sortBy)

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

solve :: [Integer] -> Integer
solve = product . take 2 . go . sortBy (flip compare)
  where go (a:yss@(b:ys)) | a == b = a : go ys
                          | a == b + 1 = b : go ys
                          | otherwise = go yss
        go _ = [0, 0]

import Data.List (sortBy)

main :: IO ()
main = getContents >>= print . solve . sortBy (flip compare) . map read . tail . words

solve :: [Integer] -> Integer
solve (a:b:c:d:xs) | a <= b - 1 && c <= d - 1 = b * d + solve xs
                   | a <= b - 1 = solve (a:b:d:xs)
                   | otherwise = solve (b:c:d:xs)
solve _ = 0

import Data.List (sortBy)

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

solve :: [Integer] -> Integer
solve = go . sortBy (flip compare)
  where go (a:b:c:d:xs) | a >= b - 1 && c >= d - 1 = b * d + go xs
                        | a >= b - 1 = go (a:b:d:xs)
                        | otherwise = go (b:c:d:xs)
        go _ = 0

import Data.List (group, sort)
import Data.Int (Int64)
import Data.Bits ((.&.))
import Control.Applicative ((<$>), liftA)
import Data.ByteString (ByteString)
import Control.Monad (replicateM, sequence)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C8

press :: [(Int64, Int)] -> [(Int64, Int64)]
press ((l, n):(l', n'):rest)
    | l == l' + 1 && n .&. 1 == 1 = (l, n'' - 1):press ((l', n' + 1):rest)
    | otherwise = (l, n''): press ((l', n'):rest)
    where n'' = fromIntegral n :: Int64
press [(l, n)] = [(l, fromIntegral n)]

area :: Int64 -> [(Int64, Int64)] -> Int64
area acc [] = acc
area acc ((l, n):rest)
    | 4 < n = area (acc + (n `div` 4) * l * l) ((l, n `mod` 4):rest)
area acc ((l, n):(l', n'):rest)
    | 1 < n = area (acc + l * l') ((l', n' - 2):rest)
area acc (_:rest) = area acc rest

parse :: ByteString -> Maybe [Int64]
parse = sequence . fmap readInt64 . C8.words
    where
    readInt64 :: ByteString -> Maybe Int64
    readInt64 = liftA (fromIntegral . fst) . C8.readInt

main = B.getLine >> parse <$> B.getLine >>= \(Just a) ->
    print . area 0 . filter ((1 < ) . snd) .  press .
    fmap (\l -> (head l, length l)) . group . reverse . sort $ a

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

maximizePairs :: [Int] -> [Int]
maximizePairs = snd . foldr step ((0 :: Int, 0 :: Int), []) . group . sort
    where
        step xs ((lastVal, cnt), list)
            | length xs `mod` 2 == 0 || lastVal /= h + 1 || cnt == 0 =
                ((h, max cnt (length xs `mod` 2)), replicate pairs h ++ list)
            | otherwise =
                ((h, 0), replicate (pairs + 1) h ++ list)
            where
                pairs = length xs `div` 2
                h = head xs

groupPairs :: [Int] -> Int64
groupPairs [] = 0
groupPairs [x] = 0
groupPairs (x:y:xys) = fromIntegral x * fromIntegral y + groupPairs xys

readIntList :: IO [Int]
readIntList = do
    _ <- B.getLine
    line <- B.getLine
    let res = map (fst . fromJust . B.readInt) $ B.words line
    return res

main = do
    a <- readIntList
    print $ groupPairs . reverse . maximizePairs $ a


import qualified Data.List  as L
calc :: Int -> Int -> [Int] -> String
calc n k a
    | k > n     = "-1"
    | otherwise = let y = a !! (k - 1) in show y ++ " " ++ show y

main = do
    s1 <- getLine
    s2 <- getLine
    let
        n : k : _ = map read . words $ s1
        a = L.reverse . L.sort . map read . words $ s2
    putStrLn . calc n k $ a

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

main = do
	[ n, k ] <- map read . words <$> getLine
	as <- reverse . sort . map read . words <$> getLine
	let
		tmp = show $ solve k as
		res = if tmp == "-1" then "-1" else tmp ++ " " ++ tmp
	putStrLn res

solve :: Int -> [Int] -> Int
solve k as
	| k == 0 = ( as !! 0 ) + 1
	| length as < k = -1
	| otherwise = as !! ( k - 1 )

import Data.List

main :: IO ()
main = do
  [n, k] <- fmap (map read . words) getLine
  a <- fmap (reverse . sort . map read . words) getLine
  if k == 0 then p $ succ $ a!!0
  else if k <= n then p $ a!!(k-1)
  else putStrLn "-1"
  where
    p :: Int -> IO ()
    p x = putStrLn $ show x ++ " " ++ show x

import Data.List

main :: IO()
main = do
    str1 <- getLine
    str2 <- getLine
    let n = read ((words str1) !! 0)
    let k = read ((words str1) !! 1)
    let a = (reverse . sort) (map read (words str2)) :: [Int]
    if (n < k)
        then putStrLn "-1"
        else putStrLn ((show (a !! (k - 1))) ++ " " ++ (show (a !! (k - 1))))

import qualified Data.List as L
import qualified Data.Maybe as M

main :: IO ()
main = do
    [n,k] <- getLine >>= return . map read . words
    l     <- getLine >>= return . map read . words
    putStrLn . M.fromMaybe ("-1") $ solve k l

solve :: Int -> [Int] -> Maybe String
solve k l = do
    x <- fmap snd . L.find ((>=k) . fst) . L.zip [1..] . L.reverse . L.sort $ l
    return (show x ++ " " ++ show x)

import Data.Ord
import Data.List
import Control.Arrow
main = do
    let int x = read x :: Int
    let ints  = map int . words <$> getLine
    let join (x,y) = x++" "++y
    [n,k] <- ints
    as <- ints
    putStrLn $
        if k > n
            then "-1"
            else show &&& show >>> join $  head $ drop (k - 1) $ sortBy (flip $ comparing id) as

import Control.Monad (liftM)
import Data.List (sort)
import Data.Maybe (fromMaybe)

solve :: Int -> [Int] -> Int -> Maybe (Int, Int)
solve n as k
  | k > n  =  Nothing
  | otherwise  =  Just (x, x)
  where
    x  =  (reverse $ sort as) !! (k - 1)

main :: IO ()
main  =  do
    [n, k]  <-  liftM (map read . words) getLine
    as  <-  liftM (map read . words) getLine
    putStrLn $ maybe "-1" show' $ solve n as k
  where
    show' (x, y)  =  show x ++ " " ++ show y

import Data.List
main=interact$unwords.map show.f.map read.words
f(n:k:x)|k>n=[-1]|1>0=[sort x!!(n-k),0]

import Data.List (sort)

main :: IO ()
main = getContents >>= putStrLn . unwords . map show . solve . map read . words

solve :: [Int] -> [Int]
solve (n:k:as) | k <= n = [ sort as !! (n - k), 0 ]
               | otherwise = [ -1 ]
solve _ = undefined

import Data.List
main=interact$unwords.map show.f.map read.words
f(n:k:x)|k<=n=[sort x!!(n-k),0]|1>0=[-1]

import Data.List (sortBy)

main :: IO ()
main = getContents >>= putStrLn . unwords . map show . solve . map read . words

solve :: [Int] -> [Int]
solve (_:k:as) | k <= length as = [ sortBy (flip compare) as !! (k - 1), 0 ]
               | otherwise = [ -1 ]
solve _ = undefined

import Data.List
main=interact$solve.map read.words
solve(n:k:xs)
  | n < k = "-1"
  | otherwise = shows x " "++show x
   where
     x = head $ drop (n-k) $ sort xs

import Data.List

main = do
	ct <- getContents
	let
		(n:k:a) = map read $ words ct
	putStrLn $ solve k $ sort a

solve :: Int -> [Int] -> String
solve k a
	| k > length a = "-1"
	| otherwise = ax ++ " " ++ ax
	where
		ax = show $ a !! (length a - k)

module Main where

import Data.List

qsort [] = []
qsort (x:xs) = qsort more ++ [x] ++ qsort less
      where
      (less, more) = partition (< x) xs

solve :: Int -> [Int] -> [Int]
solve k a = if last kFirst == head rest
              then [-1]
              else [last kFirst, 0]
                 where
                 (kFirst, rest) = splitAt k a

main = do
     nkStr <- getLine
     let [n, k] = map read $ words nkStr
     aStr <- getLine
     let a = qsort $ map read $ words aStr
     if k < n
       then putStrLn $ unwords $ map show $ solve k a
       else if k == n
              then putStrLn "0 0"
              else putStrLn "-1"

import Data.List
qsort [] = []
qsort (x:xs) = qsort more ++ [x] ++ qsort less
      where
      (less, more) = partition (< x) xs

solve :: [Int] -> Int-> [Int]
solve a k = if last kFirst == head rest
              then [-1]
              else [last kFirst, 0]
                 where
                 (kFirst, rest) = splitAt k a

main = do
     nkStr <- getLine
     let [n, k] = map read $ words nkStr
     aStr <- getLine
     let a = qsort $ map read $ words aStr
     if k < n
       then putStrLn $ unwords $ map show $ solve a k
       else if k == n
              then putStrLn "0 0"
              else putStrLn "-1"

module Main where

import Data.List

qsort [] = []
qsort (x:xs) = qsort more ++ [x] ++ qsort less
      where
      (less, more) = partition (\ x' -> x' < x) xs

solve :: Int -> [Int] -> [Int]
solve k a = if (last kFirst) == (head rest)
            then [-1]
            else [last kFirst, 0]
                 where
                 (kFirst, rest) = splitAt k a

main = do
     nkStr <- getLine
     let nk = map (read :: String -> Int) $ words nkStr
         n = nk!!0
         k = nk!!1
     aStr <- getLine
     let a = qsort $ map (read :: String -> Int) $ words aStr
     if k < n
     then putStrLn $ unwords $ map show $ solve k a
     else if k == n
          then putStrLn "0 0"
          else putStrLn "-1"

import Control.Applicative
import Data.List

main= do
	[n,k]<-  map read.words  <$> getLine ::IO [Int]
	s<-reverse.sort .map read. words <$> getLine:: IO [Int]
	putStrLn $ if length s <k then "-1" else intercalate " "$ map show  $ replicate 2  $ head $ drop (k-1) s

import Control.Applicative
import Data.List
import Control.Exception
import Data.Either
main = do
    [n,k]<-map read.words<$>getLine
    as<-map read.take n.words<$>getLine::IO[Int]
    let
        c = reverse $ take (1+k) $ reverse $ sort as
        b = (head c == (head.tail $ c)) -- || ((head.tail $ c) == head.tail.tail$c)
        ch=show(head.tail$c)
    res<-try(evaluate b)::IO(Either SomeException Bool)
    case (compare k n) of
      GT -> do
        print(-1)
        return()
      EQ -> putStrLn "0 0"
      _ ->
        case res of
            Left _ -> print (-1)
            Right r -> case r of
                            True -> print (-1)
                            False -> putStrLn(ch++" 0")

import Data.List

solve n k as    | k > n     = ["-1"]
                | otherwise = map show [x, y]
                where
                    xs = sort as
                    x = head $ drop (n - k) xs
                    y = x

parseInput input = (n, k, as) where
    ls = lines input
    [n, k] = map read $ words $ head ls :: [Int]
    as = map read $ words $ last ls :: [Int]

main = do
    input <- getContents
    let (n, k, as) = parseInput input
    putStrLn $ intercalate " " $ solve n k as

import Data.List
main=interact$unwords.map show.f.map read.words
f(n:k:x)|k<n=[-1]|1>0=[sort x!!(n-k),0]


import Data.Monoid

judgeSum :: [Integer] -> Ordering
judgeSum input = compare (sum . filter (> 0) $ input) (negate . sum . filter (< 0) $ input)

judgeLexi :: [Integer] -> Ordering
judgeLexi input = compare (filter (> 0) input) [-x | x <- input, x < 0]

judgeLast :: [Integer] -> Ordering
judgeLast input = compare (last input) 0

judge :: [Integer] -> Ordering
judge = do
    a <- judgeSum
    b <- judgeLexi
    c <- judgeLast
    return (a `mappend` b `mappend` c)

main = do
    getLine
    input <- getContents >>= (return . (map read) . lines)
    let ret = case (judge input) of
                LT -> "second"
                GT -> "first"
    putStrLn ret

solve pl = if p1 > p2 then "first" else
           if p2 > p1 then "second" else
           if l1 > l2 then "first" else
           if l2 > l1 then "second" else
           if (signum $ last pl) == 1 then "first" else "second"
	where	(p1, p2) = foldl (\(a, b) x -> if x > 0 then (a+x, b) else (a, b-x)) (0,0) pl
		(l1, l2) = foldr (\x (a, b) -> if x > 0 then (x:a, b) else (a, (-x):b)) ([],[]) pl

main = do
	n <- (getLine >>= readIO :: IO Integer)
	pl <- mapM (const (getLine >>= readIO :: IO Integer)) [1..n]
	putStrLn $ solve pl

solve input =
  let (_:all) = (map read . words) input
      first = filter (> 0) all;
      second = (map negate . filter (< 0)) all;
      first_last = (last all) > 0
  in  if sum first > sum second
      then "first"
      else
        if sum first < sum second
        then "second"
        else
          if first > second
          then "first"
          else
            if (first < second)
            then "second"
            else
              if first_last
              then "first"
              else "second"

main = interact solve

{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns, TupleSections, OverloadedStrings #-}
import Control.Applicative
import Control.Exception hiding (mask)
import Control.Monad
import Control.Monad.ST
import Data.Array.Base
import Data.Array.ST (runSTUArray, runSTArray)
import Data.Bits
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.Function
import Data.Int
import Data.List
import qualified Data.Map as M
import qualified Data.IntMap as IM
import qualified Data.Set as S
import qualified Data.IntSet as IS
import Data.STRef
import GHC.Arr (Array, STArray, Ix(..))
import Debug.Trace

bool :: a -> a -> Bool -> a
bool t f b=if b then t else f
readInteger :: B.ByteString -> Integer
readInteger bs=case B.readInteger bs of{Just(n,_)->n;_->error$"readInteger error : bs = "++show bs;}
rep, rev :: Monad m => Int -> (Int -> m ()) -> m ()
rep n f=foldr((>>).f)(return())[0..n-1]
rev n f=foldr((>>).f.negate)(return())[1-n..0]
for :: Monad m => Int -> Int -> (Int -> m ()) -> m ()
for a b f=foldr((>>).f)(return())[a..b]
{-# INLINE rep #-}
{-# INLINE rev #-}
{-# INLINE for #-}
modifyArray :: (MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m ()
modifyArray a i f=readArray a i>>=writeArray a i.f
{-# INLINE modifyArray #-}
unsafeModify :: (MArray a e m, Ix i) => a i e -> Int -> (e -> e) -> m ()
unsafeModify a i f=unsafeRead a i>>=unsafeWrite a i.f
{-# INLINE unsafeModify #-}

main :: IO ()
main = do
  n <- readLn :: IO Int
  xs <- map readInteger.B.words <$> B.getContents
  putStrLn.bool"first""second"$ solve xs

solve :: [Integer] -> Bool
solve xs
  | sumF > sumS = True
  | sumF < sumS = False
  | otherwise = case compare fs (map abs ss) of
                  LT -> False
                  GT -> True
                  EQ -> last xs > 0
   where
     (fs,ss) = partition (>0) xs
     !sumF = sum fs
     !sumS = abs $ sum ss

solve pl = if p1 > p2 then "first" else
           if p2 > p1 then "second" else
           if l1 > l2 then "first" else
           "second"
	where	(p1, p2) = foldl (\(a, b) x -> if x > 0 then (a+x, b) else (a, b-x)) (0,0) pl
		(l1, l2) = foldr (\x (a, b) -> if x > 0 then (x:a, b) else (a, (-x):b)) ([],[]) pl

main = do
	n <- (getLine >>= readIO :: IO Integer)
	pl <- mapM (const (getLine >>= readIO :: IO Integer)) [1..n]
	putStrLn $ solve pl

solve pl = if p1 > p2 then "first" else
           if p2 > p1 then "second" else
           if l1 > l2 then "first" else
           "second"
	where	(p1, p2) = foldl (\(a, b) x -> if x > 0 then (a+x, b) else (a, b-x)) (0,0) pl
		(l1, l2) = foldr (\x (a, b) -> if x > 0 then (x:a, b) else (a, (-x):b)) ([],[]) pl

main = do
	n <- (getLine >>= readIO :: IO Int)
	pl <- mapM (const (getLine >>= readIO :: IO Int)) [1..n]
	putStrLn $ solve pl

import Data.Monoid

judgeSum :: [Int] -> Ordering
judgeSum input = compare (sum . filter (> 0) $ input) (negate . sum . filter (< 0) $ input)

judgeLexi :: [Int] -> Ordering
judgeLexi input = compare (filter (> 0) input) [-x | x <- input, x < 0]

judgeLast :: [Int] -> Ordering
judgeLast input = compare (last input) 0

judge :: [Int] -> Ordering
judge = do
    a <- judgeSum
    b <- judgeLexi
    c <- judgeLast
    return (a `mappend` b `mappend` c)

main = do
    getLine
    input <- getContents >>= (return . (map read) . lines)
    let ret = case (judge input) of
                LT -> "second"
                GT -> "first"
    putStrLn ret


main = getContents >>= putStr . unlines . map solve . tail . lines

solve = (\[a, b] -> if a - b > 1 then "YES" else "NO") . map read . words

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

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

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

import qualified Data.ByteString.Char8 as B

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

-- import Debug.Trace
import Text.Printf

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

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

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

main = readInt >>= flip replicateM solve

solve = do
	[ x, y ] <- readIntegers
	let
		d = x - y
	putStrLn $ if 2 <= d
		then "YES"
		else "NO"

import Control.Monad

main :: IO ()
main = do
  t <- read <$> getLine :: IO Int
  replicateM_ t $ do
    line <- words <$> getLine
    let [x,y] = read <$> line :: [Integer]
    putStrLn $ if x > y+1 then "yes" else "no"

import Data.List
import Control.Monad

main :: IO ()
main =  do
  t <- read <$> getLine :: IO Int
  replicateM_ t $ do
    values <- map read . words <$> getLine :: IO [Integer]
    if values !! 0 - values !! 1 == 1 then
      putStrLn "NO"
    else
      putStrLn "YES"

import Control.Monad

main = do
  cases <- read <$> getLine
  replicateM_ cases $ do
    [a, b] <- fmap read <$> words <$> getLine
    if a - b == 1 then
      putStrLn "NO"
    else
      putStrLn "YES"