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;
	while(std::cin >> n >> m){
		if(n == 0 && m == 0){
			break;
		}
		std::vector<int> vegetable(n,0);
		for(int i = 0; i < n; ++i){
			std::cin >> vegetable[i];
		}
		std::sort(vegetable.begin(), vegetable.end(), std::greater<int>());
		int price = 0;
		for(int i = 0; i < n; ++i){
			price += vegetable.at(i);
		}
		for(int i = 1; i <= n/m; ++i){
			price -= vegetable.at(i * m - 1); 
		}
		std::cout << price << std::endl;
	}
	return 0;
}

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;
			std::cin >> buf;
			sum_price += 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){
				discount += *itr;
				in_bag = 0;
			}
		}

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

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

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.emplace_back(x);
    }
    
    std::sort(v.begin(), v.end(), std::greater<int>());
    
    for(int y = 0;y < n;y++){
        flag++;
        if(flag != m){
            num += v[y];
        }
        else
             flag = 0;
    }
    
    std::cout << num << std::endl;
}

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

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

int main(){
  int n,m,fig[1001];
  while(cin >> 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;i++){
      if((i+1) % m){ ans += fig[i]; cout << fig[i] << endl; }
    }
    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>
#include<functional>
using namespace std;
int main(){
int n,m;
	while(cin>>n>>m,n!=0||m!=0){
	int a[1000]={0},ans=0;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n,greater<int>());
		if(n>=m){
			for(int i=0;i<n;i++){
				if((i+1)%m==0){
				a[i]=0;
				}
				}
			}
		for(int i=0;i<n;i++)ans+=a[i];
		cout<<ans<<endl;
	}
	return 0;
}

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

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

	while(std::cin >> vnum >> capacity){
		int buf = capacity;
		std::vector<int> vprice;
		int tmp,total = 0;

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

int main(){
	std::vector<int> vegetables;
	int num,cap,price,i;

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

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

		int sum = 0;

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

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

		i = 0;

		while(i < num){

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

			++i;
		}

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

		vegetables.clear();
	}

}

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 = 1;
		for(auto itr = price.begin(); itr != price.end(); ++itr){
			++in_bag;
			if(in_bag == limit){
                                int buf = *itr;
				discount += buf;
				in_bag = 1;
			}
		}

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

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

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

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    while(cin >> n >> m, n){
        vector<int> v(n);
        for (auto &&i : v) scanf("%d", &i);
        sort(v.begin(),v.end(), greater<>());
        int ans = accumulate(v.begin(),v.end(), 0);
        for (int i = m-1; i < n; i += m) {
            ans -= v[i];
        }
        cout << ans << "\n";
    }
    return 0;
}

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

int main(){
	int n,m; //n:buy count  m:pack count
	
	while(std::cin >> n >> m){
		if(n == 0 && m == 0)
			break;
		
		std::vector<int> price;
		price.resize(n);
		for(int i=0; i<n; ++i){
			std::cin >> price[i];
		}
		
		std::sort(price.begin(), price.end(), std::greater<int>());

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

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

using namespace std;

int main() {
  for (;;) {
    int n, m, ps[1000];
    cin >> n >> m;
    if (!n && !m) return 0;
    int r = 0;
    for (int i = 0; i < n; i++)
      cin >> ps[i];
    sort(ps, ps+n);
    for (int i = 0; i < n; i++)
      r += ps[i];
    for (int i = n % m; i < n; i += m)
      r -= ps[i];
    cout << r << endl;
  }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int m,n;
    while(cin>>n>>m,n){
        int plz[1050]={0},total=0,cnt=1;
        for(int i=0;i<n;i++){
            cin>>plz[i];
        }
        sort(plz,plz+n);
        reverse(plz,plz+n);
        for(int i=0;i<n;i++){
            if(cnt!=m){
                total+=plz[i];
                cnt++;
            }
            else if(cnt==m){
                    cnt=1;
            }
        }
        cout<<total<<endl;
    }
    return 0;
}