Under construction

Still being built. Things may change

Sale!

Time limit2sMemory limit1024 MB

Summary
Given n book prices, a delivery fee e, and w free books per qualifying order, find the minimum total cost to buy all books for each q from 1 to n.
Level

Medium7 of 10

Topics
Sorting, Greedy, Prefix sum, Math
Solved
No attempts yet

Statement

Doctor Strange likes to read and study new spells. His favorite bookstore, 'Dormammu', is having a sale! But the doctor is stuck in a time loop and has no time, so he decided to order all the books online for delivery.

The doctor plans to buy nn distinct books. During the sale, when buying w+qw + q or more books, the ww cheapest of them are free. Delivery of one order costs ee coins. The doctor can order a set of distinct books that are not in any other order. There is no limit on the number of books in one order.

The doctor forgot the value of qq. For each qq from 11 to nn, find the minimum number of coins needed to buy all nn books.

Input

The first line contains three integers nn, ee, and ww: the number of books, the delivery cost, and the number of free books (1≤w≤n≤3⋅1051 \le w \le n \le 3 \cdot 10^5; 1≤e≤1061 \le e \le 10^6).

Each of the next nn lines contains tt, the price of the ii-th book (1≤t≤1061 \le t \le 10^6).

Output

Print nn numbers: the minimum number of coins needed to buy all books for each qq from 11 to nn.

Examples2

  1. Example 1

    Input
    5 1 1
    1
    2
    3
    4
    5
    
    Expected output
    12 14 15 15 16
    
  2. Example 2

    Input
    6 3 2
    2
    1
    3
    2
    1
    5
    
    Expected output
    13 15 15 15 17 17