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

using namespace std;


int main(){
  int n,m,p;
  while(true){
    cin >> n >> m;
    if(n+m == 0)break;
    vector<int> vec;
    for(int i=0;i<n;i++){
      cin >> p;
      vec.push_back(p);
    }
    sort(vec.begin(),vec.end(),greater<int>() );
    int sum = 0,cnt=1;
    for(int i=0;i<vec.size();i++){
      if(cnt%m == 0){
	cnt = 1;
	continue;
      }
      sum+=vec[i];
      cnt++;

    }
    cout << sum << endl;
  }
  return 0;
}

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

int main(){
  int n,m;
  while(1){
  int  ans=0,p[10001]={};
  cin>>n>>m;
  if(n+m==0)break;
  for(int i=1;i<=n;i++){
    cin>>p[i];
    if(p[i]<p[i+1])swap(p[i],p[i+1]);
  }

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


  cout<<ans<<endl;
  }
  return 0;
}

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

int n, m;


int main(){
    while(scanf("%d %d", &n, &m) != EOF){
        if(n == 0 && m == 0) break;

        int p[1000];
        std::fill(p, p + 1000, 0);
        for(int i = 0; i < n; i++){
            scanf("%d", &p[i]);
            p[i] = -p[i];
        }

        std::sort(p, p + n);

        int ans = 0;
        for(int i = 0; i < n; i++){
            if((i + 1) % m == 0) continue;
            ans += p[i];
        }

        printf("%d\n", -ans);
    }

    return 0;
}

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

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

    while(std::cin >> n >> m){
        std::cin.ignore();
        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;
            sum_list.push_back(sum);
        }
    }
    for(int i = 0;i < sum_list.size();i++){
        std::cout << sum_list.at(i) << std::endl;
    }
    return 0;
}

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


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;
		priority_queue<int,vector<int>,greater<int>> num;
		for(a=0;a<n;a++){
			int nn;
			scanf("%d",&nn);
			num.push(nn);
		}
		for(a=1;a<=n;a++){
			if(a%m==0)ans+=num.top();
			num.pop();
		}
		cout << ans << 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.emplace_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 <bits/stdc++.h>
using namespace std;

int main(){
    int n,m;
    while(true){
    cin >>n>>m;
    if(n==0){
    	break;
    }
   
    int p[n];
    for(int i=0;i<n;i++){
        cin >>p[i];
    }
    
    
    sort(p,p+n);
    int mon=0;
    for(int i=0;i<n;i++){
        mon += p[i];
    }
    int wari = 0;
    int t=n-m;
    while(t>=0){
        wari += p[t];
        t -= m;
    }
    
    cout <<mon-wari<<endl;
    continue;
    
    }
return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	int n,m,table[1000],sum;

	while(true){
		scanf("%d %d",&n,&m);
		if(n == 0 && m == 0)break;

		for(int i = 0; i < n; i++){
			scanf("%d",&table[i]);
		}

		for(int i = 1; i <= n-1; i++){
			for(int k = n-1; k >= i; k--){
				if(table[k] > table[k-1])swap(table[k],table[k-1]);
			}
		}

		sum = 0;

		for(int i = 0; i < n; i++){
			if(i%m != m-1){
				sum += table[i];
			}
		}
		printf("%d\n",sum);
	}

	return 0;
}

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> vegetable;
		int each_price;
		for(int i = 0; i < n; ++i){
			std::cin >> each_price;
			vegetable.push(each_price);
		}
		int sum_price = 0;
		for(int i = 0; i < n; ++i){
		    if((i % m) != (m - 1)){
	  	        sum_price += vegetable.top();
		    }
		    vegetable.pop();
		}
		std::cout << sum_price << std::endl;
	}
	return 0;
}

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

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n, m, x[1000000];
long long sum1, sum2;
int main() {
	while (true) {
		cin >> n >> m;
		if (n == 0 && m == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> x[i];
			sum1 += x[i];
		}
		sort(x, x + n);
		for (int i = n - m + 1; i >= 0; i -= m) {
			sum2 -= x[i];
		}
		cout << sum1 - sum2 << endl;
		return 0;
	}
}

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

using namespace std;

int main(){
  int i, n, m, x, sum, count;
  vector<int> data;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    for(i=0; i<n; ++i){
      cin >> x;
      data.push_back(x);
    }
    sort(data.begin(), data.end(), greater<int>());

    for(i=0, sum=0, count=1; i<data.size(); ++i, ++count){
      if(count == m) count = 0;
      else sum += data[i];
    }

    cout << sum << endl;
    data.clear();
  }
  return 0;
}

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

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

using namespace std;

int main(void){
	
	int n,m;
	
	while(scanf("%d %d", &n, &m) && n != 0 ){
		vector<int > a;
		int temp;
		int ans = 0;
		
		for(int i = 0; i < n; i++){
			scanf("%d", &temp);
			a.push_back(temp);
		}
		
		sort(a.begin(),a.end(),greater<int>());
		
		for(int i = 0; i < n; i++){
			if( ( i+1)%m != 0  ) ans += a[i];
		}
		printf("%d\n",ans);
	}
	return 0;
}

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