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> // only for GCC
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1};

int main() {
  int n, m;

  while(cin >> n >> m, n+m) {
    VI v;
    int x;

    REP(i, n) {
      cin >> x;
      v.PB(x);
    }
    sort(ALL(v), greater<int>());

    int ans = 0;
    REP(i, n) {
      if(i%m != m-1) ans += v[i];
    }
    cout << ans << endl;
  }
}

C++: #include<stdio.h>
int  main(){

int N,M;
int n[1001]={};

while(1)
{
int s=0;
scanf("%d %d",&N,M);
if(N==0&&M==0)break;

for(int i=1;i<=N;i++)
scanf("%d",&n[i]);

for(int i=1;i<=N;i++)
for(int j=N;j>i;j--)
if(n[j]>n[j-1]){int t=n[j-1];n[j-1]=n[j];n[j]=t;}

for(int i=1;i<=N;i++)
{if(i%M!=0)s+=n[i];}

printf("%d\n",s);
}

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;
    int array[n],sum=0;
    for(int i=0;i<n;i++)
      cin>>array[i];
    sort(array,array+n);
    reverse(array,array+n);
    for(int i=0;i<n;i++){
      if((i+1)%m==0) array[i]=0;
      sum+=array[i];
    }   
    cout<<sum<<endl;
  }
  return 0;
}

C++: // 2011/01/08 Tazoe

#include <iostream>
using namespace std;

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

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

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

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

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

		cout << sum << endl;
	}

	return 0;
}

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

int main(){
	int a,b;
	while(std::cin >> a >> b){
		if(a==0&&b==0) break;

		int n;
		std::cin >> n;
		std::vector<std::vector<int>> map(a,std::vector<int>(b,1)); //地図

		for(int i=0;i<n;++i){
			int x,y;
			std::cin >> x >> y;
			map[x-1][y-1]=0;
		}

		for(int i=1;i<a;++i){
			for(int j=1;j<b;++j){
				if(map[i][j]>0){
					map[i][j] = map[i-1][j]+map[i][j-1];
				}
			}
		}
		std::cout << map[a-1][b-1] << std::endl;
	}
	return 0;
}

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

int main(void){
  int n,m;
  while(cin >> n >> m,m+n){
    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<functional>

#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		int p[1000];
		rep(i,n)	scanf("%d",p+i);

		sort(p,p+n,greater<int>());

		int total=0;
		rep(i,n) if((i+1)%m!=0) total+=p[i];
		printf("%d\n",total);
	}

	return 0;
}

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

#define MAX_NM 1001

int n, m, all;
int p[MAX_NM];

void solve();

int main(){
    while(true){
        all = 0;
        std::cin >> n >> m;
        for(int i = 0; i < n; ++i){
            std::cin >> p[i];
            all += p[i];
        }
        solve();
        std::cout << all << std::endl;
    }
    return 0;
}

void solve(){
    std::sort(p, p + n, std::greater<int>());
    for(int i = 1; i <= n; ++i)
        all -= p[i * m - 1];
    return;
}

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


using namespace std;

int main(){

  int m, n;


  while(1){

    cin >> n >> m;

    if(n == 0 && m == 0)break;

    int data[n];

    for(int i = 0; i < n; i++){
      cin >> data[i];
    }

    sort(data, data+n);
    reverse(data, data+n);


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

    for(int i = 0; i < n; i++){
      sum += data[i];
    }

    cout << sum << endl;

  }

  return 0;
}

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

int main(){
  int n,m;

  while(cin >> n >> m, n){
    vector<int> a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    
    sort(a.begin(),a.end(),greater<int>());
    
    int ans = 0;
    for(int i=0;i<n;i++){
      if((i+1)%m)ans += a[i];
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,m;
	int vegetable[10001];
	while(cin>>n>>m){
		if(n+m==0)break;
		for(int i=0 ; i<n ; i++ )
			cin>>vegetable[i];
		//sort__
		for(int i=0 ; i<n ; i++ ){
			for(int j=i+1 ; j<n ; j++ ){
				if( vegetable[i] < vegetable[j] ){
					int tmp=vegetable[i];
					vegetable[i]=vegetable[j];
					vegetable[j]=tmp;
				}
			}
		}
		//_sort.
		int x=n/m;
		int y=n%m;
		int sum=0;
		int tmp;
		for(int i=n-y ; i<n ; i++ )
			sum+=vegetable[i];
		for(int i=0 ; i<n-y ; i++ ){
			if((i+1)%m){
				sum+=vegetable[i];
			}
		}
		cout<< sum << endl;
	}
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

int main(){
	while(1){
		int n, m;
		cin>>n>>m;
		if(n==0) break;
		int a[n];
		REP(i, n) cin>>a[i];
		sort(a, a+n, greater<int>());
		int sum = 0;
		REP(i, n) sum+=a[i];
		for(int i=m-1; i<n; i+=m){
			sum-=a[i];
		}
		printf("%d\n", sum);
	}
}

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

using namespace std;

int main(){

	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0)){
		int num=n/m;
		vector<int> v;
		for(int i = 0; i < n; i++){
			int t;
			cin>>t;
			v.push_back(t);
		}
		sort(v.begin(),v.end(),greater<int>());

		int sum=0;
		for(int i = 0; i < n; i++){
			if((i+1)%m==0){

			}
			else
				sum+=v[i];
		}
		cout<<sum<<endl;
	}

	return 0;
}

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

int main(){
	int n, m;
	while(std::cin >> n >> m, n){
		int total = 0;
		std::vector<int> pvec;
		for(int i=0;i<n;i++){
			int p;
			std::cin >> p;
			pvec.push_back(p);
			total += p;
		}

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

		int i = 1, discount = 0;
		for(;i*m<=n;i++){
			discount += pvec[i*m-1];
		}
	
		std::cout << total - discount << std::endl;
	}
}