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

main = do
  [n, m] <- fmap (map (fst . fromJust . C.readInt) . C.words) C.getLine
  s <- replicateM n C.getLine
  case solve n m s of
    Nothing -> putStrLn "Never"
    Just ans -> print ans

solve n m s = gao (1, 1, 1, True, 2) (0 :: Int64)
  where
  a = listArray (1, n) $ map (\i -> C.concat [C.pack "#", C.take m i, C.pack "#"]) s
  c i j = C.index (a!i) j
  gao (k, l, r, dir, ttl) ans
    | k >= n           = Just ans
    | c (k+1) p == '.' = gao (k + 1, p, p, dir, 2) $ ans + 1
    | ttl < 0          = Nothing
    | otherwise        =
      case c k q of
        '.' -> gao (k, l', r', dir, 2) $ ans + 1
        '+' -> gao (k, l', r', not dir, 2) $ ans + 1 + fromIntegral (r - l)
        '#' -> gao (k, l, r, not dir, ttl - 1) $ ans + 1 + fromIntegral (r - l)
    where
      (p, q, l', r') = ans `seq`
        if dir
          then (r, r + 1, l, r + 1)
          else (l, l - 1, l - 1, r)

{-
C.take m i  -- '\r'
ans `seq`   --  Runtime error on test 8
-}

import System.IO
import Data.List
import Data.Function(on)

data Dir = DLeft | DRight deriving (Eq)

