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<bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,roop=0,ans[100];
    while(cin>>n>>m&&n!=0&&m!=0){
        int p[n],sum=0,h=n/m;
        for(int i=0;i<n;i++){
            cin>>p[i];
            sum+=p[i];
        }
        sort(p,p+n);
        for(int i=1;i<=h;i++){
            sum-=p[n-m*i];
        }
        ans[roop]=sum;
        roop++;
    }
    for(int i=0;i<roop;i++){
        cout<<ans[i]<<endl;
    }
}

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 <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
//typedef pair<int, int> P;
struct P {
	int x, y;
	P(int x, int y):x(x), y(y){}
	P(){}
};

/** Problem0227 : Thanksgiving **/
int main()
{
	int N, M;
	while (cin>>N>>M, N||M) {
		vector<int> v(N);
		rep(i, N) cin>>v[i];
		sort(v.begin(), v.end(), greater<int>());
		int ans=0;
		int t=1;
		rep(i, N) {
			if (t!=M) {
				t++;
				ans+=v[i];
			} else {
				t=1;
			}
		}
		cout << ans << endl;
	}
}

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

int n, m, p[1000];

int main(){
    for(; scanf("%d%d", &n, &m), n||m;){
        for(int x = 0; x < n; x++){
            scanf("%d", p+x);
        }
        sort(p, p+n, greater<int>());
        int ans = 0, z;
        for(int x = 0; x < n; x++){
            if((x+1)%m) ans += p[x];
        }
        printf("%d\n", ans);
    }
    return 0;
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (int u = 0; u < 100; u++)
	{
		int n = 0,m = 0;

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

		long a[1000];

		for (int i = 0; i < n; i++)
		{
			a[i] = 0;
			cin >> a[i];
		}

		sort(a,a + n);

		int p = 0;

		if (n != 0 && n >= m)
		{
			for (int i = 0; i < n - 1; i++)
			{
				p += a[i];
			}
		}
		else
		{
			for (int i = 0; i < n; i++)
			{
				p += a[i];
			}
		}

		cout << p << endl;
	}
}

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

int main(void){
	int num_veg,bag,price,sum_price;
	std::vector<int> price_veg;
	
	while(std::cin >> num_veg >> bag){
		if(num_veg == 0 && bag == 0) break;
		
		sum_price = 0;
		price_veg.clear();

		for(int i = 0; i < num_veg; ++i){
			std::cin >> price;
			price_veg.push_back(price);
		}

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

		for(int j = 0; j < num_veg; ++j){
			if(j % bag != bag - 1) sum_price += price_veg[j];
		}

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

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <P,P> PP;
typedef pair <int,PP> PPP;

static const double eps = 1e-8;

int main(){
	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && m==0) break;
		int* bag = new int[n];
		for(int i=0;i<n;i++){
			scanf("%d",bag+i);
		}

		sort(bag,bag+n,greater<int>());

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n, m;
	while (cin >> n >> m && (n || m)) {
		VI p(n); rep(i, n)cin >> p[i];
		sort(all(p)); reverse(all(p));

		int ans = 0;
		for (int i = 0; i < n; i += m) {
			for (int j = i; j < min(i + m - 1, n); j++) {
				ans += p[j];
			}
		}
		Cout(ans);
	}
}

C++: #include<stdio.h>
#include<stdlib.h>
int comp(const void *a,const void *b){
	return *(int*)b-*(int*)a;
}

int main(){
	int n,m;
	int p[1000];
	int i,j;
	int ans;
	while(1){
		scanf("%d %d",&n,&m);
		if(n==0)return 0;
		ans=0;
		for(i=0;i<n;i++)scanf("%d",&p[i]);
		qsort(p,n,sizeof(int),comp);
		for(i=0;i<n;i++){
			if(i%m!=m-1)ans+=p[i];
		}
		printf("%d\n",ans);
	}
}

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

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

    while(std::cin >> n >> m && (n != 0 || m != 0)){
        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;
    }
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int table[1000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		int sum=0;
		for(int i=0;i<a;i++){
			scanf("%d",table+i);
			sum+=table[i];
		}
		std::sort(table,table+a);
		for(int j=a-b;j>=0;j-=b)sum-=table[j];
		printf("%d\n",sum);
	}
}