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<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 <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>

bool canPurchase(std::bitset<1000> bit, int max_cap, int num){
    int bitcnt = 0;
    for(int i = 0; i < num; ++i){
        if(bit[i] == 1){
            ++bitcnt;
            if(!(i >= bitcnt * max_cap-1)){
                return false;
            }
        }
    }
    return true;
}

int main(){

    int purchase_num;
    int max_cap;

    while(std::cin >> purchase_num >> max_cap){
        int max = 0;
        std::string str;
        int input_data;
        std::vector<int> price;
        if(purchase_num == 0 && max_cap == 0) break;
        std::cin.ignore();
        std::getline(std::cin, str);
        std::istringstream iss(str);
        while(!iss.eof()){
            iss >> input_data;
            price.push_back(input_data);
        }
        std::sort(price.begin(),price.end(),std::greater<int>());
        std::bitset<1000> select;
        int counter = pow(2.0,price.size());
        while(counter--){
            int sum = 0;
            select = static_cast<std::bitset<1000> >(counter);
            if(select.count() == (purchase_num / max_cap)){
                if(canPurchase(select,max_cap,purchase_num)){
                    //std::cout << select << std::endl;
                    for(int i = 0; i < price.size(); ++i){
                        if(select[i] == 1){
                            //std::cout << sum << std::endl;
                            sum += price[i];
                        }
                    }
                }
            }
            if(max < sum) std::swap(max,sum);
        }
        int sum = 0;
        for(int i = 0; i < price.size(); ++i){
            sum += price[i];
        }
        std::cout << sum-max << std::endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int m,n;
	int a[1000];
	int kari;
	int sum;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (int i = n-1; i > 0; i--) {
			for (int j = 0; j < i; j++) {
				if (a[j] < a[j+1]) {
					kari = a[j];
					a[j] = a[j+1];
					a[j+1] = kari;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			if ((i + 1) % m != 0) {
				sum += a[i];
			}
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,m;
  int p[1001];
  while(1){
    int ans=0;
    cin>>n>>m;
    if(n+m==0)break;
    for(int i=0;i<n;i++)
      cin>>p[i];
    
    for(int i=0;i<n;i++) 
      for(int i=0;i<n;i++)
	if(p[i]<p[i+1])swap(p[i],p[i+1]);

    for(int i=0;i<n;i++)
      if((i+1)%m==0)p[i]=0;
    
    for(int i=0;i<n;i++)ans+=p[i];
    
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 1


int main(){
	int n,m;
	int data[1024];
	while(scanf("%d%d",&n,&m),n|m){
		int sum = 0;
		rep(i,n){
			scanf("%d",data+i);
			sum += data[i];
		}
		sort(data,data+n);
		int i;
		for(i=n-m; i>=0; i-=m){
			sum -= data[i];
			//printf("i:%d  data:%d\n",i,data[i]);
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
  
int main(){
    std::priority_queue<u_int>  vegetable;
    u_int n, m, price;
     
    while(1){
        std::cin >> n >> m;
        if(n == 0 && m == 0)
            break;
             
        for(u_int i = 0; i < n; ++i){
            std::cin >> price;
            vegetable.push(price);
        }
         
        u_int sum = 0;
        for(u_int i = 1; i <= n; ++i){
            if(i % m == 0){
                sum += vegetable.top();
            }
            vegetable.pop();
        }
        std::cout << sum << std::endl;
    }
  
    return 0;
}

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

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

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


int main(){
	int n,m;
	int p[1000];
	while(cin>>n>>m,n|m){
		for(int i=0;i<n;i++)cin>>p[i];
		sort(p,p+n,greater<int>());
		int s=accumulate( p,p+n, 0 );
		for(int i=m-1;i<n;i+=m){
			s-=p[i];
		}
		cout<<s<<endl;
	}
	return 0;
}

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

int main(){
	int n, m;
	while (std::cin >> n >> m, n || m){

		int data[1001];
		for (int i = 0; i < n; i++)std::cin >> data[i];

		std::sort(data, data + n, std::greater<int>());

		int ans = 0;
		for (int i = m - 1; i < n; i += m)ans += data[i];
		ans = std::accumulate(data, data + n, 0) - ans;
		std::cout << ans << std::endl;
	}
	return 0;
}

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

int main(void) {
    u_int m, n;

    std::cin >> n >> m;
    for (; m != 0 && n != 0; std::cin >> n >> m) {
        std::priority_queue<u_int> p;
        for (u_int i = 0; i < n; ++i) {
            u_int tmp;
            std::cin >> tmp;
            p.push(std::move(tmp));
        }

        u_int sum = 0;
        for (u_int i = 1; i <= n; ++i) {
            if (i % m) {
                sum += p.top();
                p.pop();
            } else {  // 袋が一杯のとき
                if (!p.empty()) p.pop();
            }
        }

        std::cout << sum << std::endl;
    }

    return 0;
}