{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE MultiWayIf #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
import Debug.Trace
-- trace _ = id

solve :: Int -> Int -> [Int] -> Int
solve bN bK as = runST action
  where
  vA = VU.fromListN bN (map (+ (-bK)) as)
  vASum = VU.postscanl' (+) 0 vA
  vOrd = VU.fromListN bN $ map snd $ sort [(vASum VU.! i, i) | i <- [0..bN-1]]

  action = sgtCreate bN (0,0,0) >>= act
  act sgt = do
    sInit
    fst <$> foldM op (0, 0) [0..bN-1]
    where
    op (!acc, border) i = do
      cnt <- sAsk border
      sReset (i, vASum VU.! i)
      return (acc + cnt, border + (vA VU.! i))
  
    sInit = sgtAct () sgt mfInit 0 bN
    sAsk q = sgtAct q sgt mfAsk 0 bN
    sReset (i,q) = sgtAct (i,q) sgt mfReset 0 bN
  
  mfInit _ _ rcL rcR sgt node l r
    | l+1 == r = do
        let x = vASum VU.! (vOrd VU.! l)
            trip = (x,x,1::Int)
        sgtWrite sgt node trip
        return trip
    | otherwise = do
        (xL,yL,cL) <- rcL ()
        (xR,yR,cR) <- rcR ()
        let trip = (xL, yR, cL+cR)
        sgtWrite sgt node trip
        return trip

  mfAsk q _ rcL rcR sgt node _ _ = do
    (x,y,c) <- sgtRead sgt node
    if | q <= x    -> return c
       | y < q     -> return 0
       | otherwise -> (+) <$> rcL q <*> rcR q

  mfReset (i,q) _ rcL rcR sgt node l r = do
    (x,y,c) <- sgtRead sgt node
    if | q < x || y < q   -> return c
       | l+1 /= r         -> do
           newC :: Int <- (+) <$> rcL (i,q) <*> rcR (i,q)
           sgtWrite sgt node (x,y,newC)
           return newC
       | vOrd VU.! l == i -> do
           sgtWrite sgt node (x,y,0)
           return 0
       | otherwise        -> return c
  
-------------------------------------------------------------------------------

data SegTree s a = SegTree {
  sgtVec :: VUM.MVector s a,
  sgtSize :: Int
}
data SgtFT = SgtIn | SgtOut | SgtOther deriving(Show)
type SgtMF   s a b c =
  c ->             -- parameter
  SgtFT ->         -- type (In/Out/Other)
  (c -> ST s b) -> -- left recursive function
  (c -> ST s b) -> -- right recursive function
  SegTree s a ->   -- segment tree
  Int ->           -- node
  Int ->           -- left bound for the node (incl)
  Int ->           -- right bound for the node (excl)
  ST s b

sgtRead :: (VUM.Unbox a) => SegTree s a -> Int -> ST s a
{-# INLINE sgtRead #-}
sgtRead sgt node = VUM.read (sgtVec sgt) node

sgtWrite :: (VUM.Unbox a) => SegTree s a -> Int -> a -> ST s ()
{-# INLINE sgtWrite #-}
sgtWrite sgt node a = VUM.write (sgtVec sgt) node a

sgtModify :: (VUM.Unbox a) => SegTree s a -> (a -> a) -> Int -> ST s ()
{-# INLINE sgtModify #-}
sgtModify sgt f node = VUM.modify (sgtVec sgt) f node

sgtCreate :: (VUM.Unbox a) => Int -> a -> ST s (SegTree s a)
{-# INLINE sgtCreate #-}
sgtCreate n a = do
  vec <- VUM.replicate (4*n) a
  return $ SegTree { sgtVec = vec, sgtSize = n }

sgtAct :: (VUM.Unbox a) =>
          c ->             -- parameter
          SegTree s a ->   -- segment tree
          SgtMF s a b c -> -- action body
          Int ->           -- left
          Int ->           -- right
          ST s b
{-# INLINE sgtAct #-}
sgtAct c0 sgt mf left right = sub c0 0 0 (sgtSize sgt)
  where
  sub c node l r = mf c ft rcL rcR sgt node l r
    where
      ft | left <= l && r <= right = SgtIn
         | r <= left || right <= l = SgtOut
         | otherwise               = SgtOther
      mid = (l+r) `div` 2
      rcL c' = sub c' (2*node + 1) l mid
      rcR c' = sub c' (2*node + 2) mid r

sgtTrace :: (VUM.Unbox a, Show a) => SegTree s a -> ST s ()
sgtTrace sgt = 
  let size = sgtSize sgt
      sub vec node l r = do
        VUM.modify vec (\(_,_,_,a) -> (True,l,r,a)) node
        unless (l+1 == r) $ do
          let mid = (l + r) `div` 2
          sub vec (2*node+1) l mid
          sub vec (2*node+2) mid r
  in do
    vec <- VUM.new (4*size)
    forM_ [0..4*size-1] $ \node -> do
      a <- sgtRead sgt node
      VUM.write vec node (False,0,0,a)
    sub vec 0 0 size
    forM_ [0..4*size-1] $ \node -> do
      (eff,l,r,a) <- VUM.read vec node
      when eff $ 
        trace ("  " ++ show node ++ " [" ++ show l ++ ", " ++ show r ++ ")  "
               ++ show a) (return ())

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

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_bN,bs_bK]:remLines1 = remLines0
      bN = readBInt bs_bN
      bK = readBInt bs_bK
      as = map (\[x] -> readBInt x) remLines1
  in solve bN bK as

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


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

inp1 = "3 6\n7\n5\n7\n"
inp2 = "1 2\n1\n"
inp3 = "7 26\n10\n20\n30\n40\n30\n20\n10\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
test1 = tv1 == 5
test2 = tv2 == 0
test3 = tv3 == 13
alltest = test1 && test2 && test3

