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>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  int n,m,q;
  ll res;
  vector<ll> v;
  while(true) {
    cin >> n >> m;
    if(n == 0) break;
    v.clear();
    res = 0;
    for(int i = 0; i < n; i++){
      cin >> q;
      v.push_back(q);
    }
    sort(v.begin(), v.end(), greater<int>());
    for(int i=0; i < n; i++) {
      if(i % m != m - 1)
        res += v[i];
    }
    cout << res << endl;
  }
  
  return 0;
}

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

bool solve(){
    int n, m;
    cin >> n >> m;
    if(n == 0) return false;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    sort(p.rbegin(), p.rend());
    int ans = 0;
    for(int i=0;i<n;i++){
        if((i+1)%m==0) continue;
        ans += p[i];
    }
    cout << ans << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vint v(n);
		rep(i,n) cin>>v[i];
		sort(ALL(v));
		reverse(ALL(v));
		int c=0;
		int ans=0;
		rep(i,n){
			if(c==m-1){
				c=0;

			}
			else{
				ans+=v[i];
				c++;
			}
		}
		cout<<ans<<endl;
	}
}

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

int main(){

	int n,m; //問題文のn,m

	while(std::cin >> n >> m){
		if(n==0&&m==0) break;
		std::vector<int> p; //野菜価格一覧
		for(int i=0;i<n;i++){
			std::cin >> p[i];
		}
		std::sort(p.begin(), p.end());
		std::reverse(p.begin(), p.end()); //降順ソート
		
		for(int i=m-1;i<n;i+=m){
			p.erase(std::v.bigin() +i);
		}

		std::cout << std::accumulate(p.begin(), p.end(), 0) << std::endl;
	}

	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 item[1010];
    for(int i=0;i<n;i++){
      cin >> item[i];
    }
    sort(item,item+n);
    int ans=0,f=1;
    for(int i=n-1;i>=0;i--){
      if(f==m){
	f=1;
      }
      else{
	ans += item[i];
	f++;
      }
    }
    cout << ans <<"\n";
  }

}

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

int main(){

	int n=0,m=0; //問題文のn,m

	while(std::cin >> n >> m){
		if(n==0&&m==0) break;
		std::array<int, n> p; //野菜価格一覧
		for(int i=0;i<n;i++){
			std::cin >> p[i];
		}
		std::sort(p.begin(), p.end());
		
		int price=0; //最終出力

		while(n>=m){
			for(int i=0;i<m;i++){
				price += p[n-1-i];
			}
			n -= m;
		}
		for(int i=0;i<n;i++){
			price += p[i];
		}

		std::cout << price << std::endl;
	}

	return 0;
}

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

int main(){
	int n,m;
	while(std::cin >> n >> m){
		if(n == 0 && m == 0){
			break;
		}
		std::vector<int> vegetable(n,0);
		for(int i = 0; i < n; ++i){
			std::cin >> vegetable[i];
		}
		std::sort(vegetable.begin(), vegetable.end(), std::greater<int>());
		int price = 0;
		for(int i = 0; i < n; ++i){
		  if((i % m) != (m - 1)){
		        price += vegetable.at(i);
		    }
		}
		std::cout << price << std::endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.thanksgiving", "r", stdin );
	int n, m;

	while (cin >> n >> m && n && m){
		vector <int> bp(n + 1);
		int i;

		bp[0] = 10001;
		for (i = 1; i <= n; ++i){
			cin >> bp[i];
		} // end while

		sort (bp.begin(), bp.end(), greater<int>() );

		int res = 0;

		for (i = 1; i <= n; ++i){
			if (i % m == 0){
				continue;
			} // end if
			res += bp[i];
		} // end for
		cout << res << endl;	

	} // end loop
		
	return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n, m;
  while (cin >> n >> m, n) {
    vi p(n);
    cin >> p;
    sort(rall(p));
    int s = 0;
    rep(i, n) if ((i + 1) % m != 0) s += p[i];
    cout << s << endl;
  }
}

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

using namespace std;

int main(void){
	int n,m;
	int a;
	while(1){
		cin >> n >> m;
		if(n==0 && m==0)break;
		int ans=0;
		priority_queue<int,vector<int>,greater<int>> num;
		for(a=0;a<n;a++){
			int nn;
			scanf("%d",&nn);
			num.push(nn);
		}
		for(a=1;a<=n;a++){
			if(a%m==0)ans+=num.top();
			num.pop();
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int n,m,p[1000],ans;
int main(){
  while(1){
    ans=0;
    cin>>n>>m;
    if(n==0&&m==0) break;
    for(int i=0;i<n;i++)cin>>p[i];
    sort(p,p+n);
    for(int i=n-1;i>=0;i--)
      if((n-i)%m!=0)ans+=p[i];
    cout<<ans<<endl;
  }
  return 0;
}

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

int main()
{
	int n,m,total,c;
	int p[10000];
	
	while(scanf("%d%d",&n,&m) && n != 0 && m != 0){
		for(int i = 0; i < n; i++){
			scanf("%d",&p[i]);
		}
		sort(&p[0],&p[n-1]+1);
		
		c = total = 0;
		for(int i = n-1; i >= 0; i--){
			c++;
			if(c % m != 0){
				total += p[i];
			}
		}
		
		printf("%d\n",total);
	}

	return 0;
}