Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.

Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.

import Data.List
main = do interact (unwords . map show . gao . map read . tail . words)
gao a
	| null p && s < 2	= [if z then 0 else maximum n]
	| otherwise			= p ++ if even s then n else init (sort n)
	where
		z = any (==0) a
		(p, n) = partition (>0) $ filter (/=0) a
		s = length n

import Data.List
main = interact (unwords.map show.s.map read.words)
s (n:xs) = if null pos
    then if null mneg
        then if null nil then neg else nil
        else mneg
    else pos++mneg
    where
        pos = filter (>0) xs
        neg = filter (<0) xs
        nil = filter (==0) xs
        mneg = if even (length neg) then neg else (delete (maximum neg) neg)

import List
main = interact solve
solve input = output where
  inputs = lines input
  n = read ( head inputs ) :: Int
  cs = map ( read :: String -> Int ) $ words ( last inputs )
  output = unwords $ map show $ answer cs
answer xs
  | null pos && null neg = [0]
  | null pos && len == 1 && elem 0 xs = [0]
  | null pos && len == 1 = neg
  | otherwise            = pos ++ if even len then neg else init neg
  where
    pos = filter (>0) xs
    neg = sort $ filter (<0) xs
    len = length neg

import Data.List
main = do
  getLine
  c <- fmap (map read . words) getLine
  let pos = filter (>0) c
      neg = reverse . sort . filter (<0) $ c
      res = pos ++ case length neg `mod` 2 of
        0 -> neg
        _ -> tail neg
  putStrLn . unwords . map show $ if null res then [maximum c] else res

import Data.List
main = do
    (_:a) <- fmap (map read . words) getContents :: IO [Int]
    putStrLn $ intercalate " " $ map show $ f a where
        f a = b where
            neg = sort $ filter (< 0) a
            pos = filter (> 0) a
            len = length neg
            bb = pos ++ if (mod len 2) == 1 then init neg else neg
            b = if null bb then [maximum a] else bb

import Data.List
main = do interact (unwords . map show . gao . map read . tail . words)
gao a
	| null p && s < 2	= [if z then 0 else maximum n]
	| otherwise			= p ++ if even s then n else tail (sort n)
	where
		z = any (==0) a
		(p, n) = partition (>0) $ filter (/=0) a
		s = length n

import List
main = interact solve
solve input = output where
  inputs = lines input
  n = read ( head inputs ) :: Int
  cs = map ( read :: String -> Int ) $ words ( last inputs )
  output = unwords $ map show $ answer cs
answer xs
  | null pos && null neg = [0]
  | null pos && len == 1 = neg
  | otherwise            = pos ++ if even len then neg else init neg
  where
    pos = filter (>0) xs
    neg = sort $ filter (<0) xs
    len = length neg

import Data.List
main = do
  getLine
  c <- fmap (map read . words) getLine
  let pos = filter (>0) c
      neg = reverse . sort . filter (<0) $ c
      res = pos ++ case length neg `mod` 2 of
        0 -> neg
        _ -> tail neg
  putStrLn . unwords . map show $ if null res then neg else res

import Data.List
main = do
    (_:a) <- fmap (map read . words) getContents :: IO [Int]
    putStrLn $ intercalate " " $ map show $ f a where
        f a = b where
            neg = sort $ filter (< 0) a
            pos = filter (> 0) a
            len = length neg
            bb = pos ++ if (mod len 2) == 1 then tail neg else neg
            b = if null bb then [maximum a] else bb


You are given an array $$$A$$$, consisting of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$, and an array $$$B$$$, consisting of $$$m$$$ positive integers $$$b_1, b_2, \dots, b_m$$$. Choose some element $$$a$$$ of $$$A$$$ and some element $$$b$$$ of $$$B$$$ such that $$$a+b$$$ doesn't belong to $$$A$$$ and doesn't belong to $$$B$$$. For example, if $$$A = [2, 1, 7]$$$ and $$$B = [1, 3, 4]$$$, we can choose $$$1$$$ from $$$A$$$ and $$$4$$$ from $$$B$$$, as number $$$5 = 1 + 4$$$ doesn't belong to $$$A$$$ and doesn't belong to $$$B$$$. However, we can't choose $$$2$$$ from $$$A$$$ and $$$1$$$ from $$$B$$$, as $$$3 = 2 + 1$$$ belongs to $$$B$$$.It can be shown that such a pair exists. If there are multiple answers, print any.Choose and print any such two numbers.

The first line contains one integer $$$n$$$ ($$$1\le n \le 100$$$) — the number of elements of $$$A$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 200$$$) — the elements of $$$A$$$. The third line contains one integer $$$m$$$ ($$$1\le m \le 100$$$) — the number of elements of $$$B$$$. The fourth line contains $$$m$$$ different integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_i \le 200$$$) — the elements of $$$B$$$. It can be shown that the answer always exists.

Output two numbers $$$a$$$ and $$$b$$$ such that $$$a$$$ belongs to $$$A$$$, $$$b$$$ belongs to $$$B$$$, but $$$a+b$$$ doesn't belong to nor $$$A$$$ neither $$$B$$$. If there are multiple answers, print any.

NoteIn the first example, we can choose $$$20$$$ from array $$$[20]$$$ and $$$20$$$ from array $$$[10, 20]$$$. Number $$$40 = 20 + 20$$$ doesn't belong to any of those arrays. However, it is possible to choose $$$10$$$ from the second array too.In the second example, we can choose $$$3$$$ from array $$$[3, 2, 2]$$$ and $$$1$$$ from array $$$[1, 5, 7, 7, 9]$$$. Number $$$4 = 3 + 1$$$ doesn't belong to any of those arrays.In the third example, we can choose $$$1$$$ from array $$$[1, 3, 5, 7]$$$ and $$$1$$$ from array $$$[7, 5, 3, 1]$$$. Number $$$2 = 1 + 1$$$ doesn't belong to any of those arrays.

import Control.Monad
import Data.String
readListRec :: Int -> IO [String]
readListRec lineNumber =
  if (lineNumber == 0)
  then return []
  else
    getLine >>= \newLine ->
    (newLine :) <$> readListRec(lineNumber - 1)

parseLineToInt :: String -> [Int]
parseLineToInt data_s = do
  (read::String->Int) <$> (words data_s)

countLetters :: [Char] -> Char -> Int
countLetters array_ char_ = length (filter (==char_) array_)

createLists :: Int -> ([Int], [Int])
createLists 0  = ([],[])
createLists n = let
                    (l, r) = createLists (n - 1)
                in ((2 * n) : r, (2 * n - 1) : l)

main = do
  _ <- getLine
  aS <- getLine
  let a = maximum $ parseLineToInt aS
  _ <- getLine
  bS <-getLine
  let b = maximum $ parseLineToInt bS
  putStrLn $ (show a) ++ " " ++ show b

import Data.List

main = do
   _ <- getLine
   a <- maximum . map (read :: String -> Int) . words <$> getLine
   _ <- getLine
   b <- maximum . map (read :: String -> Int) . words <$> getLine
   putStrLn $ show a ++ " " ++ show b

import Control.Applicative
import Data.List

main :: IO ()
main = do
    n <- (read :: String -> Int) <$> getLine
    as <- map (read :: String -> Int) . words <$> getLine
    m <- (read :: String -> Int) <$> getLine
    bs <- map (read :: String -> Int) . words <$> getLine
    let sortedAs = reverse . sort $ as
        sortedBs = reverse . sort $ bs
    putStr . show . head $ sortedAs
    putStr " "
    putStrLn . show . head $ sortedBs

toInt n = (read n)::Int

solve :: [Int] -> [Int] -> (Int, Int)
solve a b = head [(x,y) | x <- a, y <- b, (not ((x+y) `elem` a)) && (not ((x+y) `elem` b))]

main = do
    inp <- getContents
    let lns = lines inp
    let a = map toInt (words (lns !! 1))
    let b = map toInt (words (last lns))
    let t = solve a b
    putStrLn $ (show $ fst t) ++ " " ++ (show $ snd t)

import Text.Printf
readNumbers :: String -> [Int]
readNumbers = map read . words
maxInt :: [Int] -> Int
maxInt [x] = x
maxInt (x:xs)   | (maxInt xs) > x = maxInt xs
                | otherwise        = x

main = do
  input <- getLine
  input <- getLine
  let a = readNumbers input
  input <- getLine
  input <- getLine
  let b = readNumbers input
  printf "%d %d\n" (maxInt a) (maxInt b)

main = do
    n <- getLine
    a <- getLine
    m <- getLine
    b <- getLine
    putStrLn (solve (read n) (map read $ words a) (read m) (map read $ words b))

solve :: Int -> [Int] -> Int -> [Int] -> String
solve n a m b = show (maximum a) ++ " " ++ show (maximum b)

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

main = do
		getLine
		a<-maximum <$> map read<$> words <$> getLine ::IO Int
		getLine
		b<-maximum <$> map read<$> words <$> getLine ::IO Int
		putStr $ show a
		putStr $ " " ++ show b

process :: [Int] -> [Int] -> (Int, Int)
process as bs = (maximum as, maximum bs)

readInt :: String -> Int
readInt = read

main :: IO ()
main = do
    na <- fmap readInt getLine
    as <- fmap (map readInt.words) getLine
    nb <- fmap readInt getLine
    bs <- fmap (map readInt.words) getLine
    let (a,b) = process as bs
    putStrLn $ show a ++ " " ++ show b

import Control.Monad

import qualified Data.Set as S

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

getList :: IO [Int]
getList = (map read) <$> words <$> getLine

solve :: [Int] -> [Int] -> (Int, Int)
solve a b = fst $ head [((x, y), x + y) | x <- a, y <- b, not $ S.member (x+y) $ S.union a' b']
    where a' = S.fromList a
          b' = S.fromList b

main :: IO ()
main = do
    n <- getInt
    a <- getList
    m <- getInt
    b <- getList
    putStrLn $ (\t -> (show $ fst t) ++ " " ++ (show $ snd t)) (solve a b)


Given a sequence $$$a_1, a_2, \ldots, a_n$$$, find the minimum number of elements to remove from the sequence such that after the removal, the sum of every $$$2$$$ consecutive elements is even.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2,\dots,a_n$$$ ($$$1\leq a_i\leq10^9$$$) — elements of the sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print a single integer — the minimum number of elements to remove from the sequence such that the sum of every $$$2$$$ consecutive elements is even.

NoteIn the first test case, after removing $$$3$$$, the sequence becomes $$$[2,4,6,8]$$$. The pairs of consecutive elements are $$$\{[2, 4], [4, 6], [6, 8]\}$$$. Each consecutive pair has an even sum now. Hence, we only need to remove $$$1$$$ element to satisfy the condition asked.In the second test case, each consecutive pair already has an even sum so we need not remove any element.

import Control.Monad (replicateM_)
solve arr = min (length (filter even arr)) (length (filter odd arr))
main = do
    n <- readLn :: IO Int
    replicateM_ n $ do
        _ <- getLine
        l <- getLine
        let arr = (map read . words) l
        print $ solve arr

