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 <queue>
 
int main(){
  std::priority_queue<int> price;
  int n,m;
 
  while(std::cin >> n >> m){
    int sum = 0;
    if(n == 0 && m == 0){ break; }
    for(int i = 0; i < n; ++i){
      int temp;
      std::cin >> temp;
      price.push(temp);
    }
    for(int i = 1; i <= n; ++i){
      if(i%m != 0){
        sum += price.top();
      }
      price.pop();
    }
    std::cout << sum << std::endl;
  }
 
  return 0;
}

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

int main(){
	int n, m; // n:purchase number, m:capacity of the bag
	std::cin >> n >> m;
	
	while(n != 0 || m != 0){
		std::vector<int> price; // price:the price of vegetable
		price.resize(n);
		for(int i = 0; i < n; ++i){
			std::cin >> price[i]; // input price
		}

		// sort in descending order
		std::sort(price.begin(), price.end(), std::greater<int>());

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

		std::cout << sum << std::endl; // output sum

		std::cin >> n >> m; 
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
    
int main(){
    u_int n;    // the number of vegetable
    u_int m;    // capacity
       
    while(std::cin >> n >> m){
        if(n == 0 && m == 0){
            break;
        }
            
        std::vector<u_int> p(n);  // price
        for(int i = 0; i < n; ++i){
            std::cin >> p[i];
        }
           
        //m, 2*m, 3*m, ... = free(sort by descending)
        std::sort(p.begin(), p.end(), std::greater<u_int>());
        for(int i = m; i <= n; i += m){
            p[i-1] = 0;
        }
           
        std::cout << std::accumulate(p.begin(), p.end(), 0) << std::endl;
    }
        
    return 0;
}

C++: #include "stdafx.h"
#include"iostream"
using namespace std;
int main() {
	while (1) {
		int n, m,p[10000],sum=0;
		cin >> n >> m;
		
		if (n == 0 && m == 0)break;

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

		for (int j = 0; j < n - 1; j++) {
			for (int i = 1; i < n + 1; i++) {
				if (p[i] < p[i + 1]) {
					swap(p[i], p[i + 1]);

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

			}
		
		cout << sum << endl;
	}
		
	return 0;
}

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

int main() {
    int N, M;
    while (cin >> N >> M, N || M) {
        vector<int> v(N);
        for (auto& i : v) cin >> i;
        sort(v.begin(), v.end());
        int ans = 0;
        for (int i = 1; i <= N; i++) {
            if (i % M) ans += v[N - i];
        }
        cout << ans << endl;
    }

    return 0;
}

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;
  }
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>

using namespace std;
using LL = long long;

constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;

int main() {
	int n, m;
	while (cin >> n >> m&&n&&m) {
		vector<int> v;
		int a;
		for (int i = 0; i < n; i++) {
			cin >> a;
			v.emplace_back(a);
		}
		sort(v.begin(), v.end(), greater<int>());
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if ((i + 1) % m != 0)ans += v[i];
		}
		cout << ans << endl;
	}
}

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

using namespace std;

int main() {
  int n, m, cost;
  int p[1000];
  while (true) {
    cin >> n >> m;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> p[i];
    }
    sort(p, p + n);
    cost = accumulate(p, p + n, 0);
    for (int i = n - m; i >= 0; i -= m) {
      cost -= p[i];
    }
    cout << cost << endl;
  }
}

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<int> data;
		data.clear();
		int sum = 0;
		for(int i =0; i <n;i++){
			int x;
			cin>>x;
			data.push_back(x);
			sum+=data[i];
		}
		sort(data.begin(),data.end(),greater<int>());
		int t =data.size()/m;
		for(int i =0; i<t;i++){
			sum-=data[i*m+m-1];
		}
		cout <<sum<<endl;
	}
	return 0;
}

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

vector<int> price;

int main(){
	int n,m;
	int ans;
	int i;
	while( cin >> n >> m )
	{
		if( n == 0 && m == 0 )
			break;
		ans = 0;
		price.resize( n );
		for( i = 0;i < n;i++ ){
			cin >> price[i];
			ans += price[i];
		}

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

		for( i = 0;i < n;i++ ){
			if( i%m < m-1 )
				continue;
			ans -= price[i];
		}
		cout << ans << endl;

		price.clear();
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <cmath>
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

typedef unsigned long long ull;

using namespace std;

int main() {
	int n, m;
	int ps[1000];
	for (;;) {
		cin >> n >> m;
		if (!(n | m))
			break;
		int ans = 0;
		REP(i,n) {
			cin >> ps[i];
			ans += ps[i];
		}
		if (n < m) {
			cout << ans << endl;
			continue;
		}
		sort(ps, ps + n, greater<int>());
		for (int i = m - 1; i < n; i += m) {
			ans -= ps[i];
		}
		cout << ans << endl;
	}
	return 0;
}

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


int main(){
	int k=0,n,m; //n:buy count  m: count
	std::vector<int> cheap;
	
	while(std::cin >> n >> m){
		if(n == 0 && m == 0)
			break;
		
		std::vector<int> p;
		p.resize(n);
		for(int i=0; i<n; ++i){
			std::cin >> p[i];
		}
		
		std::sort(p.begin(), p.end(), std::greater<int>());

		int sum=0;
		for(int i=0; i<n; ++i){
			if((i+1)%m != 0)
				sum += p[i];
		}
		cheap.push_back(sum);
		++k;
	}
	
	for(int i=0; i<k; ++i){
		std::cout << cheap[i] << std::endl;
	}
	
	return 0;
}