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

int main() {
  int n, m;
  long long p[1000];

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

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

    sort(p, p+n, std::greater<long long>());

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

    cout << ans << endl;
  }

}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  while(cin >> n >> m&&n && m){
    vary(ll,p,n,0);
    rep(i,n){
      cin >> p[i];
    }
    sort(all(p));
    ll cnt = 1,ans = 0;
    for(ll i = n-1; i >= 0; --i){
      if(cnt < m){
        ans += p[i];
        ++cnt;
      }
      else{
        cnt = 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
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 loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;
namespace std {
    template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){
        iter(it,v) os<<*it<<(it+1==v.end()?"":",");
        return os;
    }
    template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){
        return os << "[" << p.dirst << "," << p.second << "]";
    }
}

#include <iostream>
#include <iomanip>
#include <cmath>
 
using namespace std;
 
int main(){
    int m, n;
    while(cin>>n>>m && m|n){
        vi p(n);
        int free = 0;
        int sum = 0;
        rep(i,n){
            cin >> p[i];
            sum += p[i];
        }
        sort(all(p));
        // テ」ツ??」ツ?暗」ツ?凝」ツつ?
        for(int i=n-m;i>=0;i-=m)free+=p[i];
        cout << sum - free << endl;
    }
}

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

using namespace std;

int main(){
	int n,m;
	int yasai[1000];
	int zenbu=0;
	int c=0;
	while(true){
		cin>>n>>m;
		if(n==0&&m==0)break;
		for(int i=0;i<n;i++){
			cin>>yasai[i];
		}
		sort(yasai,yasai+n,greater<int>());
		for(int i=0;i<n;i++){
			if(c==m-1)c=0;
			else {
				zenbu+=yasai[i];
				c++;
			}
		}
		cout<<zenbu<<endl;
		zenbu=0;
		c=0;
		for(int i=0;i<n;i++)yasai[i]=0;
	}
	return 0;
}

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

int main() {
	int n, m;
	while(cin >> n >> m, n || m) {
		vector<int> v;
		for(int i = 0; i < n; i++) {
			int tmp;
			cin >> tmp; v.push_back(tmp);
		}
		sort(v.rbegin(), v.rend());
		int res = 0;

		for(int i = 0; i < v.size(); i++) {
			if((i+1) % m)
				res += v[i];
		}
		cout << res << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  while(1){
    int ans=0,n,m,p[1001]={};
    cin>>n>>m;
    if(n==0 && m==0)break;
    for(int i=0;i<n;i++)
      cin>>p[i];
    
    for(int j=0;j<n;j++) 
      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;
      ans+=p[i];
    }

    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
  int n, m, p[1001];

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0){
      break;
    }
    for(int i = 0; i < n; i++){
      cin >> p[i];
    }
    sort(p, p+n);

    int s=0;
    for(int i = n-1, j=1; i >= 0; i--, j++){
      if(j == m){
	j = 0;
      } else {
	s += p[i];
      }
    }
    cout << s << endl;
  }

  return 0;
}

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

using namespace std;

int main(void){

  int n,m;
  while( cin >> n >> m , n && m ){

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

    sort( ve , ve + n );

    for( int i = 0 ; i < n ; i++ ){
      cout << ve[i] << " ";
    }
    cout << endl;

    int sum = 0;
    int cnt = 1;
    for( int i = n - 1 ; i >= 0 ; i-- ){
      if( cnt == m ){
	cnt = 0;
      }
      else sum += ve[i];
      cnt++;
    }
    
    cout << sum << endl;

  }
  return 0;
}

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

int main(){
	int n,m, cost;

	while( cin >> n >> m , n|m ){
		int sum = 0;
		vector<int> vc;
		for(int i=0 ; i<n ; ++i){
			cin >> cost;
			vc.push_back( cost );
		}
		sort( vc.begin() , vc.end() );
		reverse( vc.begin() , vc.end() );
		for(int i=0 ; i<(int)vc.size() ; ++i ){
			if( (i+1)%m != 0 ){
				sum += vc[i];
			}
		}
		cout << sum << endl;
	}
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n, m;
	while (cin >> n >> m, m) {
		vector<int>p(n);
		for (int i = 0; i < n; i++)cin >> p[i];
		sort(p.rbegin(), p.rend());
		int sum = 0;
		for (int i = 0; i < n; i++) {
			if ((i + 1) % m == 0)continue;
			sum += p[i];
		}
		cout << sum << endl;
	}
	return 0;
}

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

#define N_MAX 1000

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