{-# LANGUAGE NegativeLiterals,  InstanceSigs, MultiParamTypeClasses, UndecidableSuperClasses, MultiWayIf, KindSignatures,
OverloadedLists,ApplicativeDo,OverloadedStrings,MonadComprehensions,ParallelListComp,TransformListComp, TupleSections,
BlockArguments, TypeApplications, PostfixOperators, TypeOperators, BangPatterns, LambdaCase, UnboxedSums, UnboxedTuples, RankNTypes,
FlexibleContexts,DeriveFoldable, DeriveTraversable, ScopedTypeVariables, GADTs, PatternSynonyms, ViewPatterns, FunctionalDependencies #-}
import Data.List (group, sort, groupBy, partition)
import qualified Data.ByteString.Lazy.Char8 as L
import Data.Function ((&),fix,on)
import Data.Maybe (fromJust)
import Data.Bifunctor (bimap)
int :: L.ByteString -> Int
int = fst . fromJust . L.readInt
readInts ::L.ByteString -> [Int]
readInts = map int . L.split ' '

solve :: [Int] -> L.ByteString
solve = L.pack . show . uncurry min . bimap length length . partition even

twos :: [L.ByteString] ->   [L.ByteString]
twos [] = []
twos (_:y:xs) = y : twos xs

main :: IO ()
main = L.interact (L.unlines . map (solve . readInts) . twos . tail . L.lines)

import Control.Monad (replicateM_)

solve arr = min (length (filter odd arr)) (length (filter even arr))

main = do
    n <- readLn :: IO Int
    replicateM_ n $ do
        _ <- getLine
        l <- getLine
        let arr = (map read . words) l
        print $ solve arr

-- https://codeforces.com/contest/1679/problem/D
{-# 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.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 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] -> Int
solve n as = uncurry min . join bimap L.length $ L.partition even as

main :: IO ()
main = do
    t <- B8.getLine <&> readIntB8
    replicateM_ t $ do
        n <- B8.getLine <&> readIntB8
        as <- B8.getLine <&> readIntB8s
        let answer = solve n as
        printf "%d\n" answer


Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for the contestants and wrote on each of them a unique id (integer from 1 to n). A gift i is characterized by integer ai — pleasantness of the gift. The pleasantness of the gift can be positive, negative or zero. Sponsors placed the gift 1 on the top of the tree. All the other gifts hung on a rope tied to some other gift so that each gift hung on the first gift, possibly with a sequence of ropes and another gifts. Formally, the gifts formed a rooted tree with n vertices.The prize-giving procedure goes in the following way: the participants come to the tree one after another, choose any of the remaining gifts and cut the rope this prize hang on. Note that all the ropes which were used to hang other prizes on the chosen one are not cut. So the contestant gets the chosen gift as well as the all the gifts that hang on it, possibly with a sequence of ropes and another gifts.Our friends, Chloe and Vladik, shared the first place on the olympiad and they will choose prizes at the same time! To keep themselves from fighting, they decided to choose two different gifts so that the sets of the gifts that hang on them with a sequence of ropes and another gifts don't intersect. In other words, there shouldn't be any gift that hang both on the gift chosen by Chloe and on the gift chosen by Vladik. From all of the possible variants they will choose such pair of prizes that the sum of pleasantness of all the gifts that they will take after cutting the ropes is as large as possible.Print the maximum sum of pleasantness that Vladik and Chloe can get. If it is impossible for them to choose the gifts without fighting, print Impossible.

The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of gifts. The next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the pleasantness of the gifts. The next (n - 1) lines contain two numbers each. The i-th of these lines contains integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the description of the tree's edges. It means that gifts with numbers ui and vi are connected to each other with a rope. The gifts' ids in the description of the ropes can be given in arbirtary order: vi hangs on ui or ui hangs on vi.  It is guaranteed that all the gifts hang on the first gift, possibly with a sequence of ropes and another gifts.

If it is possible for Chloe and Vladik to choose prizes without fighting, print single integer — the maximum possible sum of pleasantness they can get together. Otherwise print Impossible.

#!/usr/bin/env stack
{- stack
  --resolver lts-2.22
  runghc
  --package array
  --package base
  --package bytestring
  --package containers
  --package mtl
  --package parsec
  --package vector
  --
  -hide-all-packages
-}
{-# LANGUAGE BangPatterns, TupleSections, RankNTypes, ScopedTypeVariables #-}
module Main
( main
) where

import           Prelude hiding (interact, lines, unlines, words, unwords,
                                 sequence, foldr)
import           Data.ByteString.Char8 (pack, unpack, ByteString, lines, words,
                                        unlines, unwords, interact, readInt,
                                        readInteger)
import qualified Data.ByteString.Char8 as BS
import           Data.List (foldl', sort, sortBy, group, groupBy, inits, tails)
import qualified Data.List as L
import qualified Data.IntSet as IS
import           Data.IntSet (IntSet)
import qualified Data.IntMap.Strict as IM
import           Data.IntMap.Strict (IntMap)
import qualified Data.Map.Strict as M
import           Data.Map.Strict (Map)
import qualified Data.Set as S
import           Data.Set (Set)
import qualified Data.Array.IArray as A
import           Data.Array.IArray ((!), Array, listArray, array)
import           Data.Maybe (fromJust, isJust, fromMaybe, maybe, mapMaybe,
                             catMaybes)
import           Data.Either (either)
import           Control.Applicative (Applicative, pure,
                                      (<$>), (<*>), liftA2, liftA3)
import           Control.Monad (unless, when, void, filterM, ap)
import           Control.Arrow ((***), (&&&), first, second)
import           Data.Traversable (sequence, sequenceA, traverse,
                                   Traversable)
import           Data.Ord (comparing, Down(..))
import           Data.Function (on)
import           Data.Bits (complement, xor, (.|.), (.&.), testBit, zeroBits,
                            bit, shiftR, shiftL, Bits)
import qualified Data.Bits as B
import           Data.Word (Word32)
import           Control.Monad.State (State, get, put, gets, modify,
                                      evalState, execState, runState)
import           Text.Parsec (char, space, parse, Parsec)
import qualified Text.Parsec as P
import           Data.Tuple (swap)
import           Data.Foldable (Foldable, foldr)
import           Data.Monoid ((<>), Monoid, mappend, mempty)

type N = Int
toNum = toInt

data Tree = Tree { entire :: Integer
                 , best :: Integer
                 , children :: [Tree]
                 }

answer :: [Integer] -> [(N,N)] -> String
answer ps' es' = ans t $$ maybe "Impossible" show
  where ps :: Array Int Integer
        ps = listArray (1, length ps') ps'
        es = IM.fromListWith (++)
           $ concatMap (\(a, b) -> [(a, [b]), (b, [a])]) es'
        t = go Nothing 1
        go :: Maybe Int -> Int -> Tree
        go p k = let cs = fromMaybe [] (IM.lookup k es)
                       $$ sort & group & map head
                        & filter (\x -> Just x /= p) & map (go (Just k))
                     whole = sum $ (ps ! k) : map entire cs
                  in Tree whole
                          (maximum $ whole : map best cs)
                          (sortBy (comparing (best & Down)) cs)
        ans (Tree _ b cs@(x:y:_)) = maximum $ (Just $ best x + best y)
                                            : map ans cs
        ans (Tree _ b [x]) = ans x
        ans _ = Nothing

handleInput :: ByteString -> ByteString
handleInput = lines & drop 1 & map (words & map toNum)
            & coerceInput answer
            & pack

toInt = readInt & fromJust & fst
toInte = readInteger & fromJust & fst
toX :: Read a => ByteString -> a
toX = unpack & read

coerceInput f (ps:xs) = f (map fromIntegral ps) (map toTuple xs)
coerceInput _ _ = error "invalid input"

toTuple (a:b:_) = (a, b)
toTuple _ = error "invalid tuple"

main :: IO ()
main = interact handleInput

-- Util stuff --
(&) :: (a -> b) -> (b -> c) -> a -> c
(&) = flip (.)
infixl 9 &

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


Kilani is playing a game with his friends. This game can be represented as a grid of size $$$n \times m$$$, where each cell is either empty or blocked, and every player has one or more castles in some cells (there are no two castles in one cell).The game is played in rounds. In each round players expand turn by turn: firstly, the first player expands, then the second player expands and so on. The expansion happens as follows: for each castle the player owns now, he tries to expand into the empty cells nearby. The player $$$i$$$ can expand from a cell with his castle to the empty cell if it's possible to reach it in at most $$$s_i$$$ (where $$$s_i$$$ is player's expansion speed) moves to the left, up, right or down without going through blocked cells or cells occupied by some other player's castle. The player examines the set of cells he can expand to and builds a castle in each of them at once. The turned is passed to the next player after that. The game ends when no player can make a move. You are given the game field and speed of the expansion for each player. Kilani wants to know for each player how many cells he will control (have a castle their) after the game ends.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$p$$$ ($$$1 \le n, m \le 1000$$$, $$$1 \le p \le 9$$$) — the size of the grid and the number of players. The second line contains $$$p$$$ integers $$$s_i$$$ ($$$1 \le s \le 10^9$$$) — the speed of the expansion for every player. The following $$$n$$$ lines describe the game grid. Each of them consists of $$$m$$$ symbols, where '.' denotes an empty cell, '#' denotes a blocked cell and digit $$$x$$$ ($$$1 \le x \le p$$$) denotes the castle owned by player $$$x$$$. It is guaranteed, that each player has at least one castle on the grid.

Print $$$p$$$ integers — the number of cells controlled by each player after the game ends.

NoteThe picture below show the game before it started, the game after the first round and game after the second round in the first example:  In the second example, the first player is "blocked" so he will not capture new cells for the entire game. All other player will expand up during the first two rounds and in the third round only the second player will move to the left.

-- Codeforces Round #533 Div.2 (D), Contest 1105, Problem set ?.
-- UNDONE

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE TupleSections#-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE MultiWayIf #-}

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

main :: IO ()
main = do
  [n_,m_,p_] <- words <$> getLine
  let n = read n_ :: Int16
      m = read m_ :: Int16
      nm = fromIntegral n * fromIntegral m :: Int32
      p = read p_ :: Int8
  ss <- A.listArray (1,p) . map read . words <$> getLine
          :: IO (UArray Int8 Int32)
  grid <- A.newArray ((0,0),(n-1,m-1)) 0 :: IO (IOUArray (Int16,Int16) Int8)
  queueX <- A.newArray_ (0,nm-1) :: IO (IOUArray Int32 Int16)
  queueY <- A.newArray_ (0,nm-1) :: IO (IOUArray Int32 Int16)
  queueOff <- A.newArray (1,p) 0 :: IO (IOUArray Int8 Int32)
  queueLen <- A.newArray (1,p) 0 :: IO (IOUArray Int8 Int32)
  queueFree <- newIORef (0::Int32)
  acc <- A.newArray (1,p) 0 :: IO (IOUArray Int8 Int32)
  forM_ [0..n-1] $ \x -> do
    line <- getLine
    forM_ (zip [0..m-1] line) $ \(y,c) ->
      if | c == '.' -> return ()
         | c == '#' -> A.writeArray grid (x,y) 10
         | otherwise -> do
             let j = fromIntegral $ fromEnum c - fromEnum '0'
             A.writeArray grid (x,y) j
             A.writeArray queueLen j . (+1) =<< A.readArray queueLen j
             A.writeArray acc j . (+1) =<< A.readArray acc j
  A.writeArray queueOff 1 =<< A.readArray queueLen 1
  forM_ [2..p] $ \j -> do
    off <- A.readArray queueOff (j-1)
    len <- A.readArray queueLen j
    A.writeArray queueOff j (off+len)
  writeIORef queueFree =<< A.readArray queueOff p
  forM_ (A.range ((0,0), (n-1,m-1))) $ \(x,y) -> do
    j <- A.readArray grid (x,y)
    when (0 < j && j <= 9) $ do
      off <- subtract 1 <$> A.readArray queueOff j
      A.writeArray queueOff j off
      A.writeArray queueX off x
      A.writeArray queueY off y
  let loop j !b | j <= p = do
                    res <- play j (ss A.! j)
                    loop (j+1) (b || res)
                | b = loop 1 False
                | otherwise = return ()
      play j 0 = return True
      play j k = do len <- A.readArray queueLen j
                    if len <= 0 then
                      return False
                    else do
                      off <- A.readArray queueOff j
                      A.writeArray queueOff j =<< readIORef queueFree
                      A.writeArray queueLen j 0
                      forM_ [off..off+len-1] $ go j
                      play j (k-1)
      go :: Int8 -> Int32 -> IO ()
      go j q = do
        x <- A.readArray queueX q
        y <- A.readArray queueY q
        when (x > 0)   $ expand j (x-1,y)
        when (x < n-1) $ expand j (x+1,y)
        when (y > 0)   $ expand j (x,y-1)
        when (y < m-1) $ expand j (x,y+1)
      expand j (x,y) = do
        stat <- A.readArray grid (x,y)
        when (stat == 0) $ do
          q <- readIORef queueFree
          writeIORef queueFree (q+1)
          A.writeArray queueX q x
          A.writeArray queueY q y
          A.writeArray queueLen j . (+1) =<< A.readArray queueLen j
          A.writeArray acc j . (+1) =<< A.readArray acc j
          A.writeArray grid (x,y) j
  loop 1 False
  ans <- A.getElems acc
  putStrLn $ unwords $ map show $ ans


The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.

The first line contains integer n (2 ≤ n ≤ 300) — the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 300). It is guaranteed that at least one ai is positive.

Print the sequence that consists of k (1 ≤ k ≤ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.

import Control.Monad

go [] = putChar '\n'
go [0] = putChar '\n'
go [1] = putStr "P\n"
go [n] = putStr "PLR" >> go [n-1]
go (0 : ns) = putChar 'R' >> go ns
go (1 : ns) = putStr "PR" >> go ns
go (n : 0 : ns) = putStr "PRL" >> go ((n-1):0:ns)
go (n : m : ns) = putStr "PRPL" >> go ((n-1):(m-1):ns)

main = do
  n <- liftM read getLine :: IO Int
  as <- liftM (map read . words) getLine :: IO [Int]
  go as

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

solve :: [Int] -> IO()
solve [a]    | a == 0    = putStrLn ""
             | a == 1    = putStrLn "P"
             | otherwise = do putStr "PLR"
                              solve [(a-1)]
solve (a:ax) | a == 0    = do putStr "R"
                              solve ax
             | otherwise = do putStr "PRL"
                              solve ((a-1):ax)

import Control.Applicative
import Data.List

main = do
	n <- read <$> getLine ::IO Int
	a <- (map read) <$> words <$> getLine:: IO [Int]
	putStrLn $ foldl1' (++) $ map (line n a) [1..maximum a] where
		line n a i = (foldl1' (++) $ map (\(x,k) -> coin x ++ move k ) $ zip a [1..] ) ++ replicate (n - 1) 'L' where
			coin x = if x >= i then "P" else []
			move k = if k < n then "R" else []

{-# 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.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 . (,)

main = do
    getLine
    as <- readInts
    let go []  = return ()
        go [x] = replicateM_ x (putStr "PLR")
        go (x:xs) = replicateM_ x (putStr "PRL") >> putChar 'R' >> go xs
    go as
    putChar '\n'

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

printSolution :: Int -> Int -> IO ()

printSolution l 1000 = do
	str <- getLine
	let x = (read str :: Int)
	printSolution l x

printSolution l 0 = do
	if ( l /= 1 ) then putChar 'R'
	else return ();

printSolution l coins = do
			if ( l == 1 )
				then do
					putChar 'L'
					putChar 'R'
				else do
					putChar 'R'
					putChar 'L'
			putChar 'P'
			(printSolution l (coins - 1) )

printSol :: [Int] -> IO ()
printSol [] = do
				return ()
printSol (x:xs) = do
         if	(length xs) == 0
		 then
               printSolution 1 x
		 else
			   printSolution 0 x
         printSol xs

main = do
     --nStr <- getLine
	 yy <- (map read) <$> words <$> getLine :: IO [Int]
	 x <- (map read) <$> words <$> getLine :: IO [Int]
	 let n = head yy
	 printSol x

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

solve :: [Int] -> String
solve [] = ""
solve [x] = [1..x] >> "PLR"
solve (x:xs) = ([1..x] >> "PRL") ++ "R" ++ solve xs

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

data Instruction = L | R | P deriving Show

solve :: [Int] -> [Instruction]
solve (_:as) = concatMap f (zip [0..] as)
  where f (0, a) = R : concat (replicate a [ L, P, R ]) ++ [L]
        f (i, a) = replicate (i - 1) R ++ concat (replicate a [ R, P, L ]) ++ replicate (i - 1) L
solve _ = undefined

main=interact$s.map read.tail.words
s[]="";s[x]=[1..x]>>"PLR";s(x:y)=([1..x]>>"PRL")++"R"++s y

main = do
    (_:a) <- fmap (map read . words) getContents :: IO [Int]
    putStrLn $ f a where
        f [] = ""
        f [x] = [1..x]>>"PLR"
        f (x:xs) = ([1..x]>>"PRL") ++ "R" ++ (f xs)

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

solve :: [Int] -> String
solve (_:as) = concatMap (\a -> concat (replicate a "PRL") ++ "R") as
solve _ = undefined

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

data Instruction = L | R | P deriving Show

solve :: [Int] -> [Instruction]
solve (_:as) = concatMap f (zip [0..] as)
  where f (0, a) = R : concat (replicate a [ L, P, R ]) ++ [L]
        f (i, a) = replicate i R ++ concat (replicate a [ R, P, L ]) ++ replicate i L
solve _ = undefined

main = do
    (n:a) <- fmap (map read . words) getContents :: IO [Int]
    putStrLn $ f a where
        f [] = ""
        f [x] = [1..x]>>"PLR"
        f (x:xs)
            | x == 0 = "R" ++ (f xs)
            | otherwise = [1..x]>>"PRL" ++ "R" ++ (f xs)


One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2x for some integer x). If those rules don't indicate the size of the cut are clearly, then the way with which the cut part possesses the largest area is chosen. Of course, both sides of the cut area should be integer. If there are several answers to this problem, you should choose the answer with the maximal height.

The first line contains a pair of integers h and w (1 ≤ h, w ≤ 109) which are the height and width of the uploaded photo in pixels.

Print two integers which are the height and width of the cut area.

main = do
	[h, w] <- fmap (map read . words) getLine
	putStrLn $ unwords $ map show $ tail $ maximum $ (gao h w ++) $ map (\[a,b,c] -> [a,c,b]) $ gao w h
	where gao h w = [[x * y, x, y] | x <- takeWhile (<=h) $ iterate (*2) 1, 4 * x <= 5 * w, y <- [min w $ div (x * 5) 4]]

import Maybe
import List

main = do
  [h,w] <- fmap (map read.words) getLine
  putStrLn $ f $ solve w h
  where f(x,y) = unwords $ map show [x,y]

solve :: Integer -> Integer -> (Integer,Integer)
solve h w = case compare (area a) (area b) of
              LT -> b
              GT -> a
              EQ -> last $ sort [a,b]
  where a = anotherEdges h w
        b = flipTuple $ anotherEdges w h

area (x,y) = x*y

flipTuple (x,y) = (y,x)

power2 = map(2^)[0..]

anotherEdge :: Integer -> Integer -> Maybe (Integer,Integer)
anotherEdge y x = if y < lower  then Nothing else Just $ (x,min y upper)
  where z     = fromIntegral x
        lower = ceiling $ 0.8*z
        upper = floor $ 1.25*z

anotherEdges y x = head $ catMaybes $ map (anotherEdge y)
                   $ reverse $ takeWhile(<=x) power2

module Main where

readInteger :: String -> Integer
readInteger = read

main = do
    input <- getLine
    let [h, w] = map readInteger $ take 2 $ words input
    let (cutH, cutW) = solve h w
    putStrLn $ show cutH ++ " " ++ show cutW where

        solve h w = maximum $ filter (\(y,x) -> (y*x) == maxSquare) possibleList where

            possibleList = byHeightList ++ byWidthList

            maxSquare = maximum (map (\(h, w) -> h*w) possibleList)

            byWidthList = filter isPossibleHW $ map makeH $ filter (<=w) powers
            byHeightList = filter isPossibleHW $ map makeW $ filter (<=h) powers

            makeH ww = ((min h (div (5*ww) 4)), ww)
            makeW hh = (hh, (min w (div (5*hh) 4)))

            isPossibleHW (hh, ww) = (5*hh) >= (4*ww) && (4*hh) <= (5*ww)

            powers :: [Integer]
            powers = [2^n | n <- [0..30]]

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

import Data.List
import qualified Data.Map as M
-- import Data.Map ((!))
import qualified Data.IntMap as IM
-- import Data.IntMap ((!))

import Data.Array
import Data.Function

import Debug.Trace

debug = flip trace
-- debug = const

cands = takeWhile (<= 10^9) $ map (2^) [0..]

largestCand n = reverse $ takeWhile (<= n) cands

fi = fromIntegral

cmp :: (Integer, Integer) -> (Integer, Integer) -> Ordering
cmp a@(a1, a2) b@(b1, b2)
  | a1 * a2 < b1 * b2 = LT
  | a1 * a2 == b1 * b2 && a1 < b1 = LT
  | a == b = EQ
  | otherwise = GT

solve :: Integer -> Integer -> (Integer, Integer)
solve h w =
  maximumBy cmp $ concat [(heightPow h w), (widthPow h w)]
  `debug` (show (heightPow h w) ++ " " ++ show (widthPow h w))

eps :: Double
eps = 10e-9

heightPow h w = concatMap hpcalc hps
  where hps = largestCand h
        hpcalc hp
          | fi hp * 1.25 - eps < fi w = [(hp, floor (fi hp * 1.25 + eps))]
          | fi hp * 0.8  + eps > fi w = []
          | otherwise     = [(hp, w)]

widthPow h w = concatMap wpcalc wps
  where wps = largestCand w
        wpcalc wp
          | fi wp * 1.25 - eps < fi h = [(floor (fi wp * 1.25 + eps), wp)]
          | fi wp * 0.8  + eps > fi h = []
          | otherwise              = [(h, wp)]

main = do
  [h, w] <- (map read . words) `fmap` getLine
  let (hr, wr) = solve h w
  putStrLn $ show hr ++ " " ++ show wr

main = do
	[h, w] <- fmap (map read . words) getLine
	putStrLn $ unwords $ map show $ tail $ maximum $ gao h w ++ gao w h	where
	gao h w = [[x * y, x, y] | x <- takeWhile (<=h) $ iterate (*2) 1, 4 * x <= 5 * w, y <- [min w $ div (x * 5) 4]]

import Maybe
import List

main = do
  [h,w] <- fmap (map read.words) getLine
  putStrLn $ f $ solve w h
  where f(x,y) = unwords $ map show [x,y]

solve :: Integer -> Integer -> (Integer,Integer)
solve h w = case compare (area a) (area b) of
              LT -> b
              GT -> a
              EQ -> last $ sort [a,b]
  where a = anotherEdges h w
        b = flipTuple $ anotherEdges h w

area (x,y) = x*y

flipTuple (x,y) = (y,x)

power2 = map(2^)[0..]

anotherEdge :: Integer -> Integer -> Maybe (Integer,Integer)
anotherEdge y x = if y < lower  then Nothing else Just $ (x,min y upper)
  where z     = fromIntegral x
        lower = ceiling $ 0.8*z
        upper = floor $ 1.25*z

anotherEdges y x = head $ catMaybes $ map (anotherEdge y)
                   $ reverse $ takeWhile(<=x) power2


We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not.

The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.

Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't.

NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".

{-# LANGUAGE FlexibleInstances #-}
module Main (printShit, printShitV, readShit, main) where
import Data.ByteString.Builder
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Maybe
-- Meat

solve :: [Integer] -> [BS.ByteString]
solve = map (\x -> if tPrime x then yes else no)
    where yes = BS.pack "YES"
          no = BS.pack "NO"

tPrime :: Integer -> Bool
tPrime 1 = False
tPrime n = sq * sq == n && isPrime sq
    where  sq = round $ sqrt (fromIntegral n::Double)

primes :: [Integer]
primes = filter isPrime [2..]

isPrime :: Integer -> Bool
isPrime 2 = True
isPrime n = 0 `notElem` fmap (n `rem`) (takeWhile (\p -> p*p <= n) primes)

-- Shit
main :: IO ()
main = do
        [_, xs] <- readShit
        printShitV $ solve xs

class Shit a where
    printShit :: a -> IO ()
    printShitV :: a -> IO ()
    readShit :: IO a
    printShitV = printShit

instance  Shit [Int] where
    printShit = putStrLn . unwords . fmap show
    printShitV = putStrLn . unlines . fmap show
    readShit = fmap (fmap read . words) getLine

instance  Shit [Integer] where
    printShit = putStrLn . unwords . fmap show
    printShitV = putStrLn . unlines . fmap show
    readShit = fmap (fmap read . words) getLine

instance Shit [[Int]] where
    printShit = putStrLn . unlines . fmap (unwords . fmap show)
    readShit = fmap (fmap (fmap read . words) . lines) getContents

instance Shit [[Integer]] where
    printShit  = printShit . (fmap.fmap)  (toLazyByteString . integerDec)
    readShit = fmap (fmap.fmap $ fromInteger.fst.fromJust. BS.readInteger) readShit

instance Shit [String] where
    printShit = putStrLn. unwords
    printShitV = putStrLn . unlines
    readShit = fmap lines getContents

instance Shit [BS.ByteString] where
    printShit = BS.putStrLn. BS.unwords
    printShitV = BS.putStrLn . BS.unlines
    readShit = fmap BS.lines BS.getContents

instance Shit [[BS.ByteString]] where
    printShit = BS.putStrLn . BS.unlines . fmap BS.unwords
    readShit = fmap (fmap (fmap BS.words) BS.lines) BS.getContents

{-# OPTIONS -O2 -optc-O3 #-}
import Control.Arrow ((***))
import Control.Monad (forM_, when)
import Control.Monad.ST (ST)
import Data.Array.ST (STUArray, runSTUArray, newArray, readArray, writeArray)
import Data.Array.Unboxed (UArray, (!), assocs)

isqrt :: (Integral a, Integral b) => a -> b
isqrt = floor . sqrt . fromIntegral

sieveToN :: Int -> UArray Int Bool
sieveToN n = runSTUArray sieve
  where
    sieve = do
      a <- newArray (2, n) True :: ST s (STUArray s Int Bool)
      forM_ [4, 6 .. n] $ \j ->
        writeArray a j False
      forM_ [3, 5 .. isqrt n] $ \i -> do
        ai <- readArray a i
        when ai $
          forM_ [i * i, i * (i + 2) .. n] $ \j ->
            writeArray a j False
      return a

primeTab :: UArray Int Bool
primeTab = sieveToN 1000000

isPrime :: Integral a => a -> Bool
isPrime n = n >= 2 && primeTab!fromIntegral n

main = do
  getLine
  getLine >>= putStrLn . unlines . map (gao . read) . words
  where
    gao n = let m = isqrt n in if m * m == n && isPrime m then "YES" else "NO"

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Applicative
import Control.Monad hiding ((<$!>))
import Control.Monad.ST.Safe
import Control.Monad.State hiding ((<$!>))
-- import Data.Array
import Data.Array.IArray
import Data.Array.IO.Safe
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Builder as BB
import Data.Char
import qualified Data.Foldable as F
import Data.Function
import Data.Graph
import Data.Int
import Data.List
import Data.List.Split
import Data.Maybe
import Data.Monoid
import Data.Ord
import Data.Ratio
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
-- import Data.Tree
import Data.Tuple
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
-- import Debug.Trace
import System.IO

-- getInts = fmap (map read . words) getLine
getInts = unfoldr (B.readInteger . B.dropWhile isSpace) <$> B.getLine

main = do
  getLine
  xs <- map fromIntegral <$> getInts :: IO [Int64]

  let
    primes = [a | a <- [2..10^3], all ((/= 0) . mod a) [2..a-1]] :: [Int64]

    check 1 = False
    check x = isSqrt && isPrime
      where
        y = truncate $ sqrt $ fromIntegral x
        isSqrt = y*y == x
        isPrime = all (\p -> y `mod` p /= 0) $ filter (\p -> p*p <= y) primes

  putStrLn $ unlines $ map ((\x -> if x then "YES" else "NO") . check) xs

import Control.Monad (forM_,when)
import qualified Data.ByteString.Char8 as BS
import Data.Int
import Data.Word

import Data.Array.IArray
import Data.Array.MArray
import qualified Data.Array.Unboxed as U
import Data.Array.ST (runSTUArray)
import Debug.Trace

sqr :: Double -> Double
sqr = sqrt

isqrt :: Integral a => a -> Int
isqrt n = floor $ sqrt $ (fromIntegral n :: Double)

isSquare :: Int64 -> Maybe Int
isSquare n = if r'*r' == n then Just r else Nothing
  where r = isqrt n
        r' = fromIntegral r

-- create a prime sieve array
mkSieve :: Int -> U.UArray Int Word8
mkSieve n = runSTUArray $ do
  arr <- newArray (0,n) 0
  writeArray arr 1 1
  let end = isqrt n
  forM_ [2..end] $ \a -> do
    x <- readArray arr a
    when (x == 0) $ do
      forM_ [a*a,a*a+a..n] $ \b -> do
        writeArray arr b 1
  return arr

isprime :: Int -> Bool
isprime n | n <= 11 = n `elem` [2,3,5,7,11]
isprime n | n `rem` 2 == 0 = False
isprime n = all (\m -> n `rem` m /= 0) [3,5..end]
  where end = isqrt n

wheel2357 :: [Int]
wheel2357 = 2:4:2:4:6:2:6:4:2:4:6:6:2:6:4:2:6:4:6:8:4:2:4:2:4:8:6:4:6:2:4:6:2:6:6:4:2:4:6:2:6:4:2:4:2:10:2:10:wheel2357
spin (x:xs) n = n : spin xs (n + x)

wheel' = 2 : 3 : 5 : 7 : spin wheel2357 11

isprime2 :: Int -> Bool
isprime2 n | n <= 11 = n `elem` [2,3,5,7,11]
isprime2 n = all (\m -> n `rem` m /= 0) $ takeWhile (<= end) wheel'
  where end = isqrt n

tprime :: (Int -> Bool) -> Int64 -> Bool
tprime ptest 1 = False
tprime ptest n =
  case isSquare n of
    Nothing -> False
    Just r  -> ptest r

(-->) = flip fmap

readInt :: BS.ByteString -> Integer
readInt s = case BS.readInteger s of
              Nothing    -> error "bad integer"
              Just (n,_) -> n

main = do
  n <- getLine --> read
  let _ = n :: Int
  nums <- BS.getLine --> BS.words --> map (fromIntegral . readInt)
  let sieve = mkSieve 1000000
  let ptest k = sieve ! k == 0
  forM_ nums $ \n -> do
    let b = tprime ptest n
    putStrLn $ if b then "YES" else "NO"

import Data.Int
import Data.Char
import qualified Data.List as L
import qualified Data.Array as A

solve :: [Int64] -> [String]
solve queries = map (boolToString . isTPrime) queries
    where
        boolToString True = "YES"
        boolToString False = "NO"
        isTPrime n = let m = floor (sqrt (fromIntegral n)) in
                           m * m == n && isPrimeMemo m
        isPrimeMemo m = primeArr A.! m
        primeArr = A.listArray (0,1001000) [ isPrime n | n <- [0..1001000]]
        isPrime 0 = False
        isPrime 1 = False
        isPrime n = and . map (\p -> n `mod` p /= 0) . takeWhile (\p -> p*p <= n) $ primes
        primes = 2:filter isPrimeMemo [3,5..]

main :: IO ()
main = do getLine
          queries <- (getLine >>= return . map readInt64 . words)
          putStr . unlines $ solve queries

readInt64 :: String -> Int64
readInt64 s = L.foldl' (\e c -> (fromIntegral . digitToInt $ c) + 10 * e) 0 s

import Data.List
import Data.Tree
import Data.Int
import Data.Maybe
import Data.Char
import Data.Functor
import Data.Bits
import Control.Monad
import Control.Monad.ST.Safe
import Control.Arrow
import Data.Array
import Data.Array.ST.Safe
import Data.STRef
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.ByteString.Char8 as C
main=   readsolveprint
readsolveprint::IO()
readsolveprint = getLine>>= \ns-> (solve.concat =<< forM [1 ..1] ( \i -> map (fst.fromJust.C.readInteger).C.words <$> C.getLine))
solve (xs) = forM_ xs $ \i-> let (n,f)= properFraction $ sqrt $ fromIntegral i in if (f==0) && (isPrime2 n) then putStrLn "YES" else putStrLn "NO"
primes = fst $ break (>1000) $ filterPrime [2..]
  where filterPrime (p:xs) =
          p : filterPrime [x | x <- xs, rem x p /= 0]
isPrime2 1 = False
isPrime2 2 = True
isPrime2 x =let (b1,b2) =  break (\a -> x `mod` a==0 ) (take ( floor $ sqrt $ fromIntegral x) primes) in if b2==[] then True else False

import Char (ord)
import Data.Set (fromList, member)
import Monad (liftM)

isPrime :: Integer -> Bool
isPrime n  =  all (\x -> mod n x /= 0) $ takeWhile (\x -> x * x <= n) primes

primes :: [Integer]
primes  =  2 : [n | n <- [3,5..], isPrime n]

solve :: [Integer] -> [Bool]
solve xs  =  map isSqrPrime xs
  where
    set  =  fromList . takeWhile (<= 10^6) $ primes
    isSqrPrime 1  =  False
    isSqrPrime x
      | x' * x' == x  =  member x' set
      | otherwise  =  False
      where
        x'  =  round . sqrt . fromIntegral $ x

(<?>) :: a -> a -> Bool -> a
(<?>) a b p  =  if p then a else b

parseLine :: String -> [Integer]
parseLine []  =  []
parseLine (c:s)
  | c == ' '  =  parseLine s
  | otherwise  =  parseLine' (f c) s
  where
    f c  =  fromIntegral (ord c - ord '0')
    parseLine' a []  =  [a]
    parseLine' a (c:s)
      | c == ' '  =  a : parseLine s
      | otherwise  =  parseLine' (10 * a + f c) s

main :: IO ()
main  =  getLine >> liftM parseLine getLine >>= mapM_ (putStrLn . ("YES" <?> "NO")) . solve

import Control.Applicative
import Data.List
import qualified Data.ByteString.Char8 as C
import Data.Maybe
import qualified Data.HashMap.Strict as H

--isprime 4 =True
--isprime x = all (>0)[ mod sx i|i<-[2]++[3,5..ssx+1]]
--     where sx = floor $ sqrt $ fromIntegral x
--           ssx = floor $ sqrt $ fromIntegral sx
primes ::[Integer]
primes = [2,3,5,7] ++ [x|x<-[11,13..],isprime x]

isprime::Integer->Bool
isprime x = and [mod x y/=0 |y<-takeWhile (<=xx) primes ]
  where xx = floor $ sqrt $ fromIntegral x

isrprime::Integer->Bool
isrprime s = isprime r
  where r = floor $ sqrt $ fromIntegral s

nosquare x = sx*sx /=x
     where sx = floor $ sqrt $ fromIntegral x

process 1 ="NO"
process s | nosquare s = "NO"
          | isrprime s = "YES"
          | otherwise = "NO"

process1::[Integer]->H.HashMap Integer String->[String]->[String]
process1 q m a | q==[] = reverse a
               | H.lookup (head q) m == Nothing = process1 (tail q) (H.insert (head q) (process (head q) ) m)  ((process (head q )):a)
               | otherwise = process1 (tail q) m ((fromJust(H.lookup (head q) m)):a)

main=do
    n<-     read  <$> getLine::IO Integer
    q<-    map ( fst.fromJust.C.readInteger) <$> C.words <$> C.getLine::IO [Integer]
    mapM_ putStrLn $   process1 q H.empty []

main=getContents>>=mapM_(putStrLn.h.read).tail.words
h n|n==m*m&&f m="YES"|1>0="NO" where m=round$sqrt$fromIntegral n
g=2:filter f[3,5..]
f n=n>1&&foldr(\p r->p*p>n||n`mod`p/=0&&r)True g

import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = B.getContents >>= mapM_ (putStrLn . yesno . solve . fst . fromJust . B.readInteger) . tail . B.words

solve :: Integer -> Bool
solve n = n == m * m && isPrime m
  where m = round (sqrt (fromIntegral n) :: Double)

yesno :: Bool -> String
yesno True = "YES"
yesno _ = "NO"

primes :: Integral a => [a]
primes = 2 : filter isPrime [3,5..]

isPrime :: Integral a => a -> Bool
isPrime n = n > 1 && foldr (\p r -> p * p > n || n `mod` p /= 0 && r) True primes

main :: IO ()
main = getContents >>= mapM_ (putStrLn . yesno . solve . read) . tail . words

solve :: Integer -> Bool
solve n = n == m * m && isPrime m
  where m = round (sqrt (fromIntegral n) :: Double)

yesno :: Bool -> String
yesno True = "YES"
yesno _ = "NO"

primes :: Integral a => [a]
primes = 2 : filter isPrime [3,5..]

isPrime :: Integral a => a -> Bool
isPrime n = n > 1 && foldr (\p r -> p * p > n || n `mod` p /= 0 && r) True primes

main :: IO ()
main = getContents >>= mapM_ (putStrLn . yesno . solve . read) . tail . words

solve :: Integer -> Bool
solve n = let m = (round :: Double -> Integer) $ sqrt $ fromIntegral n in n == m * m && isPrime m

yesno :: Bool -> String
yesno True = "YES"
yesno _ = "NO"

primes :: Integral a => [a]
primes = 2 : filter isPrime [3,5..]

isPrime :: Integral a => a -> Bool
isPrime n = n > 1 && foldr (\p r -> p * p > n || n `mod` p /= 0 && r) True primes

main=getContents>>=mapM_(putStrLn.h.read).tail.words
h n|n==m*m&&f m="YES"|1>0="NO" where m=round$sqrt$fromIntegral n
f n=n>1&&foldr(\p r->p*p>n||n`mod`p/=0&&r)True(2:filter f[3,5..])

import           Control.Monad
import           Control.Monad.ST
import           Data.Array.ST.Safe
import           Data.Int
import           Data.STRef
import qualified Data.Set as S
main = interact $ unlines . map (format . (`S.member` squares)) . map read . tail . words
format True = "YES"
format False = "NO"
squares = runST $ do
  sieve <- newArray (2,10^6) True :: ST s (STUArray s Int64 Bool)
  squares <- newSTRef S.empty
  forM_ [2..10^6] $ \i -> do
    p <- readArray sieve i
    when p $ do
      modifySTRef' squares (S.insert (i^2 :: Int64))
      when (i <= 10^3) $ forM_ [2*i, 3*i..10^6] $ \j -> writeArray sieve j False
  readSTRef squares

{-# LANGUAGE BangPatterns #-}

import Data.Array.Base(unsafeRead,unsafeWrite,unsafeAt)
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits
import qualified Data.ByteString.Char8 as B
import Control.Monad

readInteger bs = case B.readInteger bs of Just (n,_) -> n

main = B.getContents >>= putStrLn.unlines.solve.map readInteger.tail.B.words

solve :: [Integer] -> [String]
solve xs = map go xs
   where
     !isPrime = sieveOdds 1000000
     go x
       | fromIntegral sqrtx * fromIntegral sqrtx /= x = "NO"
       | x==4 || odd sqrtx && unsafeAt isPrime (sqrtx`shiftR`1) = "YES"
       | otherwise = "NO"
      where
        !sqrtx = bigisqrt x

sieveOdds :: Int -> UArray Int Bool
sieveOdds num = runSTUArray $ do
  let !num2 = num`div`2
  isPrime <- newArray (0,num2) True
  unsafeWrite isPrime 0 False
  forM_ [1..isqrt num`shiftR`1] $ \i-> do
    b <- unsafeRead isPrime i
    when b $ do
      let !p = i`shiftL`1 + 1
          !pp = i*(p+1)
      forM_ [pp,pp+p..num2] $ \j-> do
        unsafeWrite isPrime j False
  return isPrime

isqrt :: Int -> Int
isqrt x = floor.(1e-8+).sqrt $ fromIntegral x

bigisqrt :: Integer -> Int
bigisqrt x = floor.(1e-8+).sqrt $ fromIntegral x

{-# OPTIONS_GHC -O2 #-}

import Data.List
import Data.Word

--nubSorted :: Ord a => [a] -> [a]
--nubSorted [] = []
--nubSorted [x] = [x]
--nubSorted (x1:x2:xs) = if x1 == x2 then nubSorted (x2:xs) else x1 : nubSorted (x2:xs)

isPrime :: Word64 -> Bool
isPrime n | n < 2 = False
          | n == 2 = True
          | even n = False
          | (rootF n) ^ 2 == n = False
          | otherwise = null $ filter (\x -> mod n x == 0) $ takeWhile (\x -> x*x < n) [3, 5..]

rootF = round . sqrt . fromIntegral

isTPrime2 :: Word64 -> Bool
isTPrime2 999966000289 = True
isTPrime2 n =
    let root = rootF n
        in (isPrime $! root) && root * root == n

main = do
    n <- getLine
    xs <- words `fmap` getContents
    mapM_ (\x -> putStrLn (if isTPrime2 (read x) then "YES" else "NO")) xs

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

squ x =  x==y*y && isprime y
	where y = ceiling $ sqrt $ fromIntegral x

primes = [2,3,5,7,11] ++ (filter isprime [13,15..] )
isprime 1 = False
isprime 2 = True
isprime x = all (>0) [mod x y| y<- takeWhile (<=(ceiling (sqrt (fromIntegral x)))) primes]

main= do
	n  <-  getLine
	s<- map (fst.fromJust.C.readInteger). C.words <$> C.getLine   ::IO [Integer]
	putStrLn $ intercalate "\n" $ map (\z-> if squ z   then "YES" else "NO") s

import Data.Int (Int64)
import Data.Set (Set, fromList, member)

primes :: [Int64]
primes = 2 : sieve primes [3..]
  where
    sieve (p:ps) xs =
      let (h,t) = span (< p*p) xs
      in  h ++ sieve ps (filter ((/=0).(`mod`p)) t)

primesUpTo :: Int64 -> Set Int64
primesUpTo n = fromList $ takeWhile (<=n) primes

process :: [Int64] -> [Bool]
process xs = map f xs
    where
        f x = if x_sqrt^2 == x
                then x_sqrt `member` ps
                else False
            where x_sqrt = floor.sqrt.fromIntegral $ x
        ps = primesUpTo.floor.sqrt.fromIntegral $ maximum xs

readInt :: String -> Int64
readInt = read

printBool :: Bool -> IO ()
printBool b = do
    putStrLn $ ["NO","YES"] !! fromEnum b

main :: IO ()
main = do
    n <- fmap readInt getLine
    xs <- fmap (map readInt.words) getLine
    mapM_ printBool $ process xs

import Data.List
import Data.Set hiding (map)
import Data.Int

ordminus :: Ord a => [a] -> [a] -> [a]
ordminus x [] = x
ordminus [] y = y
ordminus (x:xs) (y:ys) | x < y  = x : ordminus xs (y:ys)
                       | x == y = ordminus xs ys
                       | x > y  = ordminus (x:xs) ys

ordunion :: Ord a => [a] -> [a] -> [a]
ordunion x [] = x
ordunion [] y = y
ordunion (x:xs) (y:ys) |  x < y = x : ordunion xs (y:ys)
                       |  y < x = y : ordunion (x:xs) ys
                       | x == y = x : ordunion xs ys

foldi            :: (a -> a -> a) -> a -> [a] -> a
foldi f z []     = z
foldi f z (x:xs) = f x (foldi f z (pairs f xs))

pairs            :: (a -> a -> a) -> [a] -> [a]
pairs f (x:y:t)  = f x y : pairs f t
pairs f t        = t

primes :: [Int64]
primes = 2 : 3 : ([5,7..] `ordminus`
                     foldi (\(x:xs) -> (x:) . ordunion xs) []
                          [[p*p, p*p+2*p..] | p <- tail primes])

setP = fromList (take 80000 primes)

isT :: Int64 -> Bool
isT v = let
  sqr = floor $ sqrt $ fromIntegral v
  in sqr*sqr==v && member (fromIntegral sqr) setP

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

main = do
  n <- getLine
  xs <- getLine
  putStr $ unlines $ map (yn.isT.read) $ take (read n) (words xs)

{-# OPTIONS_GHC -O #-}
{-# LANGUAGE BangPatterns #-}
import Data.Int
import Data.Array.Unboxed
import Control.Monad.ST
import Control.Monad
import Data.Set hiding (map)
import qualified Data.Map as M

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    putStr.unlines $ map f $ go xs (M.singleton 1 False) []

go [] _ acc = reverse acc
go (x:xs) mem acc =
    case M.lookup x mem of
        Just v  -> go xs mem $ v : acc
        Nothing -> (go xs $ M.insert x b mem) $ b : acc
            where b = isinset x

isinset x = x `member` primesSqr
f True = "YES";f False = "NO"

primesSqr = fromList $ map (^2) primesList
primesList = primesToA.floor.(+1).sqrt $ 1e12
primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]]
                        :: UArray Int64 Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a

{-# OPTIONS_GHC -O #-}
{-# LANGUAGE BangPatterns #-}
import Data.Int
import Data.Array.Unboxed
import Control.Monad.ST
import Control.Monad
import Data.Set hiding (map)
import qualified Data.Map as M

magic = 1000

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    putStr.unlines $ map f $ go xs (M.singleton 1 False) []
    --go xs (M.singleton 1 False)

go [] _ acc = reverse acc
go (x:xs) mem acc =
    case M.lookup x mem of
        Just v  -> go xs mem $ v : acc
        Nothing -> (go xs $ M.insert x b mem) $ b : acc
            where b = isinset x

isinset x = x `member` primesSqr

f True = "YES";f False = "NO"

pmagic = take magic primesList
_magicth = last pmagic

isPrime n
    | n > _magicth = case or . map ((==0).(n`mod`)) $ pmagic of
                        False -> n `member` primesSet
                        True  -> False
    | True        = n `elem` pmagic
isTPrime 4 = True
isTPrime 9 = True
isTPrime n
    | n`mod`2 == 0  = False
    | n`mod`3 == 0  = False
    | n`mod`24 /= 1 = False
    | n>999983^2    = False
    | True          = sq*sq == n && isPrime sq
        where sq = round.sqrt.fromIntegral $ n

primesSet = fromList $ drop magic $ primesList
primesSqr = fromList $ map (^2) primesList
primesList = primesToA.floor.(+1).sqrt $ 1e12
primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]]
                        :: UArray Int64 Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a

{-# OPTIONS_GHC -O #-}
{-# LANGUAGE BangPatterns #-}
import Data.Int
import Data.Array.Unboxed
import Control.Monad.ST
import Control.Monad
import Data.Set hiding (map)
import qualified Data.Map as M

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.isinset) xs
    --putStr.unlines $ map f $ go xs (M.singleton 1 False) []
{-
go [] _ acc = reverse acc
go (x:xs) mem acc =
    case M.lookup x mem of
        Just v  -> go xs mem $ v : acc
        Nothing -> (go xs $ M.insert x b mem) $ b : acc
            where b = isinset x
  -}
isinset x = x `member` primesSqr
f True = "YES";f False = "NO"

primesSqr = fromList $ map (^2) primesList
primesList = primesToA.floor.(+1).sqrt $ 1e12
primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]]
                        :: UArray Int64 Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Applicative
import Control.Monad hiding ((<$!>))
import Control.Monad.ST.Safe
import Control.Monad.State hiding ((<$!>))
-- import Data.Array
import Data.Array.IArray
import Data.Array.IO.Safe
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Builder as BB
import Data.Char
import qualified Data.Foldable as F
import Data.Function
import Data.Graph
import Data.Int
import Data.List
import Data.List.Split
import Data.Maybe
import Data.Monoid
import Data.Ord
import Data.Ratio
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
-- import Data.Tree
import Data.Tuple
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
-- import Debug.Trace
import System.IO

-- getInts = fmap (map read . words) getLine
getInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

main = do
  getLine
  xs <- map fromIntegral <$> getInts :: IO [Int64]

  let
    primes = [a | a <- [2..10^3], all ((/= 0) . mod a) [2..a-1]]

    check 1 = False
    check x = isSqrt && isPrime
      where
        y = truncate $ sqrt $ fromIntegral x :: Int64
        isSqrt = y*y == x
        isPrime = all (\p -> y `mod` p /= 0) $ filter (\p -> p*p <= y) primes

  putStrLn $ unlines $ map ((\x -> if x then "YES" else "NO") . check) xs

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Applicative
import Control.Monad hiding ((<$!>))
import Control.Monad.ST.Safe
import Control.Monad.State hiding ((<$!>))
-- import Data.Array
import Data.Array.IArray
import Data.Array.IO.Safe
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Builder as BB
import Data.Char
import qualified Data.Foldable as F
import Data.Function
import Data.Graph
import Data.Int
import Data.List
import Data.List.Split
import Data.Maybe
import Data.Monoid
import Data.Ord
import Data.Ratio
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
-- import Data.Tree
import Data.Tuple
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
-- import Debug.Trace
import System.IO

-- getInts = fmap (map read . words) getLine
getInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

main = do
  getLine
  xs <- map fromIntegral <$> getInts :: IO [Int64]

  let
    primes = [a | a <- [2..10^3], all ((/= 0) . mod a) [2..a-1]]

    check x = isSqrt && isPrime
      where
        y = truncate $ sqrt $ fromIntegral x
        isSqrt = y*y == x
        isPrime = all (\p -> y `mod` p /= 0) $ filter (\p -> p*p <= y) primes

  putStrLn $ unlines $ map ((\x -> if x then "YES" else "NO") . check) xs

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Applicative
import Control.Monad hiding ((<$!>))
import Control.Monad.ST.Safe
import Control.Monad.State hiding ((<$!>))
-- import Data.Array
import Data.Array.IArray
import Data.Array.IO.Safe
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Builder as BB
import Data.Char
import qualified Data.Foldable as F
import Data.Function
import Data.Graph
import Data.Int
import Data.List
import Data.List.Split
import Data.Maybe
import Data.Monoid
import Data.Ord
import Data.Ratio
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
-- import Data.Tree
import Data.Tuple
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
-- import Debug.Trace
import System.IO

-- getInts = fmap (map read . words) getLine
getInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

main = do
  getLine
  xs <- map fromIntegral <$> getInts :: IO [Int64]

  let
    primes = [a | a <- [2..10^3], all ((/= 0) . mod a) [2..a-1]]

    check 1 = False
    check x = isSqrt && isPrime
      where
        y = truncate $ sqrt $ fromIntegral x
        isSqrt = y*y == x
        isPrime = all (\p -> y `mod` p /= 0) $ filter (\p -> p*p <= y) primes

  putStrLn $ unlines $ map ((\x -> if x then "YES" else "NO") . check) xs

import Control.Monad (forM_)
import qualified Data.ByteString.Char8 as BS
import Data.Int

sqr :: Double -> Double
sqr = sqrt

isqrt :: Int64 -> Maybe Int64
isqrt n = if r*r == n then Just r else Nothing
  where r = floor $ (sqr (fromIntegral n) )

tprime :: Int64 -> Bool
tprime n =
  case isqrt n of
    Nothing -> False
    Just r  -> isPrime' r

isPrime' :: Int64 -> Bool
isPrime' n | n `mod` 2 == 0 = n == 2
isPrime' n = all (\m -> n `rem` m /= 0) [3,5..end]
  where end = floor (sqr (fromIntegral n))

allTrue = all id

(-->) = flip fmap

readInt :: BS.ByteString -> Integer
readInt s = case BS.readInteger s of
              Nothing    -> error "bad integer"
              Just (n,_) -> n

main = do
  n <- getLine --> read
  let _ = n :: Int
  nums <- BS.getLine --> BS.words --> map (fromIntegral . readInt)
  forM_ nums $ \n -> do
    putStrLn $ if tprime n then "YES" else "NO"

import Control.Monad (forM_)
import qualified Data.ByteString.Char8 as BS
import Data.Int

sqr :: Double -> Double
sqr = sqrt

isqrt :: Int64 -> Maybe Int64
isqrt n = if r*r == n then Just r else Nothing
  where r = floor $ (sqr (fromIntegral n) )

tprime :: Int64 -> Bool
tprime n =
  case isqrt n of
    Nothing -> False
    Just r  -> isPrime' r

isPrime' :: Int64 -> Bool
isPrime' n | n `mod` 2 == 0 = n == 2
isPrime' n = all (\m -> n `rem` m /= 0) [3,5..end]
  where end = floor (sqr (fromIntegral n))

allTrue = all id

(-->) = flip fmap

readInt :: BS.ByteString -> Integer
readInt s = case BS.readInteger s of
              Nothing    -> error "bad integer"
              Just (n,_) -> n

main = do
  n <- getLine --> read
  let _ = n :: Int
  nums <- BS.getLine --> BS.words --> map (fromIntegral . readInt)
  forM_ nums $ \n -> do
    putStrLn $ (if tprime n then "YES" else "NO") ++ " " ++ show n

import Data.List
import Data.Tree
import Data.Int
import Data.Maybe
import Data.Char
import Data.Functor
import Data.Bits
import Control.Monad
import Control.Monad.ST.Safe
import Control.Arrow
import Data.Array
import Data.Array.ST.Safe
import Data.STRef
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.ByteString.Char8 as C
main=   readsolveprint
readsolveprint::IO()
readsolveprint = getLine>>= \ns-> (solve.concat =<< forM [1 ..1] ( \i -> map (fst.fromJust.C.readInt).C.words <$> C.getLine))
solve::[Int]->IO()
solve (xs) =forM_ xs $ \i-> let (n,f)= properFraction $ sqrt $ fromIntegral i in if (f==0) && (isPrime n) then putStrLn "YES" else putStrLn "NO"
isPrime 1 = False
isPrime 2 = True
isPrime x = foldr (\a b -> b && x `mod` a /=0) True [2..x-1]

import Control.Applicative
import Data.List

isprime x = all (>0)[ mod x i|i<-[2..sx+1]]
     where sx = floor $ sqrt $ fromIntegral x

nosquare x = sx*sx /=x
     where sx = floor $ sqrt $ fromIntegral x
process s | nosquare s = "NO"
          | isprime s = "YES"
          | otherwise = "NO"

main=do
    n<-     read  <$> getLine::IO Integer
    q<-    map read <$> words <$> getLine::IO [Integer]
    mapM_ putStrLn $ map process q

import Control.Applicative
import Data.List

isprime 4 =True
isprime x = all (>0)[ mod sx i|i<-[2..ssx+1]]
     where sx = floor $ sqrt $ fromIntegral x
           ssx = floor $ sqrt $ fromIntegral sx

nosquare x = sx*sx /=x
     where sx = floor $ sqrt $ fromIntegral x

process s | nosquare s = "NO"
          | isprime s = "YES"
          | otherwise = "NO"

main=do
    n<-     read  <$> getLine::IO Integer
    q<-    map read <$> words <$> getLine::IO [Integer]
    mapM_ putStrLn $ map process q

import Control.Applicative
import Data.List
import qualified Data.ByteString.Char8 as C
import Data.Maybe
import qualified Data.HashMap.Strict as H

isprime 4 =True
isprime x = all (>0)[ mod sx i|i<-[2]++[3,5..ssx+1]]
     where sx = floor $ sqrt $ fromIntegral x
           ssx = floor $ sqrt $ fromIntegral sx

nosquare x = sx*sx /=x
     where sx = floor $ sqrt $ fromIntegral x

process 1 ="NO"
process s | nosquare s = "NO"
          | isprime s = "YES"
          | otherwise = "NO"

process1::[Int]->H.HashMap Int String->[String]->[String]
process1 q m a | q==[] = reverse a
               | H.lookup (head q) m == Nothing = process1 (tail q) (H.insert (head q) (process (head q) ) m)  ((process (head q )):a)
               | otherwise = process1 (tail q) m ((fromJust(H.lookup (head q) m)):a)

main=do
    n<-     read  <$> getLine::IO Int
    q<-    map (fromIntegral. fst.fromJust.C.readInteger) <$> C.words <$> C.getLine::IO [Int]
    mapM_ putStrLn $   process1 q H.empty []

import Control.Applicative
import Data.List

isprime x = all (>0)[ mod x i|i<-[2..sx+1]]
     where sx = floor $ sqrt $ fromIntegral x

nosquare x = sx*sx ==x
     where sx = floor $ sqrt $ fromIntegral x
process s | nosquare s = "NO"
          | isprime s = "YES"
          | otherwise = "NO"

main=do
    n<-     read  <$> getLine::IO Integer
    q<-    map read <$> words <$> getLine::IO [Integer]
    mapM_ putStrLn $ map process q

import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = B.getContents >>= mapM_ (putStrLn . yesno . solve . fromIntegral . fst . fromJust . B.readInt) . tail . B.words

solve :: Integer -> Bool
solve n = n == m * m && isPrime m
  where m = round (sqrt (fromIntegral n) :: Double)

yesno :: Bool -> String
yesno True = "YES"
yesno _ = "NO"

primes :: Integral a => [a]
primes = 2 : filter isPrime [3,5..]

isPrime :: Integral a => a -> Bool
isPrime n = n > 1 && foldr (\p r -> p * p > n || n `mod` p /= 0 && r) True primes

import Data.List (group)

main :: IO ()
main = getContents >>= mapM_ (putStrLn . yesno) . solve . map read . tail . words

solve :: [Int] -> [Bool]
solve = map ((==3) . numberOfDivisors)

yesno :: Bool -> String
yesno True = "YES"
yesno _ = "NO"

primes :: Integral a => [a]
primes = 2 : filter isPrime [3,5..]

isPrime :: Integral a => a -> Bool
isPrime n = n > 1 && foldr (\p r -> p * p > n || n `mod` p /= 0 && r) True primes

primeFactors :: Integral a => a -> [a]
primeFactors n | n > 1 = go n primes
               | otherwise = []
   where go m ps@(p:t) | p * p > m  = [m]
                       | r == 0     =  p : go q ps
                       | otherwise  =      go m t
                          where (q, r) = quotRem m p
         go _ _ = []

numberOfDivisors :: Integral a => a -> Int
numberOfDivisors = product . map ((+1) . length) . group . primeFactors

import           Control.Monad
import           Control.Monad.ST
import           Data.Array.ST.Safe
import           Data.Int
import           Data.STRef
import qualified Data.Set as S
main = interact $ unlines . map (format . (`S.member` squares)) . map read . tail . words
format True = "YES"
format False = "NO"
squares = runST $ do
  sieve <- newArray (2,10^6) True :: ST s (STUArray s Int64 Bool)
  squares <- newSTRef S.empty
  forM_ [2..10^3] $ \i -> do
    p <- readArray sieve i
    when p $ do
      modifySTRef' squares (S.insert (i^2 :: Int64))
      forM_ [2*i, 3*i..10^6] $ \j -> writeArray sieve j False
  readSTRef squares

import Data.List

nubSorted :: Ord a => [a] -> [a]
nubSorted [] = []
nubSorted [x] = [x]
nubSorted (x1:x2:xs) = if x1 == x2 then nubSorted (x2:xs) else x1 : nubSorted (x2:xs)

isTPrime :: Int -> Bool
isTPrime n =
    let root = (truncate . sqrt . fromIntegral $ n) :: Int
        subr = if root*root == n then 1 else 0
        in 3 == (2 * (length . nubSorted . sort $
            filter (\x -> mod n x == 0) [1..root]) - subr)

isPrime :: Int -> Bool
isPrime n | n < 2 = False
          | n == 2 = True
          | even n = False
          | otherwise = null $ filter (\x -> mod n x == 0) [3,5..root]
    where
        root = (truncate . sqrt . fromIntegral $ n) :: Int

isTPrime2 :: Int -> Bool
isTPrime2 n =
    let root = (truncate . sqrt . fromIntegral $ n) :: Int
        in isPrime root && root * root == n

main = do
    n <- fmap (\x -> read x :: Int) getLine
    xs <- (map read.words) `fmap` getLine
    mapM_ (\x -> putStrLn (if isTPrime2 x then "YES" else "NO")) xs

import Data.List
import Data.Word

isPrime :: Word64 -> Bool
isPrime n | n < 2 = False
          | n == 2 = True
          | even n = False
          | otherwise = null $ filter (\x -> mod n x == 0) $ takeWhile (\x -> x*x <= root) [3,5..root]
    where
        root = (truncate . sqrt . fromIntegral $ n) :: Word64

isTPrime2 :: Word64 -> Bool
isTPrime2 n =
    let root = (truncate . sqrt . fromIntegral $ n) :: Word64
        in isPrime root && (root * root == n)

main = do
    n <- getLine
    xs <- (map read.words) `fmap` getLine
    mapM_ (\x -> putStrLn (if isTPrime2 x then "YES" else "NO")) xs

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

squ x =  x==y*y && isprime y
	where y = ceiling $ sqrt $ fromIntegral x

primes = [2,3,5,7,11] ++ (filter isprime [13,15..] )
isprime 2 = True
isprime x = all (>0) [mod x y| y<- takeWhile (<=(ceiling (sqrt (fromIntegral x)))) primes]

main= do
	n  <-  getLine
	s<- map (fst.fromJust.C.readInteger). C.words <$> C.getLine   ::IO [Integer]
	putStrLn $ intercalate "\n" $ map (\z-> if squ z   then "YES" else "NO") s

import Data.Int

isPrime :: Int64 -> Bool
isPrime n =
  if n `mod` 2 == 0
    then n == 2
    else not $ any (\d -> n `mod` d == 0) [3,5..(floor.sqrt.fromIntegral) n]

yn :: Bool -> [Char]
yn True = "YES"
yn False = "NO"

isT :: Int64 -> Bool
isT x = let s = floor $ sqrt $ fromIntegral x in s*s==x && isPrime s

main = do
  n <- getLine
  s_xs <- getLine
  putStr $ unlines $ map yn $ map isT $ map read $ words s_xs

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.is_square) xs

f True = "YES"
f False = "NO"

is_square 1 = False
is_square n = or . map (==n) $ [foldl (*) sq (replicate x sq)| x <- [1..44]]
    where sq = round $ sqrt $ (fromIntegral n::Double)

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.isTPrime) xs

f True = "YES"
f False = "NO"

is_square 1 = False
is_square n = case filter (==n) $ [foldl (*) (sq x) (replicate (x-1) (sq x)) | x <- [2..40]] of
            [] -> False
            (s:_) -> True
    where sq x = round . (**(1/fromIntegral x)) $ (fromIntegral n::Double)

isTPrime n = length (primeDivs n) == 1
primeDivs n = (filter (\x -> n`mod`x == 0)
                $ takeWhile (\x -> x < (round.(+1).(/2).fromIntegral $ n))
                $ primesList)
--primesArr = listArray (1,227647) primesList :: UArray Int Int64
primesList = (primesToA.round.(+1).sqrt $ 10e12)

primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]]
                        :: UArray Int64 Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed
import Data.Set hiding (map)

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.isTPrime) xs

f True = "YES";f False = "NO"

isTPrime 4 = True
isTPrime n
    | n`mod`2 == 0 = False
    | True         = sq*sq == n && isPrime sq
    where sq = floor.sqrt.fromIntegral $ n

isPrime n
    | n `mod` 24 /= 1 = False
    | True = n `member` primesSet

primesSet = fromList (primesToA.floor.(+1).sqrt $ 10e12)

primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]]
                        :: UArray Int64 Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.is_square) xs

