open System
open System.Collections.Generic

module InputUtility =
    let InputTokens = new Queue<string>()

    let EnsureInput () =
        if InputTokens.Count = 0 then
            let input = Console.ReadLine ()
            let s = input.Split ([|' '|], StringSplitOptions.RemoveEmptyEntries)
            if s.Length > 0 then
                for x in s do InputTokens.Enqueue(x)
                true
            else false
        else true

    let rec ReadNext () =
        if EnsureInput () then InputTokens.Dequeue ()
        else ReadNext ()

    let ReadNextInt () = ReadNext () |> int

    let Read2Int () = ReadNextInt (), ReadNextInt ()

    let ReadListOf f n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop ((ReadNext () |> f) :: acc) (c-1)
        loop [] n

    let MultipleCaseWithId f =
        let caseNum = ReadNextInt ()
        let rec loop index =
            if index = caseNum then ()
            else
                f index
                loop (index + 1)
        loop 0

    let MultipleCase f = MultipleCaseWithId (fun _ -> f ())

    let ReadList n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop (ReadNext () :: acc) (c-1)
        loop [] n

open InputUtility

module ARC075 =
    type 'a BinaryIndexedTree (arr: 'a array) =
        let n = arr.Length

        member b.Set x f =
            let rec loopUp c =
                if c < n then
                    arr.[c] <- f arr.[c]
                    loopUp (c + (c &&& -c))
            loopUp x

        member b.Fold x f r =
            let rec loopDown c e =
                if c > 0 then
                    let ne = f e arr.[c]
                    loopDown (c - (c &&& -c)) ne
                else e
            loopDown x r
    let private ``Meaningful Mean`` () =
        let n, k = Read2Int ()
        let ba =
            let a = Array.zeroCreate (n + 2)
            new BinaryIndexedTree<_> (a)
        let inc x = ba.Set (x + 1) ((+) 1L)
        let read x = ba.Fold (x + 1) (+) 0L
        ReadListOf int64 n
        |> Seq.scan (+) 0L
        |> Seq.mapi (fun i v -> v - int64 i * int64 k, i)
        |> Seq.sort
        |> Seq.sumBy (fun (s, i) ->
            let c = read i
            printfn "%d (%d) : %d" i s c
            inc i
            c)
        |> printfn "%d"

    let Entry = ``Meaningful Mean``

ARC075.Entry ()