Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.

The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105).  The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points. The techniques are given in chronological order.

If the first wrestler wins, print string "first", otherwise print "second"

NoteSequence x  =  x1x2... x|x| is lexicographically larger than sequence y  =  y1y2... y|y|, if either |x|  >  |y| and x1  =  y1,  x2  =  y2, ... ,  x|y|  =  y|y|, or there is such number r (r  <  |x|, r  <  |y|), that x1  =  y1,  x2  =  y2,  ... ,  xr  =  yr and xr  +  1  >  yr  +  1.We use notation |a| to denote length of sequence a.

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

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

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

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

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

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

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

main = interact solve

import Data.Monoid

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

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

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

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

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

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

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

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

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

import Data.Monoid

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

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

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

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

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


You are given two integers $$$x$$$ and $$$y$$$ (it is guaranteed that $$$x > y$$$). You may choose any prime integer $$$p$$$ and subtract it any number of times from $$$x$$$. Is it possible to make $$$x$$$ equal to $$$y$$$?Recall that a prime number is a positive integer that has exactly two positive divisors: $$$1$$$ and this integer itself. The sequence of prime numbers starts with $$$2$$$, $$$3$$$, $$$5$$$, $$$7$$$, $$$11$$$.Your program should solve $$$t$$$ independent test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ lines follow, each describing a test case. Each line contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le y < x \le 10^{18}$$$).

For each test case, print YES if it is possible to choose a prime number $$$p$$$ and subtract it any number of times from $$$x$$$ so that $$$x$$$ becomes equal to $$$y$$$. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).

NoteIn the first test of the example you may choose $$$p = 2$$$ and subtract it once.In the second test of the example you may choose $$$p = 5$$$ and subtract it twice. Note that you cannot choose $$$p = 7$$$, subtract it, then choose $$$p = 3$$$ and subtract it again.In the third test of the example you may choose $$$p = 3$$$ and subtract it $$$333333333333333333$$$ times.

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

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

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

import qualified Data.ByteString.Char8 as B

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

-- import Debug.Trace
import Text.Printf

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

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

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

main = readInt >>= flip replicateM solve

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

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

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

import Control.Monad

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

import Data.List
import Control.Monad

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

import Control.Monad

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


Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.

Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.

4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis

import Control.Monad

main = do
    line <- getLine
    let count = read line :: Int
    replicateM_ count $ getLine >>= putStrLn . solve

solve :: String -> String
solve s = solve' s $ length s
    where solve' s len | len <= 10 = s
                       | otherwise = head s : (show $ len - 2) ++ [last s]

-- Vicfred
-- Codeforces
-- Way Too Long Words https://codeforces.com/problemset/problem/71/A

main =  do
    w <- getLine
    words <- getContents
    putStrLn . unlines . map transform . lines $ words

transform :: String -> String
transform s
    | (length s <= 10) = s
    | otherwise = ([head s] ++ show (length s - 2) ++ [last s])

import Control.Monad
import Data.List
import Data.Maybe
import Data.Char

import qualified Data.ByteString.Char8 as B
readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

abbrWord :: String -> String
abbrWord s
    | length s <= 10 = s
    | otherwise      = [head s] ++ show ((-) (length s) 2) ++ [last s]

main :: IO ()
main = do
    n <- readInt
    xs <- replicateM n $ getLine
    -- print xs
    mapM_ putStrLn $ map abbrWord xs

-- Vicfred
-- https://codeforces.com/problemset/problem/71/A
-- implementation
transform :: String -> String
transform s
    | (length s <= 10) = s
    | otherwise = ([head s] ++ show (length s - 2) ++ [last s])

main :: IO ()
main =  interact $ unlines . (map transform) . tail . words

import System.IO
import Data.String

readInt :: IO Int
readInt = do
    int <- getLine
    return (read int)

solve n = do
	if n > 0
		then do
			input <- getLine
			if length(input) > 10
				then do
					let len = length(input) - 2
					let str = show len
					putStrLn( ((head input) : []) ++ str ++((last input) : []))
			else putStrLn(input)
			solve(n-1)
		else pure()

main = do
	numberOfTestCases <- readInt
	solve(numberOfTestCases)

solve s
    | l > 10    = [head s] ++ (show (l-2)) ++ [last s]
    | otherwise = s
  where
    l = length s
main = putStrLn . unlines . map solve . tail . lines =<< getContents

import Control.Monad
main=do
 n<-fmap read getLine
 replicateM_ n$getLine>>=putStrLn.q
q s|t<=10=s
 |True=head s:(show$t-2)++[last s]
 where t=length s

import Control.Applicative
import qualified Data.ByteString.Char8 as B
import Text.Printf

main = do
  n <- read <$> getLine
  mapM_ (\_ -> do
    s <- getLine
    let m = length s
    if m > 10 then
      printf "%c%d%c\n" (head s) (m-2) (last s)
    else putStrLn s
    ) [1..n]

import Data.Char
import Data.List

ans str = if l<11 then str
               else [head str] ++ show (l-2) ++ [last str]
    where l = length str
main=do
    input<-getContents
    putStr.unlines $ map ans $tail.lines $ input

main = do
    getLine
    as <- fmap lines getContents
    let
        bs = map f as
        f s
            | length s <= 10 = s
            | otherwise = [head s] ++ (show $ length s - 2) ++ [last s]

    putStr $ unlines $ bs

import Data.Char

transformWord :: String -> String
transformWord word
    | (length word <= 10) = word
    | otherwise = [head word] ++ (show $ length word - 2) ++ [last word]

getWords :: Integer -> IO [[Char]]
getWords wordsLeft = do
    if wordsLeft == 0
        then return []
    else do
        line <- getLine
        stuff <- getWords (wordsLeft - 1)
        return (line : stuff)

printWords [] = return ()
printWords wordsList = do
    putStrLn $ head wordsList
    printWords $ tail wordsList

main = do
    line <- getLine
    let numWords = read line :: Integer
    wordsList <- getWords numWords
    let newWords = map transformWord wordsList
    printWords newWords

shorten :: String -> String
shorten s
  | length s <= 10 = s
  | otherwise = [head s] ++ show (length s - 2) ++ [last s]

solve :: String -> String
solve input = unlines $ map shorten $ tail $ lines input

main :: IO ()
main = interact solve

import Control.Monad

main :: IO ()
main = do
    n <- getLine
    inputs <- replicateM (read n) getLine
    mapM_ putStrLn $ fmap abbreviate inputs

abbreviate :: String -> String
abbreviate s
    | l <= 10 = s
    | otherwise = [head s] ++ show (l - 2) ++ [last s]
    where l = length s

f w = let n = length w in if n<11 then w else [w!!0] ++ show (n-2) ++ [w!!(n-1)]

g _ = do
    w <- getLine
    putStrLn . f $ w

main = do
    n <- getLine
    mapM_  g [1..read$n]

import           Control.Monad                  ( replicateM
                                                , foldM
                                                )

solve :: String -> String
solve s
    | length s <= 10 = s
    | otherwise      = abbr s
    where
        abbr :: String -> String
        abbr s = (head s):[] ++ show (length s - 2) ++ (last s):[]

main :: IO ()
main = do
    n <- getInt
    lines <- replicateM n getLine
    mapM_ (putStrLn . solve) lines

    where
        getInt :: IO Int
        getInt = do
            line <- getLine
            return ( read line :: Int )

convertStr contents = if (length contents) > 10 then putStr ([(contents !! 0)] ++ (show ((length contents) - 2)) ++ [(contents !! ((length contents) - 1))] ++ "\n") else putStr (contents ++ "\n")

outputI18 1 = do
    contents <- getLine
    convertStr contents
outputI18 n = do
    contents <- getLine
    convertStr contents
    outputI18 (n-1)

main = do
    input1 <- getLine
    let n = (read input1 :: Int)
    outputI18 n

import Control.Monad
main = do
    count <- getLine
    forM_ [1..read count] (\_ -> do
        word <- getLine
        if length word > 10 then
            putStrLn $ [head word] ++ show (length word - 2) ++ [last word]
        else
            putStrLn word)