f True = "YES"
f False = "NO"

is_square 1 = False
is_square n = or . map (==n) $ [foldl (*) (sq x) (replicate (x-1) (sq x)) | x <- [2..40]]
    where sq x = round . (**(1/fromIntegral x)) $ (fromIntegral n::Double)

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.isTPrime) xs

f True = "YES"
f False = "NO"

is_square 1 = False
is_square n = case filter (==n) $ [foldl (*) (sq x) (replicate (x-1) (sq x)) | x <- [2..40]] of
            [] -> False
            (s:_) -> True
    where sq x = round . (**(1/fromIntegral x)) $ (fromIntegral n::Double)

isTPrime n = or (primeDivs n)
primeDivs n = map (c==) $ primesList
    where c = round.sqrt.fromIntegral $ n
--primesArr = listArray (1,227647) primesList :: UArray Int Int64
primesList = (primesToA.round.(+1).sqrt $ 10e12)

primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]]
                        :: UArray Int64 Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine
    mapM_ (putStrLn.f) xs

f :: Int64 -> String
f n
 | (round.sqrt.fromIntegral $ n)^2 == n = "YES"
 | True = "NO"

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.is_square) xs

f True = "YES"
f False = "NO"

is_square 1 = False
is_square n = sq * sq == n
    where sq = floor $ sqrt $ (fromIntegral n::Double)

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed
import Data.Set hiding (map)

