Under construction

Still being built. Things may change

Xeroxinator

Interview

Time limit2sMemory limit1024 MB

Summary
Given each minute's arrivals and a per-minute service limit b, compute the total minutes all clones spend in the post office queue over n minutes.
Level

Easy3 of 10

Topics
Queue, Simulation
Solved
No attempts yet

Problem

Doctor Heinz Fufelschmertz was tired of standing in lines, so he built a xeroxinator, a device that makes clones of people. He now sends his clones to stand in lines in his place. Unfortunately, the device malfunctioned. Now too many clones of Heinz are being made, and all of them go to the post office.

Today the post office is open for nn minutes, numbered from 1 to nn. At the start of minute ii, aia_i clones of Fufelschmertz enter the post office and join the end of the queue. In one minute, the post office serves at most bb clones. If the queue has at least bb clones, the first bb of them are served. Otherwise, everyone in the queue is served. All clones served in minute ii leave at the end of minute ii. The post office closes at the end of minute nn. Clones who were not served wait for one more minute, complain, and then leave. Help Heinz compute the total time all clones spend in the post office.

Note that a clone who enters at the start of minute ii and leaves at the end of minute ii spent one minute in the post office.

Input

The first line contains two integers nn and bb, the number of minutes the post office is open and the maximum number of clones served per minute (1≤n≤1000001 \le n \le 100000, 1≤b≤1081 \le b \le 10^8).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, where aia_i is the number of clones arriving at the start of minute ii (0≤ai≤1080 \le a_i \le 10^8).

Output

Print one integer: the total time all clones spend in the post office.

Examples1

  1. Example 1

    Input
    3 4
    1 5 9
    
    Expected output
    22