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(){
int a[10001];
int n,m;

while(true){
cin>>n>>m;
if(n==0&&m==0)break;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
int g=0;
for(int i=0;i<m;i++)
g+=a[i];
cout<<g<<endl;
}
}

C++: using namespace std;
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

typedef vector<int> VI;
typedef pair<int, int> PII;

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

int n, m, total;
VI v;

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

		v = VI(n);
		REP(i, n)
		{
			cin >> v[i];
		}
		
		sort(v.rbegin(), v.rend());
		total = 0;
		REP(i, n)
		{
			if(i%m!=m-1)
				total += v[i];
		}
		printf("%d\n", total);
	}
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,m;
  while(1){
    cin>>n>>m;
    if(n==0 && m==0)break;
    vi a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    int ans=0;
    rep(i,n)if((i+1)%m)ans+=a[n-i-1];
    cout<<ans<<endl;
  }
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n,m;
    while(cin>>n>>m){
        if(n==0 && m==0)break;
        
        vi data;
        
        rep(i,n){
            int a;
            cin>>a;
            data.pb(a);
        }
        
        sort(all(data));
        reverse(all(data));
        

        rep(i,n){
            if((i+1)%m==0){
                data[i]=0;
            }
        }
        int sum=0;
        rep(i,n){
            sum+=data[i];
        }
        cout<<sum<<endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define MAX 1000;
using namespace std;

int main(){
  int n,m,s;
  vector<int> p;
  while(cin >> n >> m){
    if(n==0 || m==0) return 0;
    p.clear();
    for(int i=0; i<n; i++){
      cin >> s;
      p.push_back(s);
    }   

    int sum=0,ans=0, min;
    sort(p.begin(), p.end(), greater<int>());

    for(int i=0; i<n; i+=m){
      min = p[i];
      for(int j=i; j<i+m; j++){
	if(j > n) continue;
	if(min > p[j]) min = p[j];
      }
      for(int k=i; k<i+m; k++){
	if(k > n) continue;
	sum += p[k];
      }
      ans += sum - min;
      sum=0;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	int n, m;
	while(cin >> n >> m, n || m){
		int price[10010];
		int ans = 0;
		for(int i=1; i <= n; i++)
			cin >> price[i];

		sort(price+1, price+n+1, greater<int>());

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

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

int main()
{
	while (1) {
		int a,b;
		cin >> a>>b;
		if (a == 0&&b==0)break;
		vector<int>s(a);
		for (int c = 0; c < a; c++) {
			cin >> s[c];
		}
		sort(s.begin(), s.end());
		int goukei = 0;
		for (int e = 0; e < a; e++) {
			if ((e + 1) % b != 0)goukei += s[s.size() - 1 - e];
		}
		cout << goukei << endl;
	}
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int main()
{
	int m, n;
	while (cin >> n >> m, n) 
	{
		vector<int> p(n+1);

		for (int i = 1; i <= n; i++)cin >> p[i];

		sort(p.begin(), p.end());
		reverse(p.begin(), p.end());

		ll sum = 0;
		for (int i = 1; i <= n; i++) {
			if (i%m != 0)sum += p[i-1];
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    while (cin >> n >> m && n) {
        vector<int> p(n);
        for (int i=0; i<n; ++i) {
            cin >> p[i];
        }
        sort(p.begin(), p.end());
        
        int res = accumulate(p.begin(), p.end(), 0);
        for (int i=n%m; i<n; i+=m) {
            res -= p[i];
        }
        cout << res << endl;
    }
    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 <list>

int main() {
  int num,bag,sum;
	
  while(std::cin >> num >> bag){
	
    if(num!=0 && bag!=0){
      std::list<int>  beg;
      for(int i=0;i<num;++i){
	int price;
	std::cin >> price;
	beg.push_back(price);
      }
      beg.sort(std::greater<int>());
      sum=0;
	        
      for(int i=1;beg.empty()!=true;i++){	   
        if(i%bag != 0){
          sum+=beg.front();
        }	
        beg.pop_front();
      }
      std::cout << sum << std::endl;
    }
  }
  return 0;
}

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

#define MAX_NM 1000

int n, m, all;
int p[MAX_NM];

void solve();

int main(){
    while(true){
        all = 0;
        std::cin >> n >> m;
        if(n == 0 && m == 0)
            break;
        for(int i = 0; i < n; ++i){
            std::cin >> p[i];
            all += p[i];
        }
        solve();
        std::cout << all << std::endl;
    }
    return 0;
}

void solve(){
    std::sort(p, p + n, std::greater<int>());
    for(int i = 1; i <= n; ++i)
        all -= p[i * m - 1];
    return;
}