main = do
    let
        primesSet = fromList primesList
        primesList = primesToA.floor.(+1).sqrt $ 10e12
        isPrime n
            | not . or . map ((==0).(n`mod`)) $ take 1000 primesList = False
            | True = n `member` primesSet
        isTPrime 4 = True
        isTPrime 9 = True
        isTPrime n
            | n`mod`2 == 0  = False
            | n`mod`24 /= 1 = False
            | True          = sq*sq == n && isPrime sq
            where sq = round.sqrt.fromIntegral $ n
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.isTPrime) xs

f True = "YES";f False = "NO"

isPrime n
    |not. or . map ((==0).(n`mod`)) $ take 1000 primesList = False
    | True = n `member` primesSet

primesSet = fromList primesList
primesList = primesToA.floor.(+1).sqrt $ 10e12
primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]]
                        :: UArray Int64 Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a

{-# OPTIONS_GHC -O2 #-}
import Data.Int

main = do
    n <- fmap read getLine :: IO Int64
    xs <- fmap (map read . words) getLine
    mapM_ (putStrLn.sln) xs

sln p =
    case (fromIntegral $ j*j)>b && b*b==a && a>1.0 of
        True -> "YES"
        False -> "NO"
      where
        c' acc
            | (round b)`mod`acc == 0  = acc
            | fromIntegral (acc*acc)<=b            = acc
            | True                  = c' (acc+1)
        a = fromIntegral p
        b = sqrt a :: Double
        j = (c' 2) :: Int64

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.isTPrime) xs

f True = "YES"
f False = "NO"

is_square 1 = False
is_square n = case filter (==n) $ [foldl (*) (sq x) (replicate (x-1) (sq x)) | x <- [2..40]] of
            [] -> False
            (s:_) -> True
    where sq x = round . (**(1/fromIntegral x)) $ (fromIntegral n::Double)

isTPrime n = length (primeDivs n) == 2
primeDivs n = filter (\x -> n`mod`x == 0) primesList
--primesArr = listArray (1,227647) primesList :: UArray Int Int64
primesList = 2 : (primesToA.round.(+1).sqrt $ 10e12)

primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]]
                        :: UArray Int64 Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.is_square) xs

