Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points!

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point.

It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$.

NoteLet's look at all possible orders of cities Monuments will be build in:   $$$[1, 2, 3]$$$:   the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$;  the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$;  the third city controls all points at distance at most $$$1$$$, or point $$$1$$$.  In total, $$$4$$$ points are controlled.  $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points.  $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points.  $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points.  $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points.  $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points.  The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$

import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits
import Data.Int
import Data.List
import Data.Maybe
import Data.Ratio
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

md :: Integer
md = 998244353

newtype MInt = MInt Integer deriving Eq

instance Show MInt where
    show (MInt a) = show a

instance Num MInt where
    (MInt a) + (MInt b) =
        let r = a + b in
            MInt $ if r >= md then r - md else r
    (MInt a) * (MInt b) = MInt $ (a * b) `mod` md
    abs = id
    signum (MInt a) = MInt $ signum a
    fromInteger a = MInt $ fromInteger (a `mod` fromIntegral md)
    negate (MInt 0) = 0
    negate (MInt a) = MInt $ md - a

instance Fractional MInt where
  recip a = a ^ (md - 2)
  fromRational x =
        let a = numerator x `mod` fromIntegral md
            b = denominator x `mod` fromIntegral md
        in
            MInt (fromInteger a) / MInt (fromInteger b)

solve :: [Int] -> MInt
solve xs = (product . map fromIntegral) (zipWith (\x i -> (x - i) `max` 0) xs [1..])

main = do
    [n, m] <- map parseInt . BS.words <$> BS.getLine
    xss <- fmap (map sort . transpose) . replicateM n $ map parseInt . BS.words <$> BS.getLine
    let f = (product . map fromIntegral) [1..n] :: MInt
        r = sum (map ((f-) . solve) xss) / f
    print r

import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits
import Data.Int
import Data.List
import Data.Maybe
import Data.Ratio
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

md :: Int64
md = 998244353

newtype MInt = MInt Int64 deriving Eq

instance Show MInt where
    show (MInt a) = show a

instance Num MInt where
    (MInt a) + (MInt b) =
        let r = a + b in
            MInt $ if r >= md then r - md else r
    (MInt a) * (MInt b) = MInt $ (a * b) `mod` md
    abs = id
    signum (MInt a) = MInt $ signum a
    fromInteger a = MInt $ fromInteger (a `mod` fromIntegral md)
    negate (MInt 0) = 0
    negate (MInt a) = MInt $ md - a

instance Fractional MInt where
  recip a = a ^ (md - 2)
  fromRational x =
        let a = numerator x `mod` fromIntegral md
            b = denominator x `mod` fromIntegral md
        in
            MInt (fromInteger a) / MInt (fromInteger b)

solve :: [Int] -> MInt
solve xs = (product . map fromIntegral) (zipWith (\x i -> (x - i) `max` 0) xs [1..])

main = do
    [n, m] <- map parseInt . BS.words <$> BS.getLine
    xss <- fmap (map sort . transpose) . replicateM n $ map parseInt . BS.words <$> BS.getLine
    let f = (product . map fromIntegral) [1..n] :: MInt
        r = sum (map ((f-) . solve) xss) / f
    print r

import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits
import Data.Int
import Data.List
import Data.Maybe
import Data.Ratio
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

md :: Int64
md = 998244353

newtype MInt = MInt Int64 deriving Eq

instance Show MInt where
    show (MInt a) = show a

instance Num MInt where
    (MInt a) + (MInt b) =
        let r = a + b in
            MInt $ if r >= md then r - md else r
    (MInt a) * (MInt b) = MInt $ (a * b) `mod` md
    abs = id
    signum (MInt a) = MInt $ signum a
    fromInteger a = MInt $ fromInteger (a `mod` fromIntegral md)
    negate (MInt 0) = 0
    negate (MInt a) = MInt $ md - a

instance Fractional MInt where
  recip a = a ^ (md - 2)
  fromRational x =
        let a = numerator x `mod` fromIntegral md
            b = denominator x `mod` fromIntegral md
        in
            MInt (fromInteger a) / MInt (fromInteger b)

