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<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,sum=0,d;
  int p[1100];
  while(1){
    sum = 0;
    cin >> n >> m;
    if(n==0 && m==0) break;
    for(int i=0; i<n; i++) {
      cin >> p[i];
      sum += p[i];
    }
    sort(p,p+n);
    reverse(p,p+n);
    /*for(int i=1; i<=n/m; i++) p[i*m-1]=0;
    for(int i=0; i<n; i++) sum += p[i];*/
    for(int i=1; i<=n/m; i++){
      d = m*i-1;
      sum -= p[d];
    }
    cout << sum << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <algorithm>

using namespace std;

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

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

int main(){

	int n,m; //問題文のn,m

	while(std::cin >> n >> m){
		if(n==0&&m==0) break;
		std::array<u_int, n> p; //野菜価格一覧
		for(int i=0;i<n;i++){
			std::cin >> p[i];
		}
		std::sort(p.begin(), p.end());
		
		int price=0; //最終出力

		while(n>=m){
			for(int i=0;i<m;i++){
				price += p[n-1-i];
			}
			n -= m;
		}
		for(int i=0;i<n;i++){
			price += p[i];
		}

		std::cout << price << std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

ll n, m;

int main(){
	while (cin >> n >> m&&n + m){
		ll p[10000];
		fill(p, p + 10000, -1);
		REP(i, n)cin >> p[i];
		sort(p, p + 10000, greater<int>());
		ll sum = 0;
		REP(i, n){
			if ((i+1)%m != 0)sum += p[i];
		}
		cout << sum << 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;
}

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

int main(){

	int num, limit;

	while(std::cin >> num >> limit){
		std::vector<int> price;
		int sum_price = 0;
		//input
		for(int i = 0; i < num; ++i){
			int buf;
			sum_price += buf;
			std::cin >> 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){
                                int buf = itr;
				discount += buf;
				in_bag = 0;
			}
		}

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

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m&&n!=0&&m!=0){
		int sum=0;
		vector<int>data;
		for(int i=0;i<n;i++){
			int p;
			cin>>p;
			sum+=p;
			data.push_back(p);
		}
		sort(data.begin(),data.end(),greater<int>());
		for(int i=m-1;i<n;i+=m){
			sum-=data[i];
		}
		cout<<sum<<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 (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 <vector>
#include <algorithm>


int main(){
	std::vector<int> vegetable; //dataset
	int n; //number of purchase
	int m; //capacity of bag
	int ans=0; //minimum cost

	while(std::cin >> n >> m){ //input dataset
		if(n == 0 && m == 0) //end of input
			break;

		std::vector<int> price; //price of vegetable
		for(int i = 0; i < n; ++i){ //input price
			int data;
			std::cin >> data;
			price.push_back(data);
		}

		//sort price in descending order
		std::sort(price.begin(), price.end(), std::greater<int>());


		for(int i = 0; i < n; ++i){
			vegetable.push_back(price[i]);
		}

		int count = 1; //counter
		while(!vegetable.empty()){
			if(count % m == 0){
				vegetable.erase(vegetable.begin());
				++count;
			} else if(count % m != 0){
				ans += (int)vegetable.front();
				vegetable.erase(vegetable.begin());
				++count;
			}
		}
		std::cout << ans << std::endl; //output answer
		
	}


	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(n == 0 || m == 0) break;
    vector<int> v(n);
    for(int i=0; i<n; i++){
      cin >> v[i];
    }
    sort(v.rbegin(),v.rend());
    int sum = 0;
    for(int i=0; i<n; i++){
      if(i % m == m-1) continue;
      sum += v[i];
    }
    cout << sum << endl;
  }
  return 0;
}

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

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