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<cstring>
using namespace std;

int main(){

  int n,m,p;
  int d[1001];
  int ans;

  while(true){
    cin >> n >> m;
    if(!n && !m) break;

    memset(d,0,sizeof(d));
    p = -1;
    ans = 0;

    for(int i=0;i<n;i++) cin >> d[i];

    sort(d,d+n);
    reverse(d,d+n);

    for(int i=0;i<n;i++){
      if(p+m == i) p += m;
      else ans += d[i];
    }

    cout << ans << endl;

  }
}

C++: #include<stdio.h>
int main(){
  int m,n,a[1000],i,k,st,c;
  while(1){
    c=0;
    scanf("%d%d",&n,&m);
    if(n==0&&m==0)break;
    k=n;
    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
    }
    while(k!=0){
      for(i=1;i<k;i++){
	if(a[i-1]>a[i]){
	  st=a[i];
	a[i]=a[i-1];
	a[i-1]=st;
	}
      }
	k--;
    }
    for(i=n;i>=0;i-=m){
      a[i]=0;
    }
    for(i=0;i<n;i++){
      c+=a[i];
    }
    printf("%d\n",c);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 99999999;

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

typedef long long ll;

using namespace std;



/*
class LightSwitchingPuzzle
{
public:
	int minFlips(string s)
	{

	}
}
*/


int main()
{
	int n, m;
	
	while (cin >> n >> m, n | m)
	{
		int p[n];
		
		REP(n) cin >> p[i];
		sort(p, p + n);
		
		int sum = 0, cnt = 0;
		for (int i=n-1; i>=0; i--)
		{
			cnt++;
			if (cnt == m)
			{
				cnt = 0;
				continue;
			}
			sum += p[i];
		}
		
		cout << sum << endl;
		
		/*
		//テスト出力
		REP(n) cout << p[i] << " ";
		*/
	}
	
	return 0;
}

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

using namespace std;

int main(void){
	int n,m,t;
	
	while(cin >> n >> m){
		if((n|m) == 0) break;
		vector<int> val;
		int ret;
		for(int i=0;i<n;i++){
			cin >> t;
			val.push_back(t);
		}
		sort(val.begin(), val.end(), greater<int>());
		ret = accumulate(val.begin(),val.end(),0);
		for(int i=m-1;i<n;i+=m) ret -= val[i];
		cout << ret << endl;
	}
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
const int N=1e5+10;
int main(){
    int n,m,a[N],ans;
    while(true){
        scanf("%d%d",&n,&m);
        if(n==0&&m==0)return 0;
        ans=0;
        for(int i=0;i<n;i++)scanf("%d",&a[i]);
        sort(a,a+n);
        reverse(a,a+n);
        for(int i=0;i<n;i++)if((i+1)%m!=0)ans+=a[i];
        printf("%d\n",ans);
    }
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
 
int main(void){
    for(int n, m, s; s = 0, cin >> n >> m, n; cout << s << endl){
        priority_queue<int> p;
        rep(i, n){
            int in; cin >> in;
            p.push(in);
        }
        COUNT(i, n){
            if(i % m) s += p.top();
            p.pop();
        }
    }
 
    return 0;
}

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

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

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N, M; cin >> N >> M;
		if (!N)break;
		vector<int>prices(N);
		for (int i = 0; i < N; ++i) {
			cin >> prices[i];
		}
		sort(prices.begin(), prices.end(), greater<int>());
		int ans=0,num = 0;
		for (int i = 0; i < N; ++i) {
			num++;
			if (num == M) {
				num = 0;
			}
			else {
				ans += prices[i];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

int a[1010];

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

C++: #include <bits/stdc++.h>
using namespace std;
int main(void) {
    int n,m,p;
    std::deque<int> deq;
    while (cin>>n>>m) {
        if (n==0&&m==0) {
            break;
        } else {
            for (int i=0;i<n;i++) {
                cin>>p;
                deq.emplace_back(p);
            }
            sort(deq.begin(),deq.end(),greater<int>());
            int sum=0;
            while (n>=m) {
                for (int j=0;j<m;j++) {
                    if (j!=m-1) {
                        sum+=deq.front();
                        deq.pop_front();
                        n--;
                    } else {
                        deq.pop_front();
                        n--;
                    }
                }
            }
            if (n!=0) {
                for (int k=0;k<n;k++) {
                    sum+=deq.front();
                    deq.pop_front();
                }
            }
            cout<<sum<<endl;
        }
    }
}

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

int main(){

	int num, limit;

	while(std::cin >> num >> limit){
		std::vector<int> price;
		int sum_price = 0;
		//input
		for(int i = 0; i < num; ++i){
			int buf;
			sum_price += buf;
			std::cin >> buf;
			price.push_back(buf);
		}
		//sort
		std::sort(price.begin(),price.end(),std::greater<int>());
		//discount
		int discount = 0;
		int in_bag = 0;
		for(auto itr = price.begin(); itr != price.end(); ++itr){
			++in_bag;
			if(in_bag == limit){
                                int buf = *itr;
				discount += buf;
				in_bag = 0;
			}
		}

		std::cout << sum_price - discount << std::endl;
	}
	return 0;
}

C++: //48
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    int p[1000];
    for(int i=0;i<n;i++){
      cin>>p[i];
    }
    sort(p,p+n,greater<int>());
    int cost=0;
    int h=0;
    for(int i=0;i<n;i++){
      h++;
      if(h%m){
	cost+=p[i];
      }
    }
    cout<<cost<<endl;
  }
  return 0;
}