Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"sort"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		m, _ := strconv.Atoi(buf[1])
		if n == 0 && m == 0 {
			break
		}
		scanner.Scan()
		buf_ := strings.Split(scanner.Text(), " ")
		items := make([]int, n)
		for i := 0; i < n; i++ {
			items[i], _ = strconv.Atoi(buf_[i])
		}
		sort.Ints(items)
		sum := 0
		for _, v := range items {
			sum += v
		}
		for i := n-m; i >= 0; i -= m {
			sum -= items[i]
		}
		fmt.Println(sum)
	}
}

C++: #include <iostream>
#include <queue>
 
int main(){
    std::priority_queue<u_int> prices;
    u_int num_of_item, size_of_bag, price;
    
    while(1){
        std::cin >> num_of_item >> size_of_bag;
        if(num_of_item == 0 && size_of_bag == 0)
            break;
            
        for(u_int i = 0; i < num_of_item; ++i){
            std::cin >> price;
            prices.push(price);
        }
        
        u_int sum = 0;
        while(!prices.empty()){
            for(u_int i = 0; i < size_of_bag; ++i){
                if(i != size_of_bag - 1){
                    sum += prices.top();
                }
                prices.pop();
                if(prices.empty())
                    break;
            }
        }
        std::cout << sum << std::endl;
    }
 
    return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>


#define CI cin >>
#define CO cout <<
#define E << endl;
#define F(i,max) (for(int i = 0;i < max;++i))

using namespace std;

int n = 0;
int m = 0;

int total = 0;

vector<int> price;

void input() {
	CI n >> m;
	
	price.resize(n);

	for (int i = 0; i < n; ++i) {
		CI price[i];
	}

}

int GetPrice() {
	int amari = 0;

	total = 0;

	sort(price.begin(), price.end(), greater<int>());
	amari = n % m;
	for (int i = 0; i < n - amari; i++) {
	
		if ((i + 1) % m != 0) {
			total += price[i];
		}
		/*else {
			if (i >= 2 ? (price[i] == price[i - 1] && price[i - 1] == price[i - 2]) : false) {
				total += price[i];
			}
			else {
				if (i >= 2 ? price[i] == price[i - 1] : false) {
					total -= price[i - 1];
				}
			}
		}*/
		/*if (n == 1) {
			total += price[i];
		}*/
		
	}
	if (amari != 0) {
		for (int i = n - amari; i < n; ++i) {
			total += price[i];
		}
		
	}
	return 0;
}

int main(void) {
	
	while (true) {
		input();
		if (n == 0 && m == 0) {
			break;
		}

		GetPrice();

		CO total;
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <functional>

#define N 1000

using namespace std;

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int d[ N ];
    int res = 0;
    int n, m;

    scanf ( "%d%d", &n, &m );
    if ( !( n | m ) ) break ;

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d", d + i );
    }
    sort ( d, d + n, greater< int > ( ) );

    for ( i = 0; i < n; ++i )
    {
      res += ( i + 1 ) % m
           ? d[ i ] : 0;
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}

C++: #include <iostream>
#include <algorithm>

#define MAX_NM 1000

int n, m, all;
int p[MAX_NM];

void solve();

int main(){
    while(true){
        all = 0;
        std::cin >> n >> m;
        for(int i = 0; i < n; ++i){
            std::cin >> p[i];
            all += p[i];
        }
        solve();
        std::cout << all << std::endl;
    }
    return 0;
}

void solve(){
    std::sort(p, p + n, std::greater<int>());
    for(int i = 1; i <= n; ++i)
        all -= p[i * m - 1];
    return;
}

C++: #include<iostream>
#include<algorithm>
#include<functional>
using namespace std;

int main(){
	int n, m;
	int p[1000];
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		for(int i = 0;i < n;i++){
			cin >> p[i];
		}
		int ans = 0;
		sort(p, p + n, greater<int>());
		for(int i = 0;i < n;i++){
			if(i % m == m - 1) continue;
			ans += p[i];
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<functional>

int *v,m,n,ans=0;

int main(){
	while(true){
		std::cin >> n >> m;
		if(!n && !m)
			return 0;
		v = new int[n];
		for(int i=0 ;i<n; i++)
			std::cin >> v[i];
		std::sort(v,v+n,std::greater<int>());
		for(int i=0; i<n; i++)
			if(!((i+1)%m == 0 && (i+1) >= m && m > 1))
				ans += v[i];
		std::cout << ans << std::endl;
		delete[] v;
		ans = 0;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
int a[1000];
int n,m;

while(true){
cin>>n>>m;
if(n==0&&m==0)break;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
int g=0;
for(int i=0;i<m;i++)
g+=a[i];
cout<<g<<endl;
}
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;
int n, m;
vector<int> vege;

const int INF = 1 << 29;

int main(void)
{
	while(cin >> n >> m && n && m)
	{
		vege.resize(n);
		for (int i = 0; i < n; i++)
		{
			cin >> vege[i];
		}

		sort(vege.begin(), vege.end(), greater<int>());
		int sum = accumulate(vege.begin(), vege.end(), 0);
		for (int i = 1; i - 1 < n / m; i++)
		{
			sum -= vege[i * m - 1];
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<set>
using namespace std;
 
int main()
{
 multiset< int,greater<int> > s;
 multiset<int>::iterator it;
 int n,m,p,i;
 int cost;
 while(cin>>n>>m,n||m){
  s.clear();
  for(i=0;i<n;i++){
   cin>>p;
   s.insert(p);
  }
  cost=0;
  i=0;
  for(it=s.begin();it!=s.end();it++){
   if(++i==m) i=0;
   else cost += *it;
  }
  cout<<cost<<endl;
 }
 return 0;
}

C++: 
#include"iostream"
using namespace std;
int main() {
	while (1) {
		int n, m,p[10000],sum=0;
		cin >> n >> m;
		
		if (n == 0 && m == 0)break;

		for (int i = 1; i < n+1; i++) {
			cin >> p[i];
	}

		for (int j = 0; j < n - 1; j++) {
			for (int i = 1; i < n + 1; i++) {
				if (p[i] < p[i + 1]) {
					swap(p[i], p[i + 1]);

				}
			}
		}
				for (int i = 1; i < n + 1; i++) {
					if (i%m != 0) {
						sum += p[i];
					}

			}
		
		cout << sum << endl;
	}
		
	return 0;
}

C++: #include<iostream>
#include<cmath>
#include<slgorithm>
using namespace std;

main(){
  int m,n;
  int b[1001];
  while(cin >> n >> m,m || n){
    int total=0;
    int k=n/m;
    for(int i=0;i<n;i++) cin >> b[i];
    sort(b,b+n);

    for(int i=1;i<=n;i++){
      if(i%m) total+=b[n-i];
    }
    cout << total << endl;
  }
}

C++: #include <iostream>
#include <queue>
 
int main(){
    std::priority_queue<u_int> prices;
    u_int num_of_item, size_of_bag, price;
    
    while(1){
        std::cin >> num_of_item >> size_of_bag;
        if(num_of_item == 0 && size_of_bag == 0)
            break;
            
        for(u_int i = 0; i < num_of_item; ++i){
            std::cin >> price;
            prices.push(price);
        }
        
        u_int sum;
        while(!prices.empty()){
            for(u_int i = 0; i < size_of_bag; ++i){
                if(i != size_of_bag - 1){
                    sum += prices.top();
                }
                prices.pop();
            }
        }
        std::cout << sum << std::endl;
    }
 
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>

int main(){
    int n,m,x;
    int flag = 0;
    int num = 0;
    std::vector<int> v;
    
    std::cin >> n >> m;
    
    while(std::cin >> x){
        v.emplace_back(x);
    }
    
    std::sort(v.begin(), v.end(), std::greater<int>());
    
    for(int y = 0;y < n;y++){
        flag++;
        if(flag != m){
            num += v[y];
        }
        else
             flag = 0;
    }
    
    std::cout << num << std::endl;
}