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>
#include <sstream>
#include <iterator>

int main(){
    int n,m,x;
    
    while(std::cin >> n >> m){
        
        //nとmが両方0ならbreak
        if(n == 0 && m == 0)
            break;
        
        int flag = 0;
        int num = 0;
        std::vector<int> v;
        std::string line;
    
        std::getline(std::cin, line);
    
        if(std::getline(std::cin, line)){
            std::istringstream ss(line);
            while(ss >> 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 <vector>
#include <algorithm>

int main(void){
    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);
        }
        std::cin.ignore();
    }
    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 <functional>
using namespace std;

int main(){
	int i,n,m,a,price[1000],count,out;
	while(cin >> n >> m && (n != 0 && m != 0)){
		count = out = 0;
		for(i = 0;i < n;i++){
			cin >> a;
			price[i] = a;
		}
		sort(price,price+n,greater<int>());
		for(i = 0;i < n;i++){
			out += price[i];
			count++;
			if(count == m) {
				out -= price[i];
				count = 0;
			}
		}
		cout << out << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
#include <list>

using namespace std;
using namespace boost;


int main(int argc, char* argv[])
{
	using sprtr = char_separator<char>;
	using tknzr = tokenizer<sprtr>;
	sprtr sep(" ", "", keep_empty_tokens);

	int f, mf, mo;

	string line;
	while(1) {

		int n, m;
		{
			getline(cin, line);
			tknzr tkns(line, sep);
			auto it = tkns.begin();
			n = lexical_cast<int>(*it++);
			m = lexical_cast<int>(*it);
		}

		if( n == 0 && m == 0 ) {
			break;
		}
		
		list<int> ps;		
		{
			getline(cin, line);
			tknzr tkns(line, sep);
			for( auto p : tkns ) {
				//cout << p << endl;
				ps.push_back(lexical_cast<int>(p));
			}
		}

		ps.sort(greater<int>());

		int div = n / m;
		int mod = n % m;

		int sum = 0;
		auto it = ps.begin();
		for( int i = 0; i < div; i++ ) {
			for( int j = 0; j < m; j++ ) {
				auto p = *it++;
				if( j == m-1 ) continue;
				sum += p;
			}
		}

		if( mod ) {
			for( int i = 0; i < mod; i++ ) {
				auto p = *it++;
				sum += p;			   
			}
		}

		cout << sum << endl;

		ps.clear();
		
	}

    return 0;
}

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

using namespace std;

int main()
{
  int n, m, p[1001];

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

    int s=0;
    for(int i = n-1, j=1; i >= 0; i--, j++){
      if(j == m){
	j = 0;
      } else {
	s += p[i];
      }
    }
    cout << s << 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 <stdio.h>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, p[1000];
int main() {
	while (true) {
		scanf("%d%d", &n, &m);
		if (n == 0 && m == 0) break;
		for (int i = 0; i < n; i++) scanf("%d", &p[i]);
		sort(p, p + n);
		int ret = 0;
		for (int i = 0; i < n; i++) ret += p[i];
		for (int i = n % m; i + m <= n; i += m) ret -= p[i];
		printf("%d\n", ret);
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),n,m){

        int yasai[1024]={0};
        for(int i = 0;i < n; i++){
            scanf("%d",&yasai[i]);
        }
        sort(yasai,yasai+n);
        for(int i = n;i >= 0; i-=m){
            yasai[i] = 0;
        }
        int ans=0;
        for(int i = 0;i < n; i++){
            ans += yasai[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}

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<algorithm>
using namespace std;

int main(){
  int n,m;
  while(cin>>n>>m,n){
    int veg[n];
    for(int i=0;i<n;i++)cin>>veg[i];
    sort(veg,veg+n,greater<int>());
    int res=0;
    for(int i=0;i<n;i++){
      if((i+1)%m==0)continue;
      res+=veg[i];
    }
    cout << res << 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=1*m-1;a<n;a+=m){
			ans-=num[a];
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
  int n,m;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    int p[11111]={0};
    for(int i=0;i<n;i++){
      cin >> p[i];
    }
    int total = 0;
    for(int i=0;i<n;i++){
      int tmp = 0;
      int flag = 0;
      for(int j=0;j<m;j++){
	if(p[i] == 0){
	  flag = 1;
	  break;
	}
	else{
	  tmp += p[i];
	  i++;
	}
      }
      i--;
      if(flag == 1){
	total += tmp;
      }
      else {
	total += tmp - p[i];
      }
    }
    cout << total << endl;
  }
}