Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:  She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .  Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones.  The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type, l and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.

Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

NotePlease note that the answers to the questions may overflow 32-bit integer type.

import Data.List
import qualified Data.Map as Map

getToken :: IO String
getToken = do
	c <- getChar
	if c == '\n' || c == ' '
		then
			return []
		else do
			cs <- getToken
			return (c:cs)

nextInt :: IO Int
nextInt = do
	token <- getToken
	return (read token :: Int)

nextIntList :: IO [Int]
nextIntList = do
	list <- fmap words getLine
	return $ fmap read list

nextDouble :: IO Double
nextDouble = do
	token <- getToken
	return (read token :: Double)

nextDoubleList :: IO [Double]
nextDoubleList = do
	list <- fmap words getLine
	return $ fmap read list

main = do
	n <- nextInt
	v <- nextIntList
	m <- nextInt
	let
		v1 = scanl (+) 0 (fmap fromIntegral v) :: [Integer]
		v2 = scanl (+) 0 (fmap fromIntegral (sort v)) :: [Integer]
	let map1 = Map.fromList $ zip [0 ..] v1
	let map2 = Map.fromList $ zip [0 ..] v2
	sequence_ [ nextInt >>= \t -> nextInt >>= \l -> nextInt >>= \r ->
		if t == 1
		then
			print $ (map1 Map.! r) - (map1 Map.! (l-1))
		else
			print $ (map2 Map.! r) - (map2 Map.! (l-1)) | _ <- [1..m]]

	where
	loop 0 _ _ = return ()
	loop m map1 map2 = do
		t <- nextInt
		l <- nextInt
		r <- nextInt
		loop (m-1) map1 map2

margeSort :: (Ord a) => [a] -> [a]
margeSort [] = []
margeSort list = help xs ys
	where
	(xs,ys) = splitAt ((length list) `div` 2) list
	help xs [] = xs
	help [] ys = ys
	help xs ys = marge (margeSort xs) (margeSort ys)

supersum :: [Int] -> Integer
supersum [] = error "empty"
supersum list = sum $ (fmap fromIntegral list)

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

import Data.List
import Control.Applicative
import qualified Data.Map as Map
import qualified Data.ByteString.Char8 as BS

getToken :: IO String
getToken = do
    c <- getChar
    if c == '\n' || c == ' '
        then
            return []
        else do
            cs <- getToken
            return (c:cs)

nextInt :: IO Int
nextInt = do
    token <- getToken
    return (read token :: Int)

nextIntList :: IO [Int]
nextIntList = do
    list <- fmap words getLine
    return $ fmap read list

nextDouble :: IO Double
nextDouble = do
    token <- getToken
    return (read token :: Double)

nextDoubleList :: IO [Double]
nextDoubleList = do
    list <- fmap words getLine
    return $ fmap read list

main = do
    getLine
    v2 <- (map BS.readInt . BS.words) <$> BS.getLine
    let v = [x | (Just (x, _)) <- v2]
--    v <- nextIntList
    m <- nextInt
    let
        v1 = scanl (+) 0 (fmap fromIntegral v) :: [Integer]
        v2 = scanl (+) 0 (fmap fromIntegral (sort v)) :: [Integer]
    let map1 = Map.fromList $ zip [0 ..] v1
    let map2 = Map.fromList $ zip [0 ..] v2
    loop m map1 map2
    where
    loop 0 _ _ = return ()
    loop m map1 map2 = do
        t <- nextInt
        l <- nextInt
        r <- nextInt
        if t == 1
        then
            print $ (map1 Map.! r) - (map1 Map.! (l-1))
        else
            print $ (map2 Map.! r) - (map2 Map.! (l-1))
        loop (m-1) map1 map2

margeSort :: (Ord a) => [a] -> [a]
margeSort [] = []
margeSort list = help xs ys
    where
    (xs,ys) = splitAt ((length list) `div` 2) list
    help xs [] = xs
    help [] ys = ys
    help xs ys = marge (margeSort xs) (margeSort ys)

supersum :: [Int] -> Integer
supersum [] = error "empty"
supersum list = sum $ (fmap fromIntegral list)

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

import Data.List
import qualified Data.Map as Map

getToken :: IO String
getToken = do
	c <- getChar
	if c == '\n' || c == ' '
		then
			return []
		else do
			cs <- getToken
			return (c:cs)

nextInt :: IO Int
nextInt = do
	token <- getToken
	return (read token :: Int)

nextIntList :: IO [Int]
nextIntList = do
	list <- fmap words getLine
	return $ fmap read list

nextDouble :: IO Double
nextDouble = do
	token <- getToken
	return (read token :: Double)

nextDoubleList :: IO [Double]
nextDoubleList = do
	list <- fmap words getLine
	return $ fmap read list

main = do
	n <- nextInt
	v <- nextIntList
	m <- nextInt
	let
		v1 = scanl (+) 0 (fmap fromIntegral v) :: [Integer]
		v2 = scanl (+) 0 (fmap fromIntegral (sort v)) :: [Integer]
	let map1 = Map.fromList $ zip [0 ..] v1
	let map2 = Map.fromList $ zip [0 ..] v2
	loop m map1 map2
	where
	loop 0 _ _ = return ()
	loop m map1 map2 = do
		t <- nextInt
		l <- nextInt
		r <- nextInt
		if t == 1
		then
			print $ (map1 Map.! r) - (map1 Map.! (l-1))
		else
			print $ (map2 Map.! r) - (map2 Map.! (l-1))
		loop (m-1) map1 map2

margeSort :: (Ord a) => [a] -> [a]
margeSort [] = []
margeSort list = help xs ys
	where
	(xs,ys) = splitAt ((length list) `div` 2) list
	help xs [] = xs
	help [] ys = ys
	help xs ys = marge (margeSort xs) (margeSort ys)

supersum :: [Int] -> Integer
supersum [] = error "empty"
supersum list = sum $ (fmap fromIntegral list)

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

import Data.List
import Data.Int
import Control.Applicative
import qualified Data.Map as Map
import qualified Data.ByteString.Char8 as BS

getToken :: IO String
getToken = do
    c <- getChar
    if c == '\n' || c == ' '
        then
            return []
        else do
            cs <- getToken
            return (c:cs)

nextInt :: IO Int
nextInt = do
    token <- getToken
    return (read token :: Int)

nextIntList :: IO [Int]
nextIntList = do
    list <- fmap words getLine
    return $ fmap read list

nextDouble :: IO Double
nextDouble = do
    token <- getToken
    return (read token :: Double)

nextDoubleList :: IO [Double]
nextDoubleList = do
    list <- fmap words getLine
    return $ fmap read list

main = do
    getLine
    v2 <- (map BS.readInt . BS.words) <$> BS.getLine
    let v = [x | (Just (x, _)) <- v2]
    m <- nextInt
    let
        v1 = scanl (+) 0 (fmap fromIntegral v) :: [Int64]
        v2 = scanl (+) 0 (fmap fromIntegral (sort v)) :: [Int64]
    let map1 = Map.fromList $ zip [0 ..] v1
    let map2 = Map.fromList $ zip [0 ..] v2
    loop m map1 map2
    where
    loop 0 _ _ = return ()
    loop m map1 map2 = do
        t <- nextInt
        l <- nextInt
        r <- nextInt
        if t == 1
        then
            print $ (map1 Map.! r) - (map1 Map.! (l-1))
        else
            print $ (map2 Map.! r) - (map2 Map.! (l-1))
        loop (m-1) map1 map2

margeSort :: (Ord a) => [a] -> [a]
margeSort [] = []
margeSort list = help xs ys
    where
    (xs,ys) = splitAt ((length list) `div` 2) list
    help xs [] = xs
    help [] ys = ys
    help xs ys = marge (margeSort xs) (margeSort ys)

supersum :: [Int] -> Integer
supersum [] = error "empty"
supersum list = sum $ (fmap fromIntegral list)

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

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.ST.Safe
import Control.Monad.State
import Data.Array
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Char
import Data.Int
import Data.List
import Data.Maybe
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Tuple
import Data.Map (Map)
import qualified Data.Map as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import qualified Data.ByteString.Char8 as B
-- import Debug.Trace

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

main = do
  n <- readLn
  vs <- map fromIntegral <$> getInts :: IO [Int64]
  m <- readLn
  qs <- replicateM m getInts

  let
    a = listArray (0, n) $ scanl (+) 0 vs
    b = listArray (0, n) $ scanl (+) 0 $ sort vs

    query [1, l, r] = a!r - a!(l-1)
    query [2, l, r] = b!r - b!(l-1)

  putStrLn $ unlines $ map show $ map query qs

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

