import Control.Arrow ((&&&))
import Data.List (transpose)

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

solve :: [[Integer]] -> Integer
solve = (^(2::Integer)) . maximum . map (uncurry (-) . (maximum &&& minimum)) . transpose

main = interact $ show . (\[a,b,c,d] -> let e = max (b-a) (d-c) in e*e) .f . map read . tail . words
f (a:b:[]) = [a,a,b,b]
f (a:b:c) = [min a p, max a q, min b r, max b s] where [p,q,r,s] = f c


import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
import Data.List

{-
import Debug.Trace
f $$ x = traceShow x (f x)
infixr 0 $$
-}

main = do
  input <- fmap B.lines B.getContents
  let [n,m] = map readI $ B.words $ head input
  let es = map ((\[x,y]->x`seq`y`seq`(x,y)) . map readI . B.words) $ tail input
  print (solve es)

readI :: B.ByteString -> Int
readI s = case B.readInt s of Just (n,_) -> n

solve :: [(Int,Int)] -> Int
solve es =
  length $ filter id $ unfoldr h edges
  where
    edges = M.filter ((==2).length) $ foldl g M.empty es

    g m (e,d) = M.alter (f d) e $ M.alter (f e) d m

    f d Nothing   = Just [d]
    f d (Just ds) = Just (d:ds)

    h m | M.null m = Nothing
        |otherwise = let (found,m') = findCycle m in Just (found,m')

findCycle :: M.Map Int [Int] -> (Bool, M.Map Int [Int])
findCycle edges =
  go start start next (M.delete start edges)
  where
    (start,next:_) = M.findMin edges

    go s t u m =
--        traceShow (s,t,u,m) $
        case fmap (filter (/=t)) (M.lookup u m) of
          Just [v] | v==s     -> (True, M.delete v (M.delete u m))
                   |otherwise -> go s u v (M.delete u m)
          _                   -> (False, M.delete u m)

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

import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST.Safe
import           Control.Monad.Trans.State.Strict
import           Data.Array.IArray
import           Data.Array.ST.Safe
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 qualified Data.Map.Strict                  as M
import           Data.Monoid
import           Data.Ord
import qualified Data.Set                         as S
import           Data.STRef
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,m] <- map read.words <$> getLine
    edges <- concatMap(\(x,y) -> [(x-1,y-1),(y-1,x-1)]).unfoldr (runStateT parseInt2) <$> B.getContents
    print $ solve n m edges

solve :: Int -> Int -> [(Int, Int)] -> Int
solve n m edges = length[vs|vs<-scc gr, all (\v->length(gr!v) == 2) vs]
  where
    !gr = mkGraph (0,n-1) edges

-------------------------------------------------------------------------------
type Vertex = Int
type Edge = (Vertex, Vertex)
type Graph = Array Vertex [Vertex]
type Path = [Vertex]

mkGraph :: (Int, Int) -> [Edge] -> Graph
mkGraph bnd edges = accumArray (flip (:)) [] bnd edges

vertices :: Graph -> [Vertex]
vertices gr = range $ bounds gr

edges :: Graph -> [Edge]
edges gr = [(from, to) | from <- vertices gr, to <- (!) gr from ]

revGraph :: Graph -> Graph
revGraph gr = mkGraph (bounds gr) . map swap $ edges gr

dfsAll :: Graph -> [Vertex] -> [[Vertex]]
dfsAll gr vs = filter (not.null) $ runST $ do
  vis <- newArray (bounds gr) False :: ST s (STUArray s Vertex Bool)
  mapM (dfsM gr vis) vs

dfsM :: Graph -> STUArray s Vertex Bool -> Vertex -> ST s [Vertex]
dfsM gr vis root = do
  let go res (v:vs) = do
        visited <- readArray vis v
        if visited then go res vs
        else do
          writeArray vis v True
          go (v:res) ((!) gr v ++ vs)
      go res [] = return $ reverse res
  go [] [root]

topSort :: Graph -> [Vertex]
topSort gr = runST $ do
  vis   <- newArray (bounds gr) False :: ST s (STUArray s Vertex Bool)
  stack <- newSTRef []                :: ST s (STRef s [Vertex])
  let visit v = do
        visited <- readArray vis v
        unless visited $ do
          writeArray vis v True
          mapM_ visit $ (!) gr v
          modifySTRef stack (v:)
  mapM_ visit $ vertices gr
  readSTRef stack

scc :: Graph -> [[Vertex]]
scc gr = dfsAll gr . topSort $ revGraph gr

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

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


