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>

int main(){

	int n,m; //問題文のn,m

	while(std::cin >> n >> m){
		if(n==0&&m==0) break;
		std::vector<int> p; //野菜価格一覧
		for(int i=0;i<n;i++){
			std::cin >> p[i];
		}
		std::sort(p.begin(), p.end());
		std::reverse(p.begin(), p.end()); //降順ソート
		
		for(int i=m-1;i<n;i+=m){
			std::p.erase(std::v.bigin() +i);
		}

		std::cout << std::accumulate(p.begin(), p.end(), 0) << std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
	int m,n,p;
	while(cin >> m >> n, (m||n)) {
		int p[10000];
		rep(i,m) {
			cin >> p[i];
		}
		sort(p,p+m,greater<int>());
		int sum = 0;
		rep(i,m) {
			if(i%n!=n-1) sum += p[i];
		}
		cout << sum << endl;
	}
}

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

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

    while(std::cin >> n >> m){
        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 <vector>
#include <iterator>
#include <algorithm>

int main(){

	int num, limit;

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

		if(num == 0 && limit == 0) break;

		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 <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int n,m,p[1000];

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

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))

using namespace std;

int n, m;
vector<int> veg;

int solve()
{
	int res = 0;
	sort(veg.rbegin(), veg.rend());
	
	FOR(i, 0 ,n)
	{
		if( (i+1)%m != 0 )
		{
			res += veg[i];
		}
	}
	
	return res;
}

int main()
{
	while( cin >> n >> m, (n||m))
	{
		veg.clear();
		
		FOR(i,0,n)
		{
			int a;
			cin >> a;
			veg.push_back(a);
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}

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

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

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>
using namespace std;
int main(){
  int n,m;
  int p[1001];
  while(1){
    int ans=0;
    cin>>n>>m;
    if(n+m==0)break;
    for(int i=0;i<n;i++)
      cin>>p[i];
    
    for(int j=0;j<n;j++) 
      for(int i=0;i<n;i++)
	if(p[i]<p[i+1])swap(p[i],p[i+1]);

    for(int i=0;i<n;i++)
      if((i+1)%m==0)p[i]=0;
    
    for(int i=0;i<n;i++)ans+=p[i];
    
    cout<<ans<<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>
int main(void)
{
	int a,s,d[2000],f,g,h,i,j;
	scanf("%d %d",&a,&s);
	while(a!=0&&s!=0){
		for(i=1;i<=a;i++){
			scanf("%d",&d[i]);
		}
		for(i=1;i<=a;i++){
			for(j=i;j<=a;j++){
				if(d[i]<d[j]){
					f=d[i];
					d[i]=d[j];
					d[j]=f;
				}
			}
		}
		g=0;
		h=0;
		for(i=1;i<=a;i++){
			if(g==s-1){
				g=0;
				d[i]=0;
			}
			else if(g!=s-1){
				g++;
				h+=d[i];
			}
			//printf("%d %d\n",g,d[i]);
		}
		printf("%d\n",h);
	scanf("%d %d",&a,&s);
	}
	return 0;
}

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


int main(){
	std::vector<int> vegetable; //dataset
	int n; //number of purchase
	int m; //capacity of bag
	//int bag; //number of bag
	int ans=0; //minimum cost

	while(std::cin >> n >> m){ //input dataset
		if(n == 0 && m == 0) //end of input
			break;

		std::vector<int> price; //price of vegetable
		for(int i = 0; i < n; ++i){ //input price
			int data;
			std::cin >> data;
			price.push_back(data);
		}

		
		std::sort(price.begin(), price.end(), std::greater<int>()); //sort price in descending order


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

		int count = 1; //counter
		while(!vegetable.empty()){
			if(count % m == 0){
				vegetable.erase(vegetable.begin());
				++count;
			} else if(count % m != 0){
				ans += (int)vegetable.front();
				vegetable.erase(vegetable.begin());
				++count;
			}
		}
		std::cout << ans << std::endl; //output answer
		
	}


	return 0;
}

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

int main(){
	int a,b;
	while(std::cin >> a >> b){
		if(a==0&&b==0) break;

		int n;
		std::cin >> n;
		std::vector<std::vector<int>> map(a,std::vector<int>(b,1)); //地図

		for(int i=0;i<n;++i){
			int x,y;
			std::cin >> x >> y;
			if(x==0&&y==0) break;
			map[x-1][y-1]=0;
		}

		for(int i=1;i<a;++i){
			for(int j=1;j<b;++j){
				if(map[i][j]>0){
					map[i][j] = map[i-1][j]+map[i][j-1];
				}
			}
		}
		std::cout << map[a-1][b-1] << std::endl;
	}
	return 0;
}