import Control.Applicative
import Control.Monad
import Control.Monad.ST.Safe
import Control.Monad.State
import Data.Array.IArray
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import Data.Char
import Data.Int
import Data.List
import Data.Maybe
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Tuple
import Data.Map (Map)
import qualified Data.Map as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import qualified Data.ByteString.Char8 as B
-- import Debug.Trace

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

main = do
  n <- readLn
  vs <- map fromIntegral <$> getInts :: IO [Int64]
  m <- readLn
  qs <- replicateM m getInts

  let
    a = listArray (0, n) $ scanl (+) 0 vs :: UArray Int Int64
    b = listArray (0, n) $ scanl (+) 0 $ sort vs :: UArray Int Int64

    query [1, l, r] = a!r - a!(l-1)
    query [2, l, r] = b!r - b!(l-1)

  putStrLn $ unlines $ map show $ map query qs

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.ST.Safe
import Control.Monad.State
import Data.Array.IArray
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import Data.Char
import Data.Int
import Data.List
import Data.Maybe
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Tuple
import Data.Map (Map)
import qualified Data.Map as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import qualified Data.ByteString.Char8 as B
-- import Debug.Trace

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

main = do
  n <- readLn
  vs <- map fromIntegral <$> getInts :: IO [Int64]
  m <- readLn
  qs <- replicateM m getInts

  let
    a = listArray (0, n) $ scanl (+) 0 vs :: UArray Int Int64
    b = listArray (0, n) $ scanl (+) 0 $ sort vs :: UArray Int Int64

    query [1, l, r] = a!r - a!(l-1)
    query [2, l, r] = b!r - b!(l-1)

  putStrLn $ unlines $ map show $ map query qs