{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Monoid
import Data.Array.Unboxed
import Data.Array.IO
import Data.Array.Base
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

readInt = fromJust . fmap fst . B.readInt
readInteger :: B.ByteString -> Int64
readInteger = fromInteger . fromJust . fmap fst . B.readInteger
readInts = map readInt . B.words <$> B.getLine
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine
cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b
swap (a,b) = (b,a)
l2p (a:b:_) = (a,b)
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
flatten :: [(a,[(b,c)])] -> [((a,b),c)]
flatten = (=<<) $ uncurry $ fmap . first . (,)
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i judge incr step = sub i where
    sub i | judge i = step i >> sub (incr i) | otherwise = return ()
thru :: Monad m => (v -> m ()) -> v -> m v
thru m v = m v >> return v
inf = maxBound `div` 2 :: Int

main = do
    (n,m) <- readIntPair
    (_ps,_bs) <- splitAt n . map (map readInteger.  B.words) . B.lines <$> B.getContents
    let ps = map l2p _ps
    let bs = head _bs
    let qs = [ (r2 - l1,l2 - r1,i) |
                ((l1,r1),(l2,r2),i) <- zip3 ps (tail ps) [0..] ]

    arr <- newArray_ (0,n-2) :: IO (IOUArray Int Int)
    let go [] _ = return True
        go ((b,a,i):qs') s = case S.lookupGT (a,0) s of
            Just (c,bi) | c <= b -> do
                unsafeWrite arr i bi
                go qs' (S.delete (c,bi) s)
            _ -> return False
    b <- go (sort qs) (S.fromList $ zip bs [1..])
    if b then do
        putStrLn "Yes"
        as <- getElems arr
        putStrLn $ unwords $ map show as
    else
        putStrLn "No"

{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Monoid
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

readInt = fromJust . fmap fst . B.readInt
readInteger = fromJust . fmap fst . B.readInteger
readInts = map readInt . B.words <$> B.getLine
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine
cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b
swap (a,b) = (b,a)
l2p (a:b:_) = (a,b)
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
flatten :: [(a,[(b,c)])] -> [((a,b),c)]
flatten = (=<<) $ uncurry $ fmap . first . (,)
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i judge incr step = sub i where
    sub i | judge i = step i >> sub (incr i) | otherwise = return ()
thru :: Monad m => (v -> m ()) -> v -> m v
thru m v = m v >> return v
inf = maxBound `div` 2 :: Int

main = do
    (n,m) <- readIntPair
    (_ps,_bs) <- splitAt n . map (map readInteger.  B.words) . B.lines <$> B.getContents
    let ps = map l2p _ps
    let bs = head _bs
    let qs = [ (r2 - l1,l2 - r1,i) | ((l1,r1),(l2,r2),i) <- zip3 ps
                                                                 (tail ps)
                                                                 [1..] ]

    let go :: [(Integer,Integer,Int)] -> S.Set (Integer,Int) -> Maybe [(Int,Int)]
        go [] _ = Just []
        go ((b,a,i):qs') s =
            case S.lookupGT (a,0) s of
                Just (c,bi) | c <= b ->
                    ((i,bi):) <$> go qs' (S.delete (c,bi) s)
                _ -> Nothing
    let x = sort qs
    let y = S.fromList (zip bs [(1 :: Int)..])
    case go x y of
        Just l -> do
            putStrLn "Yes"
            putStrLn $ unwords $ [ show bi | (i,bi) <- sort l ]
        Nothing -> putStrLn "No"

{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Monoid
import Data.Array.Unboxed
import Data.Array.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

readInt = fromJust . fmap fst . B.readInt
readInteger = fromJust . fmap fst . B.readInteger
readInts = map readInt . B.words <$> B.getLine
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine
cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b
swap (a,b) = (b,a)
l2p (a:b:_) = (a,b)
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
flatten :: [(a,[(b,c)])] -> [((a,b),c)]
flatten = (=<<) $ uncurry $ fmap . first . (,)
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i judge incr step = sub i where
    sub i | judge i = step i >> sub (incr i) | otherwise = return ()
thru :: Monad m => (v -> m ()) -> v -> m v
thru m v = m v >> return v
inf = maxBound `div` 2 :: Int

main = do
    (n,m) <- readIntPair
    (_ps,_bs) <- splitAt n . map (map readInteger.  B.words) . B.lines <$> B.getContents
    let ps = map l2p _ps
    let bs = head _bs
    let qs = [ (r2 - l1,l2 - r1,i) | ((l1,r1),(l2,r2),i) <- zip3 ps
                                                                 (tail ps)
                                                                 [1..] ]

    arr <- newArray_ (1,n-1) :: IO (IOUArray Int Int)
    let go [] _ = return True
        go ((b,a,i):qs') s =
            case S.lookupGT (a,0) s of
                Just (c,bi) | c <= b -> do
                    writeArray arr i bi
                    go qs' (S.delete (c,bi) s)
                _ -> return False
    b <- go (sort qs) (S.fromList $ zip bs [1..])
    if b then do
        putStrLn "Yes"
        as <- getElems arr
        putStrLn $ unwords $ map show as
    else
        putStrLn "No"

{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Monoid
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

readInt = fromJust . fmap fst . B.readInt
readInts = map readInt . B.words <$> B.getLine
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine
cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b
swap (a,b) = (b,a)
l2p (a:b:_) = (a,b)
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
flatten :: [(a,[(b,c)])] -> [((a,b),c)]
flatten = (=<<) $ uncurry $ fmap . first . (,)
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i judge incr step = sub i where
    sub i | judge i = step i >> sub (incr i) | otherwise = return ()
thru :: Monad m => (v -> m ()) -> v -> m v
thru m v = m v >> return v
inf = maxBound `div` 2 :: Int

main = do
    (n,m) <- readIntPair
    (_ps,_bs) <- splitAt n . map (map readInt.  B.words) . B.lines <$> B.getContents
    let ps = map l2p _ps
    let bs = head _bs
    let qs = [ (r2 - l1,l2 - r1,i) | ((l1,r1),(l2,r2),i) <- zip3 ps
                                                                 (tail ps)
                                                                 [1..] ]

    let go [] _ = Just []
        go (_:_) [] = Nothing
        go ((b,a,i):qs') ((c,bi):cs)
            | a <= c && c <= b = ((i,bi):) <$> go qs' cs
            | otherwise = go ((b,a,i):qs') cs
    let x = sort qs
    let y = sort (zip bs [1..])
    case go x y of
        Just l -> do
            putStrLn "Yes"
            putStrLn $ unwords $ [ show bi | (i,bi) <- sort l ]
        Nothing -> putStrLn "No"

{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Monoid
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

readInt = fromJust . fmap fst . B.readInt
readInteger = fromJust . fmap fst . B.readInteger
readInts = map readInt . B.words <$> B.getLine
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine
cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b
swap (a,b) = (b,a)
l2p (a:b:_) = (a,b)
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
flatten :: [(a,[(b,c)])] -> [((a,b),c)]
flatten = (=<<) $ uncurry $ fmap . first . (,)
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i judge incr step = sub i where
    sub i | judge i = step i >> sub (incr i) | otherwise = return ()
thru :: Monad m => (v -> m ()) -> v -> m v
thru m v = m v >> return v
inf = maxBound `div` 2 :: Int

main = do
    (n,m) <- readIntPair
    (_ps,_bs) <- splitAt n . map (map readInt.  B.words) . B.lines <$> B.getContents
    let ps = map l2p _ps
    let bs = head _bs
    let qs = [ (r2 - l1,l2 - r1,i) | ((l1,r1),(l2,r2),i) <- zip3 ps
                                                                 (tail ps)
                                                                 [1..] ]

    let go [] _ = Just []
        go ((b,a,i):qs') s =
            case S.lookupGT (a,0) s of
                Just (c,bi) | c <= b ->
                    ((i,bi):) <$> go qs' (S.delete (c,bi) s)
                _ -> Nothing
    let x = sort qs
    let y = S.fromList (zip bs [(1 :: Int)..])
    case go x y of
        Just l -> do
            putStrLn "Yes"
            putStrLn $ unwords $ [ show bi | (i,bi) <- sort l ]
        Nothing -> putStrLn "No"

{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Monoid
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

readInt = fromJust . fmap fst . B.readInt
readInteger = fromJust . fmap fst . B.readInteger
readInts = map readInt . B.words <$> B.getLine
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine
cmpFst (a,_) (b,_) = compare a b
cmpSnd (_,a) (_,b) = compare a b
cmpLen a b = length a `compare` length b
swap (a,b) = (b,a)
l2p (a:b:_) = (a,b)
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
flatten :: [(a,[(b,c)])] -> [((a,b),c)]
flatten = (=<<) $ uncurry $ fmap . first . (,)
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i judge incr step = sub i where
    sub i | judge i = step i >> sub (incr i) | otherwise = return ()
thru :: Monad m => (v -> m ()) -> v -> m v
thru m v = m v >> return v
inf = maxBound `div` 2 :: Int

main = do
    (n,m) <- readIntPair
    (_ps,_bs) <- splitAt n . map (map readInteger.  B.words) . B.lines <$> B.getContents
    let ps = map l2p _ps
    let bs = head _bs
    let qs = [ (r2 - l1,l2 - r1,i) | ((l1,r1),(l2,r2),i) <- zip3 ps
                                                                 (tail ps)
                                                                 [1..] ]

    let go [] _ = Just []
        go (_:_) [] = Nothing
        go ((b,a,i):qs') ((c,bi):cs)
            | a <= c && c <= b = ((i,bi):) <$> go qs' cs
            | otherwise = go ((b,a,i):qs') cs
    let x = sort qs
    let y = sort (zip bs [1..])
    case go x y of
        Just l -> do
            putStrLn "Yes"
            putStrLn $ unwords $ [ show bi | (i,bi) <- sort l ]
        Nothing -> putStrLn "No"


main = interact $ unlines . map solve . tail . lines
solve x | [a, b] <- map read $ words x = if gcd a b == 1 then "Finite" else "Infinite"

import           Data.List
import           Numeric

(|>) = flip (.)

int :: String -> Int
int x = fst $ readDec x !! 0

ints :: String -> [Int]
ints = map int . words

main = interact $
  lines
  |> solverLoop
  |> unlines

solverLoop :: [String] -> [String]
solverLoop (ts:xs) = go t xs
    where
      t = int ts
      go 0 _      = []
      go t (x:xs) = solve (ints x) : go (t-1) xs

solve :: [Int] -> String
solve (a:b:_) =
  if gcd a b == 1
    then "Finite"
    else "Infinite"

import Control.Monad

rl = map read . words <$> getLine

main :: IO ()
main = do
  [t] <- rl
  replicateM_ t $ do
    [a, b] <- rl
    putStrLn $ if a == 1 || b == 1 || max a b `mod` min a b == 1 then "Finite" else "Infinite"


import Control.Monad
import Data.Int

solve :: IO ()
solve = do
    n <- readLn :: IO Int64
    let n' | n < 6     = 6
           | odd n     = n + 1
           | otherwise = n
    print $ n' * 5 `div` 2

readMany :: Read a => IO [a]
readMany = map read . words <$> getLine

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

import Control.Monad

printResult = do
    n <- readLn :: IO Integer
    print $ if n <= 6 then 15 else div ((n + mod n 2)*5) 2

main = do
    t <- readLn :: IO Int
    replicateM_ t printResult

import Control.Monad
import Data.Int

solve :: IO ()
solve = do
    n <- readLn :: IO Int64
    let n' | n < 6     = 6
           | odd n     = n + 1
           | otherwise = n
    print $ n' * 5 `div` 2

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

{-# LANGUAGE Strict #-}
{-# LANGUAGE LambdaCase #-}
import Control.Applicative (liftA2)
import Control.Monad (replicateM)
import Control.Monad.State (State, evalState, get, gets, put)
import qualified Data.ByteString.Lazy.Char8 as C
import Data.Maybe (fromJust)

main :: IO ()
main = C.interact $ runScanner (C.unlines <$> numberOf (C.pack <$> testCase))

testCase :: Scanner String
testCase = show . solve <$> integer

lim = 400
dp :: [Integer]
dp = 0 : do
  n <- [1..lim]
  let get m = dp !! max 0 m
  return $ minimum [15 + get (n - 6), 20 + get (n - 8), 25 + get (n - 10)]

solve :: Integer -> Integer
solve n
  | n < fi lim = dp !! fi n
  | otherwise = let q = (n - 200) `div` 120 in 12 * q * 25 + solve (n - q * 120)

fi :: (Num b, Integral a) => a -> b
fi = fromIntegral

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

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

integer :: Scanner Integer
integer = read . C.unpack <$> bstr

double :: Scanner Double
double = read . C.unpack <$> bstr

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


import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (accumArray, (!))
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.List (sort)
import Data.Maybe (fromJust)
import Data.Tuple (swap)
import Prelude hiding (words, lines, getLine, getContents)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

main = do
  [n] <- readInts
  es <- replicateM (n-1) ((\[a, b] -> (a, b)) <$> readInts)

  let
    r = maximum $ map solve (g ! 1)
      where
        g = accumArray (flip (:)) [] (1, n) $ es ++ map swap es

        solve = foldl1 (\a -> max (a+1)) . sort . dfs 0 1 []
          where
            dfs d w r u
              | null vs = d:r
              | otherwise = foldl (dfs (d+1) u) r vs
              where
                vs = filter (/= w) $ g ! u

  print $ r + 1

{-# OPTIONS_GHC -O2 #-}

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.Array (accumArray, (!))
import Data.ByteString.Char8 (words, lines, readInt, getLine, getContents)
import Data.Maybe (fromJust)
import Data.Tuple (swap)
import Data.List (sort)
import Prelude hiding (words, lines, getLine, getContents)

readInt' = fst . fromJust . readInt
readInts = map readInt' . words <$> getLine

main = do
  [n] <- readInts
  es <- replicateM (n-1) ((\[a, b] -> (a, b)) <$> readInts)

  let
    r = maximum $ map solve (g ! 1)
      where
        g = accumArray (flip (:)) [] (1, n) $ es ++ map swap es

        solve u = foldl1 (\a b -> max (a+1) b) $ sort $ dfs 0 1 [] u
          where
            dfs d w r u
              | null vs = d:r
              | otherwise = foldl (dfs (d+1) u) r vs
              where
                vs = filter (/= w) $ g ! u

  print $ r + 1


-- 845B

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe (fromJust)
import Data.Function (on)
import Data.List (sortBy)

main = getLine >> (B.interact $ program . input)
    where input = (map . map) (fst . fromJust . B.readInt) . map B.words . B.lines

program :: [[Int]] -> B.ByteString
program shows = runShows sortedShows []
    where sortedShows = sortBy (compare `on` fst) $ map (\[s,e] -> (s,e)) shows

runShows :: [(Int,Int)] -> [Int] -> B.ByteString
runShows [] _ = "YES\n"
runShows ((s,e):shows) tvs =
  let tvs' = e:(filter (>=s) tvs) in
  if length tvs' > 2
  then "NO\n"
  else runShows shows tvs'

-- http://codeforces.com/contest/845/problem/C

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

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

main = do
    n <- getInt
    lrs <- (sortBy (\[x,_] [y,_] -> compare x y)) `fmap` replicateM n getInts
    if can lrs
    then putStrLn "YES"
    else putStrLn "NO"

can lrs = f lrs (-1) (-1) where
    f [] _ _ = True
    f ([l,r]:lrs) x y
        | l <= x && l <= y = False
        | l <= x && l > y = f lrs x r
        | l > x && l <= y = f lrs r y
        | x < y = f lrs r y
        | otherwise = f lrs x r

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

import qualified Data.ByteString as B (getLine, getContents)
import qualified Data.ByteString.Char8 as C (readInt, words, lines)
import qualified Data.Maybe as M (fromJust)
import Data.Function (on)
import Data.List (sortBy)

readInt = fst . M.fromJust . C.readInt
run _ _ [] = True
run i j ((xa, xb):xs) | xa <= i && xa <= j = False
    | xa <= i || (j > i && xa > j) = run i xb xs
    | otherwise = run xb j xs

main = do
    (readInt -> n) <- B.getLine
    (map ((\[a, b] -> (a, b)) . map readInt . C.words) . C.lines -> xs) <- B.getContents
    let xxs = sortBy (compare `on` snd) xs
    putStrLn $ if run (-1) (-1) xxs then "YES" else "NO"

{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-}
{-# LANGUAGE ViewPatterns #-}
module Main where
import qualified Data.ByteString.Lazy.Char8 as B
import Control.Monad
import Control.Monad.Trans.State.Lazy
import Data.List
import Data.Function

main = putStr . evalState app . B.words =<< B.getContents

app = do
  n <- poi
  ss <- replicateM n $ liftM2 (,) poi poi
  return $ if solve ss then "YES" else "NO"
  where
    pop = state $ \(x:xs) -> (x, xs)
    poi = fmap int pop
    int = maybe undefined fst . B.readInt

solve = all (<= 2) . scanl1 (+) . map (sum . map snd) . groupBy ((==) `on` fst) . sortBy (compare `on` fst) . concatMap (\(b, e) -> [(b, 1), (e + 1, -1)])

-- http://codeforces.com/contest/845/problem/C

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

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

main = do
    n <- getInt
    lrs <- (sortBy comp) `fmap` replicateM n getInts
    if can lrs
    then putStrLn "YES"
    else putStrLn "NO"

comp [l1,r1] [l2,r2] = case compare l1 l2 of
    EQ -> compare r1 r2
    x -> x

can lrs = f lrs 0 0 where
    f [] _ _ = True
    f ([l,r]:lrs) x y
        | l <= x && l <= y = False
        | l <= x && l > y = f lrs x r
        | l > x && l <= y = f lrs r y
        | x < y = f lrs r y
        | otherwise = f lrs x r

-- http://codeforces.com/contest/845/problem/C

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

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

main = do
    n <- getInt
    lrs <- (sortBy (\[_,x] [_,y] -> compare x y)) `fmap` replicateM n getInts
    if can lrs
    then putStrLn "YES"
    else putStrLn "NO"

can lrs = f lrs 0 0 where
    f [] _ _ = True
    f ([l,r]:lrs) x y
        | l <= x && l <= y = False
        | l <= x && l > y = f lrs x r
        | otherwise = f lrs r y

-- http://codeforces.com/contest/845/problem/C

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

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

main = do
    n <- getInt
    lrs <- (sortBy (\[_,x] [_,y] -> compare x y)) `fmap` replicateM n getInts
    if can lrs
    then putStrLn "YES"
    else putStrLn "NO"

can lrs = f lrs 0 0 where
    f [] _ _ = True
    f ([l,r]:lrs) x y
        | l <= x && l <= y = False
        | l <= x && l > y = f lrs x r
        | l > x && l <= y = f lrs r y
        | x < y = f lrs r y
        | otherwise = f lrs x r

-- http://codeforces.com/contest/845/problem/C

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

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

main = do
    n <- getInt
    lrs <- (sortBy comp) `fmap` replicateM n getInts
    if can lrs
    then putStrLn "YES"
    else putStrLn "NO"

comp [l1,r1] [l2,r2] = case compare r1 r2 of
    EQ -> compare l1 l2
    x -> x

can lrs = f lrs 0 0 where
    f [] _ _ = True
    f ([l,r]:lrs) x y
        | l <= x && l <= y = False
        | l <= x && l > y = f lrs x r
        | l > x && l <= y = f lrs r y
        | x < y = f lrs r y
        | otherwise = f lrs x r

-- http://codeforces.com/contest/845/problem/C

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

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

main = do
    n <- getInt
    lrs <- (sortBy (\[x,_] [y,_] -> compare x y)) `fmap` replicateM n getInts
    if can lrs
    then putStrLn "YES"
    else putStrLn "NO"

can lrs = f lrs 0 0 where
    f [] _ _ = True
    f ([l,r]:lrs) x y
        | l <= x && l <= y = False
        | l <= x && l > y = f lrs x r
        | l > x && l <= y = f lrs r y
        | x < y = f lrs r y
        | otherwise = f lrs x r

{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-}
{-# LANGUAGE ViewPatterns #-}
module Main where
import qualified Data.ByteString.Lazy.Char8 as B
import Control.Monad
import Control.Monad.Trans.State.Lazy
import Data.List
import Data.Function

main = putStr . evalState app . B.words =<< B.getContents

app = do
  n <- poi
  ss <- replicateM n $ liftM2 (,) poi poi
  return $ if solve ss then "YES" else "NO"
  where
    pop = state $ \(x:xs) -> (x, xs)
    poi = fmap int pop
    int = maybe undefined fst . B.readInt

solve = all (<= 2) . scanl1 (+) . map snd . sortBy (compare `on` fst) . concatMap (\(b, e) -> [(b, 1), (e + 1, -1)])

{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-}
{-# LANGUAGE ViewPatterns #-}
module Main where
import qualified Data.ByteString.Lazy.Char8 as B
import Control.Monad
import Control.Monad.Trans.State.Lazy
import Data.List
import Data.Function

main = putStr . evalState app . B.words =<< B.getContents

app = do
  n <- poi
  ss <- replicateM n $ liftM2 (,) poi poi
  return $ if solve ss then "YES" else "NO"
  where
    pop = state $ \(x:xs) -> (x, xs)
    poi = fmap int pop
    int = maybe undefined fst . B.readInt

solve = all (<= 2) . scanl1 (+) . map snd . sortBy (compare `on` fst) . concatMap (\(b, e) -> [(b, 1), (e, -1)])


solve :: [Char] -> Int
solve q =
  let
    in gao q
  where
    gao s
      | null s = 0
      | head s == 'M' = iter 0 0 0 s
      | otherwise = gao $ tail s
      where
        iter res num_f num_m rem
          | null rem = res
          | head rem == 'F' = iter (max (res + 1) num_m) (num_f + 1) num_m $ tail rem
          | otherwise = iter res num_f (num_m + 1) $ tail rem

main = do
  q <- getLine
  print $ solve q

solve :: [Char] -> Int
solve q = gao q
  where
    gao s
      | null s = 0
      | head s == 'M' = iter 0 0 0 s
      | otherwise = gao $ tail s
      where
        iter res num_f num_m rem
          | null rem = res
          | head rem == 'F' = iter (max (res + 1) num_m) (num_f + 1) num_m $ tail rem
          | otherwise = iter res num_f (num_m + 1) $ tail rem

main = do
  q <- getLine
  print $ solve q

solve :: [Char] -> Int
solve q =
  let
    s = reverse q
    in gao s
  where
    gao s
      | null s = 0
      | head s == 'F' = iter 0 0 $ tail s
      | otherwise = gao $ tail s
      where
        iter res nf rem
          | null rem = res
          | head rem == 'M' = let
            nr = if nf == 0 then res + 1 else (max res nf) + 1
            in iter nr 0 $ tail rem
          | otherwise = iter res (nf + 1) $ tail rem

main = do
  q <- getLine
  putStrLn $ show $ solve q


import Control.Monad (forM_)

solve n b x y z
    | n == 0 = []
    | p > q && p <= b = p : solve (n -1) b x y p
    | otherwise = q : solve (n -1) b x y q
  where
    p = z + x
    q = z - y

main :: IO ()
main = do
    t <- readLn :: IO Int
    forM_ [1 .. t] $ \i -> do
        l <- getLine
        let [n, b, x, y] = (map read . words) l
        print $ sum $ solve n b x y 0

parseInt :: String -> Int
parseInt number = (read number) :: Int

readInt :: IO Int
readInt = do
    number <- getLine
    pure $ parseInt number

readIntArr :: IO [Int]
readIntArr = do
    numbers <- getLine
    pure $ map parseInt $ words numbers

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

calc :: Int -> (Int, Int, Int, Int) -> Int
calc 0 _ = 0
calc i (a, b, x, y) = if (a + x <= b)
    then a + x + calc (i - 1) (a + x, b, x, y)
    else a - y + calc (i - 1) (a - y, b, x, y)

solve :: IO()
solve = do
    (n: b: x: y: _) <- readIntArr
    print $ calc n (0, b, x, y)

for :: Int -> IO () -> IO ()
for 0 _ = pure ()
for i f = do
    f
    for (i - 1) f

main :: IO ()
main = do
    t <- readInt
    for t solve


module Main where

main = interact $ unlines . map (\x -> unwords $ map show [1, (read x :: Int)-1])  . tail . lines

module Main where

import Control.Monad
import Data.List

getStrList :: IO [String]
getStrList = words <$> getLine

getIntList :: IO [Int]
getIntList = map read <$> getStrList

printStrList :: [String] -> IO ()
printStrList = putStrLn . intercalate " "

printList :: (Show a) => [a] -> IO ()
printList = printStrList . map show

yesOrNo :: Bool -> String
yesOrNo True = "YES"
yesOrNo False = "NO"

(-->) :: a -> (a -> b) -> b
(-->) = flip ($)

main :: IO ()
main = do
    t <- readLn
    replicateM_ t $ do
        x <- readLn
        printList [1, x - 1]

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

parseInt :: C.ByteString -> Int
parseInt = fst . fromJust . C.readInt

work :: IO ()
work = do
  x <- parseInt <$> C.getLine
  putStrLn $ "1 " ++ show (x - 1)

main :: IO ()
main = do
  n <- fmap parseInt C.getLine
  replicateM_ n work

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

main = do
		n<- read <$> getLine ::IO Int
		a<-map read<$> replicateM n getLine ::IO [Int]
		let b= map (("1 "++) .show . (\z->z-1)) a
		mapM_ putStrLn b

{-# LANGUAGE Strict #-}
import Control.Monad

solve :: [Int] -> IO ()
solve [] = return ()
solve (x:xs) = do
    putStrLn $ "1 " ++ show (x - 1)
    solve xs

main = do
    t <- readLn :: IO Int
    xs <- replicateM t readLn :: IO [Int]
    solve xs

process :: Int -> (Int,Int)
process 2 = (1,1)
process x
    | odd x = (e,o)
    | otherwise = (2,x-2)
    where
        o = until odd ( `div` 2) (x-1)
        e = (x-1) `div` o

readInt :: String -> Int
readInt = read

showPair :: (Int,Int) -> String
showPair (a,b) = show a ++ " " ++ show b

main = do
    t <- fmap readInt getLine
    xs <- fmap (map readInt.words) getContents
    putStrLn . unlines $ map (showPair.process) xs

solve :: Integer -> (Integer, Integer)
solve x = (1, x - 1)

parse :: String -> String
parse input = (show a) ++ " " ++ (show b)
  where x = read input :: Integer
        (a, b) = solve x

main :: IO ()
main = interact (unlines . map parse . tail . lines)

import Control.Monad
import Data.Foldable (traverse_)

solve :: Integer -> (Integer, Integer)
solve x = (1, x - 1)

main :: IO ()
main = do
	a <- getLine
	tests <- replicateM (read a) getLine
	traverse_ (putAns . solve . read) tests
	where putAns (x, y) = putStrLn (show x ++ " " ++ show y)

import System.IO
import Control.Monad

main :: IO ()
main = do
    getLine
    tc <- (map (solver . read) . lines) <$> getContents :: IO [[Int]]
    forM_ tc (putStrLn .unwords . map show)

solver i = [1,i-1]

import Control.Monad

solve :: [Int] -> IO ()
solve [] = return ()
solve (x:xs) = putStrLn $ "1 " ++ show (x - 1)

main = do
    t <- readLn :: IO Int
    xs <- replicateM t readLn :: IO [Int]
    solve xs

process :: Int -> (Int,Int)
process 2 = (1,1)
process x
    | odd x = (e,o)
    | otherwise = (2,x-2)
    where
        o = until odd ( `div` 2) (x-1)
        e = x `div` o

readInt :: String -> Int
readInt = read

showPair :: (Int,Int) -> String
showPair (a,b) = show a ++ " " ++ show b

main = do
    t <- fmap readInt getLine
    xs <- fmap (map readInt.words) getContents
    putStrLn . unlines $ map (showPair.process) xs


import Monad (liftM)
import Prelude hiding (print, reads)

reads :: Read a => IO [a]
reads  =  liftM (map read . words) getLine

solve :: [Int] -> [Int] -> [Int]
solve ls ks  =  solve' ([], maxBound) $ (zip ls [1..])
  where
    solve' (acc, _) []  =  reverse acc
    solve' (acc, min) ((l,num):ls)
      | m < min  =  solve' ([num], m) ls
      | m > min  =  solve' (acc, min) ls
      | otherwise  =  solve' (num:acc, min) ls
      where
        m  =  length $ filter (\k -> k `mod` l == 0) ks

print :: Show a => [a] -> IO ()
print xs  =  putStrLn (show (length xs)) >> print' xs
  where
    print' []  =  return ()
    print' [x]  =  putStrLn (show x)
    print' (x:xs)  =  putStr (show x ++ " ") >> print' xs

main :: IO ()
main  =  do
    getLine
    ls  <-  reads
    ks  <-  reads
    print $ solve ls ks

main = interact solve

solve :: String -> String
solve s = unlines $ [show $ length y, unwords $ map show $ map fst y]
  where
    [info, fInfo, mInfo] = lines s
    frogs = map (\x -> read x :: Int) $ words fInfo
    mos = map (\x -> read x :: Int) $ words mInfo
    x = map (\(i, l) -> (i, length $ filter (\m -> m `mod` l == 0) mos)) $ zip [1..] frogs
    m = minimum $ map snd x
    y = filter (\(i, c) -> c == m) x


import Data.List
import Data.Char

main = interact $ f

f :: String -> String
f = g . lines

g :: [String] -> String
g [a, b, c] =
  map (h aa bb) c
    where aa = a ++ map toUpper a
          bb = b ++ map toUpper b

h :: String -> String -> Char -> Char
h a b c =
  case elemIndex c a of
    Nothing -> c
    Just i -> b !! i

import Data.Char
import Data.List

matchCase :: Char -> Char -> Char
matchCase a b = if isUpper a then toUpper b else b

convertChar :: String -> String -> Char -> Char
convertChar keyboard1 keyboard2 c =
	    case elemIndex (toLower c) keyboard1 of
	    	 Nothing   -> c
		 Just ind -> matchCase c $ keyboard2 !! ind

main :: IO ()
main = do
     keyboard1 <- getLine
     keyboard2 <- getLine
     str <- getLine
     putStrLn $ map (convertChar keyboard1 keyboard2) str

import Data.List
import Data.Char

main = interact $ f

f :: String -> String
f = g . lines

g :: [String] -> String
g [a, b, c] =
  map h c
  where aa = a ++ map toUpper a
        bb = b ++ map toUpper b
        zipped = zip aa bb

        h :: Char -> Char
        h c =
          case elemIndex c aa of
            Nothing -> c
            Just i -> bb !! i

-- Packages installed: split text hashtables vector
-- vector-algorithms parsec bytestring unordered-containers
-- hashable scientific random async stm aeson
-- Run using: runghc file.hs
import Control.Applicative
import qualified Data.Map as M
import Data.Char

main = do
  a <- getLine
  b <- getLine
  c <- getLine
  putStrLn $ solve2 a b c

solve2 :: String -> String -> String -> String
solve2 s s' = map f
  where
    f c = maybe c id $ M.lookup c mp
    mp = foldl g M.empty (zip s s')
    g mp (a, b) = M.insert (upper a) (upper b) (M.insert a b mp)

upper a = chr (ord a - 32)

-- Try Codeforces
-- author: Leonardone @ NEETSDKASu

import Data.Char (toUpper)

main = putStrLn . solve . lines =<< getContents

solve [xs, ys, zs] = ans where
    go []     ws = ws
    go (u:us) ws = go us (trans u:ws)
    ans = reverse $ go zs []

    xxs = xs ++ map toUpper xs
    yys = ys ++ map toUpper ys

    trans c = p where
        (x1, x2) = span (/= c) xxs
        p = if x2 == [] then c
            else yys !! length x1

import Data.List
import Data.Char
import Data.Maybe
f alph1 alph2 text = zipWith toSameCase (map (\x-> (alph2++['0'..'9'])!!x) $ map fromJust [elemIndex i (alph1++['0'..'9'])|i<-map toLower text]) text
	where
		toSameCase x y
			|isUpper y=toUpper x
			|otherwise=toLower x
main=do
	a<-getLine
	b<-getLine
	c<-getLine
	putStrLn $ f a b c

import qualified Data.Map as M
import qualified Data.Char as C

main :: IO ()
main =
  do
    a <- getLine
    b <- getLine
    ans <- getLine

    putStrLn $ map (\x -> case M.lookup (C.toLower x) $ M.fromList $ zip a b of Just t -> if C.isUpper x then C.toUpper t else t ; otherwise -> x) $ ans

import Data.Char
import Data.Maybe
main = interact $ solve . lines
solve [l1,l2,t] = mapMaybe (flip lookup lut) t where
  lut = zip l1 l2 ++
        zip (map toUpper l1) (map toUpper l2) ++
        zip ['0'..'9'] ['0'..'9']

import Data.Map( fromList, (!))
import Data.Char( isUpper, isDigit, toUpper, toLower)
main = do
    from_ <- getLine
    to_ <- getLine
    toEnc_ <- getLine
    let
	mp = fromList $ zip from_ to_

	encode c = let
			c' = mp!(toLower c)
		    in
			if isDigit c
			    then c
			    else if isUpper c
				then toUpper c'
				else c'
    putStr $ map encode toEnc_

import qualified Data.Map as Map
import Data.Char
import Data.Maybe

make_layout_map::String->String->Map.Map Char Char
make_layout_map s1 s2 = Map.fromList$zipWith (\k v->(k, v)) s1 s2

convert_char::Map.Map Char Char->Char->Char
convert_char layout_map c
    |isLower c = fromJust$Map.lookup c layout_map
    |isUpper c = toUpper$fromJust$Map.lookup (toLower c) layout_map
    |otherwise = c

convert_string::Map.Map Char Char->String->String
convert_string layout_map s = map (convert_char layout_map) s

solution::[String]->String
solution [fst_layout, scn_layout, data_in] =
    convert_string (make_layout_map fst_layout scn_layout) data_in

main = interact$(solution.lines)

{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-}
module Main where
import qualified Data.ByteString.Char8 as B
import Data.Array.Unboxed
import Data.Char

main = do
  f <- getLine
  s <- getLine
  t <- getLine
  putStr $ solve f s t

solve f s = map (\c -> if isDigit c then c else (if isAsciiUpper c then toUpper else id) $ f2s!toLower c)
  where f2s = array ('a', 'z') $ zip f s :: UArray Char Char

readInt = maybe undefined fst . B.readInt
readInts = fmap readInt . B.words

import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.Map as M
import Data.Char

main = do
		a<-getLine
		b<-getLine
		c<-getLine
		let ma = M.fromList $ zip (a++ (map toUpper a) ++ "0123456789") (b++ (map toUpper b) ++ "0123456789")
		putStrLn $ map (\z-> fromJust (M.lookup z ma)) c

import Data.Char

main = interact $ f

f :: String -> String -- String is the collection of strings
f = g . lines  -- lines breaks a string up into a list of strings at newline characters.

g :: [String] -> String  -- [String] is the collection of lists of strings
g [a, b, c] = map h c    -- map :: (a -> b) -> [a] -> [b]  -- (a->b) is first arg. [a] is second arg
-- map f xs is the list obtained by applying f to each element of xs, i.e.,
-- map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]

    where
        upperA = map toUpper a  -- a is a list of characters
        upperB = map toUpper b
        aA = a ++ upperA
        bB = b ++ upperB

        h :: Char -> Char
        h c = answer
            where    zipped = zip aA bB

                     checkTuple :: (Char,Char) -> Bool
                     checkTuple (c1, _) = c == c1

                     v = filter checkTuple zipped
                     --answer = snd (head (filter checkTuple zipped) )  -- head : [a,b] \mapsto a

                     answer = if length v == 0 then c
                              else snd (head (filter checkTuple zipped) )

import Data.Array (array, (!))
import Data.Char (isDigit, isLower, toUpper, toLower)

process :: [Char] -> [Char] -> [Char] -> [Char]
process l1 l2 = map f
    where
        a = array ('a', 'z') $ zip l1 l2
        f x
            | isDigit x = x
            | isLower x = a ! x
            | otherwise = toUpper (a ! (toLower x))

main :: IO ()
main = do
    l1 <- getLine
    l2 <- getLine
    s <- getLine
    putStrLn $ process l1 l2 s

import Data.Maybe
main = interact $ solve . lines
solve [l1,l2,t] = mapMaybe (flip lookup (zip l1 l2)) t

import qualified Data.Map as Map
import Data.Char
import Data.Maybe

make_layout_map::String->String->Map.Map Char Char
make_layout_map s1 s2 = Map.fromList$zipWith (\k v->(k, v)) s1 s2

convert_char::Map.Map Char Char->Char->Char
convert_char layout_map c
    |isLower c = fromJust$Map.lookup c layout_map
    |isUpper c = toUpper$fromJust$Map.lookup (toLower c) layout_map
    |otherwise = c

convert_string::Map.Map Char Char->String->String
convert_string layout_map s = map (convert_char layout_map) s

solution::[String]->String
solution [fst_layout, scn_layout, data_in] =
    convert_string (make_layout_map fst_layout scn_layout) data_in

main = interact$(show.solution.lines)


main = interact $ unwords . map show . sol . map read . words

sol [n, m] = filter (<=m) . take (n*4) . concat . map (\x -> [2*n+x, x]) $ [1..]

import Data.Array (array, (!))

main = do
  [n, m] <- fmap (map read . words) getLine

  let
    a = array (1,4*n) $ zip (concat [[4*i+1, 4*i+4] | i <- [0..n-1]] ++ concat [[4*i+2, 4*i+3] | i <- [0..n-1]]) [1..]
    b = concat [[4*i+2,4*i+1,4*i+3,4*i+4] | i <- [0..n-1]]
    r = filter (<= m) $ map (a !) b

  putStrLn $ unwords $ map show r

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

import           System.IO hiding (char8)
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Tuple
import           Data.Int
import           Data.Char
import           Data.Function (on)
import           Data.Array
import           Data.Ix
import           Data.Maybe
import           Data.Monoid hiding ((<>))
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BL
import           Data.ByteString.Builder
-- import           Data.Array.ST
-- import           Data.Array.Unsafe
-- import           Data.Vector.Unboxed ((//), (++), (!), (!?))
-- import qualified Data.Vector.Unboxed as U
-- import           Data.IntMap.Strict (IntMap)
-- import qualified Data.IntMap.Strict as IntMap
-- import           Data.Sequence ((|>), (<|), (><),ViewR((:>)), ViewL((:<)))
-- import qualified Data.Sequence as S
-- import           Debug.Trace

out = stdout

main = do
  (n,m) <- readInt2 <$> BS.getLine
  putAns out . makeTable $ solve n m

solve :: Int -> Int -> [Int]
solve n m = filter (<= m) . concat . transpose $ [col2,col1,col3,col4] where
  col1 = map pred col4
  col2 = map (+(2*n)) col1
  col3 = map (+(2*n)) col4
  col4 = map (*2) [1..n]

makeTable :: [Int] -> Table
makeTable xs = [ListR (map (\x -> IntC x) xs)]

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

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

readInt2 :: BS.ByteString -> (Int,Int)
readInt2 = toTuple . readIntN

readInt3 :: BS.ByteString -> (Int,Int,Int)
readInt3 = toTriple . readIntN

readIntN :: BS.ByteString -> [Int]
readIntN =  map readInt1 . BS.words

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

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

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

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

-- if not applying, use "const"

applyTuple :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
applyTuple f g (x, y) = (f x, g y)

applyTriple :: (a -> a') -> (b -> b') -> (c -> c') -> (a, b, c) -> (a', b', c')
applyTriple f g h (x, y, z) = (f x, g y, h z)

-- output functions

data Cell  = ByteStringC BL.ByteString
           | IntC Int
           | Int64C Int64
           deriving( Eq, Ord, Show )

data Row   = ListR [Cell]
           | SingleR Cell
           | TupleR (Cell,Cell)
           | TripleR (Cell,Cell,Cell)
           deriving( Eq, Ord, Show )

type Table = [Row]

infixr 4 <>
(<>) :: Monoid m => m -> m -> m
(<>) = mappend

putAns :: Handle -> Table -> IO ()
putAns o = hPutBuilder o . renderTable

renderTable :: Table -> Builder
renderTable rs = mconcat [renderRow r <> char8 '\n' | r <- rs]

renderRow :: Row -> Builder
renderRow (ListR []) = mempty
renderRow (ListR (c:cs)) = renderCell c <> mconcat [ char8 ' ' <> renderCell c' | c' <- cs ]
renderRow (SingleR x) = renderCell x
renderRow (TupleR (x,y)) = renderCell x <> char8 ' ' <> renderCell y
renderRow (TripleR (x,y,z)) = renderCell x <> char8 ' ' <> renderCell y <> char8 ' ' <> renderCell z

renderCell :: Cell -> Builder
renderCell (ByteStringC cs) = lazyByteString cs
renderCell (IntC i) = intDec i
renderCell (Int64C i) = int64Dec i


module Main where

import Control.Monad
import Control.Monad.ST
import Data.Array.IO
import Data.Array
import Data.Array.ST
import Data.List

data Road = Road { roadTo, roadCost :: !Int } deriving Show;

main = do
    n <- read `liftM` getLine

    roadArray <- newArray (1,n) [] :: IO (IOArray Int [Road])
    replicateM_ n $ do
        [a, b, c] <- ( map read . words ) `liftM` getLine
        readArray roadArray a >>= writeArray roadArray a . ( Road b c : )
        readArray roadArray b >>= writeArray roadArray b . ( Road a 0 : )

    roadIArray <- freeze roadArray :: IO (Array Int [Road])
    --putStrLn $ show roadIArray

    let pathCost :: Int -> Int -> Int
        pathCost last_v v = if v == 1
            then 0
            else maybe 0 ( \Road { roadTo=to, roadCost=cost } -> cost + pathCost v to ) ( find ( \Road { roadTo=to } -> to /= last_v ) ( roadIArray ! v ) )

        routeCost = map ( \Road { roadTo=to, roadCost=cost } -> cost + pathCost 1 to ) ( roadIArray ! 1 )

    putStrLn $ show $ minimum routeCost

import Control.Monad (liftM, replicateM)
import Data.Array (Array, (!), accumArray)
import Data.List (intercalate)
import Prelude hiding (reads)

reads :: Read a => IO [a]
reads  =  liftM (map read . words) getLine

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

type City  =  Int
type Cost  =  Int
type Map  =  Array City [(City, Cost)]

solve :: [[Int]] -> Int
solve roads  =  min way1 way2
  where
    n  =  length roads
    map :: Map
    map  =  accumArray (++) [] (1, n) $ concat
        [[(a, [(b, 0)]), (b, [(a, c)])] | [a, b, c] <- roads]
    [a, b, c]  =  head roads
    way1  =  way 1 a b
    way2  =  c + way 1 b a
    way i x y
      | i == n  =  0
      | fst (head (map ! y)) /= x  =  snd (head (map ! y)) + way (i+1) y (fst (head (map ! y)))
      | otherwise  =  snd ((map ! y) !! 1) + way (i+1) y (fst ((map ! y) !! 1))

main :: IO ()
main  =  do
    n  <-  readLn
    roads  <-  replicateM n reads
    print $ solve roads

data Road = Road { src :: Int
                 , dst :: Int
                 , cost :: Int
                 } deriving (Eq)

main :: IO ()
main = interact func

func :: String -> String
func s = let ds = lines s
             n  = head ds
             rs = tail ds
         in show (func' (read n) (map toRoad rs))

toRoad :: String -> Road
toRoad s = let ws = words s in Road { src = read $ ws!!0
                                    , dst = read $ ws!!1
                                    , cost = read $ ws!!2
                                    }

func' :: Int -> [Road] -> Int
func' _ rs = if costOne < costAnother
             then costOne
             else costAnother
  where oc = ocf ++ oct
        ocf = connectFrom 1 rs
        oct = connectTo 1 rs
        costOne = cycleCost 1 (oc!!0) rs
        costAnother = cycleCost 1 (oc!!1) rs

cycleCost :: Int -> Road -> [Road] -> Int
cycleCost pos road rs = if nextPos == 1
                        then nowCost
                        else nowCost + cycleCost nextPos nextRoad rs
  where nextRoad = head $ filter (\r -> r /= road) $ connected pos rs
        (nextPos, nowCost) = if src nextRoad == pos
                             then (dst nextRoad, 0)
                             else (src nextRoad, cost nextRoad)

connected :: Int -> [Road] -> [Road]
connected n rs = connectFrom n rs ++ connectTo n rs

connectFrom :: Int -> [Road] -> [Road]
connectFrom n rs = filter (\r -> src r == n) rs

connectTo :: Int -> [Road] -> [Road]
connectTo n rs = filter (\r -> dst r == n) rs


{-# LANGUAGE OverloadedStrings #-}
import Data.Char (isDigit)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS

extract :: ByteString -> (ByteString, ByteString)
extract s0  = go s0 [] [] False False
  where
    isOK c = c /= ';' && c /= ','
    go s xs ys last_empty has_empty
      | BS.null s =
          let ys' | last_empty = "":ys | otherwise = ys
              as = BS.intercalate "," (reverse xs)
              bs = BS.intercalate "," (reverse ys')
              as' | BS.null as = "-" | otherwise = surround '"' as
              bs' | BS.null bs && not has_empty && not last_empty = "-" | otherwise = surround '"' bs
          in (as', bs')
      | not (BS.null wd)
        && (BS.head wd /= '0' || BS.length wd == 1)
        && BS.all isDigit wd = go rest (wd:xs) ys last_empty' has_empty
      | otherwise = go rest xs (wd:ys) last_empty' (has_empty || BS.null wd)
      where
        (wd, rest') = BS.span isOK s
        last_empty' = rest' == "," || rest' == ";"
        rest | BS.null rest' = rest'
             | otherwise = BS.tail rest'

surround :: Char -> ByteString -> ByteString
surround c bs = BS.cons c (BS.snoc bs c)

darnit :: ByteString -> ByteString
darnit s
  | BS.last s == '\r' = BS.init s
  | otherwise = s

main :: IO ()
main = do
  s <- BS.getLine
  let (xs, ys) = extract (darnit s)
  BS.putStrLn xs
  BS.putStrLn ys

import Text.Printf
import Data.List
import Data.Char

main = do
    s <- getLine
    let (nums, other) = solve (splitWhen (\c -> c == ',' || c == ';') s)
    printf "%s\n%s\n" (pad nums) (pad other)

pad :: [String] -> String
pad [] = "-"
pad xs = "\"" ++ (intercalate "," xs) ++ "\""

solve :: [String] -> ([String], [String])
solve [] = ([], [])
solve (x:xs)
    | isNonNegativeNumber x = let (nums,rest) = solve xs in (x:nums, rest)
    | otherwise  = let (nums,rest) = solve xs in (nums, x:rest)

isNonNegativeNumber :: String -> Bool
isNonNegativeNumber [] = False
isNonNegativeNumber "0" = True
isNonNegativeNumber s  = let (lead,rest) = span (\c -> c == '0') s
                             (_,junk) = span isDigit rest
                         in lead == [] && junk == []

splitWhen :: Eq a => (a -> Bool) -> [a] -> [[a]]
splitWhen _ [] = [[]]
splitWhen f xs = let (prefix,rest) = span (\y -> not (f y)) xs in if rest /= [] then prefix:(splitWhen f (drop 1 rest)) else [prefix]

import Data.List
import Data.List.Split
import Data.Char

main = do
    s <- getLine
    let
        l = splitOneOf ",;" s
        a = filter check l
        b = filter (not . check) l
        check s = s == "0" || (not (null s) && head s /= '0' && all isDigit s)

    if null a then putStrLn "-" else print (intercalate "," a)
    if null b then putStrLn "-" else print (intercalate "," b)

import Control.Arrow
import Data.Char
import Data.List

main = interact $ f . mySplit . filter (/= '\n')

mySplit [] = [[]]
mySplit s = let (x, y) = span (\c -> c /= ',' && c /= ';') s in if null y then [x] else x : mySplit (tail y)

f ws = let (w1, w2) = partition (\s -> if null s then False else s == "0" || (head s /= '0' && all isDigit s)) ws in (g w1) ++ "\n" ++ (g w2)
g w = if null w then "-" else (show . concat $ intersperse "," w)

-- A. Exact Numbers

import Data.Char(isDigit)
import Data.List(intercalate)

split :: String -> [String]
split []      = [""]
split (',':t) = "" : split t
split (';':t) = "" : split t
split (h:t)   = (h : (head . split) t) : (tail . split) t

isInteger :: String -> Bool
isInteger x = all isDigit x && (not . null) x && x == show (read x :: Integer)

myConcat :: [String] -> String
myConcat [] = "-"
myConcat x = '\"' : (intercalate "," x) ++ "\""

process :: String -> (String, String)
process x = (myConcat (filter isInteger (split x)), myConcat (filter (not . isInteger) (split x)))

main :: IO()
main =
    do  line <- getLine
        let (a, b) = process line
        putStrLn a
        putStrLn b
        return ()

import Data.List

main = do
    s <- getLine
    let ns = split s
        (nums, other) = partition isNum ns
    putStrLn $ if null nums then "-" else show $ intercalate "," nums
    putStrLn $ if null other then "-" else show $ intercalate "," other

split :: String -> [String]
split
    = foldr (\v (a : as) ->
        if v `elem` delim then [] : a : as else (v : a) : as) [[]]
    where delim = ",;"

isNum :: String -> Bool
isNum []
    = False
isNum "0"
    = True
isNum (x : xs)
    = isDigit x && x /= '0' && all isDigit xs

isDigit :: Char -> Bool
isDigit c
    = '0' <= c && c <= '9'

sol a b
    | a `mod` b == 0 = a `div` b
    | otherwise = a `div` b + sol b (a `mod` b)

import Data.List

main = do
    s <- getLine
    let ns = split s
        (nums, other) = partition isNum ns
    putStrLn $ if null nums then "-" else show $ intercalate "," nums
    putStrLn $ if null other then "-" else show $ intercalate "," other
    where isNum []
            = False
          isNum "0"
              = True
          isNum (x : xs)
              = isDigit x && x /= '0' && all isDigit xs
          isDigit c
              = '0' <= c && c <= '9'

split
    = foldr (\v (a : as) ->
        if v `elem` delim then [] : a : as else (v : a) : as) [[]]
    where delim = ",;"

import Data.List

main = do
	s <- getLine >>= return.split
	putStrLn $ display $ filter isNumber s
	putStrLn $ display $ filter (not.isNumber) s

display [] = "-"
display x = "\""++(concat $ intersperse "," x)++"\""

isNumber "0" = True
isNumber x = isNumber' False x

isNumber' ok [] = ok
isNumber' ok (x:xs)
	| x=='0'			= if ok then isNumber' ok xs else False
	| x`elem`['1'..'9'] = isNumber' True xs
	| otherwise 		= False

split = split' ""

split' :: String -> String -> [String]
split' cur [] = [reverse cur]
split' cur (x:xs)
	| x`elem`";," = (reverse cur):(split' "" xs)
	| otherwise   = split' (x:cur) xs

import Data.List

main = do
	s <- getLine
	let ss = sp "" s
	putStrLn $ display $ filter isNum ss
	putStrLn $ display $ filter (not.isNum) ss

display [] = "-"
display x = "\"" ++ (concat $ intersperse "," x) ++ "\""

isNum "0" = True
isNum x
	|	x==""	= False
	|	head x=='0'	=	False
	|	otherwise = all (\y -> y `elem` ['0'..'9']) x

sp x [] = [reverse x]
sp x (y:ys)
	| y==',' || y==';'	= (reverse x) : (sp "" ys)
	| otherwise			= sp (y:x) ys

import Text.Printf
import Data.List
import Data.Char

main = do
    s <- getLine
    let (nums, other) = solve (splitWhen (\c -> c == ',' || c == ';') s)
    printf "%s\n%s\n" (pad nums) (pad other)

pad :: [String] -> String
pad [] = "-"
pad xs = "\"" ++ (intercalate "," xs) ++ "\""

solve :: [String] -> ([String], [String])
solve [] = ([], [])
solve (x:xs)
    | isNonNegativeNumber x = let (nums,rest) = solve xs in (x:nums, rest)
    | otherwise  = let (nums,rest) = solve xs in (nums, x:rest)

isNonNegativeNumber :: String -> Bool
isNonNegativeNumber [] = False
isNonNegativeNumber "0" = True
isNonNegativeNumber s  = let (lead,rest) = span (\c -> c == '0') s
                             (_,junk) = span isDigit rest
                         in lead == [] && junk == []

splitWhen :: Eq a => (a -> Bool) -> [a] -> [[a]]
splitWhen _ [] = []
splitWhen f xs = let (prefix,rest) = span (\y -> not (f y)) xs in if rest /= [] then prefix:(splitWhen f (drop 1 rest)) else [prefix]

{-# LANGUAGE OverloadedStrings #-}
import Data.Char (isDigit)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS

extract :: ByteString -> (ByteString, ByteString)
extract s0  = (as', bs')
  where
    isOK c = c /= ';' && c /= ','
    (as, bs) = go s0 [] []
    as' | BS.null as = "-" | otherwise = surround '"' as
    bs' | BS.null bs = "-" | otherwise = surround '"' bs
    go s xs ys
      | BS.null s = (BS.intercalate "," (reverse xs), BS.intercalate "," (reverse ys))
      | not (BS.null wd)
        && (BS.head wd /= '0' || BS.length wd == 1)
        && BS.all isDigit wd = go rest (wd:xs) ys
      | otherwise = go rest xs (wd:ys)
      where
        (wd, rest') = BS.span isOK s
        rest | BS.null rest' = rest' | otherwise = BS.tail rest'

surround :: Char -> ByteString -> ByteString
surround c bs = BS.cons c (BS.snoc bs c)

main :: IO ()
main = do
  s <- BS.getLine
  let (xs, ys) = extract s
  BS.putStrLn xs
  BS.putStrLn ys

{-# LANGUAGE OverloadedStrings #-}
import Data.Char (isDigit)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS

extract :: ByteString -> (ByteString, ByteString)
extract s0  = go s0 [] [] False
  where
    isOK c = c /= ';' && c /= ','
    go s xs ys last_empty
      | BS.null s =
          let ys' | last_empty = "":ys | otherwise = ys
              as = BS.intercalate "," (reverse xs)
              bs = BS.intercalate "," (reverse ys')
              as' | BS.null as = "-" | otherwise = surround '"' as
              bs' | BS.null bs && not last_empty = "-" | otherwise = surround '"' bs
          in (as', bs')
      | not (BS.null wd)
        && (BS.head wd /= '0' || BS.length wd == 1)
        && BS.all isDigit wd = go rest (wd:xs) ys last_empty'
      | otherwise = go rest xs (wd:ys) last_empty'
      where
        (wd, rest') = BS.span isOK s
        last_empty' = rest' == "," || rest' == ";"
        rest | BS.null rest' = rest'
             | otherwise = BS.tail rest'

surround :: Char -> ByteString -> ByteString
surround c bs = BS.cons c (BS.snoc bs c)

darnit :: ByteString -> ByteString
darnit s
  | BS.last s == '\r' = BS.init s
  | otherwise = s

main :: IO ()
main = do
  s <- BS.getLine
  let (xs, ys) = extract (darnit s)
  BS.putStrLn xs
  BS.putStrLn ys

{-# LANGUAGE OverloadedStrings #-}
import Data.Char (isDigit)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS

extract :: ByteString -> (ByteString, ByteString)
extract s0  = go s0 [] [] False False
  where
    isOK c = c /= ';' && c /= ','
    go s xs ys last_empty has_empty
      | BS.null s =
          let ys' | last_empty = "":ys | otherwise = ys
              as = BS.intercalate "," (reverse xs)
              bs = BS.intercalate "," (reverse ys')
              as' | BS.null as = "-" | otherwise = surround '"' as
              bs' | BS.null bs && not has_empty = "-" | otherwise = surround '"' bs
          in (as', bs')
      | not (BS.null wd)
        && (BS.head wd /= '0' || BS.length wd == 1)
        && BS.all isDigit wd = go rest (wd:xs) ys last_empty' has_empty
      | otherwise = go rest xs (wd:ys) last_empty' (has_empty || BS.null wd)
      where
        (wd, rest') = BS.span isOK s
        last_empty' = rest' == "," || rest' == ";"
        rest | BS.null rest' = rest'
             | otherwise = BS.tail rest'

surround :: Char -> ByteString -> ByteString
surround c bs = BS.cons c (BS.snoc bs c)

darnit :: ByteString -> ByteString
darnit s
  | BS.last s == '\r' = BS.init s
  | otherwise = s

main :: IO ()
main = do
  s <- BS.getLine
  let (xs, ys) = extract (darnit s)
  BS.putStrLn xs
  BS.putStrLn ys

{-# LANGUAGE OverloadedStrings #-}
import Data.Char (isDigit)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS

extract :: ByteString -> (ByteString, ByteString)
extract s0  = (as', bs')
  where
    isOK c = c /= ';' && c /= ','
    (as, bs) = go s0 [] [] False
    as' | BS.null as = "-" | otherwise = surround '"' as
    bs' | BS.null bs = "-" | otherwise = surround '"' bs
    go s xs ys last_empty
      | BS.null s && last_empty = fmap (`BS.snoc` ',') (go "" xs ys False)
      | BS.null s = (BS.intercalate "," (reverse xs), BS.intercalate "," (reverse ys))
      | not (BS.null wd)
        && (BS.head wd /= '0' || BS.length wd == 1)
        && BS.all isDigit wd = go rest (wd:xs) ys last_empty'
      | otherwise = go rest xs (wd:ys) last_empty'
      where
        (wd, rest') = BS.span isOK s
        last_empty' = rest' == "," || rest' == ";"
        rest | BS.null rest' = rest'
             | otherwise = BS.tail rest'

surround :: Char -> ByteString -> ByteString
surround c bs = BS.cons c (BS.snoc bs c)

darnit :: ByteString -> ByteString
darnit s
  | BS.last s == '\r' = BS.init s
  | otherwise = s

main :: IO ()
main = do
  s <- BS.getLine
  let (xs, ys) = extract (darnit s)
  BS.putStrLn xs
  BS.putStrLn ys

import Data.List

main = do
	s <- getLine >>= return.split
	putStrLn $ display $ filter isNumber s
	putStrLn $ display $ filter (not.isNumber) s

display [] = "-"
display x = "\""++(concat $ intersperse "," x)++"\""

isNumber "0" = True
isNumber x = isNumber' False x

isNumber' ok [] = ok
isNumber' ok (x:xs)
	| x=='0'			= if ok then isNumber' ok xs else False
	| x`elem`['1'..'9'] = isNumber' True xs
	| otherwise 		= False

split = split' ""

split' :: String -> String -> [String]
split' cur [] = [cur]
split' cur (x:xs)
	| x`elem`";," = (reverse cur):(split' "" xs)
	| otherwise   = split' (x:cur) xs

main = do
	s <- getLine
	let f = gg [] s ""
	let a = gi [] [] f
	if head a == []
	then
		putStrLn "-"
	else
		putStrLn $ ['"'] ++ (foldl (\x y -> x ++ [','] ++ y) (head $ head $ a) (tail  $ head $ a)) ++ ['"']
	if last	a == []
	then
		putStrLn "-"
	else
		putStrLn $ ['"'] ++ (foldl (\x y -> x ++ [','] ++ y) (head $ last $  a) (tail $ last $  a) )++ ['"']

gi x z [] = [x,z]
gi x z (y:ys)
	| y == "" = gi x (z++[y]) ys
	| head y == '0' && y/="0" = gi x (z++[y]) ys
	| all (\x -> x `elem` ['0','1','2','3','4','5','6','7','8','9']) y == True = gi (x ++ [y]) z ys
	| otherwise = gi x (z++[y]) ys

gg x [] z
	|	z==[]	=	x
	|	otherwise = x ++ [z]
gg x (y:ys)	z
	|	y==',' || y==';'	= gg (x ++ [z]) ys []
	|	otherwise			= gg x ys (z++[y])

main = do
	s <- getLine
	let f = gg [] s ""
	let a = gi [] [] f
	if head a == []
	then
		putStrLn "\45"
	else
		putStrLn $ ['"'] ++ (foldl (\x y -> x ++ [','] ++ y) (head $ head $ a) (tail  $ head $ a)) ++ ['"']
	if last	a == []
	then
		putStrLn "\45"
	else
		putStrLn $ ['"'] ++ (foldl (\x y -> x ++ [','] ++ y) (head $ last $  a) (tail $ last $  a) )++ ['"']

gi x z [] = [x,z]
gi x z (y:ys)
	| y == "" = gi x (z++[y]) ys
	| head y == '0' && y/="0" = gi x (z++[y]) ys
	| all (\x -> x `elem` ['0','1','2','3','4','5','6','7','8','9']) y == True = gi (x ++ [y]) z ys
	| otherwise = gi x (z++[y]) ys

gg x [] z
	|	z==[]	=	x
	|	otherwise = x ++ [z]
gg x (y:ys)	z
	|	y==',' || y==';'	= gg (x ++ [z]) ys []
	|	otherwise			= gg x ys (z++[y])


module Main where

import Control.Monad

generator :: Int -> String
generator n | n <= 1         = "-1"
            | n `mod` 3 == 1 = (take m $ repeat '9') ++ "8"
            | otherwise      = (take m $ repeat '8') ++ "3"
    where m = n - 1

readInt :: IO Int
readInt = read <$> getLine

main :: IO ()
main = do
    n <- readInt
    s <- replicateM n $ readInt
    let s' = generator <$> s
    forM_ s' putStrLn

f :: Int -> String
f 1 = "-1"
f n =
  let a = replicate (n - 1) 5 ++ [3]
      b = replicate (n - 2) 5 ++ [3, 3]
  in  if sum a `mod` 3 /= 0 then concatMap show a else concatMap show b

main = interact $ unlines . map (f . read) . tail . lines

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

main = getLine >>= test.read
test 0 = return ()
test i = do
  n <- read <$> getLine
  if n == 1
    then print $ -1
    else putStrLn $ replicate (n - 1) '5' ++ "8"
  test (i - 1)

import Control.Monad (replicateM_)

main = readLn >>= flip replicateM_ (readLn >>= print . f)

f :: Int -> Integer
f 1 = -1
f n = read $ "2" ++ replicate (n-1) '7'

import Control.Monad

main = do
    numTests <- readLn
    inputs <- replicateM numTests readLn
    mapM_ (putStrLn . ans) inputs

ans :: Int -> String
ans 1 = "-1"
ans n = '2' : (replicate (n - 1) '3')


module Main
where

import           Data.List (words, all, intercalate)

main :: IO ()
main = intercalate "\n" <$> map yesNo <$> map feasible <$> (read <$> getLine >>= readNCordFields) >>= putStrLn

data Square = E | R deriving (Show, Read, Eq)
type Field = [[Square]]

  {- stdin section -}
    {- all functions trust on stdin validity -}

readNCordFields :: Int -> IO [Field]
readNCordFields n = sequence $ replicate n readOneCordField

readOneCordField :: IO Field
readOneCordField = readField <$> (fst <$> readCord <$> getLine >>= readNLines)

readNLines :: Int -> IO [String]
readNLines n = sequence $ replicate n getLine

readCord :: String -> (Int, Int)
readCord str = toPair $ map (read) $ words str

readField :: [String] -> Field
readField [] = []
readField (x:xs) = (readln x):(readField xs)
  where readln :: [] Char -> [] Square
        readln str = (read . singleton) <$> str

  {- Parsing field section -}

-- constrain: must be >= 1 robot on the field
feasible :: Field -> Bool
feasible f
  | topLeftR f = True
  | topE f = feasible (noTop f)
  | leftmostE f = feasible (noLeftmost f)
  | otherwise = False

noLeftmost :: Field -> Field
noLeftmost f = (drop 1) <$> f

leftmostE :: Field -> Bool
leftmostE f = all (\ln -> ln !! 0 == E) f

noTop :: Field -> Field
noTop f = drop 1 f

topE :: Field -> Bool
topE f = all (== E) $ f !! 0

topLeftR :: Field -> Bool
topLeftR f = f !! 0 !! 0 == R

  {- Output fmt section -}

yesNo :: Bool -> String
yesNo True = "YES"
yesNo False = "NO"

  {- util functions section -}

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

singleton :: a -> [a]
singleton a = [a]

--
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DatatypeContexts #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TupleSections #-}

import Control.Arrow ((>>>))
import Control.Monad (
    MonadPlus (mplus),
    foldM_,
    forM_,
    guard,
    join,
    replicateM,
    replicateM_,
 )
import qualified Control.Monad.ST.Strict as ST
import qualified Control.Monad.State.Strict as S

import qualified Data.Array as A
import qualified Data.Array.MArray.Safe as MA
import qualified Data.Array.IO.Safe as IOA
import qualified Data.Array.ST.Safe as STA
import qualified Data.Array.Unboxed as UA

import Data.Bits
import qualified Data.ByteString.Char8 as B8
import Data.Char
import Data.Int

import Data.Function (on)
import Data.Functor ((<&>))
import Data.Bifunctor (bimap)
import Data.Maybe (fromJust, fromMaybe, isJust)

import qualified Data.IntMap as IM
import qualified Data.IntSet as IS
import qualified Data.List   as L
import Data.List (
    elemIndices,
    find,
    findIndices,
    intersect,
    isPrefixOf,
    nub,
    sort,
    sortOn,
 )
import qualified Data.Map as M
import qualified Data.Set as S

import Control.Monad.Cont (MonadIO (liftIO))
import Data.IORef (modifyIORef, newIORef, readIORef)
import GHC.IO.Handle (hDuplicateTo)
import System.IO (
    IOMode (ReadMode, WriteMode),
    openFile,
    stdin,
    stdout,
 )
import System.Posix.Internals (puts)
import Text.Printf (printf)
import qualified Data.Array.IO.Safe as UOA

-- import Debug.Trace (trace, traceM, traceShowM)
-- debug = flip trace

readIntB8 :: B8.ByteString -> Int
readIntB8 = B8.readInt >>> (fst . fromJust)

readIntB8s :: B8.ByteString -> [Int]
readIntB8s = B8.words >>> map (B8.readInt >>> (fst . fromJust))

readIntegerB8 :: B8.ByteString -> Integer
readIntegerB8 = B8.readInteger >>> (fst . fromJust)

readIntegerB8s :: B8.ByteString -> [Integer]
readIntegerB8s = B8.words >>> map (B8.readInteger >>> (fst . fromJust))

modifyArray :: (MA.MArray a e m, MA.Ix i) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = do
    value <- MA.readArray arr ix
    MA.writeArray arr ix $ f value

putsYesNo :: Bool -> IO ()
putsYesNo value = do
    let result :: String =
            if value
                then "YES"
                else "NO"
    printf "%s\n" result

{- END OF GENERAL -}

solve :: Int -> Int -> UA.UArray (Int, Int) Char -> Bool
solve n m arr = (arr UA.! (minI, minJ)) == 'R'
    where
        rIndexes = L.map fst . L.filter (\(i, e) -> e == 'R') $ UA.assocs arr
        (minI, minJ) = foldr (\(minI, minJ) (i, j) -> (min i minI, min j minJ)) (n - 1, m - 1) rIndexes

main :: IO ()
main = do
    t <- B8.getLine <&> readIntB8
    replicateM_ t $ do
        [n, m] <- B8.getLine <&> readIntB8s
        arr <- MA.newArray ((0, 0), (n - 1, m - 1)) '_' :: IO (IOA.IOArray (Int, Int) Char)
        forM_ [0 .. n - 1] $ \i -> do
            line <- B8.getLine <&> B8.filter (\c -> c `L.elem` ['R', 'E'])
            forM_ [0 .. m - 1] $ \j -> do
                MA.writeArray arr (i, j) (line `B8.index` j)
        farr <- MA.freeze arr

        let answer = solve n m farr
        putsYesNo answer

indexOf :: Char -> [Char] -> Int
indexOf k a = search 0 k a
 where
  search _ _ [] = (-1)
  search i k (x : xs)
   | (k == x) = i
   | otherwise = search (i + 1) k xs

readLine = do
 input <- getLine
 return input

ans = do
 nmInput <- getLine
 let (n : m : []) = [read x :: Int | x <- words nmInput]
 grid <- sequence (replicate n readLine)
 let pos = [indexOf 'R' line | line <- grid]
 let (first : rest) = [x | x <- pos, x > (-1)]
 let beforeFirst = [x | x <- rest, x < first]
 let result = if (length beforeFirst > 0) then "NO" else "YES"
 return result

main = do
 tInput <- getLine
 let t = read tInput :: Int
 results <- sequence (replicate t ans)
 putStrLn (unwords results)


readInts :: IO [Int]
readInts = fmap (map read.words) getLine

sol :: [Int] -> [Char]
sol xx | odd $ sum xx = "YES"
       | any (odd) xx && any (even) xx = "YES"
       | otherwise = "NO"

loop :: Int -> IO ()
loop 0 = return ()
loop n = do
  i_dont_care <- getLine
  inputs <- readInts
  putStrLn $ sol inputs
  loop $ n - 1

main = do
  input1 <- getLine
  let t = (read input1 :: Int)
  loop t

import Control.Monad

getInts = do
    ls <- fmap words getLine
    return $ map read ls :: IO [Int]

main = do
    [t] <- getInts
    replicateM_ t $ do
        [n] <- getInts
        a <- getInts
        if all even a || (even n && all odd a)
            then putStrLn "NO"
            else putStrLn "YES"

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

solve :: [Int] -> Bool
solve xs
    | odd $ sum xs  = True
    | otherwise = not $ null e || null o
    where
        (e, o) = L.partition even xs

solvetc :: Int -> IO ()
solvetc 0 = do return ()

solvetc t = do
    n <- getLine
    xs <- getLine
    let ans = solve . map read . words $ xs
    putStrLn $ id (if ans == True then "YES" else "NO")
    solvetc(t - 1)

main = do
    t <- getLine
    solvetc (read t)

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

process a c d | odd a && c==a = "YES"
	      | c==a || d==a = "NO"
	      | otherwise = "YES"

onecase = do
		n<- read <$> getLine::IO Int
		a<- map read <$> words <$> getLine ::IO [Int]
		let c = length $ filter odd a
		let d= length $ filter even a
		putStrLn $ process n c d

main = do
		n<- read <$> getLine ::IO Int
		replicateM_ n onecase

process:: [Int] -> String
process xs
    | all even xs = "NO"
    | all odd (length xs+1:xs) = "NO"
    | otherwise = "YES"

readInt :: String -> Int
readInt = read

readCases :: [String] -> [[Int]]
readCases (n:a:xs) = map readInt (words a):readCases xs
readCases _ = []

main :: IO ()
main = do
    t <- fmap readInt getLine
    as <- fmap (readCases . lines) getContents
    putStrLn . unlines $ map process as

readInts :: IO [Int]
readInts = fmap (map read.words) getLine

sol :: [Int] -> [Char]
sol xx | odd len && any (odd) xx = "YES"
       | even len && any (odd) xx && any (even) xx = "YES"
       | otherwise = "NO"
  where len = length xx

loop 0 = return ()
loop n = do
  i_dont_care <- getLine
  inputs <- readInts
  putStrLn $ sol inputs
  loop $ n - 1

main = do
  input1 <- getLine
  let t = (read input1 :: Int)
  loop t

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

onecase = do
		getLine
		a<- map read <$> words <$> getLine ::IO [Int]
		let c = take 1 $ filter odd a
		putStrLn $ if length c==1 then "YES" else "NO"

main = do
		n<- read <$> getLine ::IO Int
		replicateM_ n onecase

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

onecase = do
		n<- read <$> getLine::IO Int
		a<- map read <$> words <$> getLine ::IO [Int]
		let c = length $ filter odd a
		let d= length $ filter even a
		putStrLn $ if (c==n || d==n)  then "NO" else "YES"

main = do
		n<- read <$> getLine ::IO Int
		replicateM_ n onecase

readInts :: IO [Int]
readInts = fmap (map read.words) getLine

sol :: [Int] -> [Char]
sol xx | odd len && any (odd) xx = "YES"
       | even len && any (odd) xx && any (even) xx = "YES"
       | otherwise = "NO"
  where len = length xx

main = do
  inputs <- readInts
  putStrLn $ sol inputs


data Operation = L Int | R Int
instance Show Operation where
    show (L n) = "L "++(show n)
    show (R n) = "R "++(show n)

solve :: String -> [Operation]
solve string = [R (l-2), L (l-1), (L 2)]
    where l = length string

showSolution :: [Operation] -> [String]
showSolution op = (show $ length op):(map (show) op)

main :: IO()
main = do
    interact $ unlines . showSolution . solve

main :: IO ()
main = do
  s <- getLine
  let
    n = length s
  putStrLn "3"
  putStrLn "L 2"
  putStrLn "R 2"
  putStr "R "
  print $ 2 * n - 1

import Control.Arrow ((>>>))

main :: IO ()
main = interact $ lines >>> head >>> process >>> unlines

process :: String -> [String]
process xs = show (length ys) : map pr ys
  where
    ys = solve xs
    pr (o, i) = o : " " ++ show i

solve :: String -> [(Char, Int)]
solve xs = [('R', n - 1), ('R', n - 1), ('L', n + 2), ('L', 2)]
  where
    n = length xs

data Operation = L Int | R Int
instance Show Operation where
    show (L n) = "L "++(show n)
    show (R n) = "R "++(show n)

solve :: String -> [Operation]
solve string = [R (l-1), L (l-1), (R 2)]
    where l = length string

showSolution :: [Operation] -> [String]
showSolution op = (show $ length op):(map (show) op)

main :: IO()
main = do
    interact $ unlines . showSolution . solve

data Operation = L Int | R Int
instance Show Operation where
    show (L n) = "L "++(show n)
    show (R n) = "R "++(show n)

solve :: String -> [Operation]
solve string = [R (l-1), L (l-1), (R 2)]
    where l = length string

main :: IO()
main = do
    interact $ unlines . map (show) . solve

data Operation = L Int | R Int
instance Show Operation where
    show (L n) = "L "++(show n)
    show (R n) = "R "++(show n)

solve :: String -> [Operation]
solve string = [R (l-1), L (l-2), (L 2)]
    where l = length string

showSolution :: [Operation] -> [String]
showSolution op = (show $ length op):(map (show) op)

main :: IO()
main = do
    interact $ unlines . showSolution . solve


{-# LANGUAGE LambdaCase #-}

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

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

type Input = (Int, Int)
type Output = Int

input :: Scanner Input
input = pair int int

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

solve :: Input -> Output
solve (l, r)
  | l <= (r `div` 2) + 1 = (r - 1) `div` 2
  | otherwise = r - l

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

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

integer :: Scanner Integer
integer = read . C.unpack <$> bstr

double :: Scanner Double
double = read . C.unpack <$> bstr

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

import Control.Monad

calc l r | l <= (r `div` 2 + 1) =
           (r-1) `div` 2

calc l r | otherwise = r-l

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

import Control.Monad

solve :: Int -> Int -> Int
solve l r = if a >= l
                then a - 1
                else r - l
        where a = (r + 1) `div` 2

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

testCase :: IO ()
testCase = do
  (l:r:_) <- fmap (map (read :: String -> Int) . words) getLine
  let ans = solve l r
  putStrLn $ show ans

chunksOf :: Int -> [a] -> [[a]]
chunksOf _ [] = []
chunksOf x l  = take x l : chunksOf x (drop x l)

toArr :: Read a => String -> [a]
toArr = map read . words

type InType  = (Int, Int)
type OutType = Int

inpLines :: Int
inpLines = 1

solve :: InType -> OutType
solve (l, r) = if l' >= l
               then l' - 1
               else r - l
    where l' = (r + 1) `div` 2

receive :: [String] -> InType
receive [s] = case toArr s of
                [l, r] -> (l, r)
                _      -> error "unexpected input"
receive _   = error "unexpected input"

main :: IO ()
main = interact $
  unlines . map (show . solve . receive) . chunksOf inpLines . tail . lines


{-# OPTIONS_GHC -O2 -optc-O2 #-}
import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

sumPoints ::[Integer] -> Integer -> Integer -> Integer -> Integer -> Integer
sumPoints [] _ _ _ acc = acc
sumPoints (x:xs) sum sqsum i acc = let newval = ((i-1) * (x*x) - (2*x*sum) + sqsum) in
          sumPoints xs (sum+x) (sqsum + (x*x)) (i+1) (acc+newval)

main :: IO ()
main =
  do all <- BS.getContents
     let Just (n,r1) = readInt all
     let Just ((xs,ys),_) = readTuples n r1
     let result = (sumPoints xs 0 0 1 0)+(sumPoints ys 0 0 1 0)
     putStrLn $ show result ++ "\n"
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readTuples 0 s = do return (([],[]),s)
        readTuples n s = do (x, r) <- readInteger s
                            (y, z) <- readInteger r
                            ((l1,l2),t) <- readTuples (n-1) z
                            return (((x : l1),(y : l2)),t)

import qualified Data.ByteString.Lazy.Char8 as C
import Data.Maybe
import IO

getLines :: IO [[Integer]]
getLines = do
	fmap C.lines (C.hGetContents stdin) >>= return . map (map (fst . fromJust . C.readInteger) . C.words)

sxx = sum . map ((^2) . head)
syy = sum . map ((^2) . last)
sx = sum . map head
sy = sum . map last

main = do
	n <- getLine >>= return . read :: IO Integer
	xys <- getLines
	putStrLn . show $ n * ((sxx xys) + (syy xys)) - (sx xys) ^ 2 - (sy xys) ^ 2

import Char (ord)
import Control.Monad (liftM)

solve :: Integer -> [(Int, Int)] -> Integer
solve n ps  =  solve' ps 0 0 0 0
  where
    solve' :: [(Int, Int)] -> Integer -> Integer -> Integer -> Integer -> Integer
    solve' [] _ _ acc1 acc2  =  (n-1) * acc1 - 2 * acc2
    solve' ((x,y) : ps) sX sY acc1 acc2  =  solve' ps sX' sY' acc1' acc2'
      where
        x'  =  fromIntegral x
        y'  =  fromIntegral y
        sX'  =  sX + x'
        sY'  =  sY + y'
        acc1'  =  acc1 + x' * x' + y' * y'
        acc2'  =  acc2 + sX * x' + sY * y'

readPoint :: String -> (Int, Int)
readPoint line  =  readPoint' line 1 0
  where
    readPoint' (' ':s) z a  =  readPoint'' s (z * a) 1 0
    readPoint' ('-':s) _ _  =  readPoint' s (-1) 0
    readPoint' (c:s) z a  =  readPoint' s z (10*a + (ord c - ord '0'))
    readPoint'' [] a z b  =  (a, z * b)
    readPoint'' ('-':s) a _ _  =  readPoint'' s a (-1) 0
    readPoint'' (c:s) a z b  =  readPoint'' s a z (10*b + (ord c - ord '0'))

main :: IO ()
main  =  do
    lines'  <-  liftM lines getContents
    let n  =  read $ head lines'
    let points  =  map readPoint $ take (fromIntegral n) $ tail lines'
    print $ solve n points

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

-- solution for: http://codeforces.com/problemset/problem/76/E

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

compute :: [Integer]->Integer->Integer->Integer->Integer->Integer
compute [] _ _ _ acc = acc
compute (x:xs) i s ss acc = compute xs (i + 1) (s + x) (ss + x*x) (acc + (i-1)*x*x - 2*x*s + ss)

solve :: [Integer]->[Integer]->Integer
solve x y = (compute x 1 0 0 0) + (compute y 1 0 0 0)

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

import Data.Char

import Control.Monad
import Data.Int(Int64)
import Data.List
import Data.Maybe
import Control.Applicative
import qualified Data.ByteString.Char8 as B

mkPt [a, b] = Pt a b

data Pt = Pt !Int64 !Int64

addPt (Pt x1 y1) (Pt x2 y2) = Pt (x1+x2) (y1+y2)
sumPt = foldl' addPt (Pt 0 0)

sqPt (Pt x y) = x*x+y*y

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

int64s :: IO [Int64]
int64s = map (fromInteger . toInteger) <$> ints

data State = State !Pt !Int64

gogogo :: Int -> IO State
gogogo n = gogo n (State (Pt 0 0) 0)

gogo :: Int -> State -> IO State
gogo 0 state = return $ state
gogo i (State sum sumSq) = do
    pt <- mkPt <$> int64s
    (gogo $! (i-1)) $! (State (addPt sum pt) (sumSq + sqPt pt))

main  = do
    [n] <- ints
    (State sum sumSq) <- gogogo n
--    input <- map mkPt <$> replicateM n int64s
--    let sumSq = sum (map sqPt input)
--    let sum = sumPt input
    let res = ((fromInteger $ toInteger $ n) * sumSq - sqPt sum)
    putStrLn $ unlines [show $ res]

inputGen = do
    putStrLn "100000"
    forM_ [1..100000] $ \i -> putStrLn "10000 10000"

 -- with readInt:
 --
 -- !Int64 = 385ms
 -- !Integer = 414
 -- Int64 = 427ms
 -- Integer = 669ms

 -- with read:
 --
 -- !Int64 = 1570
 -- !Integer = 1564
 -- Int64 = 1599
 -- Integer = 3821

import Data.Char

import Control.Monad(forM_)
import Data.Int(Int64)
import Data.List

mkPt [a, b] = Pt a b

readPt = mkPt . map readInt . words

readInt = fromInteger . toInteger . readIntRec 0
readIntRec :: Int -> String -> Int
readIntRec val "" = val
readIntRec val ('-': str) = negate $ readIntRec val str
readIntRec val (ch : str) = readIntRec (val*10 + (ord ch - ord '0')) str

data Pt = Pt !Int64 !Int64

addPt (Pt x1 y1) (Pt x2 y2) = Pt (x1+x2) (y1+y2)
sumPt = foldl' addPt (Pt 0 0)

sqPt (Pt x y) = x*x+y*y

interactor :: String -> String
interactor str = let (hl : ol) = lines str
                     n = read hl
                     input = map readPt $ ol
                     result = unlines [show $ (n * sum (map sqPt input) - sqPt (sumPt input))]
                 in result

main  = interact interactor

inputGen = do
    putStrLn "100000"
    forM_ [1..100000] $ \i -> putStrLn "10000 10000"

{-# OPTIONS_GHC -O2 -optc-O2 #-}
import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

sumPoints ::[Integer] -> Integer -> Integer -> Integer -> Integer -> Integer
sumPoints [] _ _ _ acc = acc
sumPoints (x:xs) sum sqsum i acc = let newval = ((i-1) * (x*x) - (2*x*sum) + sqsum) in
          sumPoints xs (sum+x) (sqsum + (x*x)) (i+1) (acc+newval)

main :: IO ()
main =
  do all <- BS.getContents
     let Just (n,r1) = readInt all
     let Just ((xs,ys),_) = readTuples n r1
     let result = (sumPoints xs 0 0 1 0)+(sumPoints ys 0 0 1 0)
     putStrLn $ show result ++ "\n"
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readTuples 0 s = do return (([],[]),s)
        readTuples n s = do (x, r) <- readInt s
                            (y, z) <- readInt r
                            ((l1,l2),t) <- readTuples (n-1) z
                            return ((((toInteger x) : l1),((toInteger y) : l2)),t)

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

compute :: [Integer] -> Integer -> Integer -> Integer -> Integer ->Integer
compute [] _ acc suma sumasq = acc
compute (x:xs) i acc suma sumasq = if i == 1 then compute xs (i+1) acc x (x*x) else  compute xs (i+1) (acc+(i-1)*x*x - 2*x*(suma) + sumasq) (suma+x) (sumasq+x*x)

main :: IO ()
main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let (xs, ys)  = getPoints n r1 ([],[])
     print ((compute xs 1 0 0 0 ) + (compute ys 1 0 0 0))
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readIntList 0 s = do return ([], s)
        readIntList n s = do (x, r) <- readInteger s
                             (l, t) <- readIntList (n-1) r
                             return (x : l, t)
        getPoints 0 _ (accx, accy) = (accx, accy)
        getPoints n s (accx, accy) =
          let Just (pt, r2) = readIntList 2 s
            in  getPoints (n-1) r2 (((head pt):accx), ((last pt):accy))

import qualified Data.ByteString.Lazy.Char8 as C
import Data.Maybe
import IO

readInt = fst . fromJust . C.readInteger

main = do
	(h:t) <- fmap C.lines $ C.hGetContents stdin
	let
		n = readInt h
		a = map (map readInt . C.words) t
	print $ let x = map head a; y = map last a in gao n x + gao n y

gao n x = toInteger n * sum (map (^2) x) - (sum x) ^ 2

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

-- compute [] _ acc inp = acc
-- compute (x:xs) i acc inp = compute xs (i+1) (acc+(i - 1)*x*x - 2*x*(suma inp (i-1) 0) + (sumasq inp (i-1) 0)) (inp)

-- compute :: [Integer] -> Integer -> Integer -> [Integer] -> Integer
-- compute [] _ acc inp = acc
-- compute (x:xs) i acc inp = compute xs (i+1) (acc+(i - 1)*x*x - 2*x*(suma inp (i-1) 0) + (sumasq inp (i-1) 0)) (inp)
compute :: [Integer] -> Integer -> Integer -> Integer -> Integer ->Integer
compute [] _ acc suma sumasq = acc
compute (x:xs) i acc suma sumasq = if i == 1 then compute xs (i+1) acc x (x*x) else  compute xs (i+1) (acc+(i-1)*x*x - 2*x*(suma) + sumasq) (suma+x) (sumasq+x*x)

-- suma :: [Integer] -> Integer -> Integer -> Integer
-- suma x 0 acc = acc
-- suma (x:xs) n acc = suma xs (n-1) (acc+x)

-- sumasq :: [Integer] -> Integer -> Integer -> Integer
-- sumasq x 0 acc = acc
-- sumasq (x:xs) n acc = sumasq xs (n-1) (acc+x*x)

main :: IO ()
main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let (xs, ys)  = getPoints n r1 ([],[])
     print ((compute xs 1 0 0 0 ) + (compute ys 1 0 0 0))
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readInteger s = BSC.readInteger (BSC.dropWhile isSpace s)
        readIntList 0 s = do return ([], s)
        readIntList n s = do (x, r) <- readInteger s
                             (l, t) <- readIntList (n-1) r
                             return (x : l, t)
        getPoints 0 _ (accx, accy) = (accx, accy)
        getPoints n s (accx, accy) =
          let Just (pt, r2) = readIntList 2 s
            in  getPoints (n-1) r2 (((head pt):accx), ((last pt):accy))

import Data.Char

import Control.Monad(forM_)
import Data.Int(Int64)
import Data.List

mkPt [a, b] = Pt a b

readPt = mkPt . map readInt . words

readInt = fromInteger . toInteger . readIntRec 0
readIntRec :: Int -> String -> Int
readIntRec val "" = val
readIntRec val (ch : str) = readIntRec (val*10 + (ord ch - ord '0')) str

data Pt = Pt !Int64 !Int64

addPt (Pt x1 y1) (Pt x2 y2) = Pt (x1+x2) (y1+y2)
sumPt = foldl' addPt (Pt 0 0)

sqPt (Pt x y) = x*x+y*y

interactor :: String -> String
interactor str = let (hl : ol) = lines str
                     n = read hl
                     input = map readPt $ ol
                     result = unlines [show $ (n * sum (map sqPt input) - sqPt (sumPt input))]
                 in result

main  = interact interactor

inputGen = do
    putStrLn "100000"
    forM_ [1..100000] $ \i -> putStrLn "10000 10000"

{-# OPTIONS_GHC -O2 -optc-O2 #-}
import Data.Char (isSpace)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC

sumPoints [] _ _ _ acc = acc
sumPoints (x:xs) sum sqsum i acc = let newval = ((i-1) * (x*x) - (2*x*sum) + sqsum) in
          sumPoints xs (sum+x) (sqsum + (x*x)) (i+1) (acc+newval)

main :: IO ()
main =
  do all <- BS.getContents
     let Just (n,r1) = readInt all
     let Just ((xs,ys),_) = readTuples n r1
     let result = (sumPoints xs 0 0 1 0)+(sumPoints ys 0 0 1 0)
     putStrLn $ show result ++ "\n"
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readTuples 0 s = do return (([],[]),s)
        readTuples n s = do (x, r) <- readInt s
                            (y, z) <- readInt r
                            ((l1,l2),t) <- readTuples (n-1) z
                            return (((x : l1),(y : l2)),t)

import Control.Monad;

main = do
	n <- fmap read getLine
	a <- replicateM n $ fmap (map read . words) getLine
	print $ let x = map head a; y = map last a in gao x + gao y

gao x = length x * sum (map (^2) x) - (sum x) ^ 2 where

import Control.Monad;

main = do
	n <- fmap read getLine
	a <- replicateM n $ fmap (map read . words) getLine
	print $ let x = map head a; y = map last a in gao x + gao y

gao x = length x * sum (map (^2) x) - (sum x) ^ (2::Integer) where

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

compute :: [Int] -> Int -> Int -> [Int] -> Int
compute [] _ acc inp = acc
compute (x:xs) i acc inp = compute xs (i+1) (acc+(i - 1)*x*x - 2*x*(suma inp (i-1) 0) + (sumasq inp (i-1) 0)) (inp)

suma :: [Int] -> Int -> Int -> Int
suma x 0 acc = acc
suma (x:xs) n acc = suma xs (n-1) (acc+x)

sumasq :: [Int] -> Int -> Int -> Int
sumasq x 0 acc = acc
sumasq (x:xs) n acc = sumasq xs (n-1) (acc+x*x)

main :: IO ()
main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let (xs, ys)  = getPoints n r1 ([],[])
     print ((compute xs 1 0  xs) + (compute ys 1 0 ys))
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readIntList 0 s = do return ([], s)
        readIntList n s = do (x, r) <- readInt s
                             (l, t) <- readIntList (n-1) r
                             return (x : l, t)
        getPoints 0 _ (accx, accy) = (accx, accy)
        getPoints n s (accx, accy) =
          let Just (pt, r2) = readIntList 2 s
            in  getPoints (n-1) r2 (((head pt):accx), ((last pt):accy))

getLines :: Int -> IO [(Int, Int)]
getLines 0 = return []
getLines n = do
	x <- getLine >>= return . (\(x:y:_) -> (read x, read y)) . words
	xs <- getLines (n-1)
	return (x:xs)

sxx xys = sum [(fst xy) ^ 2 | xy <- xys]
syy xys = sum [(snd xy) ^ 2 | xy <- xys]
sx xys = sum [fst xy | xy <- xys]
sy xys = sum [snd xy | xy <- xys]

main = do
	n <- getLine >>= return . read :: IO Int
	xys <- getLines n
	putStrLn . show $ length xys * (sxx xys + syy xys) - ((sx xys) ^ 2) - ((sy xys) ^ 2)

import Char (ord)
import Control.Monad (liftM)

solve :: Integer -> [(Int, Int)] -> Integer
solve n ps  =  solve' ps 0 0 0 0
  where
    solve' :: [(Int, Int)] -> Integer -> Integer -> Integer -> Integer -> Integer
    solve' [] _ _ acc1 acc2  =  (n-1) * acc1 - 2 * acc2
    solve' ((x,y) : ps) sX sY acc1 acc2  =  solve' ps sX' sY' acc1' acc2'
      where
        x'  =  fromIntegral x
        y'  =  fromIntegral y
        sX'  =  sX + x'
        sY'  =  sY + y'
        acc1'  =  acc1 + x' * x' + y' * y'
        acc2'  =  acc2 + sX * x' + sY * y'

readPoint :: String -> (Int, Int)
readPoint line  =  readPoint' line 0
  where
    readPoint' (' ':s) a  =  readPoint'' s a 0
    readPoint' (c:s) a  =  readPoint' s (10*a + (ord c - ord '0'))
    readPoint'' [] a b  =  (a, b)
    readPoint'' (c:s) a b  =  readPoint'' s a (10*b + (ord c - ord '0'))

main :: IO ()
main  =  do
    lines'  <-  liftM lines getContents
    let n  =  read $ head lines'
    let points  =  map readPoint $ take (fromIntegral n) $ tail lines'
    print $ solve n points

solve :: Integer -> [Int] -> [Int] -> Integer
solve n xs ys  =  solve' 0 xs 0 0 + solve' 0 ys 0 0
  where
    solve' :: Int -> [Int] -> Integer -> Integer -> Integer
    solve' _ [] acc1 acc2  =  (n-1) * acc1 - (acc2 + acc2)
    solve' s (x:xs) acc1 acc2  =  s' `seq` acc1' `seq` acc2' `seq` solve' s' xs acc1' acc2'
      where
        s'  =  s + x
        acc1'  =  acc1 + fromIntegral (x * x)
        acc2'  =  acc2 + fromIntegral (s * x)

readPoint :: IO (Int, Int)
readPoint  =  do
    [x, y]  <-  getLine >>= return . map read . words
    return (x, y)

main :: IO ()
main  =  do
    n  <-  readLn
    points  <-  mapM (const readPoint) [1..n]
    print $ solve n (map fst points) (map snd points)