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++: // 2011/07/27 Tazoe

#include <iostream>
using namespace std;

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

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

		// ツソツーツトツ（ツ降ツ渉）
		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(p[i]<p[j]){
					int tmp = p[i];
					p[i] = p[j];
					p[j] = tmp;
				}

		// mツ古つつィツつォツづ可鳴ウツ猟ソツづづ按づゥ
		for(int i=m-1; i<n; i+=m)
			p[i] = 0;

		// ツ債計
		int sum = 0;
		for(int i=0; i<n; i++)
			sum += p[i];

		cout << sum << endl;
	}

	return 0;
}

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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int n, m;
   while (cin >> n >> m, n) {
      vector<int> v(n);
      int sum = 0;
      for (int &x : v) {
         cin >> x;
         sum += x;
      }
      sort(v.begin(), v.end(), greater<int>());
      for (int i = m-1; i < v.size(); i+=m) {
         sum -= v[i];
      }
      cout << sum << endl;
   }

   return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define MAX 1000;
using namespace std;

int main(){
  int n,m,s;
  vector<int> p;
  while(cin >> n >> m){
    if(n==0 || m==0) return 0;

    for(int i=0; i<n; i++){
      cin >> s;
      p.push_back(s);
    }


      

    int sum=0,ans=0, min;
    sort(p.begin(), p.end(), greater<int>());

    for(int i=0; i<n; i+=m){
      min = p[i];
      for(int j=i; j<i+m; j++){
	if(j > n) continue;
	if(min > p[j]) min = p[j];
      }
      for(int k=i; k<i+m; k++){
	if(k > n) continue;
	sum += p[k];
      }
      ans += sum - min;
      sum=0;
    }
    cout << ans << endl;
    p.clear();
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,m;
  int a[1111];
  int x=-1;
  while(1){
    x=-1;
    int ans=0;
    cin >> n >> m;//nは購入数　mは最大数
    if(n==0 && m==0)break;
    for(int i=0;i<n;i++){
      cin >> a[i];
      ans+=a[i];
    }
    
    sort(a,a+n,greater<int>());
    
    
    while(n>=m){
      x+=m;
      ans-=a[x];
      n-=m;
    }
    
    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<queue>
using namespace std;
int main(){
	int n,m,sum,x;
	while(cin>>n>>m,n||m){
		sum=0;
		priority_queue<int> que;
		for(int i=0;i<n;i++){
		cin>>x;
			que.push(x);
		}
		for(int i=1;i<=n;i++){
			
			if((m+i)%m!=0){
			sum+=que.top();
			}
			que.pop();
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

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

int main(){
  int n,m,fig[1001];
  while(cin >> n >> m,n||m){
    int ans = 0;
    for(int i=0;i<n;i++) cin >> fig[i];
    sort(fig,fig+n,greater<int>());
    for(int i=0;i<(n/m)*m;i++){
      if((i+1) % m) ans += fig[i];
    }
    for(int i=n-1,j=0;j<(n%m);i--,j++) ans += fig[i];
    fill(fig,fig+1001,0);
    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){

    int n,m;
    while(cin>>n>>m,n){
        int a[1000],ans=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        reverse(a+1,a+n+1);
        for(int i=1;i<=n;i++){
            if(i%m!=0)ans+=a[i];
        }

        cout<<ans<<endl;
    }

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
#include<cstdio>  

using namespace std;

int main(void){
	int n,m;
	int a;
	while(1){
		cin >> n >> m;
		if(n==0 && m==0)break;
		int ans=0;
		vector<int> num;
		for(a=0;a<n;a++){
			int nn;
			scanf("%d",&nn);
			num.push_back(nn);
		}
		sort(num.begin(),num.end(), greater<int>() );
		for(a=0;a<n;a++){
			ans+=num[a];
		}
		for(a=0;a<=n;a++){
			if(a%m==m-1)ans-=num[a];
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
typedef pair< int , int> P;
int gcd( int x, int y ){
   return y ? gcd(y, x%y) : x;
 }
bool pairCompare(const P& firstElof, const P& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
while(  std::cin >> x>>y){
if(x==0)return 0;
  std::vector< int > v(x);
  rep(i,x)std::cin >> v[i];
  sort(rall(v));
  rep(i,x){
    if((i+1)%y==0)continue;
    z+=v[i];
  }
  std::cout << z << '\n';
  z=0;
}
}

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

int main(){
	int n, m, tmp;
	while(cin >> n >> m){
		vector<int> v;
		int ans = 0;
		if(n == 0 && m == 0) break;
		for(int i = 0; i < n; i++){
			cin >> tmp;
			v.push_back(tmp);			
		}
		sort(v.begin(), v.end(), greater<int>());
		for(vector<int>::iterator it = v.begin(); it < v.end();){
			int tmp = 1000000;
			for(int i = 0; i < m; i++){
				if(*it <= tmp) tmp = *it;
				ans += *it;
				it++;
//				if(it == v.end()) break;
				if(i == m - 1){
					ans -= tmp;
				}
			}
		}
		cout << ans << endl;
		ans = 0;
	}


}

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

int main(){
  int n,m,s;

  while(cin >> n >> m){
    int p[n];
    if(n==0 || m==0) return 0;
    for(int i=0; i<n; i++){
      cin >> p[i];
    }   

    int sum=0,ans=0, min;
    sort(p, p+n, greater<int>());

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

C++: #include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
int ps[1000];
int main(){
    int n,m;
    for(;;){
        scanf("%d%d",&n,&m);
        if(n==0&&m==0) break;
        for(int i=0;i<n;i++){
            scanf("%d",&ps[i]);
        }
        sort(ps,ps+n,greater<int>());
        int sum=0;
        for(int i=0;i<n;i++){
            if(i%m!=m-1) sum+=ps[i];
        }
        printf("%d\n",sum);
    }
}