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 "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 ; 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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n, m;
	while(cin >> n >> m && n)
	{
		vint p(n);
		rep(i, n)
			cin >> p[i];

		sort(ALL(p));

		int res = accumulate(ALL(p), 0);
		rep(i, n)
			res -= ((i + 1) % m== 0) * p[n - i - 1];

		cout << res << endl;
	}
}

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

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
    int N, M;
    while (cin >> N >> M, N) {
        vector<int> p(N);
        int sum = 0;
        for (int i = 0; i < N; i++) {
            cin >> p[i];
            sum += p[i];
        }
        sort(p.begin(), p.end());
        for (int i = N - M; i >= 0; i -= M) {
            sum -= p[i];
        }
        cout << sum << endl;
    }
    return 0;
}

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

int main(){
	int num,cap,price,i;

	while(std::cin >> num >> cap){

		if(num == 0 && cap == 0){
			break;
		}

		std::vector<int> vegetables;

		for(i=0; i<num; ++i){
			std::cin >> price;
			vegetables.push_back(price);
		}

		sort(vegetables.begin(), vegetables.end(), std::greater<int>());

		int sum = 0;
		i = 0;

		while(i < num){

			if((i+1) % cap != 0){
				sum += vegetables.at(i);
			}

			++i;
		}

		std::cout << sum << std::endl;
	}

}

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

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

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

    sort(data, data+n);
    int ans = 0;
    int cnt = 0;

    while( n > 0 ) {
      cnt++;
      n--;
      if( cnt == m ) {
	cnt = 0; 
	continue;
      } 
      ans += data[n];
    }

    cout << ans << endl;
  }
}

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();
      }
      else{
        price.pop();
      }
    }
    std::cout << sum << std::endl;
  }

  return 0;
}

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

int main(){
	int vnum, capacity;
	std::vector<int> vprice;

	while(std::cin >> vnum >> capacity){
		//end
		if(vnum == 0 && capacity == 0) break;

		int tmp,buf = capacity;
		int total = 0;
		std::vector<int> vprice;

		//input
		for(int i = 0; i < vnum; ++i){
			std::cin >> tmp;
			vprice.push_back(tmp);
	}

		//sort
		std::sort(vprice.begin(), vprice.end(), std::greater<int>());

		//sum price
		std::for_each(vprice.begin(),vprice.end(), 
			[&total,buf,&capacity](int x) { capacity != 1 ? (total += x, --capacity) : capacity = buf; } );

		//output
		std::cout << total << std::endl;
	}

	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

ll n, m, p[10000];

int main(){
	while (cin >> n >> m&&n + m){
		REP(i, n)cin >> p[i];
		sort(p, p + 10000, greater<int>());
		ll sum = 0;
		REP(i, n){
			if ((i+1)%m != 0)sum += p[i];
		}
		cout << sum << endl;
	}
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int n, m;
int p[1003];
void solve() {
    sort(p, p + n);
    reverse(p, p+n);
    int ans = 0;

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>

using namespace std;

int main(int argc, char *argv[]) {
  int price[1000];
  int n, m, pack, hoge, howmach;

  while (cin >> n >> m, n) {
    for (int i = 0; i < n; i++)
      cin >> price[i];

    sort(price, price + n);
    pack = n / m;
    hoge = n % m;
    howmach = accumulate(price, price + n, 0);
    for (int i = 0; i < pack; i++) {
      howmach -= price[m * i + hoge];
    }
    cout << howmach << endl;
  }
  return 0;
}

C++: 
#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;
}