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

int main(){
    int m,n;
    priority_queue<int> que;

    while(cin>>n>>m,m|n){
        int sum=0;

        for(int i=0;i<n;i++){
            int p;
            cin>>p;
            que.push(p);
        }

        vector<int> bag;

        while(que.size()){
            int p=que.top();que.pop();
            bag.push_back(p);
            if(que.empty() || bag.size()==m){
                for_each(bag.begin(),bag.end(),[&sum](int v){sum += v;});
                if(bag.size()==m) sum-=p;
                bag.clear();
            }
        }

        cout<<sum<<endl;
    }

    return 0;
}

C++: #include <iostream>

#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>
using namespace std;
int a[1000],n,m,ans;
int main(){
	while(true){cin>>n>>m;if(n==0&&m==0)break;ans=0;for(int i=0;i<n;i++){cin>>a[i],ans+=a[i];}sort(a,a+n);for(int i=n%m;i<n;i+=m)ans-=a[i];cout<<ans<<endl;}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int p[1010] = {};
	for (int n, m; cin >> n >> m&&n;) {
		memset(p, 0, sizeof(p));
		int ans = 0;
		rep(i, 0, n) { cin >> p[i]; ans += p[i]; }
		sort(p, p + n);
		dumpc(p);
		for (int i = n%m; i < n; i += m) {
			ans -= p[i];
		}
		cout << ans << endl;
	}
	return 0;
}

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


int main()
{
	int n, m;
	int vegetable[1005];
	int ans;

	while (true)
	{
		ans = 0;

		cin >> n >> m;
		if (n == 0 && m == 0) break;

		for (int i = 0; i < n; ++i)
		{
			cin >> vegetable[i];
		}
		//???????????§?????????????????????
		for (int i = 0; i < n - 1; ++i)
		{
			for (int j = i + 1; j < n; ++j)
			{
				if (vegetable[i] < vegetable[j])
					swap(vegetable[i], vegetable[j]);
			}
		}
		//????¨????????¨????
		for (int i = 0; i < n; ++i)
		{
			if ((i + 1) % m != 0)
				ans += vegetable[i];
		}

		cout << ans << endl;
	}

	return 0;
}

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());
        while(counter--){
            int sum = 0;
            select = static_cast<std::bitset<100> >(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 <iostream>
#include <algorithm>

using namespace std;

main(){
  int n, m, p;
  int data[1000];

  while(1){
    cin >> n >> m;
    if(n==0 && m==0) break;

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

    sort(data, data+n);
    int sum=0;

    for(int i=n, count=0;i>=0;i--, count++){
      if(count%m!=0){
	sum+=data[i];
      }
    }

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

C++: //AOJ0227
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cstdio>
#include<iostream>
int vegetable[1001];

int main(){
	int n, m;
	while (scanf("%d %d", &n, &m), n, m){
		for (int i = 0; i < n; ++i){
			scanf("%d",vegetable+i);
		}
		std::sort(vegetable, vegetable + n);
		int cnt = 0;
		int ans = 0;
		//??????
		//for (int i = 0; i < n; ++i)printf("%d ", vegetable[i]);
		for (int i = n - 1; i >= 0; i--){
			ans += vegetable[i];
			cnt++;
			if (cnt%m == 0)ans -= vegetable[i];
		}
		printf("%d\n", ans);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

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

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

int main(){
	int n, m, tmp;
	while(cin >> n >> m){
		vector<int> v;
		int ans = 0;
		if(n == 0 && m == 0) break;
		for(int i = 0; i < n; i++){
			cin >> tmp;
			v.push_back(tmp);			
		}
		sort(v.begin(), v.end(), greater<int>());
		for(vector<int>::iterator it = v.begin(); it < v.end();){
			int tmp = 100000;
			int i;
			for(i = 0; i < m; i++){
				if(*it <= tmp) tmp = *it;
				ans += *it;
				it++;
//				if(it == v.end()) break;
			}
			if(i == m){
				ans -= tmp;
			}
		}
		cout << ans << endl;
		ans = 0;
	}


}