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 <string>
#include <algorithm>
#include <numeric>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
#include <list>

using namespace std;
using namespace boost;


int main(int argc, char* argv[])
{
	using sprtr = char_separator<char>;
	using tknzr = tokenizer<sprtr>;
	sprtr sep(" ", "", keep_empty_tokens);

	int f, mf, mo;

	string line;
	while(1) {

		int n, m;
		{
			getline(cin, line);
			tknzr tkns(line, sep);
			auto it = tkns.begin();
			n = lexical_cast<int>(*it++);
			m = lexical_cast<int>(*it);
		}

		if( n == 0 && m == 0 ) {
			break;
		}
		
		list<int> ps;		
		{
			getline(cin, line);
			tknzr tkns(line, sep);
			for( auto p : tkns ) {
				//cout << p << endl;
				ps.push_back(lexical_cast<int>(p));
			}
		}

		ps.sort(greater<int>());

		int div = n / m;
		int mod = n % m;

		int sum = 0;
		auto it = ps.begin();
		for( int i = 0; i < div; i++ ) {
			for( int j = 0; j < m; j++ ) {
				auto p = *it++;
				if( j == m-1 ) continue;
				sum += p;
			}
		}

		if( mod ) {
			for( int i = 0; i < mod; i++ ) {
				auto p = *it++;
				sum += p;			   
			}
		}

		cout << sum << endl;

		ps.clear();
		
	}

    return 0;
}

C++: #include<stdio.h>
#include<algorithm>
#include<numeric>
int main()
{
	int m,n,p[10000],i,d;
	while(scanf("%d%d",&n,&m),m)
	{
		for(d=i=0;i<n;++i)scanf("%d",&p[i]);
		std::sort(p,p+n);
		for(i=n-m;i>=0;i-=m)d+=p[i];
		printf("%d\n",std::accumulate(p,p+n,0)-d);
	}
	return 0;
}

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

const float PI = 3.1415926;

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  int n,m,q;
  ll res;
  while(true) {
    cin >> n >> m;
    if(n == 0) break;
    vector<int> v;
    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+m; i+=m) {
      for(int j = i; j < m + i - 1; j++) {
        res += v[j];
      }
    }
    cout << res << endl;
  }
  
  return 0;
}

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

int main(void){
	int n,m;

	while(cin>>n>>m,n){
		int t[n];
		for(int i=0;i<n;i++){
			cin>>t[i];
		}
		sort(t,t+n);
		reverse(t,t+n);

		int ans = 0;
		for(int i=0;i<n;i+=m){
			int sum = 0;
			for(int j=i;j<n && j<i+m;j++){
				sum += t[j];
			}
			if(i+m <= n) sum -= t[i+m-1];
			ans += sum;
		}
		cout<<ans<<endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <algorithm>

int main(void)
{
	int n;
	int m;
	int data[1000];
	int ans;
	
	while (1){
		scanf("%d%d", &n, &m);
		if (n == 0){
			break;
		}
		
		for (int i = 0; i < n; i++){
			scanf("%d", &data[i]);
		}
		
		std::sort(data, data + n);
		std::reverse(data, data + n);
		
		ans = 0;
		for (int i = 0; i < n; i++){
			if (i % m != m - 1){
				ans += data[i];
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

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

main(){
  int m,n;
  int b[1001];
  while(cin >> n >> m,m || n){
    int total=0;
    int k=n/m;
    for(int i=0;i<n;i++) cin >> b[i];
    sort(b,b+n);

    for(int i=1;i<=n;i++){
      if(i%m) total+=b[n-i];
    }
    cout << total << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    while(1)
    {
        int n,m;
        cin>>n>>m;if(!n)return 0;
        int v[1000];
        for(int i=0;i<n;++i){
            cin>>v[i];
        }
        sort(v,v+n);
        reverse(v,v+n);
        int res=0;
        for(int i=0;i<n;){
            if(n-i>=m){
                for(int j=0;j<m-1;++j){
                    res+=v[i];
                    i++;
                }
                i++;
            }else{
                res+=v[i];
                i++;
            }
        }
        cout<<res<<endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
while(1){
  int n,m;
  int p[10000];
  int sum=0;
  cin>>n>>m;
  if(n==0 && m==0) break;
  for(int i=0;i<n;i++){
    cin>>p[i];
    }
  for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
      if(p[j]<p[j+1]) swap(p[j],p[j+1]);
      }
    }
  for(int i=0;i<n;i++){
    if(i%m==m-1) p[i]=0;
    }
  for(int i=0;i<n;i++){
    sum+=p[i];
    }
  cout<<sum<<endl;
}

  return 0;
}

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

int main(void)
{
	int n, m, p[10000];
	while (cin >> n >> m)
	{
		if (n == 0 && m == 0) break;
		int sum = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> p[i];
			sum += p[i];
		}
		for (int i = n - m + 1; i >= 0; i -= m) sum -= p[i];
		cout << sum << endl;
	}
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int a,b;
    while(cin>>a>>b,a+b){
        vi v(a);rep(i,a)cin>>v[i];
        sort(all(v));
        int now=1;
        int ans=0;
        for(int i=a-1;i>=0;i--){
            if(now!=b)ans+=v[i];
            else{
                now=1;continue;
            }
            now++;
        }
        cout<<ans<<endl;
    }
}

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

int main(){
    int n, m, p, sum;
    std::vector<int> price_list = {};

    while(std::cin >> n >> m &&  (n != 0 || m != 0)){
        sum = 0;
        for(int i = 0;i < n;i++){
            std::cin >> p;
            price_list.push_back(p);
            sum += p;
        }
        std::sort(price_list.begin(), price_list.end(), std::greater<int>());
        for(int i = 1;i <= n/m;i++){
            sum -= price_list.at(i * m - 1);
        }
        std::cout << sum << std::endl;
        std::cin.ignore();
    }
}

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