{-# LANGUAGE BangPatterns #-}

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

import Data.Array.IO
import Data.Bits ( (.|.), (.&.) )

update arr at by = do
  (_,hi) <- getBounds arr
  let loop i | i > hi = return ()
      loop i = do v <- readArray arr i
                  writeArray arr i (v+by)
                  loop (i .|. (i+1))
  loop at

query0 arr at = do
  (lo,_) <- getBounds arr
  let loop !s i | i < lo = return s
      loop !s i = do v <- readArray arr i
                     loop (s+v) ((i .&. (i+1)) -1)
  loop 0 at

query arr i0 i1 = do
  s0 <- query0 arr (i0-1)
  s1 <- query0 arr i1
  return (s1-s0)

readInt :: IO Int
readInt = do line <- BS.getLine
             let Just (n,_) = BS.readInt line
             return n

parseInts :: Int -> ByteString -> [Int]
parseInts k bs | k <= 0 = []
parseInts k bs = case BS.readInt (BS.dropWhile isSpace bs) of
                   Nothing -> []
                   Just (n,bs') -> n : parseInts (k-1) bs'

showArray label arr = do
  putStr $ label ++ ":"
  (lo,hi) <- getBounds arr
  forM_ [lo..hi] $ \i -> do
    v <- readArray arr i
    putStr $ " " ++ show v
  putStrLn ""

main = do
  n <- fmap read getLine
  nums <- fmap (parseInts n) BS.getLine
  a1 <- newArray (0,n) 0 :: IO (IOUArray Int Int64)
  a2 <- newArray (0,n) 0 :: IO (IOUArray Int Int64)
  forM_ (zip [1..] nums) $ \(i,v) -> update a1 i (fromIntegral v)
  forM_ (zip [1..] (sort nums)) $ \(i,v) -> update a2 i (fromIntegral v)

  -- showArray "a1" a1
  -- showArray "a2" a2

  k <- fmap read getLine
  replicateM_ k $ do
    (q:a:b:_) <- fmap (parseInts 3) BS.getLine
    if q == 1
      then query a1 a b >>= print
      else query a2 a b >>= print

import Data.List
import Data.Array
import Control.Monad
main = do
  n <- readLn
  vs <- map read . words <$> getLine
  let s = listArray (0,n) $ scanl (+) 0 vs
      c = listArray (0,n) $ scanl (+) 0 (sort vs)
  m <- readLn
  replicateM_ m $ do
    [t,l,r] <- map read . words <$> getLine
    let a = [c,s] !! fromEnum (t == 1)
    print $ a!r - a!(l-1)

{-# LANGUAGE ScopedTypeVariables #-}

import Data.Array.IArray as I
import Data.List
import Control.Applicative
import Control.Monad

getSub :: Array Int Integer -> Int -> Int -> Integer
getSub arr l r = (arr I.! r) - (arr I.! (l - 1))

main = do
  n <- read <$> getLine
  stones::[Integer] <- map read . words <$> getLine
  m <- read <$> getLine
  let
    a1 = I.listArray (0, n) $ (scanl (+) 0 stones)
    a2 = I.listArray (0, n) $ (scanl (+) 0 (sort stones))
  forM_ [1..m] $ \_ -> do
    [t, l, r] <- map read . words <$> getLine
    let a = if t == 1 then a1 else a2
    print $ getSub a l r

{-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.ST.Safe
import Control.Monad.State
import Data.Array
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Char
import Data.List
import Data.Maybe
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Tuple
import Data.Map (Map)
import qualified Data.Map as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import qualified Data.ByteString.Char8 as B
-- import Debug.Trace

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

main = do
  n <- readLn
  vs <- getInts
  m <- readLn
  qs <- replicateM m getInts

  let
    a = listArray (0, n) $ scanl (+) 0 vs
    b = listArray (0, n) $ scanl (+) 0 $ sort vs

    query [1, l, r] = a!r - a!(l-1)
    query [2, l, r] = b!r - b!(l-1)

  putStrLn $ unlines $ map show $ map query qs

{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as BS
import Data.ByteString (ByteString)
import Data.Char

import Data.Array.IO
import Data.Bits ( (.|.), (.&.) )

update arr at by = do
  (_,hi) <- getBounds arr
  let loop i | i > hi = return ()
      loop i = do v <- readArray arr i
                  writeArray arr i (v+by)
                  loop (i .|. (i+1))
  loop at

query0 arr at = do
  (lo,_) <- getBounds arr
  let loop !s i | i < lo = return s
      loop !s i = do v <- readArray arr i
                     loop (s+v) ((i .&. (i+1)) -1)
  loop 0 at

query arr i0 i1 = do
  s0 <- query0 arr (i0-1)
  s1 <- query0 arr i1
  return (s1-s0)

readInt :: IO Int
readInt = do line <- BS.getLine
             let Just (n,_) = BS.readInt line
             return n

parseInts :: Int -> ByteString -> [Int]
parseInts k bs | k <= 0 = []
parseInts k bs = case BS.readInt (BS.dropWhile isSpace bs) of
                   Nothing -> []
                   Just (n,bs') -> n : parseInts (k-1) bs'

showArray label arr = do
  putStr $ label ++ ":"
  (lo,hi) <- getBounds arr
  forM_ [lo..hi] $ \i -> do
    v <- readArray arr i
    putStr $ " " ++ show v
  putStrLn ""

main = do
  n <- fmap read getLine
  nums <- fmap (parseInts n) BS.getLine
  a1 <- newArray (0,n) 0 :: IO (IOUArray Int Int)
  a2 <- newArray (0,n) 0 :: IO (IOUArray Int Int)
  forM_ (zip [1..] nums) $ \(i,v) -> update a1 i v
  forM_ (zip [1..] (sort nums)) $ \(i,v) -> update a2 i v

  -- showArray "a1" a1
  -- showArray "a2" a2

  k <- fmap read getLine
  replicateM_ k $ do
    (q:a:b:_) <- fmap (parseInts 3) BS.getLine
    if q == 1
      then query a1 a b >>= print
      else query a2 a b >>= print

import Data.List
import Control.Monad
main = do
  getLine -- n
  vs <- map read . words <$> getLine
  let s = scanl (+) 0 vs
      c = scanl (+) 0 (sort vs)
  m <- readLn
  replicateM_ m $ do
    [t,l,r] <- map read . words <$> getLine
    let a = [c,s] !! fromEnum (t == 1)
    print $ a!!l - a!!r


Given an array $$$a$$$ of length $$$n$$$, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square.A sequence $$$b$$$ is a subsequence of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deleting some (possibly zero) elements.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$1 \le a_i \le 10^4$$$) — the elements of the array $$$a$$$.

If there's a subsequence of $$$a$$$ whose product isn't a perfect square, print "YES". Otherwise, print "NO".

NoteIn the first example, the product of the whole array ($$$20$$$) isn't a perfect square.In the second example, all subsequences have a perfect square product.

parse :: String -> [[Integer]]
parse = map (map read . words) . go . tail . lines
  where
    go [] = []
    go (_:y:ys) = y : go ys

solve :: [Integer] -> Bool
solve = any (not . square)
  where
    square n = r * r == n
      where r = floor . sqrt $ fromIntegral n

format :: [Bool] -> String
format = unlines . map go
  where
    go x = if x then "YES" else "NO"

main = interact $ format . map solve . parse

parse :: String -> [[Integer]]
parse = map (map read . words) . go . tail . lines
  where
    go [] = []
    go (_:y:ys) = y : go ys

solve :: [Integer] -> Bool
solve = any (not . square)
  where
    square x = (==x) . (^ 2) . floor . sqrt $ fromIntegral x

format :: [Bool] -> String
format = unlines . map go
  where
    go True = "YES"
    go False = "NO"

main = interact $ format . map solve . parse

import qualified Data.Set as Set
import Data.List
import Control.Monad
import Data.Char

readInts = fmap (map read.words) getLine :: IO [Integer]
printArray [] = ""
printArray (x:xs) = show(x) ++" " ++ printArray xs

isntPerfectSquare::Integer->Bool
isntPerfectSquare x = (floor (sqrt (fromIntegral x)) )*(floor (sqrt (fromIntegral x))) /= x

solve = do
    n<-readLn :: IO Int
    a<-readInts
    putStrLn $ if any isntPerfectSquare a then "YES" else "NO"

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

import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Set as S

import qualified Data.Array as A

import Control.Monad.State.Strict as State
import Control.Monad.ST

import Data.Bits(xor)

import Data.Array((!))
import Control.Monad(replicateM)
import Numeric.Natural
import Data.Maybe

intNat :: Natural -> Int
intNat = fromInteger . toInteger

isPerfectSquare :: Natural -> Bool
isPerfectSquare n = aux1 $ aux2 2 (n, True) where
	aux1 (n, b) = if n > 1 then False else b

	aux2 i (n, b) | i * i > n = (n, b)
	aux2 i (n, b) = aux2 (i+1) $ n' n b where
		n' n b
			| mod n i /= 0 = (n, b)
			| mod n (i*i) == 0 = n' (div n (i*i)) b
			| otherwise = (div n i, False)

solve list = foldr (||) False $ fmap (not . isPerfectSquare) list

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

main = do
	t <- getLine >>= return . read :: IO Int
	replicateM t $ do
		[n] <- getLine >>= return . (fmap read) . words :: IO [Natural]
		a <- getLine >>= return . (fmap read) . words :: IO [Natural]
		putStrLn $ showR $ solve a


You are given the following concurrent program. There are N processes and the i-th process has the following pseudocode: repeat ni times    yi := y    y := yi + 1end repeatHere y is a shared variable. Everything else is local for the process. All actions on a given row are atomic, i.e. when the process starts executing a row it is never interrupted. Beyond that all interleavings are possible, i.e. every process that has yet work to do can be granted the rights to execute its next row. In the beginning y = 0. You will be given an integer W and ni, for i = 1, ... , N. Determine if it is possible that after all processes terminate, y = W, and if it is possible output an arbitrary schedule that will produce this final value.

In the first line of the input you will be given two space separated integers N (1 ≤ N ≤ 100) and W ( - 109 ≤ W ≤ 109). In the second line there are N space separated integers ni (1 ≤ ni ≤ 1000).

On the first line of the output write Yes if it is possible that at the end y = W, or No otherwise. If the answer is No then there is no second line, but if the answer is Yes, then on the second line output a space separated list of integers representing some schedule that leads to the desired result. For more information see note.

NoteFor simplicity, assume that there is no repeat statement in the code of the processes, but the code from the loop is written the correct amount of times. The processes are numbered starting from 1. The list of integers represent which process works on its next instruction at a given step. For example, consider the schedule 1 2 2 1 3. First process 1 executes its first instruction, then process 2 executes its first two instructions, after that process 1 executes its second instruction, and finally process 3 executes its first instruction. The list must consists of exactly 2·Σ i = 1...N ni numbers.

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc = multiH ms ns (replicate (m*2) (n+1):acc)

multi :: Int -> Int -> [Int] -> [Int]
multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate (2*w) 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            [1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2]
        | w2 >  2 =
            let
                findli _ n3 2   []        z1 z2  _     acc = (reverse acc)++multi2 n3 2 [z1,z2] []
                findli _ n3 w3  []        z1 z2  _     acc
                    | z1  >  0 = findli  0    n3 (w3-1)   []          (z1-1) z2    [] (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      []           0     z2    []  acc
                    | z2  >  0 = findli  1    n3 (w3-1)   []           z1   (z2-1) [] (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      []           z1    0     []  acc
                findli _ n3 2   nnls      z1 z2 (i:is) acc = (reverse acc)++multi2 n3 2 (z1:z2:nnls) (i:is)
                findli 0 n3 w3  nnls      z1 z2 (i:is) acc
                    | z1  >  0 = findli  0    n3 (w3-1)   nnls         (z1-1) z2    (i:is)  (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      nnls          0     z2    (i:is)   acc
                findli 1 n3 w3  nnls      z1 z2 (i:is) acc
                    | z2  >  0 = findli  1    n3 (w3-1)   nnls          z1   (z2-1) (i:is)  (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      nnls          z1    0     (i:is)   acc
                findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                    | j   == n3 = (reverse acc)++multi2 n3 2 (z1:z2:nnl:nnls) (i:is)
                    | nnl >  0 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1    z2    (i:is) ((i+1):(i+1):acc)
                    | nnl == 0 = findli (j+1) n3  w3      nnls          z1    z2     is      acc

            in
                findli 0 n2 w2 nls nl1 nl2 [2..(n2-1)] []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc = multiH ms ns (replicate (m*2) (n+1):acc)

multi :: Int -> Int -> [Int] -> [Int]

multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate (2*w) 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            [1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2]
        | w2 >  2 =
            let
                findli _ n3 2   []        z1 z2  _     acc = (reverse acc)++multi2 n3 2 [z1,z2] []
                findli _ n3 w3  []        z1 z2  _     acc
                    | z1  >  0 = findli  0    n3 (w3-1)   []      (z1-1) z2    [] (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      []       0     z2    []  acc
                    | z2  >  0 = findli  1    n3 (w3-1)   []       z1   (z2-1) [] (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      []       z1    0     []  acc
                findli _ n3 2   nnls      z1 z2 (i:is) acc = (reverse acc)++multi2 n3 2 (z1:z2:nnls) (i:is)
                findli 0 n3 w3  nnls      z1 z2 (i:is) acc
                    | z1  >  0 = findli  0    n3 (w3-1)   nnls         (z1-1) z2    (i:is)  (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      nnls          0     z2    (i:is)   acc
                findli 1 n3 w3  nnls      z1 z2 (i:is) acc
                    | z2  >  0 = findli  1    n3 (w3-1)   nnls          z1   (z2-1) (i:is)  (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      nnls          z1    0     (i:is)   acc
                findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                    | j   == n3 = (reverse acc)++multi2 n3 2 (z1:z2:nnl:nnls) (i:is)
                    | nnl >  0 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1    z2    (i:is) ((i+1):(i+1):acc)
                    | nnl == 0 = findli (j+1) n3  w3      nnls          z1    z2     is      acc

            in
                findli 0 n2 w2 nls nl1 nl2 [2..(n2-1)] []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Irene Vlassi-Pandi (03108137)       -}
{-              ex1-plII-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

{- algorithm by:                              -}
{- http://codeforces.com/blog/entry/610       -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc = multiH ms ns (replicate (2*m) (n+1):acc)

multi :: Int -> Int -> [Int] -> [Int]
multi n w ls
    | 1 > w || w > sum ls = []

multi 1 w [l]
    | l == w =
        replicate (2*w) 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   (j+1):multiH (delete 1 ls) (delete j inds) []++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            1:multiH [nl2] [1] []++multiH nls inds []++[1]++[2]++multiH [nl1] [0] []++[2]
        | w2 >  2 =
            let
                findli _ n3 2   []        z1 z2  _     acc = reverse acc++multi2 n3 2 [z1,z2] []
                findli _ n3 w3  []        z1 z2  _     acc
                    | z1  >  0 = findli  0    n3 (w3-1)   []          (z1-1) z2    [] (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      []           0     z2    []  acc
                    | z2  >  0 = findli  1    n3 (w3-1)   []           z1   (z2-1) [] (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      []           z1    0     []  acc
                findli _ n3 2   nnls      z1 z2 (i:is) acc = reverse acc++multi2 n3 2 (z1:z2:nnls) (i:is)
                findli 0 n3 w3  nnls      z1 z2 (i:is) acc
                    | z1  >  0 = findli  0    n3 (w3-1)   nnls         (z1-1) z2    (i:is)  (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      nnls          0     z2    (i:is)   acc
                findli 1 n3 w3  nnls      z1 z2 (i:is) acc
                    | z2  >  0 = findli  1    n3 (w3-1)   nnls          z1   (z2-1) (i:is)  (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      nnls          z1    0     (i:is)   acc
                findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                    | j   == n3 = reverse acc++multi2 n3 2 (z1:z2:nnl:nnls) (i:is)
                    | nnl >  0 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1    z2    (i:is) ((i+1):(i+1):acc)
                    | nnl == 0 = findli (j+1) n3  w3      nnls          z1    z2     is      acc

            in
                findli 0 n2 w2 nls nl1 nl2 [2..(n2-1)] []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc
    | m/= 0 = multiH ms ns (replicate (m*2) (n+1):acc)
    | otherwise = []

multi :: Int -> Int -> [Int] -> [Int]

multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate (2*w) 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            [1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2]
        | w2 >  2 =
            let
                findli _ n3 2   []        z1 z2  _     acc = (reverse acc)++multi2 n3 2 [z1,z2] []
                findli _ n3 w3  []        z1 z2  _     acc
                    | z1  >  0 = findli  0    n3 (w3-1)   []      (z1-1) z2    [] (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      []       0     z2    []  acc
                    | z2  >  0 = findli  1    n3 (w3-1)   []       z1   (z2-1) [] (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      []       z1    0     []  acc
                findli _ n3 2   nnls      z1 z2 (i:is) acc = (reverse acc)++multi2 n3 2 (z1:z2:nnls) (i:is)
                findli 0 n3 w3  nnls      z1 z2 (i:is) acc
                    | z1  >  0 = findli  0    n3 (w3-1)   nnls         (z1-1) z2    (i:is)  (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      nnls          0     z2    (i:is)   acc
                findli 1 n3 w3  nnls      z1 z2 (i:is) acc
                    | z2  >  0 = findli  1    n3 (w3-1)   nnls          z1   (z2-1) (i:is)  (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      nnls          z1    0     (i:is)   acc
                findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                    | j   == n3 = (reverse acc)++multi2 n3 2 (z1:z2:nnl:nnls) (i:is)
                    | nnl >  0 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1    z2    (i:is) ((i+1):(i+1):acc)
                    | nnl == 0 = findli (j+1) n3  w3      nnls          z1    z2     is      acc

            in
                findli 0 n2 w2 nls nl1 nl2 [2..(n2-1)] []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

{-
multi n w (l1:l2:ls)
    | n >= 2 =
            let
                multi2 n2 w2 (nl1:nl2:nls) inds
                    | w2 == 2 =
                        ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
                    | w2 >  2 =
                        let
                            findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                                -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++(i:is)++[w3]++[j]
                                | j == n3 || w3  == 2 = [42]++(reverse acc)++[32]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                                -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                                | z1  >  0 && w3 > 2 && j == 0  =[j]++ findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2   (i:is) (1:1:acc)
                                | z1  == 0 && w3 > 2 && j == 0  = [j]++findli  1    n3  w3      nnls        0    z2    is     acc
                                | z2  >  0 && w3 > 2 && j == 1  = [j]++findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (i:is) (2:2:acc)
                                | z2  == 0 && w3 > 2 && j == 1  = [j]++findli  2    n3  w3    nnls        z1   0     is     acc
                                | nnl >  0 && w3 > 2 && j /=0 && j /=1  =[j]++ findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2   (i:is) ((i+1):(i+1):acc)
                                | nnl == 0 && w3 > 2 && j /=0 && j/=1  = [j]++findli (j+1) n3  w3      nnls        z1   z2    is     acc
                        in
                            findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 [0..(n2-1)] []
             in
                multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]
     | otherwise = []

-}

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-          Irene Vlassi-Pandi (03108137)     -}
{-              ex1-plII-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

{- υλοποίηση αλγορίθμου από:
 - http://codeforces.com/blog/entry/610       -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc = multiH ms ns (replicate (2*m) (n+1):acc)

multi :: Int -> Int -> [Int] -> [Int]
multi n w ls
    | 1 > w || w > sum ls = []

multi 1 w [l]
    | l == w =
        replicate (2*w) 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++multiH (delete 1 ls) (delete j inds) []++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            [1]++multiH [nl2] [1] []++multiH nls inds []++[1]++[2]++multiH [nl1] [0] []++[2]
        | w2 >  2 =
            let
                findli _ n3 2   []        z1 z2  _     acc = reverse acc++multi2 n3 2 [z1,z2] []
                findli _ n3 w3  []        z1 z2  _     acc
                    | z1  >  0 = findli  0    n3 (w3-1)   []          (z1-1) z2    [] (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      []           0     z2    []  acc
                    | z2  >  0 = findli  1    n3 (w3-1)   []           z1   (z2-1) [] (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      []           z1    0     []  acc
                findli _ n3 2   nnls      z1 z2 (i:is) acc = reverse acc++multi2 n3 2 (z1:z2:nnls) (i:is)
                findli 0 n3 w3  nnls      z1 z2 (i:is) acc
                    | z1  >  0 = findli  0    n3 (w3-1)   nnls         (z1-1) z2    (i:is)  (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      nnls          0     z2    (i:is)   acc
                findli 1 n3 w3  nnls      z1 z2 (i:is) acc
                    | z2  >  0 = findli  1    n3 (w3-1)   nnls          z1   (z2-1) (i:is)  (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      nnls          z1    0     (i:is)   acc
                findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                    | j   == n3 = reverse acc++multi2 n3 2 (z1:z2:nnl:nnls) (i:is)
                    | nnl >  0 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1    z2    (i:is) ((i+1):(i+1):acc)
                    | nnl == 0 = findli (j+1) n3  w3      nnls          z1    z2     is      acc

            in
                findli 0 n2 w2 nls nl1 nl2 [2..(n2-1)] []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-          Irene Vlassi-Pandi (03108137)     -}
{-              ex1-plII-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

{- υλοποίηση αλγορίθμου από:
 - http://codeforces.com/blog/entry/610       -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc = multiH ms ns (replicate (2*m) (n+1):acc)

multi :: Int -> Int -> [Int] -> [Int]
multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate (2*w) 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            [1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2]
        | w2 >  2 =
            let
                findli _ n3 2   []        z1 z2  _     acc = (reverse acc)++multi2 n3 2 [z1,z2] []
                findli _ n3 w3  []        z1 z2  _     acc
                    | z1  >  0 = findli  0    n3 (w3-1)   []          (z1-1) z2    [] (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      []           0     z2    []  acc
                    | z2  >  0 = findli  1    n3 (w3-1)   []           z1   (z2-1) [] (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      []           z1    0     []  acc
                findli _ n3 2   nnls      z1 z2 (i:is) acc = (reverse acc)++multi2 n3 2 (z1:z2:nnls) (i:is)
                findli 0 n3 w3  nnls      z1 z2 (i:is) acc
                    | z1  >  0 = findli  0    n3 (w3-1)   nnls         (z1-1) z2    (i:is)  (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      nnls          0     z2    (i:is)   acc
                findli 1 n3 w3  nnls      z1 z2 (i:is) acc
                    | z2  >  0 = findli  1    n3 (w3-1)   nnls          z1   (z2-1) (i:is)  (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      nnls          z1    0     (i:is)   acc
                findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                    | j   == n3 = (reverse acc)++multi2 n3 2 (z1:z2:nnl:nnls) (i:is)
                    | nnl >  0 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1    z2    (i:is) ((i+1):(i+1):acc)
                    | nnl == 0 = findli (j+1) n3  w3      nnls          z1    z2     is      acc

            in
                findli 0 n2 w2 nls nl1 nl2 [2..(n2-1)] []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc
    | m/= 0 = multiH ms ns (replicate (m*2) (n+1):acc)
    | otherwise = []

multi :: Int -> Int -> [Int] -> [Int]

multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate w 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
        | w2 >  2 =
            let
                findli j n3 w3 (nnl:nnls) z1 z2 acc
                --    | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++[w3]++[j]
                    | j == n3 || w3  == 2 = (reverse acc)++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                    -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                    | z1  >  0 && w3 > 2 && j == 0  = findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2 (1:1:acc)
                    | z1  == 0 && w3 > 2 && j == 0  = findli  1    n3  w3      nnls        0    z2      acc
                    | z2  >  0 && w3 > 2 && j == 1  = findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (2:2:acc)
                    | z2  == 0 && w3 > 2 && j == 1  = findli  2    n3  w3    nnls        z1   0          acc
                    | nnl >  0 && w3 > 2 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2  ((j+1):(j+1):acc)
                    | nnl == 0 && w3 > 2 = findli (j+1) n3  w3      nnls        z1   z2    acc
            in
                findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

{-
multi n w (l1:l2:ls)
    | n >= 2 =
            let
                multi2 n2 w2 (nl1:nl2:nls) inds
                    | w2 == 2 =
                        ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
                    | w2 >  2 =
                        let
                            findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                                -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++(i:is)++[w3]++[j]
                                | j == n3 || w3  == 2 = [42]++(reverse acc)++[32]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                                -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                                | z1  >  0 && w3 > 2 && j == 0  =[j]++ findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2   (i:is) (1:1:acc)
                                | z1  == 0 && w3 > 2 && j == 0  = [j]++findli  1    n3  w3      nnls        0    z2    is     acc
                                | z2  >  0 && w3 > 2 && j == 1  = [j]++findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (i:is) (2:2:acc)
                                | z2  == 0 && w3 > 2 && j == 1  = [j]++findli  2    n3  w3    nnls        z1   0     is     acc
                                | nnl >  0 && w3 > 2 && j /=0 && j /=1  =[j]++ findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2   (i:is) ((i+1):(i+1):acc)
                                | nnl == 0 && w3 > 2 && j /=0 && j/=1  = [j]++findli (j+1) n3  w3      nnls        z1   z2    is     acc
                        in
                            findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 [0..(n2-1)] []
             in
                multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]
     | otherwise = []

-}

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc
    | m/= 0 = multiH ms ns (replicate (m*2) (n+1):acc)
    | otherwise = []

multi :: Int -> Int -> [Int] -> [Int]

multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate w 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
        | w2 >  2 =
            let
                findli j n3 w3 (nnl:nnls) z1 z2 acc
                --    | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++[w3]++[j]
                    | j == n3 || w3  == 2 = (reverse acc)++[42]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                    -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                    | z1  >  0 && w3 > 2 && j == 0  = findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2 (1:1:acc)
                    | z1  == 0 && w3 > 2 && j == 0  = findli  1    n3  w3      nnls        0    z2      acc
                    | z2  >  0 && w3 > 2 && j == 1  = findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (2:2:acc)
                    | z2  == 0 && w3 > 2 && j == 1  = findli  2    n3  w3    nnls        z1   0          acc
                    | nnl >  0 && w3 > 2 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2  ((j+1):(j+1):acc)
                    | nnl == 0 && w3 > 2 = findli (j+1) n3  w3      nnls        z1   z2    acc
            in
                findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

{-
multi n w (l1:l2:ls)
    | n >= 2 =
            let
                multi2 n2 w2 (nl1:nl2:nls) inds
                    | w2 == 2 =
                        ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
                    | w2 >  2 =
                        let
                            findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                                -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++(i:is)++[w3]++[j]
                                | j == n3 || w3  == 2 = [42]++(reverse acc)++[32]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                                -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                                | z1  >  0 && w3 > 2 && j == 0  =[j]++ findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2   (i:is) (1:1:acc)
                                | z1  == 0 && w3 > 2 && j == 0  = [j]++findli  1    n3  w3      nnls        0    z2    is     acc
                                | z2  >  0 && w3 > 2 && j == 1  = [j]++findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (i:is) (2:2:acc)
                                | z2  == 0 && w3 > 2 && j == 1  = [j]++findli  2    n3  w3    nnls        z1   0     is     acc
                                | nnl >  0 && w3 > 2 && j /=0 && j /=1  =[j]++ findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2   (i:is) ((i+1):(i+1):acc)
                                | nnl == 0 && w3 > 2 && j /=0 && j/=1  = [j]++findli (j+1) n3  w3      nnls        z1   z2    is     acc
                        in
                            findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 [0..(n2-1)] []
             in
                multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]
     | otherwise = []

-}

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc
    | m/= 0 = multiH ms ns (replicate (m*2) (n+1):acc)
    | otherwise = []

multi :: Int -> Int -> [Int] -> [Int]

multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate (2*w) 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
        | w2 >  2 =
            let
                findli _ n3 _   []        z1 z2  _     _   = multi2 n3 2 [z1,z2] [0,1]
                findli _ n3 2   nnls      z1 z2 (i:is) acc = (reverse acc)++multi2 n3 2 (z1:z2:nnls) (i:is)
                findli 0 n3 w3 nnls z1 z2 (i:is) acc
                    | z1  >  0 = findli  0    n3 (w3-1)   nnls         (z1-1) z2    (i:is)  (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      nnls          0     z2    (i:is)   acc
                findli 1 n3 w3 nnls z1 z2 (i:is) acc
                    | z2  >  0 = findli  1    n3 (w3-1)   nnls          z1   (z2-1) (i:is)  (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      nnls          z1    0     (i:is)   acc
                findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                    | j == n3 = (reverse acc)++multi2 n3 2 (z1:z2:nnl:nnls) (0:1:i:is)
                    | nnl >  0 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1    z2    (i:is) ((i+1):(i+1):acc)
                    | nnl == 0 = findli (j+1) n3  w3      nnls          z1    z2     is      acc
    -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++[w3]++[j]
                    -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)

            in
                findli 0 n2 w2 nls nl1 nl2 [2..(n2-1)] []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

{-
multi n w (l1:l2:ls)
    | n >= 2 =
            let
                multi2 n2 w2 (nl1:nl2:nls) inds
                    | w2 == 2 =
                        ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
                    | w2 >  2 =
                        let
                            findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                                -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++(i:is)++[w3]++[j]
                                | j == n3 || w3  == 2 = [42]++(reverse acc)++[32]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                                -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                                | z1  >  0 && w3 > 2 && j == 0  =[j]++ findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2   (i:is) (1:1:acc)
                                | z1  == 0 && w3 > 2 && j == 0  = [j]++findli  1    n3  w3      nnls        0    z2    is     acc
                                | z2  >  0 && w3 > 2 && j == 1  = [j]++findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (i:is) (2:2:acc)
                                | z2  == 0 && w3 > 2 && j == 1  = [j]++findli  2    n3  w3    nnls        z1   0     is     acc
                                | nnl >  0 && w3 > 2 && j /=0 && j /=1  =[j]++ findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2   (i:is) ((i+1):(i+1):acc)
                                | nnl == 0 && w3 > 2 && j /=0 && j/=1  = [j]++findli (j+1) n3  w3      nnls        z1   z2    is     acc
                        in
                            findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 [0..(n2-1)] []
             in
                multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]
     | otherwise = []

-}

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc
    | m/= 0 = multiH ms ns (replicate (m*2) (n+1):acc)
    | otherwise = []

multi :: Int -> Int -> [Int] -> [Int]

multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate (2*w) 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
        | w2 >  2 =
            let
                findli j n3 w3 (nnl:nnls) z1 z2 acc
                --    | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++[w3]++[j]
                    | j == n3 || w3  == 2 = (reverse acc)++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                    -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                    | z1  >  0 && w3 > 2 && j == 0  = findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2 (1:1:acc)
                    | z1  == 0 && w3 > 2 && j == 0  = findli  1    n3  w3      nnls        0    z2      acc
                    | z2  >  0 && w3 > 2 && j == 1  = findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (2:2:acc)
                    | z2  == 0 && w3 > 2 && j == 1  = findli  2    n3  w3    nnls        z1   0          acc
                    | nnl >  0 && w3 > 2 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2  ((j+1):(j+1):acc)
                    | nnl == 0 && w3 > 2 = findli (j+1) n3  w3      nnls        z1   z2    acc
            in
                findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

{-
multi n w (l1:l2:ls)
    | n >= 2 =
            let
                multi2 n2 w2 (nl1:nl2:nls) inds
                    | w2 == 2 =
                        ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
                    | w2 >  2 =
                        let
                            findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                                -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++(i:is)++[w3]++[j]
                                | j == n3 || w3  == 2 = [42]++(reverse acc)++[32]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                                -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                                | z1  >  0 && w3 > 2 && j == 0  =[j]++ findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2   (i:is) (1:1:acc)
                                | z1  == 0 && w3 > 2 && j == 0  = [j]++findli  1    n3  w3      nnls        0    z2    is     acc
                                | z2  >  0 && w3 > 2 && j == 1  = [j]++findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (i:is) (2:2:acc)
                                | z2  == 0 && w3 > 2 && j == 1  = [j]++findli  2    n3  w3    nnls        z1   0     is     acc
                                | nnl >  0 && w3 > 2 && j /=0 && j /=1  =[j]++ findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2   (i:is) ((i+1):(i+1):acc)
                                | nnl == 0 && w3 > 2 && j /=0 && j/=1  = [j]++findli (j+1) n3  w3      nnls        z1   z2    is     acc
                        in
                            findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 [0..(n2-1)] []
             in
                multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]
     | otherwise = []

-}

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc
    | m/= 0 = multiH ms ns (replicate (m*2) (n+1):acc)
    | otherwise = []

multi :: Int -> Int -> [Int] -> [Int]

multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate (2*w) 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
        | w2 >  2 =
            let
                findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                --    | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++[w3]++[j]
                    | j == n3 || w3  == 2 = (reverse acc)++multi2 n3 2 (z1:z2:(nnl:nnls)) (i:is)
                    -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                    | z1  >  0 && w3 > 2 && j == 0  = findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2    (i:is)  (1:1:acc)
                    | z1  == 0 && w3 > 2 && j == 0  = findli  1    n3  w3      nnls          0     z2     is      acc
                    | z2  >  0 && w3 > 2 && j == 1  = findli  1    n3 (w3-1) ((nnl-1):nnls)  z1   (z2-1) (i:is)  (2:2:acc)
                    | z2  == 0 && w3 > 2 && j == 1  = findli  2    n3  w3      nnls          z1    0      is      acc
                    | nnl >  0 && w3 > 2            = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1    z2    (i:is) ((i+1):(i+1):acc)
                    | nnl == 0 && w3 > 2            = findli (j+1) n3  w3      nnls          z1    z2     is      acc
            in
                findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 [0..(n2-1)] []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

{-
multi n w (l1:l2:ls)
    | n >= 2 =
            let
                multi2 n2 w2 (nl1:nl2:nls) inds
                    | w2 == 2 =
                        ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
                    | w2 >  2 =
                        let
                            findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                                -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++(i:is)++[w3]++[j]
                                | j == n3 || w3  == 2 = [42]++(reverse acc)++[32]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                                -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                                | z1  >  0 && w3 > 2 && j == 0  =[j]++ findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2   (i:is) (1:1:acc)
                                | z1  == 0 && w3 > 2 && j == 0  = [j]++findli  1    n3  w3      nnls        0    z2    is     acc
                                | z2  >  0 && w3 > 2 && j == 1  = [j]++findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (i:is) (2:2:acc)
                                | z2  == 0 && w3 > 2 && j == 1  = [j]++findli  2    n3  w3    nnls        z1   0     is     acc
                                | nnl >  0 && w3 > 2 && j /=0 && j /=1  =[j]++ findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2   (i:is) ((i+1):(i+1):acc)
                                | nnl == 0 && w3 > 2 && j /=0 && j/=1  = [j]++findli (j+1) n3  w3      nnls        z1   z2    is     acc
                        in
                            findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 [0..(n2-1)] []
             in
                multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]
     | otherwise = []

-}

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc
    | m/= 0 = multiH ms ns (replicate (m*2) (n+1):acc)
    | otherwise = []

multi :: Int -> Int -> [Int] -> [Int]

multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate (2*w) 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
        | w2 >  2 =
            let
                findli _ n3 _   []        z1 z2  _     _   = multi2 n3 2 [z1,z2] [0,1]
                findli j n3 2   nnls      z1 z2 (i:is) acc = (reverse acc)++multi2 n3 2 (z1:z2:nnls) (0:1:i:is)
                findli 0 n3 w3 nnls z1 z2 (i:is) acc
                    | z1  >  0 = findli  0    n3 (w3-1)   nnls         (z1-1) z2    (i:is)  (1:1:acc)
                    | z1  == 0 = findli  1    n3  w3      nnls          0     z2    (i:is)   acc
                findli 1 n3 w3 nnls z1 z2 (i:is) acc
                    | z2  >  0 = findli  1    n3 (w3-1)   nnls          z1   (z2-1) (i:is)  (2:2:acc)
                    | z2  == 0 = findli  2    n3  w3      nnls          z1    0     (i:is)   acc
                findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                    | j == n3 = (reverse acc)++multi2 n3 2 (z1:z2:nnl:nnls) (0:1:i:is)
                    | nnl >  0 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1    z2    (i:is) ((i+1):(i+1):acc)
                    | nnl == 0 = findli (j+1) n3  w3      nnls          z1    z2     is      acc
    -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++[w3]++[j]
                    -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)

            in
                findli 0 n2 w2 nls nl1 nl2 [2..(n2-1)] []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

{-
multi n w (l1:l2:ls)
    | n >= 2 =
            let
                multi2 n2 w2 (nl1:nl2:nls) inds
                    | w2 == 2 =
                        ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
                    | w2 >  2 =
                        let
                            findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                                -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++(i:is)++[w3]++[j]
                                | j == n3 || w3  == 2 = [42]++(reverse acc)++[32]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                                -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                                | z1  >  0 && w3 > 2 && j == 0  =[j]++ findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2   (i:is) (1:1:acc)
                                | z1  == 0 && w3 > 2 && j == 0  = [j]++findli  1    n3  w3      nnls        0    z2    is     acc
                                | z2  >  0 && w3 > 2 && j == 1  = [j]++findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (i:is) (2:2:acc)
                                | z2  == 0 && w3 > 2 && j == 1  = [j]++findli  2    n3  w3    nnls        z1   0     is     acc
                                | nnl >  0 && w3 > 2 && j /=0 && j /=1  =[j]++ findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2   (i:is) ((i+1):(i+1):acc)
                                | nnl == 0 && w3 > 2 && j /=0 && j/=1  = [j]++findli (j+1) n3  w3      nnls        z1   z2    is     acc
                        in
                            findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 [0..(n2-1)] []
             in
                multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]
     | otherwise = []

-}

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc
    | m/= 0 = multiH ms ns (replicate (m*2) (n+1):acc)
    | otherwise = []

multi :: Int -> Int -> [Int] -> [Int]

--prosoxh ta arnhtika opws ta diavazw na vazo parentheseis
multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate w 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++(multiH (delete 1 ls) (delete (j+1) inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
        | w2 >  2 =
            let
                findli j n3 w3 (nnl:nnls) z1 z2 acc
                    -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++(i:is)++[w3]++[j]
                    | j == n3 || w3  == 2 = (reverse acc)++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                    -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                    | z1  >  0 && w3 > 2 && j == 0  = findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2 (1:1:acc)
                    | z1  == 0 && w3 > 2 && j == 0  = findli  1    n3  w3      nnls        0    z2      acc
                    | z2  >  0 && w3 > 2 && j == 1  = findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (2:2:acc)
                    | z2  == 0 && w3 > 2 && j == 1  = findli  2    n3  w3    nnls        z1   0          acc
                    | nnl >  0 && w3 > 2 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2  ((j+1):(j+1):acc)
                    | nnl == 0 && w3 > 2 = findli (j+1) n3  w3      nnls        z1   z2    acc
            in
                findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

{-
multi n w (l1:l2:ls)
    | n >= 2 =
            let
                multi2 n2 w2 (nl1:nl2:nls) inds
                    | w2 == 2 =
                        ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
                    | w2 >  2 =
                        let
                            findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                                -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++(i:is)++[w3]++[j]
                                | j == n3 || w3  == 2 = [42]++(reverse acc)++[32]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                                -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                                | z1  >  0 && w3 > 2 && j == 0  =[j]++ findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2   (i:is) (1:1:acc)
                                | z1  == 0 && w3 > 2 && j == 0  = [j]++findli  1    n3  w3      nnls        0    z2    is     acc
                                | z2  >  0 && w3 > 2 && j == 1  = [j]++findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (i:is) (2:2:acc)
                                | z2  == 0 && w3 > 2 && j == 1  = [j]++findli  2    n3  w3    nnls        z1   0     is     acc
                                | nnl >  0 && w3 > 2 && j /=0 && j /=1  =[j]++ findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2   (i:is) ((i+1):(i+1):acc)
                                | nnl == 0 && w3 > 2 && j /=0 && j/=1  = [j]++findli (j+1) n3  w3      nnls        z1   z2    is     acc
                        in
                            findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 [0..(n2-1)] []
             in
                multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]
     | otherwise = []

-}

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls

{-        Vlassi-Pandi Irini (03108137)       -}
{-               ex1-pl2-2012                 -}
{- http://codeforces.com/contest/26/problem/E -}

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

multiH :: [Int] -> [Int] -> [[Int]] -> [Int]
multiH  [ ]     _     acc = reverse (concat acc)
multiH   _     [ ]    acc = reverse (concat acc)
multiH (m:ms) (n:ns)  acc
    | m/= 0 = multiH ms ns (replicate (m*2) (n+1):acc)
    | otherwise = []

multi :: Int -> Int -> [Int] -> [Int]

--prosoxh ta arnhtika opws ta diavazw na vazo parentheseis
multi n w ls
    | 1 > w || w > (sum ls) = []

multi 1 w [l]
    | l == w =
        replicate w 1
    | otherwise = []

multi n 1 ls
    | n >= 2 =
        let
            js   = findIndices (==1)    ls
            inds = findIndices (/=(-1)) ls
        in
           if (js /= [])
           then
               let
                   j = head js
               in
                   [j+1]++[42]++(multiH (delete 1 ls) (delete j inds) [])++[j+1]
           else []

multi n w (l1:l2:ls) =
    let
       multi2 n2 w2 (nl1:nl2:nls) inds
        | w2 == 2 =
            ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
        | w2 >  2 =
            let
                findli j n3 w3 (nnl:nnls) z1 z2 acc
                --    | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++[w3]++[j]
                    | j == n3 || w3  == 2 = (reverse acc)++[42]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                    -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                    | z1  >  0 && w3 > 2 && j == 0  = findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2 (1:1:acc)
                    | z1  == 0 && w3 > 2 && j == 0  = findli  1    n3  w3      nnls        0    z2      acc
                    | z2  >  0 && w3 > 2 && j == 1  = findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (2:2:acc)
                    | z2  == 0 && w3 > 2 && j == 1  = findli  2    n3  w3    nnls        z1   0          acc
                    | nnl >  0 && w3 > 2 = findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2  ((j+1):(j+1):acc)
                    | nnl == 0 && w3 > 2 = findli (j+1) n3  w3      nnls        z1   z2    acc
            in
                findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 []
    in
       multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]

{-
multi n w (l1:l2:ls)
    | n >= 2 =
            let
                multi2 n2 w2 (nl1:nl2:nls) inds
                    | w2 == 2 =
                        ([1]++(multiH [nl2] [1] [])++(multiH nls inds [])++[1]++[2]++(multiH [nl1] [0] [])++[2])
                    | w2 >  2 =
                        let
                            findli j n3 w3 (nnl:nnls) z1 z2 (i:is) acc
                                -- | otherwise = (reverse acc)++[z1]++[z2]++[nnl]++nnls++(i:is)++[w3]++[j]
                                | j == n3 || w3  == 2 = [42]++(reverse acc)++[32]++multi2 n3 2 (z1:z2:(nnl:nnls)) [2..(n3-1)]
                                -- | n == 1 || w == 2 = (reverse acc)++multi2 (n+1) w  (l:ls)   (i:is)
                                | z1  >  0 && w3 > 2 && j == 0  =[j]++ findli  0    n3 (w3-1) ((nnl-1):nnls) (z1-1) z2   (i:is) (1:1:acc)
                                | z1  == 0 && w3 > 2 && j == 0  = [j]++findli  1    n3  w3      nnls        0    z2    is     acc
                                | z2  >  0 && w3 > 2 && j == 1  = [j]++findli  1    n3 (w3-1) ((nnl-1):nnls)  z1  (z2-1) (i:is) (2:2:acc)
                                | z2  == 0 && w3 > 2 && j == 1  = [j]++findli  2    n3  w3    nnls        z1   0     is     acc
                                | nnl >  0 && w3 > 2 && j /=0 && j /=1  =[j]++ findli  j    n3 (w3-1) ((nnl-1):nnls)  z1   z2   (i:is) ((i+1):(i+1):acc)
                                | nnl == 0 && w3 > 2 && j /=0 && j/=1  = [j]++findli (j+1) n3  w3      nnls        z1   z2    is     acc
                        in
                            findli 0 n2 w2 (nl1:nl2:nls) nl1 nl2 [0..(n2-1)] []
             in
                multi2 n w ((l1-1):(l2-1):ls) [2..(n-1)]
     | otherwise = []

-}

main =
  do all <- BS.getContents
     let Just (n, r1) = readInt all
     let Just (w, r2) = readInt r1
     let (x, _)  = readMany readInt r2
     let answer = (multi n w x)
     print_yesno answer
     printList answer
  where readInt s = BSC.readInt (BSC.dropWhile isSpace s)
        readMany readf s = case readf s of
          Just (x, r) -> let (xs, t) = readMany readf r
                         in  (x : xs, t)
          Nothing     -> ([], s)
        print_yesno [] = putStrLn "No"
        print_yesno _  = putStrLn "Yes"
        printList []     = putStrLn""
        printList (l:[]) =
          do
              putStrLn (show l)
        printList (l:ls) =
          do
              putStr (show l++ " ")
              printList ls


Let's call a positive integer composite if it has at least one divisor other than $$$1$$$ and itself. For example:  the following numbers are composite: $$$1024$$$, $$$4$$$, $$$6$$$, $$$9$$$;  the following numbers are not composite: $$$13$$$, $$$1$$$, $$$2$$$, $$$3$$$, $$$37$$$. You are given a positive integer $$$n$$$. Find two composite integers $$$a,b$$$ such that $$$a-b=n$$$.It can be proven that solution always exists.

The input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^7$$$): the given integer.

Print two composite integers $$$a,b$$$ ($$$2 \leq a, b \leq 10^9, a-b=n$$$). It can be proven, that solution always exists. If there are several possible solutions, you can print any.

module Main where

import Control.Monad
import Data.List

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

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

main :: IO ()
main = do
    n <- readLn
    putStrLn $ (show (n * 9) ++ " " ++ show (n * 8))

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

main = getLine >>= putStrLn.unwords.map show.(\n -> [9 * n, 8 * n]).read

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

main :: IO ()
main = do
  line <- getLine
  let [n] = convert line :: [Int]
  if n == 1
  then putStrLn "9 8"
  else putStrLn $ (show $ 3 * n) ++ " " ++ (show $ 2 * n)

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

process n | even n = do
			putStrLn $ intercalate " " $ map show [n+4,4]
	  | mod n 10 == 5 = do
			putStrLn $ intercalate " " $ map show [n+10,10]
	  | mod n 10 == 9 = do
			putStrLn $ intercalate " " $ map show [n+21,21]
	  | mod n 10 == 7 = do
			putStrLn $ intercalate " " $ map show [n+33,33]
	  | mod n 10 == 3 = do
			putStrLn $ intercalate " " $ map show [n+27,27]
	  | otherwise = do
			putStrLn $ intercalate " " $ map show [n+9,9]

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

process :: Int -> (Int, Int)
process 1 = (9,8)
process n = (3*n,2*n)

readInt :: String -> Int
readInt = read

main :: IO ()
main = do
    n <- fmap readInt getLine
    let  (a,b) = process n
    putStrLn (show a ++ " " ++ show b)

module Main where

import Control.Monad
import Data.List

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

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

main :: IO ()
main = do
    n <- readLn
    putStrLn $ (show (n * 3) ++ " " ++ show (n * 2))


Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array $$$a=[1, 3, 3, 7]$$$ is good because there is the element $$$a_4=7$$$ which equals to the sum $$$1 + 3 + 3$$$.You are given an array $$$a$$$ consisting of $$$n$$$ integers. Your task is to print all indices $$$j$$$ of this array such that after removing the $$$j$$$-th element from the array it will be good (let's call such indices nice).For example, if $$$a=[8, 3, 5, 2]$$$, the nice indices are $$$1$$$ and $$$4$$$:   if you remove $$$a_1$$$, the array will look like $$$[3, 5, 2]$$$ and it is good;  if you remove $$$a_4$$$, the array will look like $$$[8, 3, 5]$$$ and it is good. You have to consider all removals independently, i. e. remove the element, check if the resulting array is good, and return the element into the array.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — elements of the array $$$a$$$.

In the first line print one integer $$$k$$$ — the number of indices $$$j$$$ of the array $$$a$$$ such that after removing the $$$j$$$-th element from the array it will be good (i.e. print the number of the nice indices). In the second line print $$$k$$$ distinct integers $$$j_1, j_2, \dots, j_k$$$ in any order — nice indices of the array $$$a$$$. If there are no such indices in the array $$$a$$$, just print $$$0$$$ in the first line and leave the second line empty or do not print it at all.

NoteIn the first example you can remove any element with the value $$$2$$$ so the array will look like $$$[5, 1, 2, 2]$$$. The sum of this array is $$$10$$$ and there is an element equals to the sum of remaining elements ($$$5 = 1 + 2 + 2$$$).In the second example you can remove $$$8$$$ so the array will look like $$$[3, 5, 2]$$$. The sum of this array is $$$10$$$ and there is an element equals to the sum of remaining elements ($$$5 = 3 + 2$$$). You can also remove $$$2$$$ so the array will look like $$$[8, 3, 5]$$$. The sum of this array is $$$16$$$ and there is an element equals to the sum of remaining elements ($$$8 = 3 + 5$$$).In the third example you cannot make the given array good by removing exactly one element.

import Data.List
import Data.Maybe
import qualified Data.Map as Map

readInteger :: String -> Integer
readInteger = read

parseInput :: String -> [Integer]
parseInput file
    = [ readInteger word | word <- words $ last $ lines file ]

showOutput :: [Int] -> String
showOutput xs = (show $ length xs) ++ "\n" ++ showIndices xs
    where
        showIndices :: [Int] -> String
        showIndices [] = ""
        showIndices [x] = show x ++ "\n"
        showIndices (x:xs) = show x ++ " " ++ showIndices xs

main :: IO ()
main = do interact $ showOutput . process . parseInput

process :: [Integer] -> [Int]
process xs =
    let getNum x = fromMaybe 0 (Map.lookup x table) where table = getTable xs
        total = sum xs
        isGood x | odd remain = False
                 | otherwise = isAvailable (remain `div` 2)
                   where remain = total - x
                         isAvailable y = getNum y > (if x == y then 1 else 0)
    in map succ $ findIndices (\x -> isGood x) xs

getTable :: [Integer] -> Map.Map Integer Int
getTable xs = Map.fromAscList $ map (\ys -> (head ys, length ys)) (group $ sort xs)

import Data.List
import Data.Maybe
import qualified Data.Map as Map

readInteger :: String -> Integer
readInteger = read

parseInput :: String -> [Integer]
parseInput file
    = [ readInteger word | word <- words $ last $ lines file ]

showOutput :: [Int] -> String
showOutput xs = (show $ length xs) ++ "\n" ++ showIndices xs
    where
        showIndices :: [Int] -> String
        showIndices [] = ""
        showIndices [x] = show x ++ "\n"
        showIndices (x:xs) = show x ++ " " ++ showIndices xs

process :: [Integer] -> [Int]
process xs =
    let table = getTable xs
        lookupTable x = fromMaybe 0 (Map.lookup x table)
        total = sum xs
        isGood x
            | odd y = False
            | otherwise = lookupTable z > (if x == z then 1 else 0)
            where y = total - x
                  z = y `div` 2
    in map (1+) $ findIndices (\x -> isGood x) xs

getTable :: [Integer] -> Map.Map Integer Int
getTable xs = Map.fromList $ map (\ys -> (head ys, length ys)) (group $ sort xs)

main :: IO ()
main = do
    n <- getLine
    line <- getLine
    (putStr . showOutput . process . parseInput) line

main = do
    l0 <- getLine
    l1 <- getLine
    let j = calc $ readArray l1
    putStrLn $ show $ length j
    putStrLn $ join " " $ map show j

join d [] = ""
join d (x:[]) = x
join d (x:xs) = x ++ d ++ join d xs

splitByChar d "" = []
splitByChar d x = let (y, ys) = splitOneByChar d x in y:splitByChar d ys

splitOneByChar d [] = ("", "")
splitOneByChar d (x:xs)
    | x == d = ("", xs)
    | otherwise = let (y, ys) = splitOneByChar d xs in (x:y, ys)

readArray x = map read $ splitByChar ' ' x

getTwoLargest x =
    let p [] l0 l1 = (l0, l1)
        p (y:ys) l0 l1
            | y > l0 = p ys y l0
            | y > l1 = p ys l0 y
            | otherwise = p ys l0 l1
    in  p x 0 0

calc x =
    let s = sum x
        (lar0, lar1) = getTwoLargest x
        p [] _ js = js
        p (y:ys) j js
            | s - y == (if lar0 == y then lar1 else lar0) * 2 = p ys (j + 1) (j:js)
            | otherwise = p ys (j + 1) js
    in  p x 1 []

import Data.List
import Data.Maybe
import qualified Data.Map as Map

readInteger :: String -> Integer
readInteger = read

parseInput :: String -> [Integer]
parseInput file
    = [ readInteger word | word <- words $ last $ lines file ]

showOutput :: [Int] -> String
showOutput xs = (show $ length xs) ++ "\n" ++ showIndices xs
    where
        showIndices :: [Int] -> String
        showIndices [] = ""
        showIndices [x] = show x ++ "\n"
        showIndices (x:xs) = show x ++ " " ++ showIndices xs

process :: [Integer] -> [Int]
process xs
    = let table = map (\ys -> (head ys, genericLength ys)) (group $ sort xs)
          total = sum xs
          lookupTable x = fromMaybe 0 (lookup x table)
          low x y = if x == y then 1 else 0
          isGood x
            | odd y = False
            | otherwise = lookupTable x > low x z
            where y = total - x; z = y `div` 2
      in map (1+) $ findIndices (\x -> isGood x) xs

main :: IO ()
main = do interact $ showOutput . process . parseInput


You've got a undirected tree s, consisting of n nodes. Your task is to build an optimal T-decomposition for it. Let's define a T-decomposition as follows.Let's denote the set of all nodes s as v. Let's consider an undirected tree t, whose nodes are some non-empty subsets of v, we'll call them xi . The tree t is a T-decomposition of s, if the following conditions holds:  the union of all xi equals v;  for any edge (a, b) of tree s exists the tree node t, containing both a and b;  if the nodes of the tree t xi and xj contain the node a of the tree s, then all nodes of the tree t, lying on the path from xi to xj also contain node a. So this condition is equivalent to the following: all nodes of the tree t, that contain node a of the tree s, form a connected subtree of tree t. There are obviously many distinct trees t, that are T-decompositions of the tree s. For example, a T-decomposition is a tree that consists of a single node, equal to set v.Let's define the cardinality of node xi as the number of nodes in tree s, containing in the node. Let's choose the node with the maximum cardinality in t. Let's assume that its cardinality equals w. Then the weight of T-decomposition t is value w. The optimal T-decomposition is the one with the minimum weight.Your task is to find the optimal T-decomposition of the given tree s that has the minimum number of nodes.

The first line contains a single integer n (2 ≤ n ≤ 105), that denotes the number of nodes in tree s. Each of the following n - 1 lines contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi), denoting that the nodes of tree s with indices ai and bi are connected by an edge. Consider the nodes of tree s indexed from 1 to n. It is guaranteed that s is a tree.

In the first line print a single integer m that denotes the number of nodes in the required T-decomposition. Then print m lines, containing descriptions of the T-decomposition nodes. In the i-th (1 ≤ i ≤ m) of them print the description of node xi of the T-decomposition. The description of each node xi should start from an integer ki, that represents the number of nodes of the initial tree s, that are contained in the node xi. Then you should print ki distinct space-separated integers — the numbers of nodes from s, contained in xi, in arbitrary order. Then print m - 1 lines, each consisting two integers pi, qi (1 ≤ pi, qi ≤ m; pi ≠ qi). The pair of integers pi, qi means there is an edge between nodes xpi and xqi of T-decomposition. The printed T-decomposition should be the optimal T-decomposition for the given tree s and have the minimum possible number of nodes among all optimal T-decompositions. If there are multiple optimal T-decompositions with the minimum number of nodes, print any of them.

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

gao n e = concatMap (\i -> zip i $ drop 1 i) $ elems $ accumArray (flip (:)) [] (1,n) $
  concat $ zipWith (\k [i, j] -> [(i, k), (j, k)]) [1 ..] e

get = fmap (map (fst . fromJust . C.readInt) . C.words) C.getLine

put = putStr . unlines . map (unwords . map show)

main = do
  [n] <- get
  e <- replicateM (n - 1) $ get
  put $ [[n - 1]]
  put $ map (2:) e
  put $ map (\(i, j) -> [i, j]) $ gao n e

import Control.Monad
import Data.Array
import Data.Maybe
import Prelude hiding (getLine, words)
import Data.ByteString.Char8 (getLine, words, readInt)
-- import Data.ByteString.Lazy.Char8 (unwords, unlines, putStr)

gao n e = concatMap (\i -> zip i $ drop 1 i) $ elems $ accumArray (flip (:)) [] (1,n) $
  concat $ zipWith (\k [i, j] -> [(i, k), (j, k)]) [1 ..] e

get = fmap (map (fst . fromJust . readInt) . words) getLine

put = putStr . unlines . map (unwords . map show)

main = do
  [n] <- get
  e <- replicateM (n - 1) $ get
  put $ [[n - 1]]
  put $ map (2:) e
  put $ map (\(i, j) -> [i, j]) $ gao n e