Under construction

Still being built. Things may change

Train

Interview

Time limit1sMemory limit1024 MB

Summary
Given passenger counts per car, find the minimum total number of car-to-car moves so that every car ends with exactly K passengers.
Level

Medium5 of 10

Topics
Prefix sum, Greedy
Solved
No attempts yet

Problem

It is ski season! The train station is crowded with holidaymakers heading to the slopes. Afraid of missing their train, the passengers boarded the cars without checking where the free seats were.

Each car of the train has KK seats. The total number of seats equals the number of passengers exactly. That is always the case at this time of year.

Given how many passengers boarded each car, find the minimum total number of cars that passengers must pass through so that every passenger can sit down.

Input

The first line contains two integers NN, the number of cars, and KK, the number of seats in each car. The second line contains NN integers aia_i, where aia_i is the number of passengers who boarded car ii.

It is given that a1+⋯+aN=N×Ka_1 + \cdots + a_N = N \times K.

Output

Print one integer, the minimum total number of cars the passengers must pass through so that everyone can sit down.

The answer may exceed the range of a 32-bit integer. Use a 64-bit integer type to store it (long long in C/C++, Int64 in Pascal).

Constraints

1≤N≤10000001 \le N \le 1000000 1≤K≤10000001 \le K \le 1000000

Examples1

  1. Example 1

    Input
    4 30
    0 40 50 30
    
    Expected output
    50