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 <vector>
#include <algorithm>
#include <numeric>

int main(){
	int n, m;
	while(std::cin >> n >> m){
		//n及びmが0ならば終了
		if(n == 0 && m == 0){
			return 0;
		}
		
		std::vector<int> p(n);
		for(int i = 0; i < n; ++i){
			std::cin >> p[i];
		}
		
		std::sort(p.begin(), p.end(), std::greater<int>());
		//(mの倍数) 個目の商品が無料
		for(int i = m; i <= n; i += m){
			p[i-1] = 0;
		}
		
		std::cout << std::accumulate(p.begin(), p.end(), 0) << 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 <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 = n - 1; i > 0; i -= m)
        all -= p[i];
    return;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int n, m, p[1010];

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

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

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
  
int main(){
    u_int n;    // the number of vegetable
    u_int m;    // capacity
     
    while(std::cin >> n >> m){
        if(n == 0 && m == 0){
            break;
        }
          
        std::vector<u_int> p(n);  // price
        for(int i = 0; i < n; ++i){
            std::cin >> p[i];
        }
         
        //m, 2*m, 3*m, ... = free(sort by descending)
        std::sort(p.begin(), p.end(), std::greater<u_int>());
        for(int i = m; i <= n; i += m){
            p[i-1] = 0;
        }
         
        std::cout << std::accumulate(p.begin(), p.end(), 0) << std::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<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;
	}


}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m,data[1001];
  while(cin>>n>>m&&n|m){
    int sum=0;
    for(int i=0;i<n;i++){
      cin>>data[i];
      sum+=data[i];
    }
    sort(data,data+n,greater<int>());
    for(int i=m-1;i<n;i+=m)sum-=data[i];
    cout << sum << endl;
  }
}

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

int main(void){
    std::vector<int> price;
    int num_vegetable, bag_capacity;
    while(std::cin >> num_vegetable >> bag_capacity){
        if(num_vegetable == 0 && bag_capacity == 0)
            break;
        for(int p, i = 0; i < num_vegetable; ++i){
            std::cin >> p;
            price.push_back(p);
        }
        
        std::sort(price.begin(), price.end(), std::greater<int>());

        int price_sum = 0;
        for(int i = 0; i < num_vegetable; ++i){
            if((i + 1) % bag_capacity != 0)
                price_sum += price.at(i);
        }
        std::cout << price_sum << std::endl;
    }
}

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

int main(){

    int purchase_num;
    int max_cap;

    while(std::cin >> purchase_num >> max_cap){
        if(purchase_num == 0 && max_cap == 0) break;
        std::vector<int> price;
        std::string str;
        int input_data;
        int min_price = 0;
        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>());
        for(int i = 0; i < price.size(); ++i){
            if((i+1)%max_cap != 0){
                min_price += price[i];
            }
        }
        std::cout << min_price << std::endl;
    }
    return 0;
}

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

int main(){
	int n,m;

	while(std::cin >> n >> m){
		
		if(n == 0 && m == 0) return 0;

		std::vector<int> a(n);

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

		std::sort(a.begin(), a.end(), std::greater<int>());//降順

		int cost = 0;

		for(int i = 0; i < n; ++i){
			if((i+1) % m != 0) cost += a[i];//mの倍数番目に高い野菜を無料にする
		}

		std::cout << cost << std::endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	vector<int>l;
	int n, m;
	while (cin >> n >> m){
		if (n == 0 && m == 0)break;
		int k[1001];
		for (int i = 0; i < n; i++){
			cin >> k[i];
		}
		sort(k, k + n);
		int sum = 0;
		for (int i = 0; i < n; i++)
			if (n % m != i % m)sum += k[i];
		l.push_back(sum);
	}
	for (int i : l) {
		cout << i << endl;
	}
	char c;
	cin >> c;
}