solve :: [Int] -> MInt
solve xs = (product . map fromIntegral) (zipWith (\x i -> (x - i) `max` 0) xs [1..])

main = do
    [n, m] <- map parseInt . BS.words <$> BS.getLine
    xss <- fmap (map sort . transpose) . replicateM n $ map parseInt . BS.words <$> BS.getLine
    let f = (product . map fromIntegral) [1..n] :: MInt
        fi = recip f
        r = sum (map ((f-) . solve) xss) * fi
    print r

import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits
import Data.Int
import Data.List
import Data.Maybe
import Data.Ratio
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

md :: Int64
md = 998244353

newtype MInt = MInt Int64 deriving (Eq)

instance Show MInt where
    show (MInt a) = show a

instance Num MInt where
    (MInt a) + (MInt b) =
        let r = a + b
            rr = if r >= md then r - md else r
        in
            MInt rr
    (MInt a) * (MInt b) = MInt $ (a * b) `mod` md
    abs = id
    signum (MInt a) = MInt $ signum a
    fromInteger a = MInt $ fromInteger (a `mod` fromIntegral md)
    negate (MInt 0) = 0
    negate (MInt a) = MInt $ md - a

instance Fractional MInt where
  recip a = a ^ (md - 2)
  fromRational x =
        let a = numerator x `mod` fromIntegral md
            b = denominator x `mod` fromIntegral md
        in
            MInt (fromInteger a) / MInt (fromInteger b)

solve :: [Int] -> MInt
solve xs = (product . map fromIntegral) (zipWith (\x i -> (x - i) `max` 0) xs [1..])

main = do
    [n, m] <- map parseInt . BS.words <$> BS.getLine
    xss <- fmap (map sort . transpose) . replicateM n $ map parseInt . BS.words <$> BS.getLine
    let f = (product . map fromIntegral) [1..n] :: MInt
        fi = recip f
        r = sum (map ((f-) . solve) xss) * fi
    print r

import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits
import Data.Int
import Data.List
import Data.Maybe
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

md :: Int64
md = 998244353

add :: Int64 -> Int64 -> Int64
add a b =
    let
        r = a + b
    in
        if r >= md then
            r - md
        else
            r

sub :: Int64 -> Int64 -> Int64
sub a b =
    let
        r = a - b
    in
        if r < 0 then
            r + md
        else
            r

mul :: Int64 -> Int64 -> Int64
mul a b = (a * b) `mod` md

pm :: Int64 -> Int64 -> Int64
pm a 0 = 1
pm a e =
    let
        r = pm a (e `div` 2)
        rr = r `mul` r
    in
        if even e then
            rr
        else
            rr `mul` a

inv :: Int64 -> Int64
inv a = pm a (md - 2)

solve :: [Int] -> Int64
solve xs = foldr1 mul (zipWith (\x i -> (x - i) `max` 0) (map fromIntegral xs) [1..])

main = do
    [n, m] <- map parseInt . BS.words <$> BS.getLine
    xss <- fmap (map sort . transpose) . replicateM n $ map parseInt . BS.words <$> BS.getLine
    let f = foldr1 mul [1..(fromIntegral n)]
        fi = inv f
        r = foldr1 add (map ((f `sub`) . solve) xss) `mul` fi
    print r

import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits
import Data.List
import Data.Maybe
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

md :: Int
md = 998244353

add :: Int -> Int -> Int
add a b =
    let
        r = a + b
    in
        if r >= md then
            r - md
        else
            r

sub :: Int -> Int -> Int
sub a b =
    let
        r = a - b
    in
        if r < 0 then
            r + md
        else
            r

mul :: Int -> Int -> Int
mul a b = (a * b) `mod` md

pm :: Int -> Int -> Int
pm a 0 = 1
pm a e =
    let
        r = pm a (e `div` 2)
        rr = r `mul` r
    in
        if even e then
            rr
        else
            rr `mul` a

inv :: Int -> Int
inv a = pm a (md - 2)

