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,i,j;
  int p[1001];
  int sum;
  while(1){
    cin>>n>>m;
    if(n==0&&m==0) break;
    for(i=0;i<n;++i) cin>>p[i];
    sort(p,p+n);
    sum=0;
    if(n%m==0){
      for(i=0;i<n;i+=m)
	for(j=1;j<m;++j)
	  sum+=p[i+j];
    }else{
      for(i=0;i<n%m;++i)
	sum+=p[i];
      for(;i<n;i+=m)
	for(j=1;j<m;++j)
	  sum+=p[i+j];
    }
    cout<<sum<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
int p[1001];

int main(void) {
  int N, M;
  unsigned long long sum;
  while(cin >> N >> M, N != 0 && M != 0) {
    sum = 0;
    for(int i = 0 ; i < N ; i++) cin >> p[i];
    sort(p, p+N, greater<int>());
    for(int i = M-1 ; i < N ; i+=M) p[i] = 0;
    for(int i = 0 ; i < N ; i++) sum += p[i];
  
    cout << sum << endl;
  }
  return 0;
}

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

int main(){
	int purchase, capa;
	std::cin >> purchase >> capa; //input
	
	while(purchase > 0 && capa > 0){
		std::vector<int> vegetable_price;
		vegetable_price.resize(purchase);
		
		//input
		for(int i=0; i<purchase; ++i){
			std::cin >> vegetable_price[i];
		}
		
		std::sort(vegetable_price.begin(), vegetable_price.end(), std::greater<int>());
		
		// 
		for(size_t i=capa-1; i<vegetable_price.size(); i += capa-1){
			vegetable_price.erase(vegetable_price.begin() + i);
		}
		
		int sum_price = 0;
		for(size_t i=0; i<vegetable_price.size(); ++i){
			sum_price += vegetable_price[i];
		}
		
		//show
		std::cout << sum_price << std::endl;
		
		//input
		std::cin >> purchase >> capa;
	}
	
	return 0;
}

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

int main(){
  int n,m;
  vector<int> p;
  
  while(true){
    int ans = 0;
    cin >> n >> m;

    if(n + m == 0) break;

    p.resize(n);

    for(int i=0; i<n;++i){
      cin >> p[i];
    }
    
    sort(p.begin(), p.end());

    reverse(p.begin(), p.end());

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

     for(int i = 0; i < n; ++i){
       ans += p[i];
    }
     
     cout<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>

using namespace std;

int main(int argc, char *argv[]) {
  int price[1000];
  int n, m, pack, hoge, howmach;

  while (cin >> n >> m, n) {
    for (int i = 0; i < n; i++)
      cin >> price[i];

    sort(price, price + n);
    pack = n / m;
    hoge = n % m;
    howmach = accumulate(price + 1, price + n, 0);
    for (int i = 1; i < pack; i++) {
      howmach -= price[m * i + hoge];
    }
    cout << howmach << endl;
  }
  return 0;
}

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

int n,m;

void solve()
{
	vector<int> veg(n);
	int ans = 0;
	for(int i = 0; i < n; i++)
		cin >> veg[i];

	sort(veg.begin(), veg.end() );

	for(int i = 1; i <= n; i++){
		int d = veg.back();
		veg.pop_back();
		if(i % m)
			ans += d;
	}
	
	cout << ans << endl;
}


int main(void)
{
	while(cin >> n >> m, n | m){
		solve();
	}

	return 0;
}

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

int main() {
	int n, m;
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0)
			break;
			
		array<int, 1000> p;
		p.fill(0);
		for(int i = 0; i < n; ++i)
			cin >> p[i];
		sort(p.begin(), p.end(), greater<int>());
		int ans = 0;
		for(int i = 0; i < n; i += m){
			for(int j = i; j < i + m - 1; ++j)
				ans += p[j];
		}
		
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
	int n,m;
	while(std::cin >> n >> m){
		if(n == 0 && m == 0){
			break;
		}
		std::priority_queue<int> que;
		int vegetable;
		for(int i = 0; i < n; ++i){
			std::cin >> vegetable;
			que.push(vegetable);
		}
		int price = 0;
		for(int i = 0; i < n; ++i){
		    if((i % m) != (m - 1)){
	  	        price += que.top();
		        que.pop();
		    }
		}
		std::cout << price << std::endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int i, n, m;
	int sum, array[1024];
	
	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 / m * m) < m){
				sum += array[i];
			}
		}
		
		printf("%d\n", sum);
	}
	
	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<algorithm>
using namespace std;
int main(){
    int n,m;
    while(cin>>n>>m,n||m){
        int d[1000],sum=0;
        for(int i=0;i<n;i++)cin>>d[i];
        sort(d,d+n,greater<int>());
        for(int i=0;i<n;i++){
            if((i+1)%m!=0)sum+=d[i];
        }
        cout<<sum<<endl;

    }
}

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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int n, m;
   while (cin >> n >> m) {
      if (n == 0 && m == 0) break;
      vector<int> v(n);
      int sum = 0;
      for (int &x : v) {
         cin >> x;
         sum += x;
      }
      sort(v.begin(), v.end(), greater<int>());
      for (int i = m-1; i < v.size(); i+=m) {
         sum -= v[i];
      }
      cout << sum << endl;
   }

   return 0;
}

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

int main(){
	int n,m;
	int p;
	
	while(true){
		std::cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		
		std::vector<int> price;
		for(int i=0; i<n ;++i){
			std::cin >> p;
			price.push_back(p);
		}
		//sort in descending order
		std::sort(price.begin(), price.end(), std::greater<int>());
		
		int i=1; //counter
		int sum=0;
		for(int x : price){
			if(i%m != 0){
				sum += x;
			}
			++i;
		}
		//output
		std::cout << sum << std::endl;
	}
}

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

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