solve :: [String] -> Int -> Dir -> Maybe Integer
solve (l1:[]) pos _ = Just 0
solve (l1:l2:xs) pos dir
    | (l2!!pos == '.') =
        let v = solve(l2:xs) pos dir
        in case v of Nothing -> Nothing
                     Just x -> Just (1 + x)
    | otherwise = let
                    n = (length l1) - 1
                    (leftPart, _:rightPart) = splitAt pos l2
                    leftPos' = findIndices (=='.') leftPart
                    rightPos' = findIndex (=='.') rightPart
                    leftPos = if (not $ null leftPos') then (last leftPos') else 0
                    rightPos = case rightPos' of
                                    Nothing -> n
                                    Just x -> pos + 1 + x
                    (upLeftPart, _:upRightPart) = splitAt pos l1
                    blockLeft = last $ findIndices (=='#') upLeftPart
                    blockRight = pos + 1 + (head $ findIndices (=='#') upRightPart)
                    leftIndexed = zip upLeftPart [0..]
                    rightIndexed = zipWith (\x y -> (x, y + pos + 1)) upRightPart [0..]
                    in if (blockLeft >= leftPos && blockRight <= rightPos) then Nothing
                       else if blockRight > rightPos && blockLeft >= leftPos then
                            let
                                takeRight = (:) ('.', rightPos + 1) $ filter ((=='+').fst) $ takeWhile (\(x, y) -> y <= rightPos) rightIndexed
                                stepsRight = length takeRight
                                stepsLeft = stepsRight - (if dir == DRight then 1 else 0)
                                takeLeft' = take stepsLeft $ filter ((=='+').fst) $ takeWhile (\(x, y) -> x /= '#') $ reverse leftIndexed
                                takeLeft = (replicate (max 0 $ stepsLeft - length takeLeft') ('#', blockLeft)) ++ takeLeft'
                                nextAnswer = solve (l2:xs) rightPos DRight
                                -- nextAnswer = Just 0
                                in
                                -- Just (snd $ head takeRight)
                                -- Just (2 * foldl (\s (x, y) -> s + y - 1) 0 takeRight - 2 * (length takeRight) * pos)
                                -- Just ((computeTake takeLeft takeRight pos))
                                -- nextAnswer
                                case nextAnswer of
                                    Nothing -> Nothing
                                    (Just x) -> Just (x + (toInteger $ (computeTake takeLeft takeRight pos) - abs (pos - rightPos) + 1))
                        else if (blockLeft < leftPos && blockRight <= rightPos) then
                            let
                                takeLeft = (:) ('.', leftPos - 1) $ filter ((=='+').fst) $ takeWhile (\(x, y) -> y >= leftPos) $ reverse leftIndexed
                                stepsLeft = length takeLeft
                                stepsRight = stepsLeft - (if dir == DLeft then 1 else 0)
                                takeRight' = take stepsRight $ filter ((=='+').fst) $ takeWhile (\(x, y) -> x /= '#') rightIndexed
                                takeRight = (++) takeRight' $ replicate (max 0 $ stepsRight - length takeRight') ('#', blockRight)
                                nextAnswer = solve (l2:xs) leftPos DLeft
                                in
                                -- Just (length takeRight)
                                case nextAnswer of
                                    Nothing -> Nothing
                                    (Just x) -> Just (x + (toInteger $ (computeTake takeLeft takeRight pos) - abs (pos - leftPos) + 1))
                        else
                            let
                                takeLeft' = filter ((=='+').fst) $ takeWhile (\(x, y) -> y >= leftPos) $ reverse leftIndexed
                                takeRight' = filter ((=='+').fst) $ takeWhile (\(x, y) -> y <= rightPos) rightIndexed
                                minLength = (min `on` length) takeLeft' takeRight'
                                lengthLeft = length takeLeft'
                                lengthRight = length takeRight'
                                (nextPos, nextDir) = if lengthLeft == lengthRight then
                                                        if dir == DLeft then (leftPos, DLeft)
                                                        else (rightPos, DRight)
                                                     else if lengthLeft < lengthRight then (leftPos, DLeft)
                                                     else (rightPos, DRight)
                                stepsLeft = minLength + (if nextDir == DRight && dir == DLeft then 1 else 0)
                                stepsRight = minLength + (if nextDir == DLeft && dir == DRight then 1 else 0)
                                takeLeft = (if nextDir == DLeft then [('.', leftPos - 1)] else []) ++ (take stepsLeft takeLeft')
                                takeRight = (if nextDir == DRight then [('.', rightPos + 1)] else []) ++ (take stepsRight takeRight')
                                nextAnswer = solve (l2:xs) nextPos nextDir
                                -- nextAnswer = 0
                                in
                                -- Just (if nextDir == DRight then 1 else 0)
                                -- Just (2 * (length takeLeft) * pos - 2 * foldl (\s (x, y) -> s + y + 1) 0 takeLeft)
                                -- Just ((computeTake takeLeft takeRight pos)- abs (pos - nextPos) + 1)
                                case nextAnswer of
                                    Nothing -> Nothing
                                    (Just x) -> Just (x + (toInteger $ (computeTake takeLeft takeRight pos) - abs (pos - nextPos) + 1))

    where
        computeTake takeLeft takeRight pos =
            let stepsLeft = length takeLeft; stepsRight = length takeRight in
                (2 * foldl (\s (x, y) -> s + y - 1) 0 takeRight -
                2 * foldl (\s (x, y) -> s + y + 1) 0 takeLeft +
                2 * (stepsLeft - stepsRight) * pos + stepsLeft + stepsRight - 1)

main = do
    firstLine <- getLine
    other <- getContents
    let
        [n, m] = map read $ lines firstLine :: [Int]
        matrix = map (('#':).(++"#")) $ takeWhile (not.null) $ lines other
        in
        -- print $ matrix
        putStrLn $ result $ solve matrix 1 DRight
            where result Nothing = "Never"
                  result (Just x) = show x

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

main = do
  [n, m] <- fmap (map (fst . fromJust . C.readInt) . C.words) C.getLine
  s <- replicateM n C.getLine
  case solve n m s of
    Nothing -> putStrLn "Never"
    Just ans -> print ans

solve n m s = gao 1 (1, 1) True 0
  where
  a = listArray (1, n) $ map (\i -> C.concat [C.pack "#", i, C.pack "#"]) s
  c i j = C.index (a!i) j
  gao k (l, r) d t
    | k == n =
      Just t
    | c (k+1) p == '.' =
      gao (k + 1) (p, p) d $ t + 1
    | c k (l-1) == '#' && c k (r+1) == '#' =
      Nothing
    | otherwise        =
      case c k q of
        '.' -> gao k (l', r') d $ t + 1
        '+' -> gao k (l', r') (not d) $ t + 1 + (r - l)
        '#' -> gao k (l, r) (not d) $ t + 1 + (r - l)
    where
      (p, q, l', r') =
        if d
          then (r, r + 1, l, r + 1)
          else (l, l - 1, l - 1, r)

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

main = do
  [n, m] <- fmap (map (fst . fromJust . C.readInt) . C.words) C.getLine
  s <- replicateM n C.getLine
  case solve n m s of
    Nothing -> putStrLn "Never"
    Just ans -> print ans

solve n m s = gao 1 (1, 1) True 0
  where
  a = listArray (1, n) $ map (\i -> C.concat [C.pack "#", i, C.pack "#"]) s
  c i j = C.index (a!i) j
  gao k (l, r) d t
    | k == n           = Just t
    | l == 1 && r == m = Nothing
    | c (k+1) p == '.' = gao (k + 1) (p, p) d $ t + 1
    | otherwise        =
      case c k q of
        '.' -> gao k (l', r') d $ t + 1
        '+' -> gao k (l', r') (not d) $ t + 1 + (r - l)
        '#' -> gao k (l, r) (not d) $ t + 1 + (r - l)
    where
      (p, q, l', r') =
        if d
          then (r, r + 1, l, r + 1)
          else (l, l - 1, l - 1, r)

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

main = do
  [n, m] <- fmap (map (fst . fromJust . C.readInt) . C.words) C.getLine
  s <- replicateM n C.getLine
  case solve n m s of
    Nothing -> putStrLn "Never"
    Just ans -> print ans

solve n m s = gao (1, 1, 1, True, 2) 0
  where
  a = listArray (1, n) $ map (\i -> C.concat [C.pack "#", C.take m i, C.pack "#"]) s
  c i j = C.index (a!i) j
  gao (k, l, r, dir, ttl) ans
    | l < 1 || r > m   = Nothing
    | k >= n           = Just ans
    | c (k+1) p == '.' = gao (k + 1, p, p, dir, 2) $ ans + 1
    | ttl < 0          = Nothing
    | otherwise        =
      case c k q of
        '.' -> gao (k, l', r', dir, 2) $ ans + 1
        '+' -> gao (k, l', r', not dir, 2) $ ans + 1 + (r - l)
        '#' -> gao (k, l, r, not dir, ttl - 1) $ ans + 1 + (r - l)
    where
      (p, q, l', r') =
        trace (show (k, l, r, dir, ttl, ans)) $
        if dir
          then (r, r + 1, l, r + 1)
          else (l, l - 1, l - 1, r)

import System.IO
import Data.List
import Data.Function(on)

data Dir = DLeft | DRight deriving (Eq)

solve :: [String] -> Int -> Dir -> Maybe Int
solve (l1:[]) pos _ = Just 0
solve (l1:l2:xs) pos dir
    | (l2!!pos == '.') =
        let v = solve(l2:xs) pos dir
        in case v of Nothing -> Nothing
                     Just x -> Just (1 + x)
    | otherwise = let
                    n = (length l1) - 1
                    (leftPart, _:rightPart) = splitAt pos l2
                    leftPos' = findIndices (=='.') leftPart
                    rightPos' = findIndex (=='.') rightPart
                    leftPos = if (not $ null leftPos') then (last leftPos') else 0
                    rightPos = case rightPos' of
                                    Nothing -> n
                                    Just x -> pos + 1 + x
                    (upLeftPart, _:upRightPart) = splitAt pos l1
                    blockLeft = last $ findIndices (=='#') upLeftPart
                    blockRight = pos + 1 + (head $ findIndices (=='#') upRightPart)
                    leftIndexed = zip upLeftPart [0..]
                    rightIndexed = zipWith (\x y -> (x, y + pos + 1)) upRightPart [0..]
                    in if (blockLeft >= leftPos && blockRight <= rightPos) then Nothing
                       else if blockRight > rightPos && blockLeft >= leftPos then
                            let
                                takeRight = (:) ('.', rightPos + 1) $ filter ((=='+').fst) $ takeWhile (\(x, y) -> y <= rightPos) rightIndexed
                                stepsRight = length takeRight
                                stepsLeft = stepsRight - (if dir == DRight then 1 else 0)
                                takeLeft' = take stepsLeft $ takeWhile (\(x, y) -> x /= '#') $ reverse leftIndexed
                                takeLeft = (replicate (max 0 $ stepsLeft - length takeLeft') ('#', blockLeft)) ++ takeLeft'
                                nextAnswer = solve (l2:xs) rightPos DRight
                                -- nextAnswer = Just 0
                                in
                                -- Just (snd $ head takeRight)
                                -- Just (2 * foldl (\s (x, y) -> s + y - 1) 0 takeRight - 2 * (length takeRight) * pos)
                                -- Just ((computeTake takeLeft takeRight pos))
                                -- nextAnswer
                                case nextAnswer of
                                    Nothing -> Nothing
                                    (Just x) -> Just (((+) x $ computeTake takeLeft takeRight pos) - abs (pos - rightPos) + 1)
                        else if (blockLeft < leftPos && blockRight <= rightPos) then
                            let
                                takeLeft = (:) ('.', leftPos - 1) $ filter ((=='+').fst) $ takeWhile (\(x, y) -> y >= leftPos) $ reverse leftIndexed
                                stepsLeft = length takeLeft
                                stepsRight = stepsLeft - (if dir == DLeft then 1 else 0)
                                takeRight' = take stepsRight $ takeWhile (\(x, y) -> x /= '#') rightIndexed
                                takeRight = (++) takeRight' $ replicate (max 0 $ stepsRight - length takeRight') ('#', blockRight)
                                nextAnswer = solve (l2:xs) leftPos DLeft
                                in
                                -- Just (length takeRight)
                                case nextAnswer of
                                    Nothing -> Nothing
                                    (Just x) -> Just (((+) x $ computeTake takeLeft takeRight pos) - abs (pos - leftPos) + 1)
                        else
                            let
                                takeLeft' = filter ((=='+').fst) $ takeWhile (\(x, y) -> y >= leftPos) $ reverse leftIndexed
                                takeRight' = filter ((=='+').fst) $ takeWhile (\(x, y) -> y <= rightPos) rightIndexed
                                minLength = (min `on` length) takeLeft' takeRight'
                                lengthLeft = length takeLeft'
                                lengthRight = length takeRight'
                                (nextPos, nextDir) = if lengthLeft == lengthRight then
                                                        if dir == DLeft then (leftPos, DLeft)
                                                        else (rightPos, DRight)
                                                     else if lengthLeft < lengthRight then (leftPos, DLeft)
                                                     else (rightPos, DRight)
                                stepsLeft = minLength + (if nextDir == DRight && dir == DLeft then 1 else 0)
                                stepsRight = minLength + (if nextDir == DLeft && dir == DRight then 1 else 0)
                                takeLeft = (if nextDir == DLeft then [('.', leftPos - 1)] else []) ++ (take stepsLeft takeLeft')
                                takeRight = (if nextDir == DRight then [('.', rightPos + 1)] else []) ++ (take stepsRight takeRight')
                                nextAnswer = solve (l2:xs) nextPos nextDir
                                -- nextAnswer = 0
                                in
                                -- Just (if nextDir == DRight then 1 else 0)
                                -- Just (2 * (length takeLeft) * pos - 2 * foldl (\s (x, y) -> s + y + 1) 0 takeLeft)
                                -- Just ((computeTake takeLeft takeRight pos)- abs (pos - nextPos) + 1)
                                case nextAnswer of
                                    Nothing -> Nothing
                                    (Just x) -> Just (((+) x $ computeTake takeLeft takeRight pos) - abs (pos - nextPos) + 1)

    where computeTake takeLeft takeRight pos =
            let stepsLeft = length takeLeft; stepsRight = length takeRight in
                (2 * foldl (\s (x, y) -> s + y - 1) 0 takeRight -
                2 * foldl (\s (x, y) -> s + y + 1) 0 takeLeft +
                2 * (stepsLeft - stepsRight) * pos + stepsLeft + stepsRight - 1)

main = do
    firstLine <- getLine
    other <- getContents
    let
        [n, m] = map read $ lines firstLine :: [Int]
        matrix = map (('#':).(++"#")) $ takeWhile (not.null) $ lines other
        in
        -- print $ matrix
        putStrLn $ result $ solve matrix 1 DRight
            where result Nothing = "Never"
                  result (Just x) = show x

import System.IO
import Data.List
import Data.Function(on)

data Dir = DLeft | DRight deriving (Eq)

solve :: [String] -> Int -> Dir -> Maybe Int
solve (l1:[]) pos _ = Just 0
solve (l1:l2:xs) pos dir
    | (l2!!pos == '.') =
        let v = solve(l2:xs) pos dir
        in case v of Nothing -> Nothing
                     Just x -> Just (1 + x)
    | otherwise = let
                    n = (length l1) - 1
                    (leftPart, _:rightPart) = splitAt pos l2
                    leftPos' = findIndices (=='.') leftPart
                    rightPos' = findIndex (=='.') rightPart
                    leftPos = if (not $ null leftPos') then (last leftPos') else 0
                    rightPos = case rightPos' of
                                    Nothing -> n
                                    Just x -> pos + 1 + x
                    (upLeftPart, _:upRightPart) = splitAt pos l1
                    blockLeft = last $ findIndices (=='#') upLeftPart
                    blockRight = pos + 1 + (head $ findIndices (=='#') upRightPart)
                    leftIndexed = zip upLeftPart [0..]
                    rightIndexed = zipWith (\x y -> (x, y + pos + 1)) upRightPart [0..]
                    in if (blockLeft >= leftPos && blockRight <= rightPos) then Nothing
                       else if blockRight > rightPos && blockLeft >= leftPos then
                            let
                                takeRight = (:) ('.', rightPos + 1) $ filter ((=='+').fst) $ takeWhile (\(x, y) -> y <= rightPos) rightIndexed
                                stepsRight = length takeRight
                                stepsLeft = stepsRight - (if dir == DRight then 1 else 0)
                                takeLeft' = take stepsLeft $ filter ((=='+').fst) $ takeWhile (\(x, y) -> x /= '#') $ reverse leftIndexed
                                takeLeft = (replicate (max 0 $ stepsLeft - length takeLeft') ('#', blockLeft)) ++ takeLeft'
                                nextAnswer = solve (l2:xs) rightPos DRight
                                -- nextAnswer = Just 0
                                in
                                -- Just (snd $ head takeRight)
                                -- Just (2 * foldl (\s (x, y) -> s + y - 1) 0 takeRight - 2 * (length takeRight) * pos)
                                -- Just ((computeTake takeLeft takeRight pos))
                                -- nextAnswer
                                case nextAnswer of
                                    Nothing -> Nothing
                                    (Just x) -> Just (((+) x $ computeTake takeLeft takeRight pos) - abs (pos - rightPos) + 1)
                        else if (blockLeft < leftPos && blockRight <= rightPos) then
                            let
                                takeLeft = (:) ('.', leftPos - 1) $ filter ((=='+').fst) $ takeWhile (\(x, y) -> y >= leftPos) $ reverse leftIndexed
                                stepsLeft = length takeLeft
                                stepsRight = stepsLeft - (if dir == DLeft then 1 else 0)
                                takeRight' = take stepsRight $ filter ((=='+').fst) $ takeWhile (\(x, y) -> x /= '#') rightIndexed
                                takeRight = (++) takeRight' $ replicate (max 0 $ stepsRight - length takeRight') ('#', blockRight)
                                nextAnswer = solve (l2:xs) leftPos DLeft
                                in
                                -- Just (length takeRight)
                                case nextAnswer of
                                    Nothing -> Nothing
                                    (Just x) -> Just (((+) x $ computeTake takeLeft takeRight pos) - abs (pos - leftPos) + 1)
                        else
                            let
                                takeLeft' = filter ((=='+').fst) $ takeWhile (\(x, y) -> y >= leftPos) $ reverse leftIndexed
                                takeRight' = filter ((=='+').fst) $ takeWhile (\(x, y) -> y <= rightPos) rightIndexed
                                minLength = (min `on` length) takeLeft' takeRight'
                                lengthLeft = length takeLeft'
                                lengthRight = length takeRight'
                                (nextPos, nextDir) = if lengthLeft == lengthRight then
                                                        if dir == DLeft then (leftPos, DLeft)
                                                        else (rightPos, DRight)
                                                     else if lengthLeft < lengthRight then (leftPos, DLeft)
                                                     else (rightPos, DRight)
                                stepsLeft = minLength + (if nextDir == DRight && dir == DLeft then 1 else 0)
                                stepsRight = minLength + (if nextDir == DLeft && dir == DRight then 1 else 0)
                                takeLeft = (if nextDir == DLeft then [('.', leftPos - 1)] else []) ++ (take stepsLeft takeLeft')
                                takeRight = (if nextDir == DRight then [('.', rightPos + 1)] else []) ++ (take stepsRight takeRight')
                                nextAnswer = solve (l2:xs) nextPos nextDir
                                -- nextAnswer = 0
                                in
                                -- Just (if nextDir == DRight then 1 else 0)
                                -- Just (2 * (length takeLeft) * pos - 2 * foldl (\s (x, y) -> s + y + 1) 0 takeLeft)
                                -- Just ((computeTake takeLeft takeRight pos)- abs (pos - nextPos) + 1)
                                case nextAnswer of
                                    Nothing -> Nothing
                                    (Just x) -> Just (((+) x $ computeTake takeLeft takeRight pos) - abs (pos - nextPos) + 1)

    where computeTake takeLeft takeRight pos =
            let stepsLeft = length takeLeft; stepsRight = length takeRight in
                (2 * foldl (\s (x, y) -> s + y - 1) 0 takeRight -
                2 * foldl (\s (x, y) -> s + y + 1) 0 takeLeft +
                2 * (stepsLeft - stepsRight) * pos + stepsLeft + stepsRight - 1)

main = do
    firstLine <- getLine
    other <- getContents
    let
        [n, m] = map read $ lines firstLine :: [Int]
        matrix = map (('#':).(++"#")) $ takeWhile (not.null) $ lines other
        in
        -- print $ matrix
        putStrLn $ result $ solve matrix 1 DRight
            where result Nothing = "Never"
                  result (Just x) = show x


main = do
	n <- getLine
	input <- getLine
	let ls = map (read::String->Int) $ words input
	putStrLn $ show $ 2 * maximum ls - sum ls + 1

module Main where

import Data.List
import Data.Ord
import Data.Maybe

main :: IO ()
main = do
	getLine
	getInts >>= (print . fromJust . minFix)

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

type CounterExample a = (a, [a])

-- Lists with at most two members are bad

-- Any list with at least three elements can have at most one counterexample; and that, if any, is always the maximum member of the list

-- A good list cannot be spoiled by a new member that is less than its sum

minFix :: (Num a, Ord a, Enum a) => [a] -> Maybe a
minFix  = safe minFix0

minFix0 :: (Num a, Ord a, Enum a) => a -> [a] -> Maybe a
minFix0 = fmap mend .-. counterExample
--minFix0 a as = fmap mend $ counterExample a as

safe, safe0 :: Ord a => (a -> [a] -> Maybe b) -> [a] -> Maybe b
safe  f            = safe0 f . sortDesc
safe0 f (x:y:more) = f x (y:more)
safe0 _ _          = Nothing

counterExample :: (Ord a, Num a) => a -> [a] -> Maybe (CounterExample a)
counterExample a as = if a < sum as
    then Nothing
    else Just (a, as)

mend :: (Num a, Ord a, Enum a) => CounterExample a -> a
mend (a, as) = succ $ a - sum as

sortDesc :: Ord a => [a] -> [a]
sortDesc = reverse . sort -- sortBy (rev compare)

(.-.) :: (c -> d) -> (a ->b -> c) -> a -> b -> d
(f .-. g) x y = f $ g x y

import Data.List

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

solve :: [Int] -> Int
solve a = maximum a * 2 - sum a + 1

import Data.List

main = do
  _ <- getLine
  inp <- fmap (map read . words) getLine
  print (solve inp)

solve :: [Int] -> Int
solve ls = 2*maximum ls + 1 - sum ls

main = do
		n <- getLine
		c <- getLine
		let a = (map (\x -> read x :: Integer) .words) c
		--print (foldr (max) (-1) a)
		print $ max (2 * (foldr (max) (-1) a) - (foldr (+) (0) a) + 1) 1

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

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

main = do
  n <- readInt641 <$> BS.getLine
  ns <- readInt64N <$> BS.getLine
  print $ solve ns

solve :: [Int64] -> Int64
solve ns = 2 * maximum ns - sum ns + 1

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

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

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

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

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

readInt641 :: BS.ByteString -> Int64
readInt641 = fromIntegral . fst . fromJust . BS.readInteger

readInt642 :: BS.ByteString -> (Int64,Int64)
readInt642 = toTuple . readInt64N

readInt643 :: BS.ByteString -> (Int64,Int64,Int64)
readInt643 = toTriple . readInt64N

readInt64N :: BS.ByteString -> [Int64]
readInt64N =  map readInt641 . BS.words

readInteger1 :: BS.ByteString -> Integer
readInteger1 = fst . fromJust . BS.readInteger

readInteger2 :: BS.ByteString -> (Integer,Integer)
readInteger2 = toTuple . readIntegerN

readInteger3 :: BS.ByteString -> (Integer,Integer,Integer)
readInteger3 = toTriple . readIntegerN

readIntegerN :: BS.ByteString -> [Integer]
readIntegerN =  map readInteger1 . BS.words

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

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

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

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

-- if not applying, use "const"

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

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

main = do
    _ <- getLine
    s <- getLine
    let l = map read . words $ s
        m = maximum l
        rest = sum l - m
    print $ m - rest + 1

{-
instructions go here...
-}

module Main where
import Data.List (group, sort)

solve :: [Integer] -> Integer
solve rods = delta $ foldr f (0,0) (sort rods)
  where f :: Integer -> (Integer,Integer) -> (Integer,Integer)
        f x (a,b) | a < b     = (a+x,b)
                  | otherwise = (a,b+x)
        delta :: (Integer,Integer) -> Integer
        delta (a,b) = 1 + abs (a - b)

main :: IO ()
main = do
  _ <- getLine
  rodsStr <- getLine
  let rods = map read (words rodsStr) :: [Integer]
  putStrLn $ show (solve rods)

main = do
	n <- getLine
	input <- getLine
	let ls = map (read::String->Int) $ words input
	putStrLn $ show $ sum ls - maximum ls * 2 + 1


import Control.Monad
import Data.Maybe
import Data.Char
import Data.Int
import qualified Data.ByteString.Char8 as C
import Data.ByteString.Builder
import System.IO

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

getInts :: IO [Int]
getInts = map parseInt . C.words <$> C.getLine

main :: IO ()
main = do
  [t] <- getInts
  output <- fmap mconcat $ replicateM t $ do
    s <- filter (not . isSpace) . C.unpack <$> C.getLine
    let func [] = (0 :: Int64, 0, -1, 0)
        func (x : xs)
          | x == '0' || x == '1' =
              case digitToInt x /= h of
                True -> (total + 1 + l + c, 0, digitToInt x, 1 + l + c)
                False -> (total + 1 + l, 0, digitToInt x, 1 + l)
          | otherwise = (total + 1 + l + c, l + 1, if h == -1 then -1 else 1 - h, c)
          where (total, l, h, c) = func xs
        (result, _, _, _) = func s
    return $ int64Dec result `mappend` charUtf8 '\n'
  hPutBuilder stdout output

import Control.Monad
import Data.Int
import Data.List

solve :: IO ()
solve = do
    s <- getLine
    let f (lst, d, lstV, t) cur
            | cur == '?'            = (lst, d + 1, lstV,     t + lstV + d)
            | (lst == cur) /= odd d = (cur, 1,     lstV + d, t + lstV + d)
            | otherwise             = (cur, 1,     d,        t + d)
    print $ let (_, _, _, t) = foldl' f (head s, 1, 0, 0 :: Int64) s in t

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

import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.Array.Base
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits
import Data.Bool
import Data.Char
import Data.Int
import Data.List
import Data.Maybe
import Data.Ord
import Data.Ratio
import qualified Data.Set as Set
import System.IO
import System.IO.Unsafe

deb s e = unsafePerformIO $ do
    hPutStrLn stderr s
    return e

parseInt = fst . fromJust . BS.readInt
parseInteger = fst . fromJust . BS.readInteger

solve :: String -> Int64 -> (Int64, Int64) -> Int64
solve [] _ _ = 0
solve ('?':cs) i x@(x0,x1) = i - (x0 `min` x1) + solve cs (i+1) x
solve (c:cs) i (x0,x1)
    | ord c - ord '0' == fromIntegral i `mod` 2 =
        i - x1 + solve cs (i+1) (i,x1)
    | otherwise =
        i - x0 + solve cs (i+1) (x0,i)

main = do
    tn <- parseInt <$> BS.getLine
    replicateM_ tn $ do
        cs <- dropWhileEnd isSpace . BS.unpack <$> BS.getLine
        print $ solve cs 0 (-1,-1)

{-# 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

printList [a] = print a
printList (a:as) = putStr ( show a ) >> putChar ' ' >> printList as

main = readInt >>= flip replicateM solve

solve = do
	s <- getLine
	let
		match01 :: Integer = solve' match s $ cycle "01"
		match10 = solve' match s $ cycle "10"
		match_q = solve' (==) s $ repeat '?'
	print $ match01 + match10 - match_q

solve' m s t = sum $ map ( f . fromIntegral . length ) $ filter head $ group $ zipWith m s t
	where
		f x = x + x * ( x - 1 ) `div` 2

match _ '?' = True
match '?' _ = True
match c1 c2 = c1 == c2

import Control.Applicative (liftA2)
import Control.Arrow ((>>>))
import Data.List (group)

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

solve :: String -> Integer
solve s = compute "01" s + compute "10" s - compute "?" s

compute :: String -> String -> Integer
compute st = sum . map (count  . length) . filter head . group . zipWith match (concat (repeat st))
  where
    match _ '?' = True
    match a b = a == b

count :: Int -> Integer
count n = let n' = toInteger n in (n' * (n' + 1)) `div` 2

import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.Array.Base
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits
import Data.Bool
import Data.Char
import Data.Int
import Data.List
import Data.Maybe
import Data.Ord
import Data.Ratio
import qualified Data.Set as Set
import System.IO
import System.IO.Unsafe

deb s e = unsafePerformIO $ do
    hPutStrLn stderr s
    return e

parseInt = fst . fromJust . BS.readInt
parseInteger = fst . fromJust . BS.readInteger

solve :: String -> Int64 -> (Int64, Int64) -> Int64
solve [] _ _ = 0
solve ('?':cs) i x@(x0,x1) = i - (x0 `min` x1) + solve cs (i+1) x
solve (c:cs) i (x0,x1)
    | ord c - ord '0' == fromIntegral i `mod` 2 =
        i - x1 + solve cs (i+1) (i,x1)
    | otherwise =
        i - x0 + solve cs (i+1) (x0,i)

main = do
    tn <- parseInt <$> BS.getLine
    replicateM_ tn $ do
        cs <- BS.unpack <$> BS.getLine
        print $ solve cs 0 (-1,-1)

import Control.Monad
import Data.Maybe
import Data.Char
import Data.Int
import qualified Data.ByteString.Char8 as C
import Data.ByteString.Builder
import System.IO

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

getInts :: IO [Int]
getInts = map parseInt . C.words <$> C.getLine

main :: IO ()
main = do
  [t] <- getInts
  output <- fmap mconcat $ replicateM t $ do
    s <- filter (not . isSpace) . C.unpack <$> C.getLine
    let func [] = (0 :: Int64, 0, -1, 0)
        func (x : xs)
          | x == '0' || x == '1' = (total + if f then c' else 1 + l, 0, digitToInt x, c')
          | otherwise = (total + l + 1 + c, l + 1, if h == -1 then -1 else 1 - h, c)
          where (total, l, h, c) = func xs
                f = x == '?' || h == -1 || digitToInt x /= h
                c' = if not f then 1 else 1 + l + c
        (result, _, _, _) = func s
    return $ int64Dec result `mappend` charUtf8 '\n'
  hPutBuilder stdout output

import Control.Monad
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as C
import Data.ByteString.Builder
import System.IO

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

getInts :: IO [Int]
getInts = map parseInt . C.words <$> C.getLine

main :: IO ()
main = do
  [t] <- getInts
  output <- fmap mconcat $ replicateM t $ do
    s <- filter (not . isSpace) . C.unpack <$> C.getLine
    let func [] = (0, 0, -1, 0)
        func (x : xs)
          | x == '0' || x == '1' = (total + if f then c' else 1 + l, 0, digitToInt x, c')
          | otherwise = (total + l + 1 + c, l + 1, if h == -1 then -1 else 1 - h, c)
          where (total, l, h, c) = func xs
                f = x == '?' || h == -1 || digitToInt x /= h
                c' = if not f then 1 else 1 + l + c
        (result, _, _, _) = func s
    return $ int64Dec result `mappend` charUtf8 '\n'
  hPutBuilder stdout output


main = do
	input <- getContents
	let ws = words input
	putStr $ toString $ isValid ws
		where toString b = if b then "YES" else "NO"

data Gender = Male | Female | Unknown deriving (Eq, Show)

isValid [] = False
isValid (x:xs)
	| xs == [] = any (\w -> endsWith w x) ["lios","liala","etr","etra","initis","inites"]
	| otherwise = adj (x:xs) Unknown

adj [] g = False
adj (x:xs) g
	| endsWith "lios" x = if g == Female then False else adj xs Male
	| endsWith "liala" x = if g == Male then False else adj xs Female
	| otherwise = noun (x:xs) g

noun [] g = False
noun (x:xs) g
	| endsWith "etr" x = if g == Female then False else verb xs Male
	| endsWith "etra" x = if g == Male then False else verb xs Female
	| otherwise = False

verb [] g = True
verb (x:xs) g
	| endsWith "initis" x = if g == Female then False else verb xs Male
	| endsWith "inites" x = if g == Male then False else verb xs Female
	| otherwise = False

endsWith suf str
	| length suf > length str = False
	| otherwise = suf == drop (length str - length suf) str

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
import Debug.Trace
import Data.List
import Data.Array
import Data.Char
class Scan a where scan' :: String -> a
instance Scan Int where scan' = read
instance Scan Char where scan' (x:_) = x
instance Scan Float where scan' = read
instance Scan Double where scan' = read
instance Scan Integer where scan' = read
instance Scan String where scan' x = x
instance (Scan a,Scan b) => Scan (a,b) where scan' x = (\(x:y:_) -> (scan' x,scan' y)) (words x)
instance (Scan a,Scan b,Scan c) => Scan (a,b,c) where scan' x = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)) (words x)
instance (Scan a,Scan b,Scan c,Scan d) => Scan (a,b,c,d) where scan' x = (\(w:x:y:z:_) -> (scan' w,scan' x,scan' y,scan' z)) (words x)
instance (Scan a,Scan b,Scan c,Scan d,Scan e) => Scan (a,b,c,d,e) where scan' x = (\(v:w:x:y:z:_) -> (scan' v,scan' w,scan' x,scan' y,scan' z)) (words x)
class Ans a where showans :: a -> String
instance Ans Int where showans x = show x
instance Ans Char where showans x = [x]
instance Ans Float where showans x = show x
instance Ans Double where showans x = show x
instance Ans Integer where showans x = show x
instance Ans String where showans x = x
instance (Ans a, Ans b) => Ans (a,b) where showans (x,y) = showans x ++ " " ++ showans y
instance (Ans a, Ans b,Ans c) => Ans (a,b,c) where showans (x,y,z) = showans x ++ " " ++ showans y ++ " " ++ showans z
scan :: (Scan a) => IO a
scan = getLine>>=(return.scan')
scans :: (Scan a) => Int -> IO [a]
scans n = if n==0 then return [] else scan>>=(\x->scans (n-1)>>=return.(x:))
scanlist :: (Scan a) => IO [a]
scanlist = getLine>>=return.(map scan').words
scanlists :: (Scan a) => Int -> IO [[a]]
scanlists n = if n==0 then return [] else scanlist>>=(\x->scanlists (n-1)>>=return.(x:))
putAnsLn :: (Ans a) => a -> IO ()
putAnsLn = putStrLn.showans
putAnsLns :: (Ans a) => [a] -> IO ()
putAnsLns = mapM_ putAnsLn

isAdj f = isSuffixOf (if f then "lios" else "liala")
isNoun f = isSuffixOf (if f then "etr" else "etra")
isVerb f = isSuffixOf (if f then "initis" else "inites")

parse f s = let s' = dropWhile (isAdj f) s in
            case s' of
              [] -> "NO"
              (x:xs) -> if isNoun f x && all (isVerb f) xs then
                            "YES"
                        else
                            "NO"

validword [] = False
validword (x:_) = (isVerb True x)
                  ||(isVerb False x)
                  ||(isNoun True x)
                  ||(isNoun False x)
                  ||(isAdj True x)
                  ||(isAdj False x)

solve s = if length s == 1 && validword s then
              "YES"
          else
              if parse True s == "NO" then
                  parse False s
              else
                  "YES"

main = do statement <- scanlist :: IO [String]
          putAnsLn (solve statement)

import Control.Applicative
import Control.Monad
import Data.List
import Data.Ord
import Data.Function
import Data.Array

same [] = True
same (h:t) = all(==h)t

r w=case reverse w of
  ('s':'o':'i':'l':_) -> (True, 0)
  ('a':'l':'a':'i':'l':_) -> (False, 0)
  ('r':'t':'e':_) -> (True, 1)
  ('a':'r':'t':'e':_) -> (False, 1)
  ('s':'i':'t':'i':'n':'i':_) -> (True, 2)
  ('s':'e':'t':'i':'n':'i':_) -> (False, 2)
  _ -> (False, 3)
g = g' . (dropWhile (==0))
g' (1:l) = all (==2) l
g' _ = False
gg [x]=x/=3
gg l=g l
s w=same(map fst w)&&(gg$map snd w)
p b|b="YES"|1>0="NO"
main=interact$p.s.map r.words

import Data.List

masc = ["lios", "etr", "initis"]
femi = ["liala", "etra", "inites"]

adj = ["lios", "liala"]
noun = ["etr", "etra"]
verb = ["initis", "inites"]

isMasc w = any (\m -> isSuffixOf m w) masc
isFemi w = any (\f -> isSuffixOf f w) femi

isAdj w = any (\a -> isSuffixOf a w) adj
isNoun w = any (\n -> isSuffixOf n w) noun
isVerb w = any (\v -> isSuffixOf v w) verb

kind w
  | isAdj w = "A"
  | isNoun w = "N"
  | isVerb w = "V"
  | otherwise = "X"

main = do
  contents <- getContents
  let d = words contents
  let order = concat $ map nub $ group.concat $ map kind d
  let nouns = length $ filter isNoun d
  let isValidStmt = nouns == 1 && any (== order) ["ANV", "AN", "NV", "N"]
  if (all isMasc d || all isFemi d) && (isValidStmt || length d == 1) then
  	putStrLn "YES"
  else
    putStrLn "NO"

import List
d=words"soil alail rte arte sitini setini"`zip`[(i,j)|j<-[0..2],i<-[0..1]]
r w=maybe(8,3)snd$find((`isPrefixOf`reverse w).fst)d
g(1:l)=all(==2)l
g _=1<0
c[x]=x<3
c l=g$dropWhile(==0)l
s((h:g),t)|all(==h)g&&c t="YES"|1>0="NO"
main=interact$s.unzip.map r.words

main = do
	input <- getContents
	let ws = words input
	putStr $ toString $ isValid ws
		where toString b = if b then "YES" else "NO"

data Gender = Male | Female | Unknown deriving (Eq, Show)

isValid [] = False
isValid (x:xs)
	| xs == [] = any (\w -> endsWith w x) ["lios","liala","etr","etra","initis","inites"]
	| otherwise = adj (x:xs) Unknown

adj [] g = False
adj (x:xs) g
	| endsWith "lios" x = sendTailIfMale g adj xs
	| endsWith "liala" x = sendTailIfFemale g adj xs
	| otherwise = noun (x:xs) g

noun [] g = False
noun (x:xs) g
	| endsWith "etr" x = sendTailIfMale g verb xs
	| endsWith "etra" x = sendTailIfFemale g verb xs
	| otherwise = False

verb [] g = True
verb (x:xs) g
	| endsWith "initis" x = sendTailIfMale g verb xs
	| endsWith "inites" x = sendTailIfFemale g verb xs
	| otherwise = False

endsWith suf str
	| length suf > length str = False
	| otherwise = suf == drop (length str - length suf) str

sendTailIfOK badG expG g fun xs = if g == badG then False else fun xs expG
sendTailIfMale = sendTailIfOK Female Male
sendTailIfFemale = sendTailIfOK Male Female

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

isMadj btr | BS.length btr >= 4 = let end = BS.drop (BS.length btr - 4)  btr
                                  in end == BS.pack "lios"
           | otherwise = False

isFadj btr | BS.length btr >= 5 = let end = BS.drop (BS.length btr - 5)  btr
                                  in end == BS.pack "liala"
           | otherwise = False

isMnou btr | BS.length btr >= 3 = let end = BS.drop (BS.length btr - 3)  btr
                                  in end == BS.pack "etr"
           | otherwise = False
isFnou btr | BS.length btr >= 4 = let end = BS.drop (BS.length btr - 4)  btr
                                  in end == BS.pack "etra"
           | otherwise = False

isMver btr | BS.length btr >= 6 = let end = BS.drop (BS.length btr - 6)  btr
                                  in end == BS.pack "initis"
           | otherwise = False

isFver btr | BS.length btr >= 6 = let end = BS.drop (BS.length btr - 6)  btr
                                  in end == BS.pack "inites"
           | otherwise = False

inir btr = if isMadj btr
           then 1
           else if isFadj btr
                then 2
                else if isMnou btr
                     then 3
                     else if isFnou btr
                          then 4
                          else 5

f 5 _ = 5
f 1 btr | isMadj btr = 1
        | isMnou btr = 3
f 2 btr | isFadj btr = 2
        | isFnou btr = 4
f 3 btr | isMver btr = 3
f 4 btr | isFver btr = 4
f _ _ = 5

main = do
  str <- BS.words <$> BS.getLine
  let w = head str
      b = isMadj w || isFadj w || isMnou w || isFnou w || isMver w || isFver w
      ans = foldl' f (inir . head $ str) (tail str)
  case str of
    [x] -> if b
           then putStrLn "YES"
           else putStrLn "NO"
    _ ->   case ans of
           1 -> putStrLn "NO"
           2 -> putStrLn "NO"
           3 -> putStrLn "YES"
           4 -> putStrLn "YES"
           5 -> putStrLn "NO"

{-# OPTIONS -O2 #-}

import Data.List

data Ws = MA | FA | MN | FN | MV | FV | NO deriving (Eq, Show)

main = do
  ws' <- fmap words getLine
  let ws = map formalize ws'
  putStrLn $ if check ws then "YES" else "NO"

formalize w
  | isSuffixOf "lios" w = MA
  | isSuffixOf "liala" w = FA
  | isSuffixOf "etr" w = MN
  | isSuffixOf "etra" w = FN
  | isSuffixOf "initis" w = MV
  | isSuffixOf "inites" w = FV
  | otherwise = NO

check ws
  | elem NO ws = False
  | length ws == 1 = True
  | otherwise = checkGender ws && checkNumWord ws && checkSyntax ws

checkGender ws = checkGenderMas ws || checkGenderFem ws

checkGenderMas ws = all (`elem` [MA, MN, MV]) ws
checkGenderFem ws = all (`elem` [FA, FN, FV]) ws

checkNumWord l = 1 == length (filter (`elem` [MN, FN]) l)

checkSyntax ws
  | elem MA nvs || elem FA nvs = False
  | head nvs /= MN && head nvs /= FN = False
  | all (== MV) (tail nvs) || all (== FV) (tail nvs) = True
  | otherwise = False
  where
    nvs = dropWhile (`elem` [MA, FA]) ws

import Data.List
solve::[String]->String
solve input | length input == 1  = case isWord $ head input of
                                           True -> "YES"
                                           False -> "NO"
            | not $ any isWord input = "NO"
            | otherwise = if isStatement input then "YES" else "NO"
                             where isWord xs = any (flip elem (tails xs)) allw
                                   adj1 = ["lios"]
                                   adj2 = ["liala"]
                                   adjs = adj1 ++ adj2
                                   n1 = ["etr"]
                                   n2 = ["etra"]
                                   ns = n1 ++ n2
                                   v1 = ["initis"]
                                   v2 = ["inites"]
                                   vs = v1 ++ v2
                                   ms = adj1 ++ n1 ++ v1
                                   fs = adj2 ++ n2 ++ v2
                                   allw = adj1 ++ adj2 ++ n1 ++ n2 ++ v1 ++ v2
                                   genderEqm xs = any (flip elem (tails xs)) ms
                                   genderEqf xs = any (flip elem (tails xs)) fs
                                   isNoun xs =  any (flip elem (tails xs)) ns
                                   isVerb xs =  any (flip elem (tails xs)) vs
                                   isAdj xs =  any (flip elem (tails xs)) adjs
                                   samepart x y = (isNoun x && isNoun y) ||
                                                  (isVerb x && isVerb y) ||
                                                  (isAdj x && isAdj y)
                                   isStatement xs = (all genderEqm xs
                                            ||
                                       all genderEqf xs) &&
                                          case length gr of
                                               1 -> ((isNoun.head) (gr !! 0)) &&
                                                      (length (head gr) == 1)
                                               2 -> ((isAdj.head.head) gr &&
                                                    (isNoun.head) (gr !! 1) &&
                                                    length (gr !! 1) == 1 ) ||
                                                    ((isNoun.head.head) gr &&
                                                    (isVerb.head) (gr !! 1) &&
                                                    length (head gr) == 1)
                                               3 -> (isAdj.head.head) gr &&
                                                    (isNoun.head) (gr !! 1) &&
                                                    (isVerb.head) (gr !! 2) &&
                                                    length (gr !! 1) == 1

                                             where  gr = groupBy samepart xs
main = do
           input <- getLine >>= return.words
           putStrLn $ solve input

import Data.List

grm :: String -> Maybe (Char, Char)
grm x
	| (reverse . take 4 . reverse) x == "lios" = Just ('m', 'a')
	| (reverse . take 5 . reverse) x == "liala" = Just ('f', 'a')
	| (reverse . take 3 . reverse) x == "etr" = Just ('m', 'n')
	| (reverse . take 4 . reverse) x == "etra" = Just ('f', 'n')
	| (reverse . take 6 . reverse) x == "initis" = Just ('m', 'v')
	| (reverse . take 6 . reverse) x == "inites" = Just ('f', 'v')
	| otherwise = Nothing

rex :: Int -> String -> Bool
rex 0 [] = False
rex _ [] = True
rex 0 ('v':xs) = rex 0 xs
rex 0 ('n':xs) = rex 1 xs
rex 0 ('a':xs) = False
rex 1 ('v':xs) = False
rex 1 ('n':xs) = False
rex 1 ('a':xs) = rex 2 xs
rex 2 ('v':xs) = False
rex 2 ('n':xs) = False
rex 2 ('a':xs) = rex 2 xs

solve :: [String] -> String
solve strs
	| grms == Nothing = "NO"
	| (grms >>= Just . length) == Just 1 = "YES"
	| (grms >>= Just . (/=1) . length . group . map fst) == Just True = "NO"
	| (grms >>= Just . rex 0 . map snd) == Just True = "YES"
	| otherwise = "NO"
	where
		grms = foldl (\x y -> do xx <- x; yy <- y; Just (yy:xx)) (Just []) (map grm strs)

main = do
	getLine >>= putStrLn . solve . words

ok :: [String] -> Bool
ok s
	| length s /= 1 = isValid (map gender s) && checkSpeech 0 (map speech s)
	| otherwise 	= speech (s !! 0) > 0

isValid :: [Int] -> Bool
isValid [] = True
isValid (a:(b:c)) = a == b && (a /= 0 && isValid (b:c))
isValid [a] = (a /= 0)

checkSpeech :: Int -> [Int] -> Bool
checkSpeech cur [] = cur >= 2
checkSpeech cur (x:xs)
	| x < cur				= False
	| cur < 2 && x == 3		= False
	| cur == 2 && x == 2	= False
	| otherwise				= checkSpeech x xs

speech :: String -> Int
speech s
	| suffixMatch s "lios"		= 1
	| suffixMatch s "liala"		= 1
	| suffixMatch s "etr"		= 2
	| suffixMatch s "etra"		= 2
	| suffixMatch s "initis"	= 3
	| suffixMatch s "inites"	= 3
	| otherwise					= 0

gender :: String -> Int
gender s
	| suffixMatch s "lios"		= 1
	| suffixMatch s "etr"		= 1
	| suffixMatch s "initis"	= 1
	| suffixMatch s "liala"		= 2
	| suffixMatch s "etra"		= 2
	| suffixMatch s "inites"	= 2
	| otherwise					= 0

suffixMatch :: String -> String -> Bool
suffixMatch s a = prefixMatch (reverse s) (reverse a)

prefixMatch :: String -> String -> Bool
prefixMatch _ []  = True
prefixMatch [] _  = False
prefixMatch (x:xs) (y:ys) = (x == y) && (prefixMatch xs ys)

main :: IO()
main = do
	str <- getLine
	if (ok(words (str)))
		then putStrLn "YES"
		else putStrLn "NO"

{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-}
{-# OPTIONS_GHC -O2 #-}

import Data.List
import Data.Maybe
import Data.Char
import Data.Array.IArray
import Data.Array.Unboxed (UArray)
import Data.Int
import Data.Ratio
import Data.Bits
import Data.Function
import Data.Ord
--import Control.Monad.State
import Control.Monad
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Map (Map)
import qualified Data.Map as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.Sequence (Seq, (<|), (|>), (><), ViewL(..), ViewR(..))
import qualified Data.Sequence as Seq
import qualified Data.Foldable as F
import Data.Graph

parseInput = do
    BS.words <$> readLine
  where
    readInt = state $ fromJust . BS.readInt . BS.dropWhile isSpace
    readInteger = state $ fromJust . BS.readInteger . BS.dropWhile isSpace
    readString = state $ BS.span (not . isSpace) . BS.dropWhile isSpace
    readLine = state $ BS.span (not . isEoln) . BS.dropWhile isEoln
    isEoln ch = ch == '\r' || ch == '\n'

main = putStr =<< solve . evalState parseInput <$> BS.getContents

solve words
    | any isNothing typesMaybe   = "NO"
    | length types == 1          = "YES"
    | any ((/=gender).snd) types = "NO"
    | checkStatement types'      = "YES"
    | otherwise                  = "NO"
  where
    typesMaybe = map getType words
    types = map fromJust typesMaybe
    gender = snd $ head types

    types' = map fst types

checkStatement :: [Words] -> Bool
checkStatement (Adjective:xs) = checkStatement xs
checkStatement (Noun:Verb:xs) = checkStatement (Noun:xs)
checkStatement [Noun] = True
checkStatement _ = False

data Words = Adjective | Noun | Verb deriving (Show, Eq)

getType :: ByteString -> Maybe (Words, Bool)
getType word
    | BS.pack "lios"   `BS.isSuffixOf` word = Just (Adjective, False)
    | BS.pack "liala"  `BS.isSuffixOf` word = Just (Adjective, True)
    | BS.pack "etr"    `BS.isSuffixOf` word = Just (Noun, False)
    | BS.pack "etra"   `BS.isSuffixOf` word = Just (Noun, True)
    | BS.pack "initis" `BS.isSuffixOf` word = Just (Verb, False)
    | BS.pack "inites" `BS.isSuffixOf` word = Just (Verb, True)
    | otherwise                             = Nothing

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

class (Monad m) => MonadState s m | m -> s where
	get :: m s
	put :: s -> m ()

modify :: (MonadState s m) => (s -> s) -> m ()
modify f = do
	s <- get
	put (f s)

gets :: (MonadState s m) => (s -> a) -> m a
gets f = do
	s <- get
	return (f s)

newtype State s a = State { runState :: s -> (a, s) }

instance Functor (State s) where
	fmap f m = State $ \s -> let
		(a, s') = runState m s
		in (f a, s')

instance Applicative (State s) where
    pure = return
    (<*>) = ap

instance Monad (State s) where
	return a = State $ \s -> (a, s)
	m >>= k  = State $ \s -> let
		(a, s') = runState m s
		in runState (k a) s'

instance MonadState s (State s) where
	get   = State $ \s -> (s, s)
	put s = State $ \_ -> ((), s)

evalState :: State s a -> s -> a
evalState m s = fst (runState m s)

execState :: State s a -> s -> s
execState m s = snd (runState m s)

mapState :: ((a, s) -> (b, s)) -> State s a -> State s b
mapState f m = State $ f . runState m

withState :: (s -> s) -> State s a -> State s a
withState f m = State $ runState m . f

state = State

import List
t s=last$6:[i|i<-[0..5],isSuffixOf(words"lios liala etr etra initis inites"!!i)s]
n="NO"
c x|any(>5)x=n
c[_]="YES"
c(x:y)|any((/=odd x).odd)y=n
c x=g$map(`div`2)x
g(0:x)=g x
g(1:2:x)=g(1:x)
g[1]="YES"
g _=n
main=interact$c.map t.words

import Data.List

grm :: String -> Maybe (Char, Char)
grm x
	| (reverse . take 4 . reverse) x == "lios" = Just ('m', 'a')
	| (reverse . take 5 . reverse) x == "liala" = Just ('f', 'a')
	| (reverse . take 3 . reverse) x == "etr" = Just ('m', 'n')
	| (reverse . take 4 . reverse) x == "etra" = Just ('f', 'n')
	| (reverse . take 6 . reverse) x == "initis" = Just ('m', 'v')
	| (reverse . take 6 . reverse) x == "inites" = Just ('f', 'v')
	| otherwise = Nothing

rex :: Int -> String -> Bool
rex 0 [] = False
rex _ [] = True
rex 0 ('v':xs) = rex 0 xs
rex 0 ('n':xs) = rex 1 xs
rex 0 ('a':xs) = False
rex 1 ('v':xs) = False
rex 1 ('n':xs) = False
rex 1 ('a':xs) = rex 2 xs
rex 2 ('v':xs) = False
rex 2 ('n':xs) = False
rex 2 ('a':xs) = rex 2 xs

solve :: [String] -> String
solve strs
	| grms == Nothing = "NO"
	| (grms >>= Just . (/=1) . length . group . map fst) == Just True = "NO"
	| (grms >>= Just . rex 0 . map snd) == Nothing = "NO"
	| otherwise = "YES"
	where
		grms = foldl (\x y -> do xx <- x; yy <- y; Just (yy:xx)) (Just []) (map grm strs)

main = do
	getLine >>= putStrLn . solve . words

import Data.List

grm :: String -> Maybe (Char, Char)
grm x
	| (reverse . take 4 . reverse) x == "lios" = Just ('m', 'a')
	| (reverse . take 5 . reverse) x == "liala" = Just ('f', 'a')
	| (reverse . take 3 . reverse) x == "etr" = Just ('m', 'n')
	| (reverse . take 4 . reverse) x == "etra" = Just ('f', 'n')
	| (reverse . take 6 . reverse) x == "initis" = Just ('m', 'v')
	| (reverse . take 6 . reverse) x == "inites" = Just ('f', 'v')
	| otherwise = Nothing

rex :: Int -> String -> Bool
rex 0 [] = False
rex _ [] = True
rex 0 ('v':xs) = rex 0 xs
rex 0 ('n':xs) = rex 1 xs
rex 0 ('a':xs) = False
rex 1 ('v':xs) = False
rex 1 ('n':xs) = False
rex 1 ('a':xs) = rex 2 xs
rex 2 ('v':xs) = False
rex 2 ('n':xs) = False
rex 2 ('a':xs) = rex 2 xs

solve :: [String] -> String
solve strs
	| grms == Nothing = "NO"
	| (grms >>= Just . (/=1) . length . group . map fst) == Just True = "NO"
	| (grms >>= Just . rex 0 . map snd) == Just False = "NO"
	| otherwise = "YES"
	where
		grms = foldl (\x y -> do xx <- x; yy <- y; Just (yy:xx)) (Just []) (map grm strs)

main = do
	getLine >>= putStrLn . solve . words

import Data.List

grm :: String -> Maybe (Char, Char)
grm x
	| (reverse . take 4 . reverse) x == "lios" = Just ('m', 'a')
	| (reverse . take 5 . reverse) x == "liala" = Just ('f', 'a')
	| (reverse . take 3 . reverse) x == "etr" = Just ('m', 'n')
	| (reverse . take 4 . reverse) x == "etra" = Just ('f', 'n')
	| (reverse . take 6 . reverse) x == "initis" = Just ('m', 'v')
	| (reverse . take 6 . reverse) x == "inites" = Just ('f', 'v')
	| otherwise = Nothing

rex :: Int -> String -> Bool
rex 0 [] = False
rex _ [] = True
rex 0 ('v':xs) = rex 0 xs
rex 0 ('n':xs) = rex 1 xs
rex 0 ('a':xs) = False
rex 1 ('v':xs) = False
rex 1 ('n':xs) = False
rex 1 ('a':xs) = rex 2 xs
rex 2 ('v':xs) = False
rex 2 ('n':xs) = False
rex 2 ('a':xs) = rex 2 xs

solve :: [String] -> String
solve strs
	| grms == Nothing = "NO"
	| (grms >>= Just . (/=1) . length . group . map fst) == Just True = "NO"
	| (grms >>= Just . rex 0 . map snd) == Just True = "YES"
	| otherwise = "NO"
	where
		grms = foldl (\x y -> do xx <- x; yy <- y; Just (yy:xx)) (Just []) (map grm strs)

main = do
	getLine >>= putStrLn . solve . words

{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-}
{-# OPTIONS_GHC -O2 #-}

import Data.List
import Data.Maybe
import Data.Char
import Data.Array.IArray
import Data.Array.Unboxed (UArray)
import Data.Int
import Data.Ratio
import Data.Bits
import Data.Function
import Data.Ord
--import Control.Monad.State
import Control.Monad
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Map (Map)
import qualified Data.Map as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.Sequence (Seq, (<|), (|>), (><), ViewL(..), ViewR(..))
import qualified Data.Sequence as Seq
import qualified Data.Foldable as F
import Data.Graph

parseInput = do
    BS.words <$> readString
  where
    readInt = state $ fromJust . BS.readInt . BS.dropWhile isSpace
    readInteger = state $ fromJust . BS.readInteger . BS.dropWhile isSpace
    readString = state $ BS.span (not . isSpace) . BS.dropWhile isSpace
    readLine = state $ BS.span (not . isEoln) . BS.dropWhile isEoln
    isEoln ch = ch == '\r' || ch == '\n'

main = putStr =<< solve . evalState parseInput <$> BS.getContents

solve words
    | any isNothing typesMaybe   = "NO"
    | any ((/=gender).snd) types = "NO"
    | length types == 1          = "YES"
    | checkStatement types'      = "YES"
    | otherwise                  = "NO"
  where
    typesMaybe = map getType words
    types = map fromJust typesMaybe
    gender = snd $ head types

    types' = map fst types

checkStatement :: [Words] -> Bool
checkStatement (Adjective:xs) = checkStatement xs
checkStatement (Noun:Verb:xs) = checkStatement (Noun:xs)
checkStatement [Noun] = True
checkStatement _ = False

data Words = Adjective | Noun | Verb deriving (Show, Eq)

getType :: ByteString -> Maybe (Words, Bool)
getType word
    | BS.pack "lios"   `BS.isSuffixOf` word = Just (Adjective, False)
    | BS.pack "liala"  `BS.isSuffixOf` word = Just (Adjective, True)
    | BS.pack "etr"    `BS.isSuffixOf` word = Just (Noun, False)
    | BS.pack "etra"   `BS.isSuffixOf` word = Just (Noun, True)
    | BS.pack "initis" `BS.isSuffixOf` word = Just (Verb, False)
    | BS.pack "inites" `BS.isSuffixOf` word = Just (Verb, True)
    | otherwise                          = Nothing

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

class (Monad m) => MonadState s m | m -> s where
	get :: m s
	put :: s -> m ()

modify :: (MonadState s m) => (s -> s) -> m ()
modify f = do
	s <- get
	put (f s)

gets :: (MonadState s m) => (s -> a) -> m a
gets f = do
	s <- get
	return (f s)

newtype State s a = State { runState :: s -> (a, s) }

instance Functor (State s) where
	fmap f m = State $ \s -> let
		(a, s') = runState m s
		in (f a, s')

instance Applicative (State s) where
    pure = return
    (<*>) = ap

instance Monad (State s) where
	return a = State $ \s -> (a, s)
	m >>= k  = State $ \s -> let
		(a, s') = runState m s
		in runState (k a) s'

instance MonadState s (State s) where
	get   = State $ \s -> (s, s)
	put s = State $ \_ -> ((), s)

evalState :: State s a -> s -> a
evalState m s = fst (runState m s)

execState :: State s a -> s -> s
execState m s = snd (runState m s)

mapState :: ((a, s) -> (b, s)) -> State s a -> State s b
mapState f m = State $ f . runState m

withState :: (s -> s) -> State s a -> State s a
withState f m = State $ runState m . f

state = State

import List
d=words"soil alail rte arte sitini setini"`zip`[(i,j)|j<-[0..2],i<-[1..0]]
r w=maybe(0,3)snd$find((`isPrefixOf`reverse w).fst)d
g(1:l)=all(==2)l
g _=1<0
c[x]=x<3
c l=g$dropWhile(==0)l
s((h:g),t)|all(==h)g&&c t="YES"|1>0="NO"
main=interact$s.unzip.map r.words

import Control.Applicative
import Control.Monad
import Data.List
import Data.Ord
import Data.Function
import Data.Array

same [] = True
same (h:t) = all(==h)t

r w=case reverse w of
  ('s':'o':'i':'l':_) -> (True, 0)
  ('a':'l':'a':'i':'l':_) -> (False, 0)
  ('r':'t':'e':_) -> (True, 1)
  ('a':'r':'t':'e':_) -> (False, 1)
  ('s':'i':'t':'i':'n':'i':_) -> (True, 2)
  ('s':'e':'t':'i':'n':'i':_) -> (False, 2)
  _ -> (False, 3)
g = g' . (dropWhile (==0))
g' (1:l) = all (==2) l
g' _ = False
s w=same(map fst w)&&g(map snd w)
p b|b="YES"|1>0="NO"
main=interact$p.s.map r.words

import Data.List

masc = ["lios", "etr", "initis"]
femi = ["liala", "etra", "inites"]

adj = ["lios", "liala"]
noun = ["etr", "etra"]
verb = ["initis", "inites"]

isMasc w = any (\m -> isSuffixOf m w) masc
isFemi w = any (\f -> isSuffixOf f w) femi

isAdj w = any (\a -> isSuffixOf a w) adj
isNoun w = any (\n -> isSuffixOf n w) noun
isVerb w = any (\v -> isSuffixOf v w) verb

kind w
  | isAdj w = "A"
  | isNoun w = "N"
  | isVerb w = "V"
  | otherwise = "X"

main = do
  contents <- getContents
  let d = words contents
  let order = concat $ map nub $ group.concat $ map kind d
  let nouns = length $ filter isNoun d
  if (all isMasc d || all isFemi d) && nouns == 1 && any (== order) ["ANV", "AN", "NV", "N"] then
  	putStrLn "YES"
  else
    putStrLn "NO"

import Data.List

masc = ["lios", "etr", "initis"]
femi = ["liala", "etra", "inites"]

adj = ["lios", "liala"]
noun = ["etr", "etra"]
verb = ["initis", "inites"]

isMasc w = any (\m -> isSuffixOf m w) masc
isFemi w = any (\f -> isSuffixOf f w) femi

isAdj w = any (\a -> isSuffixOf a w) adj
isNoun w = any (\n -> isSuffixOf n w) noun
isVerb w = any (\v -> isSuffixOf v w) verb

kind w
  | isAdj w = "A"
  | isNoun w = "N"
  | isVerb w = "V"
  | otherwise = "X"

main = do
  contents <- getContents
  let d = words contents
  let order = concat $ map nub $ group.concat $ map kind d
  let nouns = length $ filter isNoun d
  let isValidStmt = nouns == 1 && any (== order) ["ANV", "AN", "NV", "N"]
  if (all isMasc d || all isFemi d) && isValidStmt || length d == 1 then
  	putStrLn "YES"
  else
    putStrLn "NO"

ok :: [String] -> Bool
ok s = isValid (map gender s) && checkSpeech 0 (map speech s)

isValid :: [Int] -> Bool
isValid [] = True
isValid (a:(b:c)) = a == b && (a /= 0 && isValid (b:c))
isValid [a] = (a /= 0)

checkSpeech :: Int -> [Int] -> Bool
checkSpeech cur [] = cur >= 2
checkSpeech cur (x:xs)
	| x < cur				= False
	| cur == 2 && x == 2	= False
	| otherwise				= checkSpeech x xs

speech :: String -> Int
speech s
	| suffixMatch s "lios"		= 1
	| suffixMatch s "liala"		= 1
	| suffixMatch s "etr"		= 2
	| suffixMatch s "etra"		= 2
	| suffixMatch s "initis"	= 3
	| suffixMatch s "inites"	= 3
	| otherwise					= 0

gender :: String -> Int
gender s
	| suffixMatch s "lios"		= 1
	| suffixMatch s "etr"		= 1
	| suffixMatch s "initis"	= 1
	| suffixMatch s "liala"		= 2
	| suffixMatch s "etra"		= 2
	| suffixMatch s "inites"	= 2
	| otherwise					= 0

suffixMatch :: String -> String -> Bool
suffixMatch s a = prefixMatch (reverse s) (reverse a)

prefixMatch :: String -> String -> Bool
prefixMatch _ []  = True
prefixMatch [] _  = False
prefixMatch (x:xs) (y:ys) = (x == y) && (prefixMatch xs ys)

main :: IO()
main = do
	str <- getLine
	if (ok(words (str)))
		then putStrLn "YES"
		else putStrLn "NO"

ok :: [String] -> Bool
ok s = isValid (map gender s) && checkSpeech 0 (map speech s)

isValid :: [Int] -> Bool
isValid [] = True
isValid (a:(b:c)) = a == b && (a /= 0 && isValid (b:c))
isValid [a] = (a /= 0)

checkSpeech :: Int -> [Int] -> Bool
checkSpeech cur [] = cur >= 2
checkSpeech cur (x:xs)
	| x < cur				= False
	| cur < 2 && x == 3		= False
	| cur == 2 && x == 2	= False
	| otherwise				= checkSpeech x xs

speech :: String -> Int
speech s
	| suffixMatch s "lios"		= 1
	| suffixMatch s "liala"		= 1
	| suffixMatch s "etr"		= 2
	| suffixMatch s "etra"		= 2
	| suffixMatch s "initis"	= 3
	| suffixMatch s "inites"	= 3
	| otherwise					= 0

gender :: String -> Int
gender s
	| suffixMatch s "lios"		= 1
	| suffixMatch s "etr"		= 1
	| suffixMatch s "initis"	= 1
	| suffixMatch s "liala"		= 2
	| suffixMatch s "etra"		= 2
	| suffixMatch s "inites"	= 2
	| otherwise					= 0

suffixMatch :: String -> String -> Bool
suffixMatch s a = prefixMatch (reverse s) (reverse a)

prefixMatch :: String -> String -> Bool
prefixMatch _ []  = True
prefixMatch [] _  = False
prefixMatch (x:xs) (y:ys) = (x == y) && (prefixMatch xs ys)

main :: IO()
main = do
	str <- getLine
	if (ok(words (str)))
		then putStrLn "YES"
		else putStrLn "NO"

main = do
	input <- getContents
	let ws = words input
	putStr $ toString $ isValid ws
		where toString b = if b then "YES" else "NO"

data Gender = Male | Female | Unknown deriving (Eq, Show)

isValid [] = False
isValid (x:xs)
	| xs == [] = any (\w -> endsWith w x) ["lios","liala","etr","liala","etr","etra"]
	| otherwise = adj xs Unknown

adj [] g = False
adj (x:xs) g
	| endsWith "lios" x = if g == Female then False else adj xs Male
	| endsWith "liala" x = if g == Male then False else adj xs Female
	| otherwise = noun (x:xs) g

noun [] g = False
noun (x:xs) g
	| endsWith "etr" x = if g == Female then False else verb xs Male
	| endsWith "etra" x = if g == Male then False else verb xs Female
	| otherwise = False

verb [] g = True
verb (x:xs) g
	| endsWith "initis" x = if g == Female then False else verb xs Male
	| endsWith "inites" x = if g == Male then False else verb xs Female
	| otherwise = False

endsWith suf str
	| length suf > length str = False
	| otherwise = suf == drop (length str - length suf) str

import Debug.Trace
main = do
	input <- getContents
	let ws = words input
	putStr $ toString $ isValid ws
		where toString b = if b then "YES" else "NO"

data Gender = Male | Female | Unknown deriving (Eq, Show)

isValid [] = False
isValid (x:xs)
	| xs == [] = any (\w -> endsWith w x) ["lios","liala","etr","liala","etr","etra"]
	| otherwise = adj (x:xs) Unknown

adj [] g = False
adj (x:xs) g
	| endsWith "lios" x = if g == Female then False else adj xs Male
	| endsWith "liala" x = if g == Male then False else adj xs Female
	| otherwise = noun (x:xs) g

noun [] g = False
noun (x:xs) g
	| endsWith "etr" x = if g == Female then False else verb xs Male
	| endsWith "etra" x = if g == Male then False else verb xs Female
	| otherwise = False

verb [] g = True
verb (x:xs) g
	| endsWith "initis" x = if g == Female then False else verb xs Male
	| endsWith "inites" x = if g == Male then False else verb xs Female
	| otherwise = False

endsWith suf str
	| length suf > length str = False
	| otherwise = suf == drop (length str - length suf) str

main = do
	input <- getContents
	let ws = words input
	putStr $ toString $ isValid ws
		where toString b = if b then "YES" else "NO"

data Gender = Male | Female | Unknown deriving (Eq, Show)

isValid [] = False
isValid (x:xs)
	| xs == [] = any (\w -> endsWith w x) ["lios","liala","etr","etra","initis","inites"]
	| otherwise = adj (x:xs) Unknown

adj [] g = False
adj (x:xs) g
	| endsWith "lios" x = sendTailIfMale g adj xs
	| endsWith "liala" x = sendTailIfFemale g adj xs
	| otherwise = noun (x:xs) g

noun [] g = False
noun (x:xs) g
	| endsWith "etr" x = sendTailIfMale g verb xs
	| endsWith "etra" x = sendTailIfFemale g verb xs
	| otherwise = False

verb [] g = True
verb (x:xs) g
	| endsWith "initis" x = sendTailIfMale g verb xs
	| endsWith "inites" x = sendTailIfFemale g verb xs
	| otherwise = False

endsWith suf str
	| length suf > length str = False
	| otherwise = suf == drop (length str - length suf) str

sendTailIfOK badG expG g fun xs = if g == expG then False else fun xs expG
sendTailIfMale = sendTailIfOK Female Male
sendTailIfFemale = sendTailIfOK Male Female

main = do
	input <- getContents
	let ws = words input
	putStr $ toString $ isValid ws
		where toString b = if b then "YES" else "NO"

data Gender = Male | Female | Unknown deriving (Eq, Show)

isValid [] = False
isValid xs = adj xs Unknown

adj [] g = False
adj (x:xs) g
	| endsWith "lios" x = if g == Female then False else adj xs Male
	| endsWith "liala" x = if g == Male then False else adj xs Female
	| otherwise = noun (x:xs) g

noun [] g = False
noun (x:xs) g
	| endsWith "etr" x = if g == Female then False else verb xs Male
	| endsWith "etra" x = if g == Male then False else verb xs Female
	| otherwise = False

verb [] g = True
verb (x:xs) g
	| endsWith "initis" x = if g == Female then False else verb xs Male
	| endsWith "inites" x = if g == Male then False else verb xs Female
	| otherwise = False

endsWith suf str
	| length suf > length str = False
	| otherwise = suf == drop (length str - length suf) str

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
import Debug.Trace
import Data.List
import Data.Array
import Data.Char
class Scan a where scan' :: String -> a
instance Scan Int where scan' = read
instance Scan Char where scan' (x:_) = x
instance Scan Float where scan' = read
instance Scan Double where scan' = read
instance Scan Integer where scan' = read
instance Scan String where scan' x = x
instance (Scan a,Scan b) => Scan (a,b) where scan' x = (\(x:y:_) -> (scan' x,scan' y)) (words x)
instance (Scan a,Scan b,Scan c) => Scan (a,b,c) where scan' x = (\(x:y:z:_) -> (scan' x,scan' y,scan' z)) (words x)
instance (Scan a,Scan b,Scan c,Scan d) => Scan (a,b,c,d) where scan' x = (\(w:x:y:z:_) -> (scan' w,scan' x,scan' y,scan' z)) (words x)
instance (Scan a,Scan b,Scan c,Scan d,Scan e) => Scan (a,b,c,d,e) where scan' x = (\(v:w:x:y:z:_) -> (scan' v,scan' w,scan' x,scan' y,scan' z)) (words x)
class Ans a where showans :: a -> String
instance Ans Int where showans x = show x
instance Ans Char where showans x = [x]
instance Ans Float where showans x = show x
instance Ans Double where showans x = show x
instance Ans Integer where showans x = show x
instance Ans String where showans x = x
instance (Ans a, Ans b) => Ans (a,b) where showans (x,y) = showans x ++ " " ++ showans y
instance (Ans a, Ans b,Ans c) => Ans (a,b,c) where showans (x,y,z) = showans x ++ " " ++ showans y ++ " " ++ showans z
scan :: (Scan a) => IO a
scan = getLine>>=(return.scan')
scans :: (Scan a) => Int -> IO [a]
scans n = if n==0 then return [] else scan>>=(\x->scans (n-1)>>=return.(x:))
scanlist :: (Scan a) => IO [a]
scanlist = getLine>>=return.(map scan').words
scanlists :: (Scan a) => Int -> IO [[a]]
scanlists n = if n==0 then return [] else scanlist>>=(\x->scanlists (n-1)>>=return.(x:))
putAnsLn :: (Ans a) => a -> IO ()
putAnsLn = putStrLn.showans
putAnsLns :: (Ans a) => [a] -> IO ()
putAnsLns = mapM_ putAnsLn

isAdj f = isSuffixOf (if f then "lios" else "liala")
isNoun f = isSuffixOf (if f then "etr" else "etra")
isVerb f = isSuffixOf (if f then "initis" else "inites")

parse f s = let s' = dropWhile (isAdj f) s in
            case s' of
              [] -> "NO"
              (x:xs) -> if isNoun f x && all (isVerb f) xs then
                            "YES"
                        else
                            "NO"

solve s = if parse True s == "NO" then
              parse False s
          else
              "YES"

main = do statement <- scanlist :: IO [String]
          putAnsLn (solve statement)

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

isMadj btr | BS.length btr >= 4 = let end = BS.drop (BS.length btr - 4)  btr
                                  in end == BS.pack "lios"
           | otherwise = False

isFadj btr | BS.length btr >= 5 = let end = BS.drop (BS.length btr - 5)  btr
                                  in end == BS.pack "liala"
           | otherwise = False

isMnou btr | BS.length btr >= 3 = let end = BS.drop (BS.length btr - 3)  btr
                                  in end == BS.pack "etr"
           | otherwise = False
isFnou btr | BS.length btr >= 4 = let end = BS.drop (BS.length btr - 4)  btr
                                  in end == BS.pack "etra"
           | otherwise = False

isMver btr | BS.length btr >= 6 = let end = BS.drop (BS.length btr - 6)  btr
                                  in end == BS.pack "initis"
           | otherwise = False

isFver btr | BS.length btr >= 6 = let end = BS.drop (BS.length btr - 6)  btr
                                  in end == BS.pack "inites"
           | otherwise = False

inir btr = if isMadj btr
           then 1
           else if isFadj btr
                then 2
                else if isMnou btr
                     then 3
                     else if isFnou btr
                          then 4
                          else 5

f 5 _ = 5
f 1 btr | isMadj btr = 1
        | isMnou btr = 3
f 2 btr | isFadj btr = 2
        | isFnou btr = 4
f 3 btr | isMver btr = 3
f 4 btr | isFver btr = 4
f _ _ = 5

main = do
  str <- BS.words <$> BS.getLine
  let ans = foldl' f (inir . head $ str) (tail str)
  case ans of
    1 -> putStrLn "NO"
    2 -> putStrLn "NO"
    3 -> putStrLn "YES"
    4 -> putStrLn "YES"
    5 -> putStrLn "NO"


import Control.Monad.Except (replicateM_)
import Data.Int (Int64)

main = do
    n <- readLn :: IO Int
    replicateM_ n run

run = do
    (hc:dc:_) <- readInt64s
    (hm:dm:_) <- readInt64s
    (k:w:a:_) <- readInt64s
    let x = ok hc dc hm dm k w a
    if x then putStrLn "YES" else putStrLn "NO"

ok hc dc hm dm k w a = or [ok' (hc+n*a) (dc+(k-n)*w) hm dm |n <- [0..k]]

ok' hc dc hm dm = f hc dm >= f hm dc

f health attack = (health - 1) `div` attack + 1

readInt64s :: IO [Int64]
readInt64s = fmap (map read.words) getLine

import Data.Int (Int64)
import Control.Monad (replicateM_)
main = read <$> getLine >>= flip replicateM_ scase
scase =  readNums >>=
        \[hc, dc] -> readNums >>=
        \[hm, dm] -> readNums >>=
        \[k, w, a] -> putStrLn (if slay hc dc hm dm k w a then "YES" else "NO")
  where
    readNums :: IO [Int64]
    readNums = map read . words <$> getLine

ceil a b = if mod a b == 0 then div a b else 1 + div a b
slay hc dc hm dm k w a = any (\t -> s' (hc+t*a) (dc+(k-t)*w) hm dm) [0..k]
  where s' hc dc hm dm =  (ceil hc dm >= ceil hm dc)


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

solve :: String -> String
solve [] = []
solve [a] = []
solve (a:b:c)
    | a /= b    = (a:b:(solve c))
    | otherwise = solve (b:c)

main :: IO ()
main = do
    _ <- getLine
    s <- getLine
    print $ (-) (length s) (length $ solve s)
    putStrLn $ solve s

--prewritten code: https://github.com/antma/algo
{-# LANGUAGE BangPatterns, Safe #-}
{-# Options_GHC -O2 #-}
import Data.ByteString.Builder
import Data.Monoid
import System.IO
import qualified Data.ByteString.Char8 as C
import Data.Time (diffTimeToPicoseconds, utctDayTime, getCurrentTime)
import Data.Char

getSeed = return . fromInteger . (`mod` 999983) . diffTimeToPicoseconds . utctDayTime =<< getCurrentTime :: IO Int

ru, ri :: C.ByteString -> Int

ru = C.foldl' (\a c -> a * 10 - 48 + ord c) 0
ri s
  | C.head s == '-' = negate $ ru $ C.tail s
  | otherwise = ru s

solve :: [C.ByteString] -> Builder
solve (sn:s:_) = intDec (n - C.length r) <> char7 '\n' <> byteString r <> char7 '\n'
  where
    !n = ri sn
    z = C.take n s
    loop :: String -> String -> String
    loop [] r = r
    loop [a] r = r
    loop (a:b:xs) r
      | a == b = loop (b:xs) r
      | True = loop xs (b : a : r)
    r = C.reverse $ C.pack $ loop (C.unpack z) []

main :: IO ()
main = hPutBuilder stdout . solve . C.words =<< C.getContents

module Main where

main :: IO ()
main = do
  count <- read <$> getLine
  string <- getLine
  let (removed, goodString) = goodCount count string
  print $ removed
  putStrLn goodString

goodCount::Int -> String -> (Int, String)
goodCount count string =
  let
    indexedString s = zip [1..] s
    evens s = snd <$> filter (even .fst) ( indexedString s)
    odds s = snd <$> filter (odd .fst) ( indexedString s)
    goodLength:: String -> Int
    goodLength s = length $ takeWhile (uncurry (/=)) $ zip (odds s) (evens s)
    extension [] = []
    extension (x:[]) = []
    extension s@(x:y:xs) = if x == y
      then extension (y:xs)
      else finalString s
    good  s = take ((goodLength s)*2) s
    bad s = drop ((goodLength s)*2) s
    finalString s = (good s) ++ extension (bad s)
    fs = finalString string
  in (length string - length fs, fs)

main = do
    unusefulThrash <- getLine
    s <- getLine
    let ans = solve s
    putStrLn $ show $ length s - length ans
    putStrLn ans

solve :: String -> String
solve [] = []
solve [x] = []
solve (x:y:xs) =
    if x == y
    then solve (x:xs)
    else x:y:(solve xs)