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;
    while (cin >> n >> m, n|m) {
        vector<int> ps(n);
        for (int i = 0; i < n; i++) {
            cin >> ps[i];
        }
        sort(ps.begin(), ps.end(), greater<int>());
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if ((i+1) % m != 0) {
                ans += ps[i];
            }
        }
        cout << ans << endl;
    }
}

C++: #include <cstdio>
#include <algorithm>
#include <vector>
#include <numeric>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back

int main() {
	while(1) {
		int n, m; scanf("%d %d", &n, &m);
		if(n == 0 && m == 0) break;
		vector<int> p;
		rep(i,n) {
			int t; scanf("%d", &t);
			p.pb(t);
		}
		sort(p.begin(), p.end(), greater<int>());
		int sum = 0;
		rep(i,n/m) {
			p[(i + 1) * m - 1] = 0;
		}
		printf("%d\n", accumulate(p.begin(), p.end(), 0));
	}
	return 0;
}

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

const int N_MAX = 1000;

int n, m;
int p[N_MAX];

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

C++: #include <iostream>
int main() {
	int n, m;
	std::cin >> n >> m;
	while (n != 0 && m != 0) {
		int whole_price = 0;
		int vegi_price;
		for (auto i = 1; i <= n; ++i) {
			std::cin >> vegi_price;
			if (i % m != 0) whole_price += vegi_price;
		}
		std::cout << whole_price << std::endl;
		std::cin >> n >> m;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
long n,m,i,p[10000],s;
while(cin>>n>>m){
if(n==0)break;
for(i=0;i<n;i++)cin>>p[i];
sort(p,p+n,greater<long>());
for(s=i=0;i<n;i++)if(i%m!=m-1)s+=p[i];
cout<<s<<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> vegetable;
		int each_price;
		for(int i = 0; i < n; ++i){
			std::cin >> each_price;
			vegetable.push(each_price);
		}
		int sum_price = 0;
		for(int i = 0; i < n; ++i){
		    if((i % m) != (m - 1)){
	  	        sum_price += vegetable.top();
		    }
		    vegetable.pop();
		}
		std::cout << sum_price << std::endl;
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

int n, m;
int p[1010];

int main()
{
	while (cin >> n >> m, n){
		rep(i, n) cin >> p[i];
		sort(p, p + n, greater<int>());
		int res = 0;
		rep(i, n) res += p[i];
		for (int i = m - 1; i < n; i += m){
			res -= p[i];
		}
		cout << res << endl;
	}
}

C++: #include <stdio.h>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, 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);
		int ret = 0;
		for (int i = 0; i < n; i++) ret += p[i];
		for (int i = 0; i + m <= n; i += m) ret -= p[i];
		printf("%d\n", ret);
	}
	return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;


bool cmp(const int &p1, const int &p2) {
	return p1 > p2;
}

int main() {
	int n, m, sum;
	int price[1000];

	while (cin >> n >> m, n) {
		memset(price, 0, sizeof(price));
		for (int i = 0; i < n; ++i) {
			cin >> price[i];
		}
		sort(price, price + n,cmp);
		
		sum = 0;
		for (int i = 0; i < n; ++i) {
			//cout << price[i] << " ";
			if ((i + 1) % m == 0) {
				price[i] = 0;
			}
			sum += price[i];
		}
		cout << sum << endl;
	}

	return 0;
}

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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n, m;
  while((n = getInt()) + (m = getInt())){
    vector<int> v(n);
    int ans = 0;
    REP(i,n) v[i] = getInt();
    sort(v.rbegin(), v.rend());
    REP(i,n) if(i % m != (m - 1))
      ans += v[i];
    print(ans);
  }
  return 0;
}

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

int main(){
  int n,m,fig[1001];
  while(cin >> n >> m){
    int ans = 0;
    for(int i=0;i<n;i++) cin >> fig[i];
    sort(fig,fig+n,greater<int>());
    for(int i=0;i<(n/m)*m;i++){
      if((i+1) % m) ans += fig[i];
    }
    for(int i=n-1,j=0;j<(n%m);i--,j++) ans += fig[i];
    fill(fig,fig+1001,0);
    cout << ans << endl;
  }
}

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

using namespace std;

int main()
{
  int n,m;
  for(;cin>>n>>m,n;)
    {
      vector<int> price;

      for(int i=0;i<n;i++)
	{
	  int tmp;
	  cin>>tmp;
	  price.push_back(tmp);
	}
      sort(price.begin(),price.end());
      int ans=0;
      int cnt=1;
      for(int i=n-1;i>=0;i--)
	{
	  if(cnt==m)
	    cnt=1;
	  else
	    {
	      ans+=price[i];
	      cnt++;
	    }
	}
      cout<<ans<<endl;
    }
}

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

using namespace std;

int main()
{
    int n, m;

    while (cin >> n >> m, n || m) {
        vector<int> p(n);
        int sum = 0;

        for (int i = 0; i < n; i++)
            cin >> p[i];

        sort(p.begin(), p.end(), greater<int>());
        
        for (int i = 0; i < n; i += m) {
            for (int j = 0; j < m - 1; j++) {
                if (i + j > n - 1)
                    break;
                sum += p[i + j];
            }
        }
        cout << sum << endl;
    }

    return 0;
}

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

int main(){

  int n,m;
  scanf("%d %d",&n,&m);

  while(n!=0 || m!=0){
    int p[1111];
    for(int i=0;i<n;i++){
      scanf("%d",&p[i]);
    }
    
    
    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(p[j]>p[j-1]){
	  int tmp=p[j];
	  p[j]=p[j-1];
	  p[j-1]=tmp;
	}
      }
    }
    
    int sum=0;
    
    for(int i=0;i<n;i++){
      if(i%m == m-1);
      else{
	sum+=p[i];
      }
    }
    printf("%d\n",sum);
    scanf("%d %d",&n,&m);
  }
      
    
  return 0;
}