{-# LANGUAGE OverloadedStrings #-}

import Control.Monad.Writer.Strict (liftM, replicateM_)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C

main = do
  n <- read `fmap` getLine :: IO Int
  replicateM_ n $ do
    q <- B.getLine
    let r = simplify . head . C.words $ q
    -- C.putStrLn . C.pack . show $ (B.length q)
    C.putStrLn r

simplify :: B.ByteString -> B.ByteString
simplify s = sim s (B.length s)
  where
    sim s l
      | l <= 10 = s
      | otherwise = B.concat $ [prefix s, intToBs (l - 2), suffix s]
    prefix = B.singleton . B.head
    suffix = B.singleton . B.last
    intToBs i = C.pack . show $ i

import Control.Monad

abbreviate s
    | length s <= 10 = s
    | otherwise = head s : show(length s - 2) ++ [last s]

main = do
    n <- readLn
    replicateM_ n $ do
        s <- getLine
        putStrLn $ abbreviate s

main :: IO ()
main = interact $ output

compactWord :: String -> String
compactWord x = firstLetter x ++ middleSize x ++ endLetter x
                where
                  firstLetter x = take 1 x
                  middleSize x  = (show . length) (init $ tail x)
                  endLetter x   = drop ((length x) - 1) x

transformWord :: String -> String
transformWord x | (length x) > 10 = compactWord x
                | otherwise       = x

input :: [String] -> [String]
input inputWords = map transformWord inputWords

output :: String -> String
output = unlines . input . tail . lines

f s = if 10 < length s then
        [head s] ++ show (len s) ++ [last s]
      else
        s
  where len s = length $ init $ tail s

answer (x:xs) = inner (take (read x) xs) []
  where inner [] rv = reverse rv
        inner (x:xs) rv = inner xs (f x:rv)

main = interact
  $ foldl (\x y -> x ++ y ++ "\n") ""
  . answer
  . lines

import Control.Applicative

process x | length x <=10  = x
          | otherwise = [head x]++ (show (length x -2))++ [last x]

main=do
  x<-tail .lines <$> getContents
  mapM_ putStrLn $ map process x

-- RandomUsername (Nikola Jovanovic)
-- Codeforces
-- Way Too Long Words (http://codeforces.com/problemset/problem/71/A)

main = do
    w <- getLine
    words <- getContents
    putStrLn . unlines . solve . lines $ words

solve :: [String] -> [String]
solve xs = foldr change [] xs
    where change x acc
            | (length x <= 10) = x:acc
            | otherwise = ( [head x] ++ lenstr x ++ [last x] ):acc
          lenstr x = show $ length x - 2

{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -cpp #-}
{-# OPTIONS_GHC -funbox-strict-fields -fexcess-precision -monly-3-regs #-}
{-# LANGUAGE BangPatterns, OverloadedStrings, ScopedTypeVariables #-}
module Main where
import Control.Applicative
import Data.List
import Text.Printf
import Data.Time
import Data.Time.Calendar

text = [ "4"
       , "word"
       , "localization"
       , "internationalization"
       , "pneumonoultramicroscopicsilicovolcanoconiosis"
       ]

f text = if len > 10 then  [f] ++ show (len - 2) ++ [l] else text
    where
      len = length text
      f   = head text
      l   = last text

main :: IO ()
main = do { _:ts <- lines <$> getContents
          ; mapM_ (printf "%s\n") . map f $ ts
          }

clear xs = [x | x <- xs, x /= '\'']

solve :: [Char] -> String

solve x
	| len <= 10 = x
	| otherwise = clear (show (x !! 0) ++ (show (len-2)) ++ (show (x !! (len-1))))
	where len = length x

main = interact $ unlines . map solve . tail . words

import Control.Monad

main = do
    n <- getLine
    let times = read n ::Int
    forM [1..times] (\i -> do
        word <- getLine
        putStrLn $ waytoolong word)

waytoolong :: String -> String
waytoolong w
    | length w <= 10 = w
    | otherwise     = head w : (show $ length w - 2) ++ [last w]

-- PROBLEM https://cideforces.com/contest/71/problem/A

import Control.Arrow ((>>>))

main :: IO()
main =
  interact $
    lines >>> drop 1 >>> map solve >>> unlines

solve :: String -> String
solve s
  | length s <= 10 = s
  | otherwise = head s : show len ++ [last s]
  where
    len = length s - 2

-- Vicfred
-- Codeforces
-- Way Too Long Words https://codeforces.com/problemset/problem/71/A

main =  do
    w <- getLine
    words <- getContents
    putStrLn . unlines . map transform . lines $ words

transform :: String -> String
transform s
    | (length s <= 10) = s
    | otherwise = ([head s] ++ show (length s - 2) ++ [last s])

f :: String -> String
f x
  | l <= 10 = x
  | otherwise = [head x] ++ (show (l - 2)) ++ [x !! (l - 1)]
  where l = length x

main = do
  n <- readInt
  a <- readStrN n
  printStrList $ map f a

-- Int from line
readInt :: IO Int
readInt = do
  line <- getLine
  return $ read line

-- Int from N lines
readStrN :: Int -> IO [String]
readStrN 0 = return []
readStrN n = do
  x  <- getLine
  xs <- readStrN (n - 1)
  return (x:xs)

printStrList :: [String] -> IO()
printStrList [] = return ()
printStrList (x:xs) = do
  putStrLn x
  printStrList xs

main=interact$unlines.map f.tail.lines
f l@(x:xs)
	|length l<=10 = l
	|otherwise = [x] ++ (show ((length l)-2)) ++ [last xs]

-- http://codeforces.com/problemset/problem/71/A

abbreviate :: String -> String
abbreviate w =
  if length w <= 10
    then w
    else [head w] ++ show ((length w) - 2) ++ [last w]

main = do
  n <- getLine
  contents <- getContents
  putStr $ unlines $ map abbreviate $ lines contents

-- RandomUsername (Nikola Jovanovic)
-- Codeforces
-- Way Too Long Words (http://codeforces.com/problemset/problem/71/A)

main = do
    w <- getLine
    words <- getContents
    putStrLn . unlines . map transform . lines $ words

solve :: [String] -> [String]
solve xs = foldr change [] xs
    where change x acc
            | (length x <= 10) = x:acc
            | otherwise = ( [head x] ++ lenstr x ++ [last x] ):acc
          lenstr x = show $ length x - 2

transform :: String -> String
transform s
    | (length s <= 10) = s
    | otherwise = ([head s] ++ show (length s - 2) ++ [last s])

module Main where

isTooLong word = length word > 10
lengthBetweenFirstAndLast word = length word - 2
solveCases remainingCases results = do
    word <- getLine
    let result = if isTooLong word then ([head word] ++ (show $ lengthBetweenFirstAndLast word) ++ [last word]) else word
    if remainingCases - 1 > 0 then solveCases (remainingCases - 1) (results ++ [result]) else return (results ++ [result])

main = do
    line <- getLine
    let caseCount = read line :: Int
    results <- solveCases caseCount []
    mapM putStrLn results

f x | l > 10 = (head x):(show (l - 2))++[last x]
    | otherwise  = x
    where l = length x
main = interact $ unlines.(map f).tail.words

main = interact w

w = unlines . map f . tail . lines

f s | length s > 10 = [head s] ++ show ( (length s) - 2 ) ++ [last s]
    | otherwise = s

import Control.Monad
f str@(x:xs)
	| length str > 10 = x : show (length str - 2) ++ [last str]
	| otherwise = str

main = do
	n <- readLn
	replicateM_ n (do
		s <- getLine
		putStrLn (f s))

process :: Int -> String -> String
process n str
    | len > n = [head str] ++ show (len-2) ++ [last str]
    | otherwise = str
    where len = length str

readInt :: String -> Int
readInt = read

main = do
    n <- fmap readInt getLine
    strs <- fmap lines getContents
    sequence . map (putStrLn . process 10) $ strs

shorten :: String -> String
shorten s
  | l <= 10 = s
  | otherwise = [head s] ++ (show $ l - 2) ++ [s !! (l - 1)]
  where l = length s

main = do
  n <- getLine
  interact (unlines . map shorten . lines)

main = do
  n <- readLn
  arr <- sequence (replicate  n getLine)
  let b = fmap shrt arr
  mapM putStrLn b

shrt :: String -> String
shrt x = if length x <= 10 then x else ((head x) : (show $ length x - 2) ++ (last x :[]))

import Control.Monad

main = do
    lines <- getLine
    let cases = read lines :: Int
    results <- forM [1..cases] (\_ -> do
        line <- getLine
        let result = solve line
        return result)
    mapM putStrLn results

solve :: String -> String
solve s
    | length s <= 10 = s
    | otherwise     = [head s] ++ (show (length s - 2)) ++ [last s]

s :: String -> String
s word =
  if length word <= 10
  then word
  else h ++ [last word]
  where
    h = head word : (show $ (length word) - 2)

solve :: Int -> [String] -> [String]
solve 1 (x:_) = [s x]
solve n (x:xs) = s x : solve (n - 1) xs

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

main = do
  (n:_) <- readInts
  c <- getContents
  putStrLn (unlines $ solve n (lines c))

import Control.Applicative
import Control.Monad

solve s = if len > 8 then concat [[f], show len, [l]] else s
	where	len = (length s) - 2
		l = last s
		(f:_) = s

main = do
	sn <- getLine
	let n = read sn :: Int
	res <- forM [1..n]	(\_ -> do
					solve <$> getLine
				)
	mapM putStrLn res
	return ()

{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns #-}
import Data.Maybe
import Data.Char
import Data.List
import Data.Int
import Data.Bits
import Data.Ratio
import Data.IORef
-- import Data.Array.IO
import Control.Monad
import Control.Applicative
import qualified Data.ByteString.Char8 as BS
import qualified Data.Map              as Map
import qualified Data.Set              as Set
import Text.Printf
-- import Debug.Trace
import System.Exit

solveCase t n
  | t == n = return ()
  | otherwise = getLine >>= putStrLn . solve >> solveCase (t + 1) n
  where
    solve s | l <= 10 = s
            | otherwise = [head s] ++ show (l - 2) ++ [last s]
            where
              l = length s

main = (readLn :: IO Int) >>= solveCase 0

main = do
	n <- getLine
	interact$ (unlines.map s).lines
s a
	| length a > 10 = [head a] ++ show ((length a)-2) ++ [last a]
	| otherwise = a

import Data.List
f (s:ss) | length ss > 9 = [s]++(show (length ss - 1))++[last ss]
	 | otherwise = s:ss
main = do
	n <- read `fmap` getLine
	mapM_ (\_ -> putStrLn =<< (f `fmap` getLine)) [1..n]

    main=interact$unlines.map f.tail.lines
    l=length
    f x|l x<11=x|1>0=(head x:show(l x-2))++[last x]

ans :: String -> String
ans s | length s <= 10 = s
      | otherwise = [head s] ++ show (length s - 2) ++ [last s]

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

import System.IO
main =
  do
    n <- readLn :: IO Int
    f n

f 0 = return ()
f n =
  do
    s <- getLine
    --let s = read t :: String
    if length s <= 10
       then putStrLn s
       else let str = head s : show (length s - 2) ++ [last s]
                in putStrLn str
    f (n-1)

import Data.List
main = interact $ intercalate "\n" . map solve . tail . lines
solve xs
    | length xs > 10 = [head xs] ++ (show . (subtract 2) . length $ xs) ++ [last xs]
    | otherwise      = xs

-- Vicfred
-- https://codeforces.com/problemset/problem/71/A
-- implementation
import Control.Monad

transform :: String -> String
transform s
    | (length s <= 10) = s
    | otherwise = ([head s] ++ show (length s - 2) ++ [last s])

main :: IO ()
main =  do
    n <- getLine
    inputs <- replicateM (read n) getLine
    let answers = map transform inputs
    sequence_ (map putStrLn answers)

import Control.Monad
main = do
    count <- getLine
    forM_ [1..read count] (\_ -> do
        word <- getLine
        if length word > 10 then
            putStrLn $ [head word] ++ show (length word - 2) ++ [last word]
        else
            putStrLn word)

f xs
  | length xs < 11 = xs
  | otherwise = [head xs] ++ l ++ [last xs]
  where l = show (length xs - 2)

main = interact $ unlines . map f . tail . lines

solve s
    | l > 10    = [head s] ++ (show (l-2)) ++ [last s]
    | otherwise = s
  where
    l = length s
main = putStrLn . unlines . map solve . tail . lines =<< getContents

import System.IO (readFile, getLine)
import Data.Char (digitToInt)
import Data.List (intercalate)
import Control.Monad (sequence)
import Text.Printf (printf)

abr_internal :: Int -> String -> Maybe (Int, Char)
abr_internal n [h] = Just (n + 1, h)
abr_internal n (h:s) = abr_internal (n + 1) s
abr_internal n [] = Nothing

abbreviate :: String -> String
abbreviate s = case abr_internal 0 s of
                    Nothing -> error "Invalid string passwd"
                    (Just (n, c)) -> if n > 10 then (head s) : (printf "%d" (n - 2)) ++ [c] else s

abbreviateInput :: Int -> IO [String]
abbreviateInput n | n <= 0 = return ([] :: [String])
                  | otherwise = do
                        s <- getLine
                        rtail <- abbreviateInput (n-1)
                        return ((abbreviate s) : rtail)

main = do
    cnt_s <- getLine
    result <- abbreviateInput ((read cnt_s) :: Int)
    mapM putStrLn result

-- PROBLEM https://cideforces.com/contest/71/problem/A

import Control.Arrow ((>>>))

main :: IO()
main =
  interact $
    lines >>> drop 1 >>> map solve >>> unlines

solve :: String -> String
solve s
  | length s <= 10 = s
  | otherwise = head s : show len ++ [last s]
  where
    len = length s - 2

module Main where

--import Debug.Trace

import Control.Monad
import Control.DeepSeq
import Data.Function
import Data.Ratio
import Data.Fixed
import Data.List
import Data.Char

getWords  = words <$> getLine :: IO [String]
getInts   = map read <$> getWords :: IO [Int]
getDoubles = map read <$> getWords :: IO [Double]
getInt    = read <$> getLine :: IO Int
getDouble  = read <$> getLine :: IO Double
printLines = fmap head . sequence . map putStrLn

abbreviate w = abb w 0 where
    abb [c]    n = show (n-1) ++ [c]
    abb (c:cs) 0 = c : abb cs 1
    abb (c:cs) n = abb cs (n+1)

process :: String -> String
process w = if length w > 10 then abbreviate w else w

main = do
    n <- getInt
    lines <- replicateM n getLine
    printLines $ map process lines

{-# LANGUAGE OverloadedStrings #-}

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

getInt = fst . fromJust . B.readInt

procWord w
    | l <= 10 = w
    | otherwise = (head w) : (show $ l - 2) ++ [last w]
    where
        l = length w

main = do
    n <- getInt <$> B.getLine
    replicateM_ n $ fmap procWord getLine >>= putStrLn

import Data.Char
import Data.List

ans str = if l<11 then str
               else [head str] ++ show (l-2) ++ [last str]
    where l = length str
main=do
    input<-getContents
    putStr.unlines $ map ans $tail.lines $ input

import Data.Maybe
import Control.Monad

main = do
    numCasesLine <- getLine
    let numCases = (read numCasesLine) :: Int in replicateM_ numCases processCase
        where
            processCase = do
                line <- getLine
                if length line > 10
                    then putStrLn $ (head line) : show ((length line) - 2) ++ [last line]
                    else putStrLn line

import Control.Applicative
import qualified Data.ByteString.Char8 as B
import Text.Printf

main = do
  n <- read <$> getLine
  mapM_ (\_ -> do
    s <- getLine
    let m = length s
    if m > 10 then
      printf "%c%d%c\n" (head s) (m-2) (last s)
    else putStrLn s
    ) [1..n]

import Prelude

toInt::[String] -> Integer
toInt (x:xs) = read x

firs::[Char] -> Char
firs = head

las::[Char] -> Char
las = firs . reverse

cnt::[Char] -> Integer
cnt [] = (-2)
cnt (x:xs) = 1 + (cnt xs)

func::Integer -> IO ()
func 0 = return ()
func x = do
    input <- getLine
    putStrLn $ if ((cnt input) > 8) then ([firs input]++(show (cnt input))++[las input]) else input
    func (x-1)

main = do
	input <- getLine
	let n = toInt (words input)
	func n

ans :: String -> String
ans s | length s <= 10 = s
      | otherwise = [head s] ++ show (length s - 2) ++ [last s]

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

import Control.Monad

readNLines :: Int -> IO [String]
readNLines n = replicateM n getLine

checkAndConstructWord :: String -> String
checkAndConstructWord x
        | length x > 10 = (charToString $ head x)++(show $ length x - 2)++(charToString $ x!!(length x - 1))
        | otherwise = x
    where charToString y = [y]

main :: IO()
main = do
    n <- readLn :: IO Int
    x <- readNLines n
    mapM_ putStrLn $ map checkAndConstructWord x

import Control.Monad

main = do
    n <- fmap read getLine
    replicateM_ n $ getLine >>= putStrLn . solve

solve s | len <= 10 = s
        | otherwise = head s : (show $ len - 2) ++ [last s]
    where
        len = length s

import Control.Monad

solve :: String -> String
solve (x:xs) = if length (x:xs) > 10
                  then x : go 0 xs
                  else (x:xs)
    where go n [x] = show n ++ [x]
          go n (x:xs) = go (n + 1) xs

main :: IO ()
main = do
    n <- fmap read getLine
    ss <- replicateM n getLine
    mapM_ putStrLn (map solve ss)

module Main where

main :: IO ()
main = do
  n <- getLine
  let
    go n =
      if n == 0 then
        return ()
      else do
        line <- getLine
        (putStrLn . shortenString) line
        go $ n - 1
  go $ read n

shortenString :: String -> String
shortenString string = let
  helper :: Int -> String -> String
  helper n (char : "")
    | n > 9              = head string : (show $ n - 1) ++ [char]
    | otherwise           = string
  helper n (char : chars) = helper (n + 1) chars
  in helper 0 string

main=interact$unlines.map f.tail.lines
l=length
f x|l x<11=x|1>0=(head x:show(l x-2))++[last x]

extract (x:xs)=take (read x::Int) xs
f x
	|l<=10 = x
	|otherwise   = head x:(show (l-2)++[last x])
	where l=length x
main=interact$unlines.map f.extract.lines

f s
    | l > 10 = (head s : show (l - 2)) ++ [last s]
    | otherwise = s
    where
        l = length s

main = interact $ unlines.map f.tail.lines

main :: IO()
main = do
    _ <- getLine
    mapM_ putStrLn . (map trans) . lines =<< getContents
    where
        trans x = if length x < 11 then x
                      else (head x) : (show $ length x - 2) ++ [last x]

import Control.Monad

main = do
    n <- getLine
    let times = read n ::Int
    forM [1..times] (\i -> do
        word <- getLine
        putStrLn $ waytoolong word)

waytoolong :: String -> String
waytoolong w
    | length w <= 10 = w
    | otherwise     = head w : (show $ length w - 2) ++ [last w]

process :: Int -> String -> String
process n str
    | len > n = [head str] ++ show (len-2) ++ [last str]
    | otherwise = str
    where len = length str

readInt :: String -> Int
readInt = read

main = do
    n <- fmap readInt getLine
    strs <- fmap lines getContents
    sequence . map (putStrLn . process 10) $ strs

import Control.Monad

solve :: String -> String
solve s =
    let len = length s
    in if len <= 10
        then s
        else ([s!!0] ++ (show(len - 2)) ++ [s!!(len-1)])

main :: IO ()
main = do
    n <- getLine
    inputs <- replicateM (read n) getLine
    let answers = map solve inputs
    sequence_ (map putStrLn answers)

import Control.Monad

main = do
    lines <- getLine
    let cases = read lines :: Int
    results <- forM [1..cases] (\_ -> do
        line <- getLine
        let result = solve line
        return result)
    mapM putStrLn results

solve :: String -> String
solve s
    | length s <= 10 = s
    | otherwise     = [head s] ++ (show (length s - 2)) ++ [last s]

import Control.Monad (forM_)

main = (\x -> forM_ [1..x] $ const (((\ y -> if length y > 10 then head y:(show $ length y - 2) ++ last y:[] else y) <$> getLine) >>= putStrLn)) =<< (readLn :: IO Int)

-- Vicfred
-- Codeforces
-- Way Too Long Words https://codeforces.com/problemset/problem/71/A

main =  do
    w <- getLine
    words <- getContents
    putStrLn . unlines . map transform . lines $ words

transform :: String -> String
transform s
    | (length s <= 10) = s
    | otherwise = ([head s] ++ show (length s - 2) ++ [last s])

import Control.Applicative

process x | length x <=10  = x
          | otherwise = [head x]++ (show (length x -2))++ [last x]

main=do
  x<-tail .lines <$> getContents
  mapM_ putStrLn $ map process x

-- Vicfred
-- https://codeforces.com/contest/71/problem/A

import Control.Monad

solve :: String -> String
solve s =
    let len = length s
    in if len <= 10
        then s
        else ([head s] ++ show (len - 2) ++ [last s])

main = do
    n <- getLine
    inputs <- replicateM (read n) getLine
    let answers = map solve inputs
    sequence_ (map putStrLn answers)

import Control.Applicative
import qualified Data.ByteString.Char8 as B
import Text.Printf

main = do
  n <- read <$> getLine
  mapM_ (\_ -> do
    s <- getLine
    let m = length s
    if m > 10 then
      printf "%c%d%c\n" (head s) (m-2) (last s)
    else putStrLn s
    ) [1..n]

module Main where

import Control.Monad (replicateM_)
import Data.Maybe (fromJust)

readNumber :: IO Int
readNumber = read `fmap` getLine

abbreviateWord :: String -> String
abbreviateWord w =
    concat [ firstLetter
           , (show ((length w) - 2))
           , lastLetter ]
  where
    firstLetter = take 1 w
    lastLetter  = take 1 (reverse w)

main :: IO ()
main = do
  nCases <- readNumber
  replicateM_ nCases $ do
    word <- getLine
    putStrLn (if (length word) > 10
              then abbreviateWord word
              else word)

import Data.Maybe
import Control.Monad

main = do
    numCasesLine <- getLine
    let numCases = (read numCasesLine) :: Int in replicateM_ numCases processCase
        where
            processCase = do
                line <- getLine
                if length line > 10
                    then putStrLn $ (head line) : show ((length line) - 2) ++ [last line]
                    else putStrLn line

{-# LANGUAGE CPP, TemplateHaskell #-}

module Main (
    main
) where

import Control.Monad (unless)
import Data.List (stripPrefix)
import System.Exit (exitFailure)

#ifdef MAIN_FUNCTION
import Test.Framework.TH
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2

import Test.QuickCheck
import Test.HUnit

import Data.List
#endif

abbrevate all@(h:s)
    | len <=10 = all
    | otherwise = [h] ++ show (len - 2) ++ [head $ reverse s]
    where len = length all

process 0 = do
    return ()
process n = do
    s <- getLine
    putStrLn (abbrevate s)
    process (n-1)

exeMain = do
    [n] <- (map read . words) `fmap` getLine

    process n

-- Tests --

#ifdef MAIN_FUNCTION
testMain = $(defaultMainGenerator)

#endif

#ifndef MAIN_FUNCTION
#define MAIN_FUNCTION exeMain
#endif
main = MAIN_FUNCTION

import Control.Applicative
import Control.Monad

onecase= do
		x<-getLine
		let s= length x
		putStrLn $ if s <=10 then  x else  ( [head x ] ++show(s-2) ++[last x])

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

main = do
    rs <- getLine
    putStr (result rs)

result rs
  | length rs > 10 = (head rs):(long rs) ++ ((last rs):[])
  | otherwise = rs

long rs = show (length rs - 2)

main = getContents>>=mapM_ print.map slv.tail.words
slv w
    | len > 10 = head w : (show $ len-2) ++ [last w]
    | True = w
    where len = length w

{-# LANGUAGE OverloadedStrings #-}

import Control.Monad.Writer.Strict (liftM, replicateM_)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C

main = do
  n <- read `fmap` getLine :: IO Int
  replicateM_ n $ do
    r <- B.getLine
    let s = simplify r
    C.putStrLn s

solve = (C.putStrLn)

simplify :: B.ByteString -> B.ByteString
simplify s = sim s (B.length s)
  where
    sim :: B.ByteString -> Int -> B.ByteString
    sim s l
      | l < 10 = s
      | otherwise =
        B.concat $
        [ B.singleton . B.head $ s
        , C.pack . show $ (l - 2) :: B.ByteString
        , (B.singleton . B.last $ s)
        ]

{-# LANGUAGE OverloadedStrings #-}

import Control.Monad.Writer.Strict (liftM, replicateM_)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C

main = do
  n <- read `fmap` getLine :: IO Int
  replicateM_ n $ do
    q <- B.getLine
    let r = simplify . head . C.words $ q
    -- C.putStrLn . C.pack . show $ (B.length q)
    C.putStrLn r

simplify :: B.ByteString -> B.ByteString
simplify s = sim s (B.length s)
  where
    sim s l
      | l < 10 = s
      | otherwise = B.concat $ [prefix s, intToBs (l - 2), suffix s]
    prefix = B.singleton . B.head
    suffix = B.singleton . B.last
    intToBs i = C.pack . show $ i

{-# LANGUAGE OverloadedStrings #-}

import Control.Monad.Writer.Strict (liftM, replicateM_)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C

main = do
  n <- read `fmap` getLine :: IO Int
  replicateM_ n $ do
    q <- B.getLine
    let r = simplify . strip $ q
    C.putStrLn r

strip = B.filter (\s -> s /= (B.head " "))

simplify :: B.ByteString -> B.ByteString
simplify s = sim s (B.length s)
  where
    sim s l
      | l < 10 = s
      | otherwise = B.concat $ [prefix s, intToBs (l - 2), suffix s]
    prefix = B.singleton . B.head
    suffix = B.singleton . B.last
    intToBs i = C.pack . show $ i

{-# LANGUAGE OverloadedStrings #-}

import Control.Monad.Writer.Strict (liftM, replicateM_)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C

main = do
  n <- read `fmap` getLine :: IO Int
  replicateM_ n $ do
    q <- B.getLine
    let r = simplify . strip $ q
    C.putStrLn . C.pack . show $ (B.length q)
    C.putStrLn r

strip = B.filter (\s -> s /= (B.head " "))

simplify :: B.ByteString -> B.ByteString
simplify s = sim s (B.length s)
  where
    sim s l
      | l < 10 = s
      | otherwise = B.concat $ [prefix s, intToBs (l - 2), suffix s]
    prefix = B.singleton . B.head
    suffix = B.singleton . B.last
    intToBs i = C.pack . show $ i

import Data.Char

transformWord :: String -> String
transformWord word
    | (length word <= 10) = word
    | otherwise = [head word] ++ (show $ length word) ++ [last word]

getWords :: Integer -> IO [[Char]]
getWords wordsLeft = do
    if wordsLeft == 0
        then return []
    else do
        line <- getLine
        stuff <- getWords (wordsLeft - 1)
        return (line : stuff)

printWords [] = return ()
printWords wordsList = do
    putStrLn $ head wordsList
    printWords $ tail wordsList

main = do
    line <- getLine
    let numWords = read line :: Integer
    wordsList <- getWords numWords
    let newWords = map transformWord wordsList
    printWords newWords

import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString as B
import Control.Arrow

solve :: B.ByteString -> B.ByteString
solve s
    | B.length s > 10 = B.snoc (B.cons (B.head s) (B8.pack (show $ B.length s - 2))) (B.last s)
    | otherwise     = s

main :: IO ()
main = B.interact $
   B8.lines >>> map solve . tail >>> B8.unlines

import Control.Arrow

solve :: String -> String
solve s@(x:xs)
    | length s > 10 = [x] ++ show (length s - 2) ++ [last s]
    | otherwise     = s

main :: IO ()
main = interact $
   lines >>> map solve >>> unlines

import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString as B
import Control.Arrow

solve :: B.ByteString -> B.ByteString
solve s
    | B.length s > 10 = B8.snoc (B8.cons (B8.head s) (B8.pack (show $ B8.length s - 2))) (B8.last s)
    | otherwise       = s

main :: IO ()
main = B.interact $
   B8.lines >>> map solve . tail >>> B8.unlines

import Control.Monad

genAns s
  | n < 10 = s
  | otherwise = a:(show (n-2)) ++ [b]
  where
    n = length s
    (a,b) = (head s, last s)

main = do
  n <- readLn :: IO Int
  forM_ [1..n] $ \i -> do
    aa <- getLine
    putStrLn $ genAns aa

module Main where

main :: IO ()
main = interact $ unlines . map solve . tail . words

solve :: String -> String
solve xs
    | len <= 10 = xs
    | otherwise = [head xs] ++ show len ++ [last xs]
    where len = length xs

g :: [Char] -> [Char]
g s
    | length s > 10 = [head s] ++ (show . length $ s) ++ [last s]
    | otherwise     = s

main = interact $ tail . init . show . g

import Control.Monad

solve :: String -> String
solve s =
    let len = length s
    in if len < 10
        then s
        else ([s!!0] ++ (show(len - 2)) ++ [s!!(len-1)])

main :: IO ()
main = do
    n <- getLine
    inputs <- replicateM (read n) getLine
    let answers = map solve inputs
    sequence_ (map putStrLn answers)

import Control.Applicative

solve xs
  |length xs <= 10 = xs
  |otherwise = abbr xs

abbr xs = (take 1 xs) ++ show (length xs - 2) ++ (take 1 $ reverse xs)

main = do
  result <- map solve . tail . lines <$> getContents
  print result

import Control.Applicative

solve xs
  |length xs < 10 = xs
  |otherwise = abbr xs

abbr xs = (take 1 xs) ++ show (length xs - 2) ++ (take 1 $ reverse xs)

main = do
  result <- unlines . map solve . lines . tail <$> getContents
  putStrLn result

import Control.Applicative

solve xs
  |length xs <= 10 = xs
  |otherwise = abbr xs

abbr xs = (take 1 xs) ++ show (length xs - 2) ++ (take 1 $ reverse xs)

main = do
  result <- unlines . map solve . lines . tail <$> getContents
  putStrLn result

import Control.Monad

main = do
    n <- getLine
    let times = read n ::Int
    forM [1..times] (\i -> do
        word <- getLine
        putStrLn $ waytoolong word)

waytoolong :: String -> String
waytoolong w
    | length w <= 4 = w
    | otherwise     = head w : (show $ length w - 2) ++ [last w]

main = do
    getLine
    as <- fmap lines getContents
    let
        bs = map f as
        f s
            | length s > 10 = s
            | otherwise = [head s] ++ (show $ length s - 2) ++ [last s]

    putStr $ unlines $ bs

main = do
	n <- getLine
	interact$ (unlines.map s).lines
s a
	| length a > 10 = [head a] ++ (show (length a)) ++ [last a]
	| otherwise = a

import Data.List
main = interact $ intercalate "\n" . map solve . tail . lines
solve xs
    | length xs > 10 = [head xs] ++ (show . length $ xs) ++ [last xs]
    | otherwise      = xs

s :: Int -> String -> String
s n word =
  if length word <= n
  then word
  else h ++ [last word]
  where
    h = head word : (show $ (length word) - 2)

solve :: Int -> [String] -> [String]
solve n words =
  map (s n) words

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

main = do
  (n:_) <- readInts
  c <- getContents
  putStrLn (unlines $ solve n (lines c))

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

main = do
    numCases <- fst . fromJust . B.readInt <$> B.getLine
    replicateM_ numCases processCase
    where
        processCase = do
            line <- B.getLine
            if B.length line > 10
                then putStrLn $ (B.head line) : show ((B.length line) - 2) ++ [B.last line]
                else putStrLn . tail . init . show $ line

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

main = do
    numCases <- fst . fromJust . B.readInt <$> B.getLine
    replicateM_ numCases processCase
    where
        processCase = do
            line <- B.getLine
            if B.length line > 10
                then putStrLn $ (B.head line) : show ((B.length line) - 2) ++ [B.last line]
                else putStrLn . tail . init . init . show $ line

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

main = do
    numCases <- fst . fromJust . B.readInt <$> B.getLine
    replicateM_ numCases processCase
    where
        processCase = do
            line <- B.getLine
            if B.length line > 10
                then putStrLn $ (B.head line) : show ((B.length line) - 2) ++ [B.last line]
                else putStrLn . tail . init . init. init . show $ line

import System.IO (readFile, getLine)
import Data.Char (digitToInt)
import Data.List (intercalate)
import Control.Monad (sequence)
import Text.Printf (printf)

abr_internal :: Int -> String -> Maybe (Int, Char)
abr_internal n [h] = Just (n, h)
abr_internal n (h:s) = abr_internal (n + 1) s
abr_internal n [] = Nothing

abbreviate :: String -> String
abbreviate s = case abr_internal 0 s of
                    Nothing -> error "Invalid string passwd"
                    (Just (n, c)) -> if n > 10 then (head s) : (printf "%d" (n - 1)) ++ [c] else s

abbreviateInput :: Int -> IO [String]
abbreviateInput n | n <= 0 = return ([] :: [String])
                  | otherwise = do
                        s <- getLine
                        rtail <- abbreviateInput (n-1)
                        return ((abbreviate s) : rtail)

main = do
    cnt_s <- getLine
    result <- abbreviateInput ((read cnt_s) :: Int)
    mapM putStrLn result

import System.IO
main =
  do
    n <- readLn :: IO Int
    f n

f 0 = return ()
f n =
  do
    s <- getLine
    --let s = read t :: String
    if length s < 10
       then putStrLn s
       else let str = head s : show (length s - 2) ++ [last s]
                in putStrLn str
    f (n-1)

extract (x:xs)=take (read x::Int) xs
f x
	|l<=4 = x
	|otherwise   = head x:(show (l-2)++[last x])
	where l=length x
main=interact$unlines.map f.extract.lines

import Control.Monad

cutString :: String -> String
cutString s
  | (length s) > 10 = [head s] ++ (show ((length s) - 2)) ++ [last s]
  | otherwise = s

readInt :: IO Int
readInt = readLn

main :: IO ()
main = do
  n <- readInt
  strings <- replicateM n getLine
  print $ map cutString strings

main = getLine >> getContents >>= putStrLn . unlines . inout . lines

inout :: [String] -> [String]
inout str = map (func) str

func :: String -> String
func wrd = if length wrd < 9 then wrd else codWrd wrd

codWrd :: String -> String
codWrd wrd = head wrd : cutWrd wrd ++ last wrd :[]
			where cutWrd = show . length . init . tail

main = getLine >> getContents >>= putStrLn . unlines . inout . lines

inout :: [String] -> [String]
inout str = map (func) str

func :: String -> String
func wrd = if length wrd < 10 then wrd else codWrd wrd

codWrd :: String -> String
codWrd wrd = head wrd : cutWrd wrd ++ last wrd :[]
			where cutWrd = show . length . init . tail

{-# LANGUAGE CPP, TemplateHaskell #-}

module Main (
    main
) where

import Control.Monad (unless)
import Data.List (stripPrefix)
import System.Exit (exitFailure)

#ifdef MAIN_FUNCTION
import Test.Framework.TH
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2

import Test.QuickCheck
import Test.HUnit

import Data.List
#endif

abbrevate all@(h:s)
    | len <=10 = all
    | otherwise = [h] ++ show (len - 2) ++ [head $ reverse s]
    where len = length all

process 0 = do
    return ()
process n = do
    s <- getLine
    print (abbrevate s)
    process (n-1)

exeMain = do
    [n] <- (map read . words) `fmap` getLine

    process n

-- Tests --

#ifdef MAIN_FUNCTION
testMain = $(defaultMainGenerator)

#endif

#ifndef MAIN_FUNCTION
#define MAIN_FUNCTION exeMain
#endif
main = MAIN_FUNCTION

f s
  | length s < 10 = s
  | otherwise = head s:show (l-2) ++ [last s]
  where l = length s
main =
    interact $ unlines.map f .tail.lines

f s
  | length s < 10 = s
  | otherwise = head s:show (l-2) ++ [last s]
  where l = length s
main =
    interact $ unlines.map f .lines

len [] = 0
len (x:xs) = (len xs) + 1

llast [x] = x
llast (x:xs) = llast xs

solve (x:xs) | (len xs - 1) > 4 = [x] ++ show (len xs - 1) ++ [llast xs]
             | otherwise        = [x] ++ xs

doSolve 0 = putStr ""
doSolve n = do
	line <- getLine
	putStrLn (solve line)
	doSolve (n-1)

main = do
	line <- getLine
	doSolve (read line :: Integer)

len [] = 0
len (x:xs) = (len xs) + 1

llast [x] = x
llast (x:xs) = llast xs

solve (x:xs) | (len xs) > 10 = [x] ++ show (len xs - 1) ++ [llast xs]
             | otherwise     = [x] ++ xs

doSolve 0 = putStr ""
doSolve n = do
	line <- getLine
	putStrLn (solve line)
	doSolve (n-1)

main = do
	line <- getLine
	doSolve (read line :: Integer)

len [] = 0
len (x:xs) = (len xs) + 1

llast [x] = x
llast (x:xs) = llast xs

solve (x:xs) | (len xs - 1) > 10 = [x] ++ show (len xs - 1) ++ [llast xs]
             | otherwise         = [x] ++ xs

doSolve 0 = putStr ""
doSolve n = do
	line <- getLine
	putStrLn (solve line)
	doSolve (n-1)

main = do
	line <- getLine
	doSolve (read line :: Integer)

import Control.Applicative
import qualified Data.ByteString.Char8 as B
import Text.Printf

main = do
  n <- read <$> getLine
  mapM_ (\_ -> do
    s <- B.getLine
    let m = B.length s
    if m > 10 then
      printf "%c%d%c\n" (B.head s) (m-2) (B.last s)
    else B.putStrLn s
    ) [1..n]

abbreviate :: String -> String
abbreviate input
  | (length input) <= 10 = input
  |  otherwise = (\str -> [head str] ++ (show $ (length str) - 2) ++ [last str]) input

main = interact abbreviate

module Main where

main :: IO ()
main = do
  n <- getLine
  let
    go n =
      if n == 0 then
        return ()
      else do
        line <- getLine
        (putStrLn . shortenString) line
        go $ n - 1
  go $ read n

shortenString :: String -> String
shortenString string = let
  helper :: Int -> String -> String
  helper n (char : "")
    | n > 10              = head string : (show $ n - 1) ++ [char]
    | otherwise           = string
  helper n (char : chars) = helper (n + 1) chars
  in helper 0 string

main=interact$unlines.map f.tail.lines
l=length
f x|l x<10=x|1>0=(head x:show(l x))++[last x]

main=interact$unlines.map f.tail.lines
l=length
f x|l x<11=x|1>0=(head x:show(l x))++[last x]

convertStr contents = if (length contents) > 10 then print ([(contents !! 0)] ++ (show ((length contents) - 2)) ++ [(contents !! ((length contents) - 1))]) else print contents

outputI18 1 = do
    contents <- getLine
    convertStr contents
outputI18 n = do
    contents <- getLine
    convertStr contents
    outputI18 (n-1)

main = do
    input1 <- getLine
    let n = (read input1 :: Int)
    outputI18 n

module Main where

import Control.Arrow

main = do
  n:ws <- lines `fmap` getContents
  putStr $ ($ ws) $ take (read n) >>> map abbreviation >>> unlines
    where abbreviation w
            | length w > 10 = head w: show (length w) ++ [last w]
            | otherwise = w

import Control.Monad
import Data.List
import Data.Maybe
import Data.Char

import qualified Data.ByteString.Char8 as B
readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

abbrWord :: String -> String
abbrWord s
    | length s <= 10 = s
    | otherwise      = [head s] ++ show ((-) (length s) 2) ++ [last s]

main :: IO ()
main = do
    n <- readInt
    xs <- replicateM n $ getLine
    print xs
    mapM_ putStrLn $ map abbrWord xs

import Control.Monad

shorten :: String -> String
shorten w | length w > 10 = [head w] ++ show (length w - 2) ++ [last w]
          | otherwise = "test"

main = do n <- fmap read getLine
          strings <- sequence $ take n (repeat getLine)
          forM_ strings (putStrLn . shorten)

main = do
  n <- fmap read getLine :: IO Int
  rep n solve

rep 0 x = return ()
rep n x = x >> rep (n-1) x

solve :: IO ()
solve = do
  cs <- getLine
  let l = length cs
  putStrLn $
    if l > 4
    then (head cs) : (show (l-2))++[(last cs)]
    else cs

main = do
  n <- fmap read getLine :: IO Int
  rep n solve

rep 0 x = return ()
rep n x = print n >> x >> rep (n-1) x

solve :: IO ()
solve = do
  cs <- getLine
  let l = length cs
  putStrLn $
    if l > 4
    then (head cs) : (show (l-2))++[(last cs)]
    else cs

module Main where

isTooLong word = length word > 10
lengthBetweenFirstAndLast word = length word - 2
solveCases remainingCases results = do
    word <- getLine
    let result = if isTooLong word then ([head word] ++ (show $ lengthBetweenFirstAndLast word) ++ [last word]) else word
    if remainingCases - 1 > 0 then solveCases (remainingCases - 1) (results ++ [result]) else return (results ++ [result])

main = do
    line <- getLine
    let caseCount = read line :: Int
    results <- solveCases caseCount []
    mapM print results

f w = let n = length w in if n<10 then w else [w!!0] ++ show (n-2) ++ [w!!(n-1)]

g _ = do
    w <- getLine
    print . f $ w

main = do
    n <- getLine
    mapM_  g [1..read$n]

f w = let n = length w in if n<10 then w else [w!!0] ++ show (n-2) ++ [w!!(n-1)]

g _ = do
    w <- getLine
    putStrLn . f $ w

main = do
    n <- getLine
    mapM_  g [1..read$n]

shorten s | length s < 10 = s
          | otherwise     = head s : show (length s - 2) ++ [last s]
main = interact $ unlines . map shorten . tail . lines

func [] = []
func str
     |(length str > 4) =
          let
               left = head str
               center = (show $ length $ tail $ init str)
               right = last str
          in  reverse ((:) right (reverse ((:) left center)))
     |otherwise = str
main :: IO()
main = do
   a <- getLine
   putStrLn $ func a

func x
     |((length x) < 10) = x
     |otherwise = (:) (head x) (reverse ((:) (last x) (reverse $ show ((length x) - 2))))
main :: IO()
main = do
     a <- getLine
     print $ func a

func [] = []
func str
     |(length str > 4) =
          let
               left = head str
               center = (show $ length $ tail $ init str)
               right = last str
          in  reverse ((:) right (reverse ((:) left center)))
     |otherwise = str

func2 :: Int -> IO()
func2 n =
     if n > 0
     then do
               str <- getLine
               putStrLn $ func str
               func2 (n - 1)
     else return ()
main :: IO()
main = do
   a <- getLine
   func2 (read a::Int)

import Control.Applicative
import Control.Monad

solve s = if len > 10 then concat [[f], show len, [l]] else s
	where	len = (length s) - 2
		l = last s
		(f:_) = s

main = do
	sn <- getLine
	let n = read sn :: Int
	forM [1..n]	(\_ -> do
				ln <- solve <$> getLine
				putStrLn $ ln
			)
	return ()

import Control.Applicative
import Control.Monad

solve s = if len > 10 then concat [[f], show len, [l]] else s
	where	len = (length s) - 2
		l = last s
		(f:_) = s

main = do
	sn <- getLine
	let n = read sn :: Int
	res <- forM [1..n]	(\_ -> do
					solve <$> getLine
				)
	mapM putStrLn res
	return ()

f s = if 10 < length s then
        [head s] ++ (show $ len s) ++ [last s]
      else
        s
  where len s = length $ init $ tail s

main = interact $ (++ "\n")
  . f
  . head . lines

import Control.Monad

main = do
    lines <- getLine
    let cases = read lines :: Int
    results <- forM [1..cases] (\_ -> do
        line <- getLine
        let result = solve line
        return result)
    mapM putStrLn results

solve :: String -> String
solve s
    | length s <= 4 = s
    | otherwise     = [head s] ++ (show (length s - 2)) ++ [last s]

main :: IO ()
main = do
    word <- getLine
    putStrLn $ compress word

compress :: String -> String
compress str
    | tooLong str   = first ++ len ++ final
    | otherwise       = str
    where first = [head str]
          len   = show $ length str - 2
          final = [last str]

tooLong :: String -> Bool
tooLong str = length str > 10

main :: IO ()
main = do
    n <- getInt
    ls <- getContents
    putStrLn $ (unlines . map compress . take n . lines) (tail ls)

compress :: String -> String
compress str
    | tooLong str   = first ++ len ++ final
    | otherwise       = str
    where first = [head str]
          len   = show $ length str - 2
          final = [last str]

tooLong :: String -> Bool
tooLong str = length str > 10

getInt :: IO Int
getInt = do
    n <- getLine
    return $ read n

import Control.Monad (replicateM)

charToString :: Char -> String
charToString ch = [ch]

createAbbreviation :: String -> String
createAbbreviation str =
    (charToString $ head str) ++ (show $ (length str - 2)) ++ (charToString $ last str)

processString :: String -> String
processString str
    | (length str) > 10 = createAbbreviation str
    | otherwise = str

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

processCount :: IO Int
processCount = fmap read getLine

processItems :: Int -> IO [String]
processItems n =
    getLines n >>= return . fmap processString

main :: IO ()
main = do
    count <- processCount
    items <- processItems count
    print items

import Control.Monad (replicateM)

charToString :: Char -> String
charToString ch = [ch]

createAbbreviation :: String -> String
createAbbreviation str =
    (charToString $ head str) ++ (show $ length str) ++ (charToString $ last str)

processString :: String -> String
processString str
    | (length str) > 10 = createAbbreviation str
    | otherwise = str

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

processCount :: IO Int
processCount = fmap read getLine

processItems :: Int -> IO [String]
processItems n =
    getLines n >>= return . fmap processString

main :: IO ()
main = do
    count <- processCount
    items <- processItems count
    print items

main = interact f
f s | length s > 10 = [head s] ++ show ( (length s) - 2 ) ++ [last s]
    | otherwise = s

shorten :: String -> String
shorten s
  | length s <= 10 = s
  | otherwise = [head s] ++ show (length s - 2) ++ [last s]

solve :: String -> String
solve input = unlines $ map shorten $ lines input

main :: IO ()
main = interact solve

module Main where

import Control.Monad (replicateM_)
import Data.Maybe (fromJust)
import qualified Data.ByteString.Char8 as BS

readNumber :: IO Int
readNumber = (fromJust . fmap fst . BS.readInt) `fmap` BS.getLine

abbreviateWord :: BS.ByteString -> BS.ByteString
abbreviateWord w =
    BS.concat [ BS.pack [firstLetter]
              , BS.pack (show ((BS.length w) - 2))
              , BS.pack [lastLetter] ]
  where
    firstLetter = BS.head w
    lastLetter  = BS.head (BS.reverse w)

main :: IO ()
main = do
  nCases <- readNumber
  replicateM_ nCases $ do
    word <- BS.getLine
    BS.putStrLn (if (BS.length word) > 10
                 then abbreviateWord word
                 else word)

module Main where

import Control.Monad (replicateM_)
import Data.Maybe (fromJust)
import qualified Data.ByteString.Char8 as BS

readNumber :: IO Int
readNumber = (fromJust . fmap fst . BS.readInt) `fmap` BS.getLine

abbreviateWord :: BS.ByteString -> BS.ByteString
abbreviateWord w =
    BS.concat [ firstLetter
              , BS.pack (show ((BS.length w) - 2))
              , lastLetter ]
  where
    firstLetter = BS.take 1 w
    lastLetter  = BS.take 1 (BS.reverse w)

main :: IO ()
main = do
  nCases <- readNumber
  replicateM_ nCases $ do
    word <- BS.getLine
    BS.putStrLn (if (BS.length word) > 10
                 then abbreviateWord word
                 else word)

get_and_parse = do s <- getLine
                   let len = length s
                   if len <= 10
                   then print s
                   else print ([(head s)] ++ (show (len-2)) ++ [(last s)])

work n = if n > 0
         then do get_and_parse
                 work (n-1)
         else return ()

main = do s <- getLine
          let num = read s :: Int
          work num

import Control.Monad (forM_)

main = (\x -> forM_ [1..x] $ const (((\ y -> if length y > 10 then head y:(show $ length y) ++ last y:[] else y) <$> getLine) >>= putStrLn)) =<< (readLn :: IO Int)

import Control.Applicative
import Control.Monad

onecase= do
		x<-getLine
		let s= length x
		if s <=10 then print s else print $ [(head x )] ++show(s-2) ++[(last x)]

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

module Main where
import Control.Applicative
import Data.List
import Text.Printf
import Data.Time
import Data.Time.Calendar

text = [ "4"
       , "word"
       , "localization"
       , "internationalization"
       , "pneumonoultramicroscopicsilicovolcanoconiosis"
       ]

f text = [f] ++ show (len - 2) ++ [l]
    where
      len = length text
      f   = head text
      l   = last text

main = do { _:ts <- lines <$> getContents
          ; mapM_ (printf "%s\n") . map f $ ts
          }

module Main where
import Control.Applicative
import Data.List
import Text.Printf
import Data.Time
import Data.Time.Calendar

text = [ "4"
       , "word"
       , "localization"
       , "internationalization"
       , "pneumonoultramicroscopicsilicovolcanoconiosis"
       ]

f text = [f] ++ show (len - 2) ++ [l]
    where
      len = length text
      f   = head text
      l   = last text

main = do { t:ts <- lines <$> getContents
          ; mapM_ (printf "%s\n") . map f $ ts
          }

module Main where
import Control.Applicative
import Data.List
import Text.Printf
import Data.Time
import Data.Time.Calendar

f text = [f] ++ show (len - 2) ++ [l]
    where
      len = length text
      f   = head text
      l   = last text

main = do { t:ts <- lines <$> getContents
          ; print . map f $ ts
          }

{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -cpp #-}
{-# OPTIONS_GHC -funbox-strict-fields -fexcess-precision -monly-3-regs #-}
{-# LANGUAGE BangPatterns, OverloadedStrings, ScopedTypeVariables #-}
module Main where
import Control.Applicative
import Data.List
import Text.Printf
import Data.Time
import Data.Time.Calendar

text = [ "4"
       , "word"
       , "localization"
       , "internationalization"
       , "pneumonoultramicroscopicsilicovolcanoconiosis"
       ]

f text = [f] ++ show (len - 2) ++ [l]
    where
      len = length text
      f   = head text
      l   = last text

main :: IO ()
main = do { _:ts <- lines <$> getContents
          ; mapM_ (printf "%s\n") . map f $ ts
          }

module Main where
import Control.Applicative
import Data.List
import Text.Printf
import Data.Time
import Data.Time.Calendar

main = do { ns <- lines <$> getContents
          ; print ns
          }

shorten :: String -> String
shorten x | length x > 10 = [head x] ++ (show $ length $ init $ tail x) ++ [last x]
          | otherwise     = x

main :: IO ()
main = do cont <- getContents
          mapM_ (putStrLn . shorten) $ lines cont

import Data.Char
import Data.List

ans str = if l<10 then str
               else [head str] ++ show (l-2) ++ [last str]
    where l = length str
main=do
    input<-getContents
    putStr.unlines $ map ans $tail.lines $ input

import Data.Char
import Data.List

ans str = if l<10 then str
               else [head str] ++ show l ++ [last str]
    where l = length str
main=do
    input<-getContents
    putStr.unlines $ map ans $tail.lines $ input


On the well-known testing system MathForces, a draw of $$$n$$$ rating units is arranged. The rating will be distributed according to the following algorithm: if $$$k$$$ participants take part in this event, then the $$$n$$$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants.For example, if $$$n = 5$$$ and $$$k = 3$$$, then each participant will recieve an $$$1$$$ rating unit, and also $$$2$$$ rating units will remain unused. If $$$n = 5$$$, and $$$k = 6$$$, then none of the participants will increase their rating.Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help.For example, if $$$n=5$$$, then the answer is equal to the sequence $$$0, 1, 2, 5$$$. Each of the sequence values (and only them) can be obtained as $$$\lfloor n/k \rfloor$$$ for some positive integer $$$k$$$ (where $$$\lfloor x \rfloor$$$ is the value of $$$x$$$ rounded down): $$$0 = \lfloor 5/7 \rfloor$$$, $$$1 = \lfloor 5/5 \rfloor$$$, $$$2 = \lfloor 5/2 \rfloor$$$, $$$5 = \lfloor 5/1 \rfloor$$$.Write a program that, for a given $$$n$$$, finds a sequence of all possible rating increments.

The first line contains integer number $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each line contains an integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the total number of the rating units being drawn.

Output the answers for each of $$$t$$$ test cases. Each answer should be contained in two lines. In the first line print a single integer $$$m$$$ — the number of different rating increment values that Vasya can get. In the following line print $$$m$$$ integers in ascending order — the values of possible rating increments.

import Data.List
import Control.Monad

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

getNLists :: (Read a) => Int -> IO [[a]]
getNLists n = sequence $ replicate n getList

main :: IO ()
main = do
    t <- readLn
    replicateM_ t $ do
        n <- (readLn :: IO Int)
        let ans = myNub . sort $ f n in
            putStrLn $ (show . length $ ans) ++ "\n" ++
                (unwords . map show $ ans)

f :: Int -> [Int]
f x = 0 : x : c x 1

c :: Int -> Int -> [Int]
c x i
    | z > x = []
    | z == x = [i]
    | and [div x i == d, div x d == i] = i : d : (c x $ i + 1)
    | otherwise = c x $ i + 1
    where d = div x i
          z = i * i

myNub :: [Int] -> [Int]
myNub [x] = [x]
myNub (x:y:xs)
    | x == y = myNub (y:xs)
    | otherwise = x : myNub (y:xs)

import Data.List
import Control.Monad

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

getNLists :: (Read a) => Int -> IO [[a]]
getNLists n = sequence $ replicate n getList

main :: IO ()
main = do
    t <- readLn
    replicateM_ t $ do
        n <- (readLn :: IO Int)
        let ans = sort $ f n in
            putStrLn $ (show . length $ ans) ++ "\n" ++
                (unwords . map show $ ans)

f :: Int -> [Int]
f x = 0 : c x 1

c :: Int -> Int -> [Int]
c x i
    | z > x = []
    | d == div x d = [d]
    | and [div x i == d, div x d == i] = i : d : (c x $ i + 1)
    | otherwise = c x $ i + 1
    where d = div x i
          z = i * i

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

main = getLine >>= test.read
test 0 = return ()
test i = do
  n <- read <$> getLine
  let vs = solve n
  print $ length vs
  putStrLn $ unwords $ map show vs
  test (i - 1)

solve n = map head $ group $ sort $ as ++ bs where
  r = floor $ sqrt $ fromIntegral n
  as = [0..r]
  bs = map (div n) [1..r]

--solve :: Int -> (Int,[Int])
import Data.List
import Control.Monad
--solve :: Int -> Int
solve x = (n,l3)
	where
		n = (if b then x2*2 else x2*2+1)
		x2 = (floor.sqrt.fromIntegral) x
		b = x2 ^2 +x2 > x
		l1=[0..x2]
		l2=map (\y -> x `div` y) (tail l1)
		l3 = if b then l1 ++ (tail $ reverse l2) else l1 ++ (reverse l2)

routine = do
	n <- readLn
	let (x,y)=solve n
	print x
	putStrLn $ unwords $ map show y

main= do
	n <- readLn
	replicateM_ n routine

import Data.List
import Control.Monad

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

getNLists :: (Read a) => Int -> IO [[a]]
getNLists n = sequence $ replicate n getList

main :: IO ()
main = do
    t <- readLn
    replicateM_ t $ do
        n <- (readLn :: IO Int)
        let ans = sort $ f n in
            putStrLn $ (show . length $ ans) ++ "\n" ++
                (unwords . map show $ ans)

f :: Int -> [Int]
f x = 0 : c x 1

c :: Int -> Int -> [Int]
c x i
    | z > x = []
    | d == div x i = [i]
    | and [div x i == d, div x d == i] = i : d : (c x $ i + 1)
    | otherwise = c x $ i + 1
    where d = div x i
          z = i * i

import Data.List
import Control.Monad

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

getNLists :: (Read a) => Int -> IO [[a]]
getNLists n = sequence $ replicate n getList

main :: IO ()
main = do
    t <- readLn
    replicateM_ t $ do
        n <- (readLn :: IO Int)
        let ans = sort $ f n in
            putStrLn $ (show . length $ ans) ++ "\n" ++
                (unwords . map show $ ans)

f :: Int -> [Int]
f x = 0 : c x 1

c :: Int -> Int -> [Int]
c x i
    | z > x = []
    | z == x = [i]
    | and [div x i == d, div x d == i] = i : d : (c x $ i + 1)
    | otherwise = c x $ i + 1
    where d = div x i
          z = i * i


Bertown is a city with $$$n$$$ buildings in a straight line.The city's security service discovered that some buildings were mined. A map was compiled, which is a string of length $$$n$$$, where the $$$i$$$-th character is "1" if there is a mine under the building number $$$i$$$ and "0" otherwise.Bertown's best sapper knows how to activate mines so that the buildings above them are not damaged. When a mine under the building numbered $$$x$$$ is activated, it explodes and activates two adjacent mines under the buildings numbered $$$x-1$$$ and $$$x+1$$$ (if there were no mines under the building, then nothing happens). Thus, it is enough to activate any one mine on a continuous segment of mines to activate all the mines of this segment. For manual activation of one mine, the sapper takes $$$a$$$ coins. He can repeat this operation as many times as you want.Also, a sapper can place a mine under a building if it wasn't there. For such an operation, he takes $$$b$$$ coins. He can also repeat this operation as many times as you want.The sapper can carry out operations in any order.You want to blow up all the mines in the city to make it safe. Find the minimum number of coins that the sapper will have to pay so that after his actions there are no mines left in the city.

The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case begins with a line containing two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 1000$$$) — the cost of activating and placing one mine, respectively. The next line contains a map of mines in the city — a string consisting of zeros and ones. The sum of the string lengths for all test cases does not exceed $$$10^5$$$.

For each test case, output one integer — the minimum number of coins that the sapper will have to pay.

NoteIn the second test case, if we place a mine under the fourth building and then activate it, then all mines on the field are activated. The cost of such operations is six, $$$b=1$$$ coin for placing a mine and $$$a=5$$$ coins for activating.

{-# LANGUAGE ViewPatterns #-}

import Control.Arrow ((>>>))
import Data.List (dropWhileEnd, group)

main :: IO ()
main = interact $ words >>> drop 1 >>> process >>> map show >>> unlines

process :: [String] -> [Int]
process [] = []
process ((read -> a):(read -> b):xs:xss) = solve a b xs : process xss

solve :: Int -> Int -> String -> Int
solve a b = sum . map cost . group . dropWhile (== '0') . dropWhileEnd (== '0')
  where
    cost ys
      | head ys == '0' = min 0 $ b * length ys - a
      | otherwise = a

import Control.Monad
import Data.List
import Data.Ord

main :: IO ()
main = do
    t <- read <$> getLine
    replicateM_ t $ do
        [a, b] <- map read . words <$> getLine :: IO [Int]
        s <- getLine
        print $! solve a b s

trimZeros = f . f
          where f = dropWhile (=='0') . reverse

solve :: Int -> Int -> String -> Int
solve a b s = if o > 0 then minimum $ zipWith (+) [o, o-a..a] $ scanl (+) 0 z else 0
    where t = group $ trimZeros s
          o = a * (length $ filter ((=='1') . head) t)
          z = sort $ map ((b*). length) $ filter ((=='0') . head) t

import Control.Monad
import Data.List
import Data.Ord

main :: IO ()
main = do
    t <- read <$> getLine
    replicateM_ t $ do
        [a, b] <- map read . words <$> getLine :: IO [Int]
        s <- getLine
        print $! solve a b $ trimZeros s

trimZeros = f . f
          where f = dropWhile (=='0') . reverse

solve :: Int -> Int -> String -> Int
solve _ _ [] = 0
solve a b s = minimum $ zipWith (+) [o, o-a..a] $ scanl (+) 0 z
    where t = group s
          o = a * (length $ filter ((=='1') . head) t)
          z = sort $ map ((b*). length) $ filter ((=='0') . head) t

import Control.Monad
import Data.List
import Data.Ord

main :: IO ()
main = do
    t <- read <$> getLine
    replicateM_ t $ do
        [a, b] <- map read . words <$> getLine :: IO [Int]
        s <- getLine
        print $! solve a b s

trimZeros = f . f
          where f = dropWhile (=='0') . reverse

solve :: Int -> Int -> String -> Int
solve a b s = foldl min 0 $ zipWith (+) [o, o-a..a] $ scanl (+) 0 z
    where t = group $ trimZeros s
          o = a * (length $ filter ((=='1') . head) t)
          z = sort $ map ((b*). length) $ filter ((=='0') . head) t


Harry, Ron and Hermione have figured out that Helga Hufflepuff's cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatrix's family vault in Gringott's Wizarding Bank. The Wizarding bank is in the form of a tree with total n vaults where each vault has some type, denoted by a number between 1 to m. A tree is an undirected connected graph with no cycles.The vaults with the highest security are of type k, and all vaults of type k have the highest security.There can be at most x vaults of highest security. Also, if a vault is of the highest security, its adjacent vaults are guaranteed to not be of the highest security and their type is guaranteed to be less than k.Harry wants to consider every possibility so that he can easily find the best path to reach Bellatrix's vault. So, you have to tell him, given the tree structure of Gringotts, the number of possible ways of giving each vault a type such that the above conditions hold.

The first line of input contains two space separated integers, n and m — the number of vaults and the number of different vault types possible. (1 ≤ n ≤ 105, 1 ≤ m ≤ 109). Each of the next n - 1 lines contain two space separated integers ui and vi (1 ≤ ui, vi ≤ n) representing the i-th edge, which shows there is a path between the two vaults ui and vi. It is guaranteed that the given graph is a tree. The last line of input contains two integers k and x (1 ≤ k ≤ m, 1 ≤ x ≤ 10), the type of the highest security vault and the maximum possible number of vaults of highest security.

Output a single integer, the number of ways of giving each vault a type following the conditions modulo 109 + 7.

NoteIn test case 1, we cannot have any vault of the highest security as its type is 1 implying that its adjacent vaults would have to have a vault type less than 1, which is not allowed. Thus, there is only one possible combination, in which all the vaults have type 2.

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

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

app = do
  n <- poi
  show `fmap` liftM4 (solve n) poi (replicateM (n - 1) $ liftM2 (,) poi poi) poi poi
  where
  pop = state $ \(x:xs) -> (x, xs)
  poi = fmap int pop
  int = maybe undefined fst . B.readInt

solve n m0 es k0 x = (\(lt, eq, gt) -> sum lt + sum eq + sum gt) $ dfs (accumArray (flip (:)) [] (1, n) $ concatMap (\(a, b) -> [(a, b), (b, a)]) es) (\_ ->  (\(!lt, !eq, !gt) -> (map ((k - 1) *) lt, 0:eq, map ((m - k) *) gt)) . foldl' (\(!lt, !eq, !gt) (clt, ceq, cgt) -> (combine x lt $ zipWith3 (((+) .) . (+)) clt ceq cgt, combine (x - 1) eq clt, combine x gt $ zipWith (+) clt cgt)) def)
  where
  def = let d = 1:replicate x 0 in (d, d, d)
  k = fromIntegral k0
  m = fromIntegral m0
  combine hi xs ys = map Mnum $ elems (accumArray (+) 0 (0, hi) [(i + j, getMnum $ x' * y) | (i, x') <- ix xs, (j, y) <- ix ys, i + j <= hi] :: UArray Int Int64)
    where ix = zip [0..]

dfs :: Array Int [Int] -> (Int -> [b] -> b) -> b
dfs g f = go 0 1
  where go p u = f u $ map (go u) $ filter (/= p) (g!u)

mbase = 1000000007
newtype Mnum = Mnum { getMnum :: Int64 }
instance Show Mnum where
  show (Mnum x) = show x
instance Num Mnum where
  (Mnum a) + (Mnum b) = Mnum $ (a + b) `rem` mbase
  (Mnum a) * (Mnum b) = Mnum $ (a * b) `rem` mbase
  (Mnum a) - (Mnum b) = Mnum $ (a - b) `mod` mbase
  fromInteger = Mnum . fromInteger

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

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

app = do
  n <- poi
  show `fmap` liftM4 (solve n) poi (replicateM (n - 1) $ liftM2 (,) poi poi) poi poi
  where
  pop = state $ \(x:xs) -> (x, xs)
  poi = fmap int pop
  int = maybe undefined fst . B.readInt

solve n m0 es k0 x = (\(lt, eq, gt) -> sum lt + sum eq + sum gt) $ dfs (accumArray (flip (:)) [] (1, n) $ concatMap (\(a, b) -> [(a, b), (b, a)]) es) (\_ ->  (\(lt, eq, gt) -> (map ((k - 1) *) lt, 0:eq, map ((m - k) *) gt)) . foldl' (\(!lt, !eq, !gt) (clt, ceq, cgt) -> (combine x lt $ zipWith3 (((+) .) . (+)) clt ceq cgt, combine (x - 1) eq clt, combine x gt $ zipWith (+) clt cgt)) def)
  where
  def = let d = 1:replicate x 0 in (d, d, d)
  k = fromIntegral k0
  m = fromIntegral m0
  combine hi xs ys = map Mnum $ elems (accumArray (+) 0 (0, hi) [(i + j, getMnum $ x' * y) | (i, x') <- ix xs, (j, y) <- ix ys, i + j <= hi] :: UArray Int Int64)
    where ix = zip [0..]

dfs :: Array Int [Int] -> (Int -> [b] -> b) -> b
dfs g f = go 0 1
  where go p u = f u $ map (go u) $ filter (/= p) (g!u)

mbase = 1000000007
newtype Mnum = Mnum { getMnum :: Int64 }
instance Show Mnum where
  show (Mnum x) = show x
instance Num Mnum where
  (Mnum a) + (Mnum b) = Mnum $ (a + b) `rem` mbase
  (Mnum a) * (Mnum b) = Mnum $ (a * b) `rem` mbase
  (Mnum a) - (Mnum b) = Mnum $ (a - b) `mod` mbase
  fromInteger = Mnum . fromInteger

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

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

app = do
  n <- poi
  show `fmap` liftM4 (solve n) poi (replicateM (n - 1) $ liftM2 (,) poi poi) poi poi
  where
  pop = state $ \(x:xs) -> (x, xs)
  poi = fmap int pop
  int = maybe undefined fst . B.readInt

solve n m0 es k0 x = (\(!lt, !eq, !gt) -> sum lt + sum eq + sum gt) $ dfs (accumArray (flip (:)) [] (1, n) $ concatMap (\(a, b) -> [(a, b), (b, a)]) es) (\_ ->  (\(!lt, !eq, !gt) -> (map ((k - 1) *) lt, 0:eq, map ((m - k) *) gt)) . foldl' (\(!lt, !eq, !gt) (!clt, !ceq, !cgt) -> (combine x lt $ zipWith3 (((+) .) . (+)) clt ceq cgt, combine (x - 1) eq clt, combine x gt $ zipWith (+) clt cgt)) def)
  where
  def = (d, d, d)
    where d = 1:replicate x 0
  k = Mnum $ fromIntegral k0
  m = Mnum $ fromIntegral m0
  combine hi xs ys = map Mnum $ elems (accumArray (+) 0 (0, hi) [(i + j, getMnum $ x' * y) | (i, x') <- ix xs, (j, y) <- ix ys, i + j <= hi] :: UArray Int Int64)
    where ix = zip [0..]

dfs :: Array Int [Int] -> (Int -> [b] -> b) -> b
dfs g f = go 0 1
  where go p u = f u $ map (go u) $ filter (/= p) (g!u)

mbase = 1000000007
newtype Mnum = Mnum { getMnum :: Int64}
instance Show Mnum where
  show (Mnum x) = show x
instance Num Mnum where
  (Mnum a) + (Mnum b) = Mnum $ (a + b) `rem` mbase
  (Mnum a) * (Mnum b) = Mnum $ (a * b) `rem` mbase
  (Mnum a) - (Mnum b) = Mnum $ (a - b) `mod` mbase
  fromInteger = Mnum . fromInteger

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

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

app = do
  n <- poi
  show `fmap` liftM4 (solve n) poi (replicateM (n - 1) $ liftM2 (,) poi poi) poi poi
  where
  pop = state $ \(x:xs) -> (x, xs)
  poi = fmap int pop
  int = maybe undefined fst . B.readInt

solve n m0 es k0 x = (\(!lt, !eq, !gt) -> sum lt + sum eq + sum gt) $ dfs (accumArray (flip (:)) [] (1, n) $ concatMap (\(a, b) -> [(a, b), (b, a)]) es) (\_ ->  (\(!lt, !eq, !gt) -> (map ((k - 1) *) lt, 0:eq, map ((m - k) *) gt)) . foldl' (\(!lt, !eq, !gt) (!clt, !ceq, !cgt) -> (combine lt $ zipWith3 (((+) .) . (+)) clt ceq cgt, combine eq clt, combine gt $ zipWith (+) clt cgt)) def)
  where
  def = (d, d, d)
    where d = 1:replicate x 0
  k = Mnum $ fromIntegral k0
  m = Mnum $ fromIntegral m0
  combine xs ys = map Mnum $ elems (accumArray (+) 0 (0, x) [(i + j, getMnum $ x' * y) | (i, x') <- ix xs, (j, y) <- ix ys, i + j <= x] :: UArray Int Int64)
    where ix = zip [0..]

dfs :: Array Int [Int] -> (Int -> [b] -> b) -> b
dfs g f = go 0 1
  where go p u = f u $ map (go u) $ filter (/= p) (g!u)

mbase = 1000000007
newtype Mnum = Mnum { getMnum :: Int64}
instance Show Mnum where
  show (Mnum x) = show x
instance Num Mnum where
  (Mnum a) + (Mnum b) = Mnum $ (a + b) `rem` mbase
  (Mnum a) * (Mnum b) = Mnum $ (a * b) `rem` mbase
  (Mnum a) - (Mnum b) = Mnum $ (a - b) `mod` mbase
  fromInteger = Mnum . fromInteger