f True = "YES"
f False = "NO"

is_square 1 = False
is_square n = or . map (==n) $ [foldl (*) sq (replicate x sq)| x <- [1..44]]
    where sq = floor $ sqrt $ (fromIntegral n::Double)

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.isTPrime) xs

f True = "YES"
f False = "NO"

is_square 1 = False
is_square n = case filter (==n) $ [foldl (*) (sq x) (replicate (x-1) (sq x)) | x <- [2..40]] of
            [] -> False
            (s:_) -> True
    where sq x = round . (**(1/fromIntegral x)) $ (fromIntegral n::Double)

isTPrime n = length (primeDivs n) == 3
primeDivs n = 1 : filter (\x -> n`mod`x == 0) primesList
--primesArr = listArray (1,227647) primesList :: UArray Int Int64
primesList = (primesToA.round.(+1).sqrt $ 10e12)

primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]]
                        :: UArray Int64 Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed
import Data.Set hiding (map)

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.isTPrime) xs

f True = "YES";f False = "NO"

isTPrime 4 = True
isTPrime n
    | n`mod`2 == 0  = False
    | n`mod`24 /= 1 = False
    | True          = sq*sq == n && isPrime sq
    where sq = floor.sqrt.fromIntegral $ n

isPrime = (`member` primesSet)

