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

int main(void)
{
	int n, m, p[10000];
	while (cin >> n >> m)
	{
		if (n == 0 && m == 0) break;
		int sum = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> p[i];
			sum += p[i];
		}
		sort(p, p + n);
		for (int i = n - m; i >= 0; i -= m) sum -= p[i];
		cout << sum << endl;
	}
}

C++: // 2011/02/17 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n, m;
		cin >> n >> m;
		if(n==0&&m==0)
			break;

		int p[1000];		// ツ姪ャツ催伉づ個値ツ段
		for(int i=0; i<n; i++)
			cin >> p[i];

		// ツソツーツトツ（ツ降ツ渉）
		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(p[i]<p[j]){
					int tmp = p[i];
					p[i] = p[j];
					p[j] = tmp;
				}

		// mツ古つつィツつォツづ可鳴ウツ猟ソツづづ按づゥ
		for(int i=m-1; i<n; i+=m)
			p[i] = 0;

		// ツ債計
		int sum = 0;
		for(int i=0; i<n; i++)
			sum += p[i];

		cout << sum << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int main()
{
	int n,m,p[1000];
	while(cin>>n>>m,n){
		rep(i,n)cin>>p[i];
		sort(p,p+n,greater<int>());
		
		int ans=accumulate(p,p+n,0);
		for(int i=m-1;i<n;i+=m)ans-=p[i];
		cout<<ans<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
   
int main(){
    u_int n;    // the number of vegetable
    u_int m;    // capacity
      
    while(std::cin >> n >> m){
        if(n == 0 && m == 0){
            break;
        }
           
        std::vector<u_int> p(n);  // price
        for(int i = 0; i < n; ++i){
            std::cin >> p[i];
        }
          
        //m, 2*m, 3*m, ... = free(sort by descending)
        std::sort(p.begin(), p.end(), std::greater<u_int>());
        for(int i = m; i <= n; i += m){
            p[i-1] = 0;
        }
          
        std::cout << std::accumulate(p.begin(), p.end(), 0) << std::endl;
    }
       
    return 0;
}

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

using namespace std;

int main(){
	int data[1010];
	
	int n,m;
	while(cin>>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++){
			int tmp=i;
			for(;i-tmp<m-1;i++){
				ans+=data[i];
			
			}

		}
		
		cout<<ans<<endl;
	}
}

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) {
		for (int i = amari; i < n; ++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 <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) break;
    vector<int> p(n);
    REP(i, n) cin >> p[i];
    sort(ALL(p));
    reverse(ALL(p));
    int ans = 0;
    REP(i, n) {
      if ((i + 1) % m == 0) continue;
      ans += p[i];
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n,m,v,ans;
	vector<int>  b ;
	while(1){
		ans=0;
		cin >> n >> m ;
		if( (n==0) && (m==0) ){
			return 0;
		}
		for(int i=0;i<n;i++){
			cin >> v;
			ans += v;
			b.push_back(v);
		}
		sort(b.begin(),b.end());
		reverse(b.begin(),b.end());
		for(int i=m-1;i<n;i+=m){
			ans -= b[i];
		}
		cout << ans << "\n";
	}
}

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 <cstdio>
#include <vector>
#include <algorithm>
int main(){
	int i,n,m,x;
	for(;scanf("%d%d",&n,&m),n;printf("%d\n",x)){
		std::vector<int>v;
		for(i=0;i<n;i++)scanf("%d",&x),v.push_back(x);
		std::sort(v.begin(),v.end());
		for(x=i=0;i<n;i++)x+=(i%m==n%m)?0:v[i];
	}
}

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

std::vector<int> getArrayToLine(void);
int getMinimumPrice(std::vector<int> v, int i);

int main(void){
	int n; //number of bought vegetables
	int m; //number of vegetables that can be packed

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

		std::cout << getMinimumPrice(getArrayToLine(), m) << std::endl; //output result
	}

	return 0;
}

std::vector<int> getArrayToLine(void){
	std::vector<int> v;
	std::string buf;
	int tmp;

	std::cin.ignore();
	std::getline(std::cin, buf); //input line data
	std::istringstream is(buf);

	while(is >> tmp){ //input number
		v.push_back(tmp); //add number to array
	}

	return v;
}

int getMinimumPrice(std::vector<int> v, int i){
	int ans = 0;
	size_t cnt = 0; 

	//do process
	std::sort(v.begin(), v.end());

	while(!(v.empty())){
		++cnt;

		if(cnt % i == 0){
			v.pop_back();
		}else{
			ans = ans + v.back();
			v.pop_back();
		}
	}

	return ans;
}