solve :: [Int] -> Int
solve xs = foldr1 mul (zipWith (\x i -> (x - i) `max` 0) xs [1..])

main = do
    print (maxBound::Int)
    -- [n, m] <- map parseInt . BS.words <$> BS.getLine
    -- xss <- fmap (map sort . transpose) . replicateM n $ map parseInt . BS.words <$> BS.getLine
    -- let f = foldr1 mul [2..n]
    --     fi = inv f
    --     r = foldr1 add (map ((f `sub`) . solve) xss) `mul` fi
    -- print r

import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits
import Data.List
import Data.Maybe
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

md :: Int
md = 998244353

add :: Int -> Int -> Int
add a b =
    let
        r = a + b
    in
        if r >= md then
            r - md
        else
            r

sub :: Int -> Int -> Int
sub a b =
    let
        r = a - b
    in
        if r < 0 then
            r + md
        else
            r

mul :: Int -> Int -> Int
mul a b = (a * b) `mod` md

pm :: Int -> Int -> Int
pm a 0 = 1
pm a e =
    let
        r = pm a (e `div` 2)
        rr = r `mul` r
    in
        if even e then
            rr
        else
            rr `mul` a

inv :: Int -> Int
inv a = pm a (md - 2)

solve :: [Int] -> Int
solve xs = foldr1 mul (zipWith (\x i -> (x - i) `max` 0) xs [1..])

main = do
    [n, m] <- map parseInt . BS.words <$> BS.getLine
    xss <- fmap (map sort . transpose) . replicateM n $ map parseInt . BS.words <$> BS.getLine
    let f = foldr1 mul [2..n]
        fi = inv f
        r = foldr1 add (map ((f `sub`) . solve) xss) `mul` fi
    print r


