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 <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 <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int n,m,p[1000];
	while(scanf("%d%d",&n,&m), n != 0){
		for(int i=0; i<n;i++){
			scanf("%d",&p[i]);
		}
		sort(p,p+n);
		int sum = 0;
		int it = 0;
		for(int i = n-1; i >= 0; i--,it++){
			if(it % m != m-1)
				sum += p[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

        vector<int> p(n);
        for(int i=0; i<n; ++i)
            cin >> p[i];
        sort(p.rbegin(), p.rend());

        for(int i=m-1; i<n; i+=m)
            p[i] = 0;
        cout << accumulate(p.begin(), p.end(), 0) << endl;
    }
}

C++: #include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int n, m; n = in(), m = in();) {
		vector<int> v(n);
		for (int &x: v)
			x = in();
		sort(v.rbegin(), v.rend());
		int p = 0;
		for (int i = 0; i < n; i++)
			if ((i + 1) % m)
				p += v[i];
		outl(p);
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define MAX 1000;
using namespace std;

int main(){
  int n,m,s;
  vector<int> p;
  while(cin >> n >> m){
    if(n==0 || m==0) return 0;
    p.clear();
    for(int i=0; i<n; i++){
      cin >> s;
      p.push_back(s);
    }   

    int sum=0,ans=0, min;
    sort(p.begin(), p.end(), greater<int>());

    for(int i=0; i<n; i+=m){
      min = p[i];
      for(int j=i; j<i+m; j++){
	if(j > n) continue;
	if(min > p[j]) min = p[j];
      }
      for(int k=i; k<i+m; k++){
	if(k > n) continue;
	sum += p[k];
      }
      ans += sum - min;
      sum=0;
    }
    cout << ans << endl;
  }
}

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

using namespace std;

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		vector<int> Vec;
		for(int i = 0; i < n; ++i)
		{
			int price;
			cin >> price;
			Vec.push_back(price);
		}
		sort(Vec.begin(), Vec.end());
		int count = 1;
		int sum = 0;
		for(int i = Vec.size() - 1; i >= 0; --i)
		{
			if(count == m)
			{
				count = 1;
				continue;
			}
			sum += Vec[i];
			++count;
		}
		cout << sum << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int main(){

	int num, limit;

	while(std::cin >> num >> limit){

		if(num == 0 && limit == 0) break;

		std::vector<int> price;
		int sum_price = 0;
		//input
		for(int i = 0; i < num; ++i){
			int buf;
			std::cin >> buf;
			sum_price += buf;
			price.push_back(buf);
		}
		//sort
		std::sort(price.begin(),price.end(),std::greater<int>());
		//discount
		int discount = 0;
		int in_bag = 0;
		
		for(auto itr = price.begin(); itr != price.end(); ++itr){
			++in_bag;
			if(in_bag == limit){
				discount += *itr;
				in_bag = 0;
			}
		}

		std::cout << sum_price - discount << std::endl;
	}
	return 0;
}

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

using namespace std;

int main() {
	int n, m;
	while (cin >> n >> m, n || m) {
		vector<int> v;
		for (int i = 0; i < n; ++i) {
			int p; cin >> p;
			v.push_back(p);
		}

		sort( v.begin(), v.end() );
		reverse( v.begin(), v.end() );

		int ans = 0, count = 0;
		for (int i = 0; i < n; ++i)
			if (++count >= m)
				count = 0;
			else
				ans += v[i];

		cout << ans << endl;
	}
}