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<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
   int n,m;
   int item[1000];
   while(cin>>n>>m,n){
       int sum=0;
       for(int i=0;i<n;i++){
           cin>>item[i];
           sum+=item[i];
       }
       sort(item,item+n);
       for(int i=n-m;i>=0;i-=m) sum-=item[i];
       cout<<sum<<endl;
   }
    return 0;
}

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

int main() {
	int n, m, p, ans; vector<int> pv;
	while(1) {
		cin >> n >> m;
		if(!n&&!m) break;
		pv.clear(); ans = 0;
		for(int i=0; i<n; ++i) {
			cin >> p; pv.push_back(p);
		}
		sort(pv.begin(), pv.end(), greater<int>());
		for(int i=0; i<n; ++i) {
			if(i%m<m-1) ans += pv[i];
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main (){
    int n = 0, m = 0;
    while(true){
        int ans = 0; //for answer
        std::cin >> n >> m;
        //exit when n = m = 0
        if(n == 0 && m == 0){
            break;
        }
        std::vector<int> price(n); //each vegetable price
        //put price to vector
        for(int i = 0; i < n; ++i){
            std::cin >> price[i];
        }
        //descending sort
        std::sort(price.begin(), price.end(), std::greater<int>());
        //m'th vegetable don't add
        for(int i = 0; i < n; ++i){
            if((i+1) % m != 0){
                ans += price[i];
            }
        }
        std::cout << ans << std::endl;
    }
    return 0;
}

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){
				discount += itr;
				in_bag = 0;
			}
		}

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

C++: 
#include"iostream"
using namespace std;
int main() {
	while (1) {
		int n, m,p[10000],sum=0;
		cin >> n >> m;
		if (n == 0 && m == 0)break;
		for (int i = 1; i < n+1; i++) {
			cin >> p[i];
	}
		for (int j = 0; j < n + 1; j++) {
			for (int i = 1; i < n + 1; i++) {
				if (p[i] < p[i + 1]) {
					swap(p[i], p[i + 1]);

				}
			}
		}
				for (int i = 1; i < n + 1; i++) {
					if (i%m != 0) {
						sum += p[i];
					}

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

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

main(){
  int m,n;
  int b[1001];
  while(cin >> n >> m,m || n){
    int total=0;
    int k=n/m;
    for(int i=0;i<n;i++) cin >> b[i];
    sort(b,b+n);

    for(int i=1;i<=n;i++){
      if(i%m) total+=b[n-i];
    }
    cout << total << endl;
  }
}

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

int main(){
    int n,m,x;
    int flag = 0;
    int num = 0;
    std::vector<int> v;
    
    std::cin >> n >> m;
    
    while(std::cin >> x){
        v.emplace_back(x);
    }
    
    std::sort(v.begin(), v.end(), std::greater<int>());
    
    for(int y = 0;y < n;y++){
        flag++;
        if(flag != m){
            num += v[y];
        }
        else
             flag = 0;
    }
    
    std::cout << num << std::endl;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <functional>

using namespace std;

int main() {
  while( true ) {
	int n, m;
	cin >> n >> m;
	if ( n == 0 && m == 0 ) break;

	vector<int> xs( n );
	for ( int i = 0; i < n; i++ ) {
	  cin >> xs[ i ];
	}
	sort( xs.begin(), xs.end(), greater<int>() );
	
	int sum = 0;
	for ( int i = 0; i < n; i++ ) {
	  sum += ( (i + 1) % m == 0 ? 0 : xs[ i ] );
	}
	cout << sum << endl;
  }  
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

int n,m;
int p[1000];

int main(){
  while(1){
    cin >> n >> m;
    if(!n&&!m){
      return 0;
    }
    for(int i=0;i<n;i++){
      cin >> p[i];
    }
    sort(p,p+n);
    int sum=0;
    for(int i=1;i<=n;i++){
      if(i%m!=0){
        sum += p[n-i];
      }
    }
    cout << sum << endl;
  }
}

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

int main(){
	int num,cap,price;

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

		if(num == 0 && cap == 0){
			break;
		}

		std::vector<int> vegetables;

		for(int i=0; i<num; ++i){
			std::cin >> price;
			vegetables.push_back(price);
		}

		sort(vegetables.begin(), vegetables.end(), std::greater<int>());

		int sum = 0;
		int i = 0;

		while(i < num){

			if((i+1) % cap != 0){
				sum += vegetables.at(i);
			}

			++i;
		}

		std::cout << sum << std::endl;
	}

}

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

int main(void){
    std::vector<int> price;
    int num_vegetable, bag_capacity, price_sum = 0;
    while(std::cin >> num_vegetable >> bag_capacity){
        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>());
        
        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;
    }
}