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>
using namespace std;

int main(){
  int n,m;
  vector<int> v;
  int ans;

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

    ans = 0;
    v.resize(n);
    for(int i=0;i<n;i++){
      cin >> v[i];
      ans += v[i];
    }
    sort(v.begin(),v.end());
    for(int i=v.size()-m;i>=0;i-=m){
      ans -= v[i];
    }

    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int N,M;
int P[1000];
int main()
{
	while(true){
		scanf("%d%d",&N,&M);
		if(N==0&M==0)break;
		for(int i=0;i<N;i++)scanf("%d",&P[i]);
		sort(P,P+N);reverse(P,P+N);
		int ans=0;
		for(int i=0;i<N;i++){
			if(i%M!=M-1)ans+=P[i];
		}
		printf("%d\n",ans);
	}
	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>
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;
  }
}

C++: #include <stdio.h>

#define MAX 20000
#define MYSCAN scanf

int main(void){
	int n, m;
	int p[2000];
	int i, j;
	int ans, tmp;

	while (true){
		MYSCAN("%d%d", &n, &m);
		if (n == 0 && m == 0){	break;	}

		ans = 0;

		// テ」ツ?セテ」ツ?堙」ツつステ」ツδシテ」ツδ暗」ツ?凖」ツつ?
		for (i = 0; i < n; i++){
			p[i] = 0;
			MYSCAN("%d", &p[i]);
			for (j = i - 1; j >= 0; j--){
				if (p[j] < p[j+1]){
					tmp = p[j];
					p[j] = p[j+1];
					p[j+1] = tmp;
				}
				else{
					break;
				}
			}
		}

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

		printf("%d\n", ans);


	}

	return 0;

}

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

int main(){
	int vnum, capacity;
	std::vector<int> vprice;

	while(std::cin >> vnum >> capacity){
		int buf = capacity;
		std::vector<int> vprice;
		int tmp,total = 0;

		//input
		for(int i = 0; i < vnum; ++i){
			std::cin >> tmp;
			vprice.push_back(tmp);
	}

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

		//sum price
		std::for_each(vprice.begin(),vprice.end(), [&total,buf,&capacity](int x) { capacity != 1 ? (total += x, --capacity) : capacity = buf; } );

		//output
		std::cout << total << std::endl;
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int p[1024];

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int2(n, m);
    if(!(n | m))break;

    scn(n, p);
    sort(p, p + n);

    int cnt = 0, sum = 0;
    per(i, n){
      ++cnt;
      if(cnt == m)cnt = 0;
      else sum += p[i];
    }
    pri(sum);


//*/

//*/ break;
  }
  return 0;
}

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

main(){
    int n, m, P[MAX], sum;
    while(1){
	cin >> n >> m;
	if ( n == 0 && m == 0 ) break;
	sum = 0;
	for ( int i = 0; i < n; i++ ) {
	    cin >> P[i];
	    sum += P[i];
	}
	sort(P, P+n, greater<int>());
	for ( int i = m-1; i < n; i += m ) sum -= P[i];
	cout << sum << endl;
    }
    
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,sum=0,d;
  int p[3001000]={};
  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++){
      d = m*i-1;
      sum -= p[d];
    }
    cout << sum << endl;
  }
  return 0;
}

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

/*The function calculates vegetables which you purchase.*/
int purchase_price(const int n,const int m) {

	//The price of purchased vegetables
	std::vector<int> purchase;

	//input
	for (int i = 0; i < n; ++i){
		int tmp;
		std::cin >> tmp;
		purchase.push_back(tmp);
	}

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

	int sum = 0;

	//surplus eqals to (m-1) is free
	for (int i = 0; i < n; ++i){
		if (i%m != m-1) {
			sum += purchase.at(i);
		}
	}

	return sum;

}


int main() {

	//n:the number of purchase vegetables
	//m:the number of you can stuff vegetables
	int n, m;
	//sum of price
	int sum;

	while (true) {

		std::cin >> n >> m;

		//case of input is (n,m)=(0,0)
		if (n == 0 && m == 0) {
			break;
		}

		sum = purchase_price(n, m);
		std::cout << sum;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(i=0;i<n;i++)
using namespace std;
int main(){
  int a,b,i;
  while(cin>>a>>b,a){
    int c[a],s=0,k=0,p=0;
    r(i,a){cin>>c[i];p+=c[i];}
    sort(c,c+a);
    for(i=a-1;i>=0;i--){
      k++;
      if(k==b){
        s+=c[i];
        k=0;
      }
    }
    cout<<p-s<<endl;;
  }
}