Title: Customer Appreciation Festival

In the midst of soaring vegetable prices due to bad weather, Seven Mart is conducting a bulk purchase sale for its customers. Even vegetables that are not usually available in the store are now attracting attention due to their affordable prices, resulting in a bustling atmosphere within the store.

One day, a trio of friends living in Matsunaga Housing Estate were discussing the advertisement for Seven Mart. This sale, named "Customer Appreciation Festival," features a highlight where the cheapest vegetable in a bag of up to M vegetables becomes free. Upon reading the advertisement, it appears to be a sale structured as follows:

- Each bag can contain up to M vegetables.
- In a bag with M vegetables, the cheapest vegetable becomes free.
- Bags with fewer than M vegetables are not eligible for the discount.

The trio promptly went shopping at Seven Mart.

After finishing their shopping and meeting outside the store, the three friends, satisfied with their affordable and plentiful purchases, realized that they had all bought the same vegetable. One of them exclaimed, "It's really cheap, only XXX yen!" Another friend, surprised, said, "Huh? I paid more than that! Why?" Meanwhile, the remaining friend, upon checking the receipt, realized that they had made the cheapest purchase.

Now, how should they pack the bags to minimize the purchase price? Create a program that takes input for the number of vegetables to be purchased, the number of vegetables per bag, and the price of each vegetable, and outputs the lowest purchase price.

Input:
Multiple datasets are provided as input. The end of input is indicated by two consecutive zeros. Each dataset is given in the following format:

n m
p1 p2 ... pn

The first line provides the number of vegetables to be purchased, n (1 ≤ n ≤ 1000), and the number of vegetables per bag, m (1 ≤ m ≤ 1000). The second line provides the price of each vegetable, pi (10 ≤ pi ≤ 10000).

The number of datasets does not exceed 100.

Output:
For each input dataset, output the lowest purchase price on a new line.

Sample Input:
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0

Output for the Sample Input:
150
2100

# Buggy version:
for i in range(1, 101):
    count = 0
    temp = 0
    SetCount = 0

    try:
        str1 = input()
        list1 = str1.split(" ")
        str2 = input()
        list2 = str2.split(" ")
        list2.sort(reverse=True)
        for m in range(0, int(list1[0])):
            if (m+1) % int(list1[1]) == 0:
                SetCount = SetCount + 1
            #elif (m+1) % int(list1[1]) != 0 | SetCount == int(list1[0])//int(list1[1]):
             #   count = count + int(list2[m])
            else:
                count = count + int(list2[m])
        print(count)

    except:
        break


# Fixed version:
for i in range(1, 101):
    count = 0
    temp = 0
    SetCount = 0

    try:
        str1 = input()
        list1 = str1.split(" ")
        str2 = input()
        list2 = str2.split(" ")
        list2.sort(key=int, reverse=True)
        for m in range(0, int(list1[0])):
            if (m+1) % int(list1[1]) == 0:
                SetCount = SetCount + 1
            #elif (m+1) % int(list1[1]) != 0 | SetCount == int(list1[0])//int(list1[1]):
             #   count = count + int(list2[m])
            else:
                count = count + int(list2[m])
        print(count)

    except:
        break