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 <vector>
#include <algorithm>

int main(){
    int n, m, p, sum;

    while(std::cin >> n >> m){
        std::vector<int> price_list = {};

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

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

using namespace std;

int main()
{
  while(true){
    int n,m;
    int res = 0;
    scanf("%d%d", &n, &m);
    if(n == 0 && m == 0 )break;
    vector<int> p;
    for(int i = 0; i < n; ++i){
      int t; scanf("%d", &t); p.push_back(t);
    }
    sort(p.begin(),p.end(),greater<int>() );
    int s=0;
    for(int i = 0; i < n; ++i){
      if((i+1)%m==0){
	//cout << " s = " << s << endl;
	res += s;
	s=0;
	continue;
      }
      s+=p[i];
    }
    res += s;
    printf("%d\n", res);
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

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

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		vi ps(n);
		rep(i,n) cin>>ps[i];
		sort(all(ps));
		
		int sum=accumulate(all(ps),0);
		for(int i=n-m;i>=0;i-=m)
			sum-=ps[i];
		cout<<sum<<endl;
	}
	
	return 0;
}

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

const float PI = 3.1415926;
const int N = 100000;

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  int n,m,q;
  ll res;
  while(true) {
    cin >> n >> m;
    if(n == 0) break;
    vector<int> v;
    res = 0;
    for(int i = 0; i < n; i++){
      cin >> q;
      v.push_back(q);
    }
    sort(v.begin(), v.end(), greater<int>());
    for(int i=0; i < n; i+=m) {
      for(int j = i; j < m + i - 1; j++) {
        res += v[j];
      }
    }
    cout << res << endl;
  }
  
  return 0;
}

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

int main(){
    int n,m,x;
    int flag = 0;
    int num = 0;
    std::vector<int> v;
    
    std::cin >> n >> m;
    
    while(std::cin >> x){
        v.push_back(x);
    }
    
    sort(v.rbegin(),v.rend());
    
    for(int y = 0;y < n;++y){
        flag++;
        if(flag != m){
            num += v[y];
        }
        else
             flag = 0;
    }
    std::cout << num << std::endl;
}

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 <queue>

int main(){
	int n,m;
	while(std::cin >> n >> m){
		if(n == 0 && m == 0){
			break;
		}
		std::priority_queue<int> que;
		int vegetable;
		for(int i = 0; i < n; ++i){
			std::cin >> vegetable;
			que.push();
		}
		int price = 0;
		for(int i = 0; i < n; ++i){
		    if((i % m) != (m - 1)){
	  	        price += que.top();
		        que.pop();
		    }
		}
		std::cout << price << std::endl;
	}
	return 0;
}

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

const float PI = 3.1415926;

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  int n,m,q;
  ll res;
  vector<ll> v;
  while(true) {
    cin >> n >> m;
    if(n == 0) break;
    v.clear();
    res = 0;
    for(int i = 0; i < n; i++){
      cin >> q;
      v.push_back(q);
    }
    sort(v.begin(), v.end(), greater<int>());
    for(int i=0; i < n; i+=m) {
      for(int j = i; j < m + i - 1; j++) {
        res += v[j];
      }
    }
    cout << res << 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 ; 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;
#define lp(i,n) for(int i=0;i<n;i++)

int main(){
  while(1){
    int n,m;
    cin>>n>>m;
    if(n==0&& m==0) break;
    int a[1000];
    lp(i,n){
      cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    int ans=0;
    lp(i,n){
      if((i+1)%m==0) continue;
      else ans+=a[i];
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
  while (1){
    int i,m,n,sum=0;
    int L[1000];
    scanf("%d %d",&n,&m);
    if (n==0 && m==0) return 0;
    for (i=0;i<n;i++){
      scanf("%d",&L[i]);
      sum+=L[i];
    }
    sort(L,L+n);
    for (i=n-m;i>=0;i-=m)
      sum-=L[i];
    printf("%d\n",sum);
  }
}

C++: #include<iostream>
#include<algorithm>
#include<functional>
#define MAX 1000

int main(){
	int n,m,p[MAX];
	while(1){
		int f=0,m1=0;
		std::cin>>n>>m;
		if(n==0&&m==0)
			break;
		for(int i=0;i<n;++i){
			std::cin>>p[i];
		    m1+=p[i];
		}
		std::sort(p,p+n,std::greater<int>());
		int c=n%m;
		for(int i=0;i<n-c;++i){
			if((i+1)%m==0)
				f+=p[i];
		}
		std::cout<<m1-f<<std::endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int p[1000];
int main() {
	int n, m;
	while (cin >> n >> m, n) {
		int sum = 0;
		rep(i, n) {
			scanf("%d", &p[i]);
			sum += p[i];
		}
		sort(p, p + n, greater<>());
		for (int i = m - 1; i < n; i += m) {
			sum -= p[i];
		}
		cout << sum << endl;
	}
}