primesSet = fromList (primesToA.floor.(+1).sqrt $ 10e12)

primesToA m = sieve 3 (array (3,m) [(i,odd i) | i<-[3..m]]
                        :: UArray Int64 Bool)
  where
    sieve p a
      | p*p > m   = 2 : [i | (i,True) <- assocs a]
      | a!p       = sieve (p+2) $ a//[(i,False) | i <- [p*p, p*p+2*p..m]]
      | otherwise = sieve (p+2) a

{-# OPTIONS_GHC -O2 #-}
import Data.Int
import Data.Array.Unboxed

main = do
    n <- fmap read getLine
    xs <- fmap (take n . map read . words) getLine :: IO [Int64]
    mapM_ (putStrLn.f.is_square) xs

f True = "YES"
f False = "NO"

is_square n = sq * sq == n
    where sq = floor $ sqrt $ (fromIntegral n::Double)

{-# LANGUAGE FlexibleInstances #-}
module Main (printShit, printShitV, readShit, main) where

-- Meat

solve :: [Integer] -> [String]
solve = map (\x -> if isSquare x && x /= 1 then "YES" else "NO")

isSquare :: Integer -> Bool
isSquare n = sq * sq == n
    where sq = floor $ sqrt (fromIntegral n::Double)

-- Shit
main :: IO ()
main = do
        [_, xs] <- readShit
        printShitV $ solve xs

class Shit a where
    printShit :: a -> IO ()
    printShitV :: a -> IO ()
    readShit :: IO a
    printShitV = printShit

instance  Shit [Int] where
    printShit = putStrLn . unwords . fmap show
    printShitV = putStrLn . unlines . fmap show
    readShit = fmap (fmap read . words) getLine

instance  Shit [Integer] where
    printShit = putStrLn . unwords . fmap show
    printShitV = putStrLn . unlines . fmap show
    readShit = fmap (fmap read . words) getLine

instance Shit [[Int]] where
    printShit = putStrLn . unlines . fmap (unwords . fmap show)
    readShit = fmap (fmap (fmap read . words) . lines) getContents

instance Shit [[Integer]] where
    printShit = putStrLn . unlines . fmap (unwords . fmap show)
    readShit = fmap (fmap (fmap read . words) . lines) getContents

instance Shit [String] where
    printShit = putStrLn. unwords
    printShitV = putStrLn . unlines
    readShit = fmap lines getContents


Edo has got a collection of n refrigerator magnets!He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be positive integers.Edo figured out how he wants to place the magnets on the refrigerator. He introduced a system of coordinates on the plane, where each magnet is represented as a rectangle with sides parallel to the coordinate axes.Now he wants to remove no more than k magnets (he may choose to keep all of them) and attach all remaining magnets to the refrigerator door, and the area of the door should be as small as possible. A magnet is considered to be attached to the refrigerator door if its center lies on the door or on its boundary. The relative positions of all the remaining magnets must correspond to the plan.Let us explain the last two sentences. Let's suppose we want to hang two magnets on the refrigerator. If the magnet in the plan has coordinates of the lower left corner (x1, y1) and the upper right corner (x2, y2), then its center is located at (, ) (may not be integers). By saying the relative position should correspond to the plan we mean that the only available operation is translation, i.e. the vector connecting the centers of two magnets in the original plan, must be equal to the vector connecting the centers of these two magnets on the refrigerator.The sides of the refrigerator door must also be parallel to coordinate axes.

The first line contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ min(10, n - 1)) — the number of magnets that Edo has and the maximum number of magnets Edo may not place on the refrigerator. Next n lines describe the initial plan of placing magnets. Each line contains four integers x1, y1, x2, y2 (1 ≤ x1 < x2 ≤ 109, 1 ≤ y1 < y2 ≤ 109) — the coordinates of the lower left and upper right corners of the current magnet. The magnets can partially overlap or even fully coincide.

Print a single integer — the minimum area of the door of refrigerator, which can be used to place at least n - k magnets, preserving the relative positions.

NoteIn the first test sample it is optimal to remove either the first or the third magnet. If we remove the first magnet, the centers of two others will lie at points (2.5, 2.5) and (3.5, 3.5). Thus, it is enough to buy a fridge with door width 1 and door height 1, the area of the door also equals one, correspondingly.In the second test sample it doesn't matter which magnet to remove, the answer will not change — we need a fridge with door width 8 and door height 8.In the third sample you cannot remove anything as k = 0.

import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.Array as Arr
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Set as Set
import Data.Set (Set)
import Data.List
import Data.Ord
import Control.Applicative
import Control.Monad
import Data.Function

read' = foldl (\a x -> a * 10 + fromIntegral (fromEnum x - fromEnum '0')) 0

genCounts 0 0 = [[]]
genCounts 0 _ = []
genCounts n k = [i : is|i<-[0..k],is<-genCounts (n-1) (k - i)]

s :: [[Integer]] -> Integer
s ([n,k] : magnets) = (minimum $ map (\(x, y, cc) -> ((max 1 $ (x + 1) `div` 2) * (max 1 $ (y + 1) `div` 2))) sizes) where
  centers = map (\[x1,y1,x2,y2] -> (x1 + x2, y1 + y2)) magnets
  counts = genCounts 4 k
  sorteds = map (\f -> (f, sortBy (comparing f) centers)) [fst, negate . fst, snd, negate . snd]
--  sizes :: [(Int, Int)]
  sizes = map (\cc ->
    let
     ([mbot,top,mright,left], _) =
      foldl (\(bounds, isFilteredOut) (c, (f, sorted)) ->
        case reverse . genericTake (c + 1) $ (filter (\p -> not $ isFilteredOut p) (genericTake 11 sorted)) of
          [] -> error "everything filtered out! impossiburu!"
          keeping : maybeDropping ->
            if genericLength maybeDropping /= c then error "can't be" else (f keeping : bounds, (\p -> isFilteredOut p || f p < f keeping))
        ) ([], (const False)) (zip cc sorteds)
    in
     ((- mbot) - top, (- mright) - left, (cc, (left, top), (-mright, -mbot)))
      ) counts

main = interact $ show . s . map (map read' . words) . lines

import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.Array as Arr
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Set as Set
import Data.Set (Set)
import Data.List
import Data.Ord
import Control.Applicative
import Control.Monad
import Data.Function

read' = foldl (\a x -> a * 10 + fromIntegral (fromEnum x - fromEnum '0')) 0

genCounts 0 0 = [[]]
genCounts 0 _ = []
genCounts n k = [i : is|i<-[0..k],is<-genCounts (n-1) (k - i)]

s :: [[Integer]] -> Integer
s ([n,k] : magnets) = (minimum $ map (\(x, y, cc) -> (((x + 1) `div` 2) * ((y + 1) `div` 2))) sizes) where
  centers = map (\[x1,y1,x2,y2] -> (x1 + x2, y1 + y2)) magnets
  counts = genCounts 4 k
  sorteds = map (\f -> (f, sortBy (comparing f) centers)) [fst, negate . fst, snd, negate . snd]
--  sizes :: [(Int, Int)]
  sizes = map (\cc ->
    let
     ([mbot,top,mright,left], _) =
      foldl (\(bounds, isFilteredOut) (c, (f, sorted)) ->
        case reverse . genericTake (c + 1) $ (filter (\p -> not $ isFilteredOut p) (genericTake 11 sorted)) of
          [] -> error "everything filtered out! impossiburu!"
          keeping : maybeDropping -> (f keeping : bounds, (\p -> isFilteredOut p || f p < f keeping))
        ) ([], (const False)) (zip cc sorteds)
    in
     ((- mbot) - top, (- mright) - left, (cc, (left, top), (-mright, -mbot)))
      ) counts

main = interact $ show . s . map (map read' . words) . lines

import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.Array as Arr
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Set as Set
import Data.Set (Set)
import Data.List
import Data.Ord
import Control.Applicative
import Control.Monad
import Data.Function

read' = foldl (\a x -> a * 10 + (fromEnum x - fromEnum '0')) 0

genCounts 0 0 = [[]]
genCounts 0 _ = []
genCounts n k = [i : is|i<-[0..k],is<-genCounts (n-1) (k - i)]

-- s :: [[Int]] -> Int
s ([n,k] : magnets) = (minimum $ map (\(x, y, cc) -> (((x + 1) `div` 2) * ((y + 1) `div` 2))) sizes) where
  centers = map (\[x1,y1,x2,y2] -> (x1 + x2, y1 + y2)) magnets
  counts = genCounts 4 k
  sorteds = map (\f -> (f, sortBy (comparing f) centers)) [fst, negate . fst, snd, negate . snd]
--  sizes :: [(Int, Int)]
  sizes = map (\cc ->
    let
     ([mbot,top,mright,left], _) =
      foldl (\(bounds, isFilteredOut) (c, (f, sorted)) ->
        case reverse . take (c + 1) $ (filter (\p -> not $ isFilteredOut p) (take 11 sorted)) of
          [] -> error "everything filtered out! impossiburu!"
          keeping : maybeDropping -> (f keeping : bounds, (\p -> isFilteredOut p || f p < f keeping))
        ) ([], (const False)) (zip cc sorteds)
    in
     ((- mbot) - top, (- mright) - left, (cc, (left, top), (-mright, -mbot)))
      ) counts

main = interact $ show . s . map (map read' . words) . lines

import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.Array as Arr
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Set as Set
import Data.Set (Set)
import Data.List
import Data.Ord
import Control.Applicative
import Control.Monad
import Data.Function

read' = foldl (\a x -> a * 10 + fromIntegral (fromEnum x - fromEnum '0')) 0

genCounts 0 0 = [[]]
genCounts 0 _ = []
genCounts n k = [i : is|i<-[0..k],is<-genCounts (n-1) (k - i)]

s :: [[Integer]] -> Integer
s ([n,k] : magnets) = (minimum $ map (\(x, y, cc) -> (((x + 1) `div` 2) * ((y + 1) `div` 2))) sizes) where
  centers = map (\[x1,y1,x2,y2] -> (x1 + x2, y1 + y2)) magnets
  counts = genCounts 4 k
  sorteds = map (\f -> (f, sortBy (comparing f) centers)) [fst, negate . fst, snd, negate . snd]
--  sizes :: [(Int, Int)]
  sizes = map (\cc ->
    let
     ([mbot,top,mright,left], _) =
      foldl (\(bounds, isFilteredOut) (c, (f, sorted)) ->
        case reverse . genericTake (c + 1) $ (filter (\p -> not $ isFilteredOut p) (genericTake 11 sorted)) of
          [] -> error "everything filtered out! impossiburu!"
          keeping : maybeDropping ->
            if genericLength maybeDropping /= c then error "can't be" else (f keeping : bounds, (\p -> isFilteredOut p || f p < f keeping))
        ) ([], (const False)) (zip cc sorteds)
    in
     ((- mbot) - top, (- mright) - left, (cc, (left, top), (-mright, -mbot)))
      ) counts

main = interact $ show . s . map (map read' . words) . lines