#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int m,n;
    while(cin>>n>>m,n){
        int plz[1050]={0},total=0,cnt=1;
        for(int i=0;i<n;i++){
            cin>>plz[i];
        }
        sort(plz,plz+n);
        reverse(plz,plz+n);
        for(int i=0;i<n;i++){
            if(cnt!=m){
                total+=plz[i];
                cnt++;
            }
            else if(cnt==m){
                    cnt=1;
            }
        }
        cout<<total<<endl;
    }
    return 0;
}
#include <iostream>
using namespace std;
int sum,h,w,a,b;
int main(){
	while(1){
		cin >> h>>w;
		if(!(h||w))break;
		sum=h*h+w*w;
		a=h+1;
		while(1){
			while(a*a<sum){
				b=a+1;
				while(a*a+b*b<=sum){
					if(a*a+b*b==sum)goto END;
					b++;
				}
				a++;
			}
			sum++;
			a=1;
		}
		END:;
		cout <<a <<" " <<b <<endl;
	}
}