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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int beg[1010];

int main() {
	int n,m;
	while(n=in(),m=in()){
		int i;
		for(i=0;i<n;i++)beg[i]=in();
		sort(beg,beg+n,greater<int>());
		int res=0;
		for(i=0;i<n;i++){
			if((i+1)%m==0)continue;
			res+=beg[i];
		}
		cout<<res<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
using namespace std;

int main() {
    int n, m;
    while (cin >> n >> m && n) {
        vector<int> p(n);
        for (int i=0; i<n; ++i) {
            cin >> p[i];
        }
        sort(p.begin(), p.end());
        
        int res = accumulate(p.begin(), p.end(), 0);
        for (int i=n%m; i<n; i+=m) {
            res -= p[i];
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

#define INF 1e9
#define LLINF 1e18
#define PI 3.1415926535897932384
#define MOD 1000000007

#define REP(i, n) for(int i=0; i<n; ++i)
#define REPR(i, n) for(int i=n; i>=0; --i)
#define REPS(i, m, n) for(int i=m; i<n; ++i)
#define SORT(v, n) sort(v, v+n)
#define RSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define PB(n) push_back(n)
using namespace std;

int main() {
  for(;;) {
    int n, m;
    cin >> n >> m;
    if(n == 0) return 0;

    vector<int> v(n);
    REP(i,n) 
      cin >> v[i];
    RVSORT(v);

    for(int i=m-1; i<n; i+=m)
      v[i] = 0;

    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
}

C++: #include <cstdio>
#include <algorithm>
#include <vector>
#include <numeric>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back

int main() {
	int n, m; scanf("%d %d", &n, &m);
	vector<int> p;
	rep(i,n) {
		int t; scanf("%d", &t);
		p.pb(t);
	}
	sort(p.begin(), p.end(), greater<int>());
	int sum = 0;
	rep(i,n/m) {
		p[(i + 1) * m - 1] = 0;
	}
	printf("%d\n", accumulate(p.begin(), p.end(), 0));
	return 0;
}

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

int main() {
	int cnt,hukuro;
	int n,m,yasai[1000],total=0;
	
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)break;
		cnt=0;
		hukuro=n/m;
		for(int i=0;i<n;i++){
			cin>>yasai[i];
		}
		sort(yasai,yasai+n);
		reverse(yasai,yasai+n);
		for(int i=0;i<n;i++){
			if((i+1)%m!=0)total+=yasai[i];
			cnt++;
		}
		
		cout<<total<<endl;
		total=0;
	}
	return 0 ;
}

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

int main(){
	int n,m;
	int p;
	
	while(true){
		std::cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		
		std::vector<int> price;
		for(int i=0; i<n ;++i){
			std::cin >> p;
			price.push_back(p);
		}
		//sort in descending order
		std::sort(price.begin(), price.end(), std::greater<int>());
		
		int i=1; //counter
		int sum=0;
		for(int x : price){
			if(i%m != 0){
				sum += x;
			}
			++i;
		}
		//output
		std::cout << sum << std::endl;
	}
}

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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pi;
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair

int n,m,p[1000];

main(){
	while(cin>>n>>m,n){
		rep(i,n)cin>>p[i];
		sort(p,p+n,greater<int>());
		int ans=0;
		
		rep(i,n)if((i+1)%m)ans+=p[i];
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>

bool canPurchase(std::bitset<100> 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<100> select;
        int counter = pow(2.0,price.size()-2);
        int cnt = purchase_num / max_cap;
        
        while(counter--){
            int sum = 0;
            select = static_cast<std::bitset<100> >(counter);
            if(select.count() == cnt){
                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;
}