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<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    vector<int>in(n);
    rep(i,n)cin>>in[i];
    sort(all(in),greater<int>());
    int sum=0;
    rep(i,n){
      if(!((i+1)%m))continue;
      sum+=in[i];
    }
    cout<<sum<<endl;
  }
}

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

int main(){
	int n, m; // n:konyu m:hukuro
	std::cin >> n >> m;
	while(n != 0 || m != 0){
		std::vector<int> price;
		price.resize(n);
		for(int i = 0; i < n; ++i){
			cin >> price[i]; // input
		}
		
		std::sort(price.begin(), price.end(), std::greater<int>());

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

		std::cout << sum << endl;
		std::cin >> n >> m; 
	}

	return 0;
}

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

int main(){
	int n, m; // n:konyu m:hukuro
	std::cin >> n >> m;
	while(n != 0 || m != 0){
		std::vector<int> price;
		price.resize(n);
		for(int i = 0; i < n; ++i){
			std::cin >> price[i]; // input
		}
		
		std::sort(price.begin(), price.end(), std::greater<int>());

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

		std::cout << sum << std::endl;
		std::cin >> n >> m; 
	}

	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>


#define CI cin >>
#define CO cout <<
#define E << endl;
#define F(i,max) (for(int i = 0;i < max;++i))

using namespace std;

int n = 0;
int m = 0;

int total = 0;

vector<int> price;

void input() {
	CI n >> m;
	
	price.resize(n);

	for (int i = 0; i < n; ++i) {
		CI price[i];
	}

}

int GetPrice() {
	int amari = 0;

	total = 0;

	sort(price.begin(), price.end(), greater<int>());
	amari = n % m;
	for (int i = 0; i < n - amari; i++) {
		if ((i + 1) % m != 0) {
			total += price[i];
		}
	}
	if (amari != 0) {
		if (amari == 1) {
			total += price[n - 1];
		}
		else {
			for (int i = amari; i < n - 1; ++i) {
				total += price[i];
			}
		}
	}
	return 0;
}

int main(void) {
	
	while (true) {
		input();
		if (n == 0 && m == 0) {
			break;
		}

		GetPrice();

		CO total;
	}
	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);
    }
    
    std::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<vector>
#include<iostream>
using namespace std;

vector<int> l;
int n,m;

bool input(){
  cin>>n>>m;
  if(n==m&&n==0)return false;
  l.clear(),l.resize(n);
  for(int i=0;i<n;i++){
    cin>>l[i];
  }
  return true;
}

int solve(){
  sort(l.rbegin(),l.rend());
  int ans = 0;
  for(int i=0;i<n;i++){
    if( (i+1) %m == 0){
      continue;
    }
    ans += l[i];
  }
  return ans;
}

int main(){
  while(input()){
    cout<<solve()<<endl;
  }
}

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

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

using namespace std;

int main(){
	int data[1010];
	
	int n,m;
	while(cin>>n>>m && n &&m){
		for(int i=0;i<n;i++){
			cin>>data[i];
		}
		sort(data,data+n,greater<int>());
		int ans=0;
		
		for(int i=0;i<n;i++){
			if((i+1)%m!=0)ans+=data[i];
		}
		
		cout<<ans<<endl;
	}
}

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

using namespace std;
int n, m;
vector<int> vege;

const int INF = 1 << 29;

int main(void)
{
	while(cin >> n >> m)
	{
		vege.resize(n);
		for (int i = 0; i < n; i++)
		{
			cin >> vege[i];
		}

		sort(vege.begin(), vege.end(), greater<int>());
		int sum = accumulate(vege.begin(), vege.end(), 0);
		for (int i = 1; i - 1 < n / m; i++)
		{
			sum -= vege[i * m - 1];
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;
namespace std {
    template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){
        iter(it,v) os<<*it<<(it+1==v.end()?"":",");
        return os;
    }
    template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){
        return os << "[" << p.dirst << "," << p.second << "]";
    }
}

#include <iostream>
#include <iomanip>
#include <cmath>
 
using namespace std;
 
int main(){
    int n,m;
    while(cin>>n>>m && n|m){
        vi p(n);
        rep(i,n) cin >> p[i];
        sort(rall(p));
        int ans = 0;
        for(int i=0; i+m<n; i+=m){
            rep(j,m-1) ans+=p[i+j];
        }
        for(int i=n/m*m; i<n; i++){
            ans+=p[i];
        }
        cout << ans << endl;
    }
}

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

int *v,m,n,ans=0;

int main(){
	while(true){
		std::cin >> n >> m;
		if(!n && !m)
			return 0;
		v = new int[n];
		for(int i=0 ;i<n; i++)
			std::cin >> v[i];
		std::sort(v,v+n,std::greater<int>());
		for(int i=0; i<n; i++){
			if((i+1)%m == 0 && (i+1) >= m)
				i++;
			if(i != n)
				ans += v[i];
		}
		std::cout << ans << std::endl;
		delete[] v;
		ans = 0;
	}
}

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

int main(){
    int n, m, p, sum;
    std::vector<int> price_list = {};

    while(std::cin >> n >> m && (n != 0 && m != 0)){
        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;
    }
}