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 <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int n, m;
int p[1000];

int main() {
	while (cin >> n >> m, n || m) {
		REP(i, n) scanf("%d", p + i);
		sort(p, p + n);
		
		int ans = 0;
		REP(i, n) ans += p[i];
		
		for (int i = 0; i <= n - m; i += m) ans -= p[i];
		cout << ans << endl;
	}
	return 0;
}

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

main(){
	int n , m ;
	int c[1010] ;
	while( cin >> n >> m , n , m ){
		for( int i=0 ; i<n ; i++ ) cin >> c[i] ;
		sort(c,c+n,greater<int>()) ;
		int sum = 0 ;
		for( int i=0 ; i<n ; i++ ){
			if( (i+1)%m ) sum += c[i] ;
		}
		cout << sum << endl ;
	}
}

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 p[1000];
		//fill_n(p, 1000, 0);
		for(int i = 0; i < n; ++i)
			cin >> p[i];
		sort(p, p + n, greater<int>());
		int ans = 0;
		for(int i = 0; i < n; i += m){
			for(int j = i; j < n && j < i + m; ++j)
				ans += p[j];
			if(i + m <= n)
				ans -= p[i + m - 1];
		}
		
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m, p[10000];

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

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

int main( void )
{
    int n, m;
    while ( cin >> n >> m && n && m ) {
        vector <int> p(n);
        for ( int i = 0; i < n; i++ ) {
            cin >> p[i];
        }

        int answer = 0;
        sort( p.rbegin(), p.rend() );
        for ( int i = 0, j = 1; i < n; i++, j++ ) {
            if ( j < m ) {
                answer += p[i];
            } else {
                j = 0;
            }
        }

        cout << answer << endl;
    }
    return 0;
}

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

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

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int n, m;
int p[1000];

int main() {
	while (cin >> n >> m, n || m) {
		REP(i, n) scanf("%d", p + i);
		sort(p, p + n, greater<int>());
		
		int ans = 0;
		REP(i, n) ans += p[i];
		
		for (int i = m - 1; i < n; i += m)
			ans -= p[i];
		
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, m;
	while (scanf("%d%d", &n, &m), n|m)
	{
		int p[10000];
		for (int i = 0; i < n; ++i)
			scanf("%d", p + i);
		sort(p, p + n);

		int res = accumulate(p, p + n, 0);
		for (int i = 0; i < n / m; ++i)
			res -= p[n-m - m*i];
		printf("%d\n", res);
	}

	return 0;
}

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

int main()
{
	int N,M;
	while(cin >> N >> M,(N||M))
	{
		int a[1000],ans=0;
		for(int i=0; i<N; i++)
		{
			cin >> a[i];
			ans+=a[i];
		}

		sort(a,a+N);
		reverse(a,a+N);

		for(int i=M-1; i<N; i+=M)
			ans-=a[i];

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

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,m;
  while(cin >> n >> m , n + m){
    int yasai[1000] = {0};

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

    sort(yasai,yasai+(n+1),greater<int>());

    for(int i = n ; i >0 ; i--){
      yasai[i] = yasai[i-1];
    }
    int sum = 0;
    for(int i = 1 ; i <= n ; i++){
      if(i%m != 0)sum+=yasai[i];
    }
    cout << sum << endl;
  }
}