Consider a conveyor belt represented using a grid consisting of $$$n$$$ rows and $$$m$$$ columns. The cell in the $$$i$$$-th row from the top and the $$$j$$$-th column from the left is labelled $$$(i,j)$$$. Every cell, except $$$(n,m)$$$, has a direction R (Right) or D (Down) assigned to it. If the cell $$$(i,j)$$$ is assigned direction R, any luggage kept on that will move to the cell $$$(i,j+1)$$$. Similarly, if the cell $$$(i,j)$$$ is assigned direction D, any luggage kept on that will move to the cell $$$(i+1,j)$$$. If at any moment, the luggage moves out of the grid, it is considered to be lost. There is a counter at the cell $$$(n,m)$$$ from where all luggage is picked. A conveyor belt is called functional if and only if any luggage reaches the counter regardless of which cell it is placed in initially. More formally, for every cell $$$(i,j)$$$, any luggage placed in this cell should eventually end up in the cell $$$(n,m)$$$. This may not hold initially; you are, however, allowed to change the directions of some cells to make the conveyor belt functional. Please determine the minimum amount of cells you have to change.Please note that it is always possible to make any conveyor belt functional by changing the directions of some set of cells.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n, m$$$ ($$$1 \le n \le 100$$$, $$$1 \le m \le 100$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines each contain $$$m$$$ characters. The $$$j$$$-th character in the $$$i$$$-th line, $$$a_{i,j}$$$ is the initial direction of the cell $$$(i, j)$$$. Please note that $$$a_{n,m}=$$$ C.

For each case, output in a new line the minimum number of cells that you have to change to make the conveyor belt functional.

4
3 3
RRD
DDR
RRC
1 4
DDDC
6 9
RDDDDDRRR
RRDDRRDDD
RRDRDRRDR
DDDDRDDRR
DRRDRDDDR
DDRDRRDDC
1 1
C

NoteIn the first case, just changing the direction of $$$(2,3)$$$ to D is enough.You can verify that the resulting belt is functional. For example, if we place any luggage at $$$(2,2)$$$, it first moves to $$$(3,2)$$$ and then to $$$(3,3)$$$. In the second case, we have no option but to change the first $$$3$$$ cells from D to R making the grid equal to RRRC.

readInts :: IO [Int]
readInts = do
    line <- getLine
    return $ map (read) $ words line

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

getNLines :: Int -> IO [String]
getNLines 0 = return []
getNLines n = do
    line <- getLine
    lines' <- getNLines (n-1)
    return $ line : lines'

countR :: [String] -> Int
countR [] = 0
countR (line:other) = (if (head $ reverse line) == 'R' then 1 else 0) + (countR other)

countD :: [String] -> Int
countD matrix = let work = last matrix in foldl (\acc x -> acc + (if x == 'D' then 1 else 0)) 0 work

main :: IO ()
main = do
    t <- readInt
    for t where
        for 0 = return ()
        for i = do
            [n,_] <- readInts
            matrix <- getNLines n
            putStrLn $ show $ countR matrix + countD matrix
            for (i-1)

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

main = getLine >>= flip replicateM_ test . read

test = do
  [n, _] <- map read . words <$> getLine
  as <- replicateM n getLine
  print $ length (filter (== 'R') (last <$> as)) + length (filter (== 'D') (last as))

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

onecase = do
		[x,y]<- map read <$> words <$> getLine ::IO [Int]
		z<-replicateM x getLine
		let a1= length $ filter (=='R') $ map last z
		let a2 = length $ filter (=='D') $ last z
		print $ a1+a2

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

import Control.Monad (replicateM, replicateM_)

main :: IO ()
main = do
  t <- read <$> getLine
  replicateM_ t $ do
    [n, _m] <- map read . words <$> getLine
    a <- replicateM n getLine
    let lastColIssues = length [() | conv <- map last a, conv == 'R']
        lastRowIssues = length [() | conv <- last a,     conv == 'D']
    print (lastColIssues + lastRowIssues)


You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.

The first line contains single positive integer n (1 ≤ n ≤ 105) — the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Print the maximum length of an increasing subarray of the given array.

import Data.Maybe
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8

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

main = do
    n <- getInt
    xs <- getInts
    print $ solve xs

solve (x:xs) = f xs x 1 1 where
    f [] prev cnt maxCnt = max cnt maxCnt
    f (curr:xs) prev cnt maxCnt
        | curr > prev = f xs curr (cnt+1) maxCnt
        | otherwise = f xs curr 1 (max cnt maxCnt)

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

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

main = getLine >> getList >>= print . succ . maximum . ( 0 : ) . map length . filter head . group . f

f [] = []
f [a] = []
f ( a : b : l ) = ( a < b ) : f ( b : l )

-- ttt lst len mx
--   | (length lst) == 1 = mx
--   | (head lst) < (head (tail lst)) = ttt (tail lst) (succ len) (maximum [(succ len), mx])
--   | otherwise = ttt (tail lst) 1 mx

ttt (a : b : cc) len mx
  | a < b = ttt (b : cc) (succ len) (maximum [(succ len), mx])
  | otherwise = ttt (b : cc) 1 mx
ttt (a : bb) len mx = mx

conv (a : bb) = ((read a) :: Integer) : (conv bb)
conv mpt = []

main = do
  ff <- getLine
  gg <- getLine
  let aa = (conv (words gg))

      ans = ttt aa 1 1

  putStrLn (show ans)

{-# LANGUAGE BangPatterns #-}

import Control.Applicative

main = do
    getLine
    arr <- foldr(\n acc -> (read n :: Int) : acc) [] . words <$> getLine
    print $ func arr (1, 1)

func :: [Int] -> (Int, Int) -> Int
func (x:y:s) !(cr, mx)
    | y > x = func (y:s) (cr + 1, mx)
    | otherwise = func (y:s) (1, max cr mx)
func _ !(cr, mx) = max cr mx

import Control.Applicative

main = do
    getLine
    arr <- foldr (\n acc -> (read n :: Int) : acc) [] . words <$> getLine
    print $ func arr (1, 1)

func :: [Int] -> (Int, Int) -> Int
func (x:y:s) (cr, mx)
    | y > x = func (y:s) (cr + 1, mx)
    | otherwise = func (y:s) (1, max cr mx)
func _ (cr, mx) = max cr mx

import Control.Applicative
import Data.Foldable

main = do
    getLine
    arr <- foldr'(\n acc -> (read n :: Int) : acc) [] . words <$> getLine
    print $ func arr (1, 1)

func :: [Int] -> (Int, Int) -> Int
func (x:y:s) (cr, mx)
    | y > x = func (y:s) (cr + 1, mx)
    | otherwise = func (y:s) (1, max cr mx)
func _ (cr, mx) = max cr mx

main = do
  n <- getLine
  l <- getLine
  let a = readInt l
  putStrLn . show . get1st $ foldl f (0, 0, 0) a
    where f (ans, cur, num) x = if num < x
            then (max ans (cur + 1), cur + 1, x)
            else (ans, 1, x)
          get1st (x, _, _) = x

readInt :: String -> [Int]
readInt l = map read (words l)

import Control.Applicative
import Data.List

main = interact $ show . (+ 1) . maximum . (0 :) . map length . filter (id . head) . group . (zipWith (<) <$> id <*> tail) . map (read :: String -> Int) . tail . words

import Data.List
import Data.Int
import Data.Maybe
import Data.Char
import Control.Monad
import Control.Monad.ST.Safe
import Data.Array
import Data.Array.ST.Safe
import Data.STRef
main=   readsolveprint
readsolveprint::IO()
readsolveprint = interact $ solve. concat. map (map read.words).take 2.lines
solve :: [Int]-> String
solve (x:xs) = show $ (\ (a,b,c)->a) $foldl f (1,1, head xs) xs
  where
  f (b1,b2,b3) a | a<=b3              = (b1, 1, a)
                 | a>b3 && b2+1 > b1 =  (b2+1, b2+1, a)
                 | otherwise         =  (b1, b2+1, a)

main :: IO ()
main = do
    _ <-getLine
    inp <- getLine
    let nums = map read (words inp) :: [Int]
    print $ maximum $ map length $ doTheThing nums

doTheThing :: [Int] -> [[Int]]
doTheThing = foldl makeNum [[]]

makeNum :: [[Int]] -> Int -> [[Int]]
makeNum [[]] num = [[num]]
makeNum nums num =
    if head (head nums) < num
        then let newFirstNums = num : head nums in newFirstNums : tail nums
        else [num] : nums

import Data.List

toint :: String -> Int
toint = read

main = getLine >> getLine >>= print . solve . map toint . words

solve a = succ . maximum . (0 : ) . map length . filter head . group . zipWith (<) a $ tail a

import Control.Applicative
import Data.List

third (_, _, c) = c

solve a =
    third $ foldl' f (-1, 0, 0) a
    where
        f (prev, cont, maxv) curr =
            if prev < curr then
                (curr, cont + 1, max maxv (cont + 1))
            else
                (curr, 1, max maxv 1)

main = do
    _ <- getLine
    a <- map read . words <$> getLine :: IO [Int]
    print $ solve a

import Data.Function
import Data.List
main = interact $ show . solve . map read . tail . words
solve xs = succ $ maximum $ (0 :) $ map length $ filter ((> 0) . head) $ group $ map signum $ zipWith (-) (tail xs) xs

main = getContents >>= print . solve 1 1 . map read . tail . words

solve :: Int -> Int -> [Int] -> Int
solve x y [a0] = max x y
solve x y (a0:a1:as) = if a0 < a1
                       then solve x (y + 1) (a1:as)
                       else solve (max x y) 1 (a1:as)

--le me trying to write a reading function
import Control.Monad (mfilter)

--am facut citirea de mana si nu da rasp corect decat pt cifre
citesc_nr :: String -> Int
citesc_nr s = read s
citesc_array :: [String] -> [Int]
citesc_array = map read
main = do
    x <- getLine
    let n = (citesc_nr x)
    --putStrLn (x)
    --vector <- read `fmap` getLine :: IO Int
    vector <- getLine
    --print vector
    --let i = (citesc_nr (takeWhile (/= '\n') vector) )
    --let y = filter (/=' ') vector
    let y = words vector

    --let replace a b = map $ maybe b id . mfilter (/= a) . Just
    --let y = replace ' ' '3' vector
    --let despart c = c:[]
    --let f x = map despart x
    --let array = f y
    let int_array = citesc_array y
    print $ solve int_array
    --print y

solve(x:xs) = dp xs x 1 1 where
    dp [] pred current ans = max current ans
    dp (curr:xs) pred current ans
        | curr > pred = dp xs curr (current+1) ans
        | otherwise = dp xs curr 1 (max current ans)

{--main :: IO ()
main = do
    line <- getLine
    if null line
        then return ()
        else do
            putStrLn $ reverseWords line
            main

reverseWords :: String -> String
reverseWords = unwords . map reverse . words
--}

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

process m n _ [] = max m n
process m n l (a:as) | a>l = process m (n+1) a as
                     | otherwise = process (max m n) 1 a as

main::IO ()
main=do
	s<- read <$> getLine:: IO Int
	a<- map read <$> words <$> getLine ::IO [Int]
	print $ process 0 0 0 a

import Data.List

main = interact $ show . f . map read . words

f :: [Int] -> Int
f (n:as) = 1 +
    case filter head . group . zipWith (<) as $ tail as of
        [] -> 0
        xs -> maximum . map length $ xs

import Control.Applicative
import Data.List

main = interact $ show . maximum . (0 :) . map ((+ 1) . length) . filter (id . head) . group . (zipWith (<) <$> id <*> tail) . map (read :: String -> Int) . tail . words

import Data.Function
import Data.List
main = interact $ show . solve . map read . tail . words
solve xs = succ $ maximum $ (0 :) $ map length $ filter ((/= 0) . head) $ group $ map signum $ zipWith (-) (tail xs) xs


You are given an array of $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. After you watched the amazing film "Everything Everywhere All At Once", you came up with the following operation.In one operation, you choose $$$n-1$$$ elements of the array and replace each of them with their arithmetic mean (which doesn't have to be an integer). For example, from the array $$$[1, 2, 3, 1]$$$ we can get the array $$$[2, 2, 2, 1]$$$, if we choose the first three elements, or we can get the array $$$[\frac{4}{3}, \frac{4}{3}, 3, \frac{4}{3}]$$$, if we choose all elements except the third.Is it possible to make all elements of the array equal by performing a finite number of such operations?

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$)  — the number of integers. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 100$$$).

For each test case, if it is possible to make all elements equal after some number of operations, output $$$\texttt{YES}$$$. Otherwise, output $$$\texttt{NO}$$$. You can output $$$\texttt{YES}$$$ and $$$\texttt{NO}$$$ in any case (for example, strings $$$\texttt{yEs}$$$, $$$\texttt{yes}$$$, $$$\texttt{Yes}$$$ will be recognized as a positive response).

NoteIn the first test case, all elements are already equal.In the second test case, you can choose all elements except the third, their average is $$$\frac{1 + 2 + 4 + 5}{4} = 3$$$, so the array will become $$$[3, 3, 3, 3, 3]$$$.It's possible to show that it's impossible to make all elements equal in the third and fourth test cases.

chunksOf :: Int -> [a] -> [[a]]
chunksOf count (item1:item2:items) = [item1, item2]:chunksOf count items
chunksOf count [] = []
chunksOf count [x] = []

processLine :: [[String]] -> [String]
processLine args = do
    [countS, itemsS] <- args
    let count = read countS :: Int
    let items = read <$> words itemsS :: [Int]
    let sumItems = sum items

    let {
        _go item = (_sum `div` _count) == item && (_sum `mod` _count) == 0
        where _sum = sumItems - item
              _count = count - 1
        }

    let result = or (_go <$> items)
    return (if result then "YES" else "NO")

main = do
    input <- tail . lines <$> getContents
    let chunks = chunksOf 2 input

    let results = processLine chunks

    mapM_ putStrLn results

poss :: [Int] -> Bool
poss ls = avg `elem` ls'
  where
    ls' = map (fromIntegral :: Int -> Float) ls
    avg = (sum ls') / (fromIntegral $ length ls')

solve = solves . lines

val s = poss (map read (words s))

solves [] = ""
solves [a, b] = if val b then "yes" else "no"
solves (a : b : s) = (if val b then "yes\n" else "no\n") ++ solves s

main = do
    getLine
    interact solve

import Control.Monad (replicateM_)
main = read <$> getLine >>= flip replicateM_ scase
scase = read <$> getLine >>=
        \n -> map read . words <$> getLine >>=
        \as -> putStrLn $ if (possible as n) then "YES" else "NO"

possible :: [Int] -> Int -> Bool
possible as n = any (f (sum as) n) as
  where f :: Int -> Int -> Int -> Bool
        f s n e = (s-e) == (n-1) * e

import Control.Monad (replicateM)
-- import Data.Array.IArray

main :: IO ()
main = do
  t <- readLn :: IO Int
  res <- replicateM t run
  putStrLn $ unlines res

run :: IO String
run = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  return . toRes $ solve n as

toRes :: Bool -> String
toRes b = if b then "YES" else "NO"

solve :: Int -> [Int] -> Bool
solve n as = md == 0 && mean `elem` as
  where
    (mean, md) = sum as `divMod` n

-- https://codeforces.com/contest/1679/problem/D
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DatatypeContexts #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TupleSections #-}

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

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

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

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

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

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

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

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

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

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

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

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

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

{- END OF GENERAL -}

solve :: Int -> [Int] -> Bool
solve n as = any checkElem $ as
    where
        sumAs = sum as
        checkElem e = isDivisible && midElement == e
            where
                isDivisible = (sumAs - e) `mod` (n - 1) == 0
                midElement = (sumAs - e) `div` (n - 1)

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

chunksOf :: Int -> [a] -> [[a]]
chunksOf count (item1:item2:items) = [item1, item2]:chunksOf count items
chunksOf count [] = []
chunksOf count [x] = []

processLine :: [[String]] -> [String]
processLine args = do
    [countS, itemsS] <- args
    let count = read countS :: Int
    let items = read <$> words itemsS :: [Int]
    let sumItems = sum items

    let {
        _go item = (_sum `div` _count) == item && (_sum `mod` _count) == 0
        where _sum = sumItems - item
              _count = count - 1
        }

    let result = or (_go <$> items)
    return (if result then "YES" else "NO")

main = do
    input <- tail . lines <$> getContents
    let chunks = chunksOf 2 input

    let results = processLine chunks

    mapM_ print results

poss :: [Int] -> Bool
poss ls = avg `elem` ls
  where
    avg = (sum ls) `div` (length ls)

solve = solves . lines

val s = poss (map read (words s))

solves [] = ""
solves [a, b] = if val b then "yes" else "no"
solves (a : b : s) = (if val b then "yes\n" else "no\n") ++ solves s

main = do
    getLine
    interact solve


Let's dive into one of the most interesting areas of magic — writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output.

The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 ( = 220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means.

Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter.

#   include <cstdio>

using namespace std;

int main     (   ){
puts("Hello # World"); #
#
}

#   include <cstdio>
usingnamespacestd;intmain(){puts("Hello#World");#
#
}

NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other.

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

isStrong xs = case dropWhile (isSpace) xs of
                ('#':_) -> True
                _ -> False

solve :: [String] -> [String]
solve [] = [""]
solve lst@(x:xs)
      | isStrong x = x : ending xs
      | otherwise  = (:) (filter (not.isSpace) $ concat $ stuff) (ending other)
      where (stuff, other) = break (isStrong) lst
            ending [] = []
            ending xs = solve xs

main = do
  ls <- getContents
  putStr $ unlines $ solve (lines ls)

import Data.Char

main=interact$unlines.solve.lines

solve :: [String] -> [String]
solve [] = []
solve (s:ss) = case break isAmp ss of
                 ([],ys) | isAmp s   -> s:solve ys
                         | otherwise -> f[s]:solve ys
                 (xs,ys) | isAmp s   -> s:f xs:solve ys
                         | otherwise -> f(s:xs):solve ys

f :: [String] -> String
f = filter(not.isSpace).concat

isAmp :: String -> Bool
isAmp cs = case dropWhile(' '==)cs of
                    ('#':_) -> True
                    _       -> False

import Data.List

main :: IO ()
main = interact solver

solver :: String -> String
solver str = let p = lines str
                 fu st = [x|x<-st,x/=' ']
                 rev st = if fu st /= [] && head (fu st) == '#' then
                           (st,False)
                          else
                           (fu st,True)
                 comp st = groupBy (\x y->(snd x)&&(snd y)) st
             in unlines $ map (foldr (++) [] . map fst) $ comp $ map rev $ lines str

import Data.List
import Data.Char

solve :: [String] -> Maybe String -> [String]
solve [] (Just x) = [x]
solve [] _ = []
solve (x:xs) acc
      | (headM $ dropWhile (isSpace) x) == Just '#' =
          case acc of
            Nothing -> x : solve xs Nothing
            Just y  -> y : (x : solve xs Nothing)
      | True = solve xs $ appendM (filter (not.isSpace) x) acc
      where headM [] = Nothing
            headM (x:_) = Just x
            appendM x (Just y) = Just (y ++ x)
            appendM x _ = Just x

main = do
  ls <- getContents
  putStrLn.unlines $ solve (lines ls) Nothing

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

isStrong xs = case dropWhile (isSpace) xs of
                ('#':_) -> True
                _ -> False

solve :: [String] -> [String]
solve [] = [""]
solve lst@(x:xs)
      | isStrong x = x : solve xs
      | otherwise  = (filter (not.isSpace) $ concat $ stuff) : solve other
      where (stuff, other) = break (isStrong) lst

main = do
  ls <- getContents
  putStr $ unlines $ solve (lines ls)

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

appendM x (Just y) = Just (y ++ x)
appendM x _ = Just x

isStrong xs = case dropWhile (isSpace) xs of
                ('#':_) -> True
                _ -> False

solve :: [String] -> Maybe String -> [String]
solve [] (Just x) = [x]
solve [] _ = []
solve (x:xs) acc
      | isStrong x = solve xs $ appendM (filter (not.isSpace) x) acc
solve (x:xs) (Just y) = y : (x : solve xs Nothing)
solve (x:xs) _ = x : solve xs Nothing

main = do
  ls <- getContents
  mapM_ (putStrLn) $ solve (lines ls) Nothing

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

isStrong xs = case dropWhile (isSpace) xs of
                ('#':_) -> True
                _ -> False

solve :: [String] -> [String]
solve [] = [""]
solve lst@(x:xs)
      | isStrong x = x : solve xs
      | otherwise  = (:) (filter (not.isSpace) $ concat $ stuff) (ending other)
      where (stuff, other) = break (isStrong) lst
            ending [] = []
            ending xs = solve xs

main = do
  ls <- getContents
  putStr $ unlines $ solve (lines ls)

import Data.Char

main=interact$unlines.solve.lines

solve :: [String] -> [String]
solve [] = []
solve (s:ss)
  | isAmp s   = s:g(f xs:solve ys)
  | otherwise = f(s:xs):solve ys
   where (xs,ys) = break isAmp ss

f :: [String] -> String
f = filter(not.isSpace).concat
g :: [String] -> [String]
g [""] = []
g ss = ss
h :: [String] -> [String]
h ("":ss) = ss
h ss =ss

isAmp :: String -> Bool
isAmp cs = case dropWhile(' '==)cs of
                    ('#':_) -> True
                    _       -> False

import Data.Char

main=interact$unlines.solve.lines

solve :: [String] -> [String]
solve [] = []
solve (s:ss)
  | isAmp s   = s:g(f xs:solve ys)
  | otherwise = f(s:xs):solve ys
   where (xs,ys) = break isAmp ss

f :: [String] -> String
f = filter(not.isSpace).concat
g :: [String] -> [String]
g [""] = []
g ss = ss

isAmp :: String -> Bool
isAmp cs = case dropWhile(' '==)cs of
                    ('#':_) -> True
                    _       -> False