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<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n, m;
    while(cin >> n >> m, n){
        vector<int> p(n);
        int ans = 0;
        rep(i, n){
            cin >> p[i];
            ans += p[i];
        }

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

        cout << ans << endl;
    }

    cout << flush;

    return 0;
}

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

const int N_MAX = 1000;

int n, m;
int p[N_MAX];

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

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

int n, m;
int p[1005];
int sum=0;

void solve(){
  for(int i=0;i<n;i++){
    cin >> p[i];
    sum+=p[i];
  }
  sort(p,p+n);
  reverse(p,p+n);
  for(int i=m-1;i<n;i+=m){
    sum-=p[i];
  }
  cout << sum << endl;
  sum=0;
}

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

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

using namespace std;

int main() {

  int n,m;
  vector<int> p;

  int sum;

  
  while(cin >> n >> m) {

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

    p.clear();

    for(int i=0;i<n;i++) {

      int temp;

      cin >> temp;

      p.push_back(temp);

    }

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

    //for(int i=0;i<(int)p.size();i++) cout << p[i] << " ";

    sum=0;

    for(int i=0;i<(int)p.size();i++) {

      if(i%m!=m-1) sum+=p[i];

    }

    cout << sum << endl;

  }

  return 0;

}

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

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

    while(std::cin >> n >> m){
        if(n == 0 && m == 0){
            break;
        } else{
            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;
            sum_list.push_back(sum);
        }
    }
    for(int i = 0;i < sum_list.size();i++){
        std::cout << sum_list.at(i) << std::endl;
    }
    return 0;
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i;
  int n,m,s;
  int *a;
  while(cin>>n>>m&&n+m){
    a=new int[n];
    for(i=0;i<n;i++)
      cin>>a[i];
    do{
      h=0;
      for(i=1;i<n;i++){
	if(a[i-1]<a[i]){
	  swap(a[i-1],a[i]);
	  h=1;
	}
      }
    }while(h);
    s=0;
    for(i=0;i<n;i++){
      if((i+1)%m)
	s+=a[i];
    }
    cout<<s<<endl;
    delete[]a;
  }
  return 0;
}

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

int main(){
	int purchase, capa;
	
	while(std::cin >> purchase >> capa){
		if(purchase == 0 && capa == 0)
			break;
		
		std::vector<int> vegetable_price;
		vegetable_price.resize(purchase);
		
		//input
		for(int i=0; i<purchase; ++i){
			std::cin >> vegetable_price[i];
		}
		
		std::sort(vegetable_price.begin(), vegetable_price.end(), std::greater<int>());
		
		// 
		for(size_t i=capa-1; i<vegetable_price.size(); i += capa-1){
			vegetable_price.erase(vegetable_price.begin() + i);
		}
		
		int sum_price = 0;
		for(size_t i=0; i<vegetable_price.size(); ++i){
			sum_price += vegetable_price[i];
		}
		
		//show
		std::cout << sum_price << std::endl;
		
		//input
		std::cin >> purchase >> capa;
	}
	
	return 0;
}

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

int main(){
	int n, m; // n:konyu m:hukuro
	std::cin >> n >> m;
	while(n != 0 || m != 0){
		std::vector<int> price;
		price.resize(n);
		for(int i = 0; i < n; ++i){
			std::cin >> price[i]; // input
		}
		
		std::sort(price.begin(), price.end(), std::greater<int>());

		int sum = 0;
		for(int i = 0; i < n; ++i){
			if((i+1) % m != 0){ sum += price[i];}
		}

		std::cout << sum << std::endl;
		std::cin >> n >> m; 
	}

	return 0;
}

C++: #include<iostream>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m,dt;
	while(1){
		cin>>n>>m;
		if(!(n&&m))break;
		priority_queue<int> que;
		rep(i,n){cin>>dt;que.push(dt);}
		int cnt=0,sum=0;
		while(!que.empty()){
			cnt++;
			if(cnt!=m)sum+=que.top();
			else cnt=0;
			que.pop();
		}
		cout<<sum<<endl;
	}
	return 0;
}

C++: #include <iostream>

#define MAX_NM 1000

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>
#include <vector>
using namespace std;

int n,m;

void solve()
{
	vector<int> veg(n);
	int ans = 0;
	for(int i = 0; i < n; i++)
		cin >> veg[i];
	
	for(int i = 1; i <= n; i++){
		if(i % m){
			ans += veg[i-1];
		}

	}
	cout << ans << endl;
}


int main(void)
{
	while(cin >> n >> m, n | m){
		solve();
	}

	return 0;
}