Problem:


お客様大感謝祭

 悪天候が続き野菜の価格が高騰する中、セブンマートではお客様に野菜のまとめ買いセールを実施しています。 日ごろなかなか店頭に並ばない野菜もお手頃価格で手に入るとあって、        店内はとても賑わっています。

 ある日、松長団地に住む仲良し 3 人組がセブンマートの広告を手に話に花を咲かせていました。今回のセールは「お客様大感謝祭」と銘打っただけに、袋詰めした野菜の中で最も安いものが無料になるのが目玉となっています。広告を読んでみると、どうやら以下のようなセールのようです。

 
 1 つの袋には m 個まで野菜を詰められる。

 
 野菜が m 個詰めてある袋については、その中で最も安い野菜が無料となる。

 
 野菜の個数が m 個に達しない袋は割引の対象外。

 3人は早速セブンマートへ買い物に行きました。

 買い物が終わり、  お店の外で待ち合わせた 3 人は安くてたくさん購入できたことに満足した様子で話をしていると、どうやら 3 人とも同じ野菜を購入していたことが分かりました。ある一人が、「本当に安いわよねぇ。これでXXX円だもの!」と言うと、もう一人は、「え?私はそれより**円高かったわ!どうして?」と驚き、また、残りの一人はレシートを見て自分が一番安く購入したことに気付きました。

さて、どのように袋詰めすれば購入価格を一番安くできるでしょうか。 購入する野菜の個数、袋に入る野菜の個数、各野菜の値段を入力とし、最低購入価格を出力するプログラムを作成してください。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。
各データセットは以下の形式で与えられます。

n m
p1 p2 ... pn

1 行目に購入する野菜の個数 n (1 ≤ n ≤ 1000) と袋に入る野菜の個数 m (1 ≤ m ≤ 1000)　が与えられます。２行目に各野菜の値段 pi (10 ≤ pi ≤ 10000) が与えられます。

データセットの数は 100 を超えません。

Output

入力データセットごとに、最低購入価格を１行に出力します。

Sample Input

4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0

Output for the Sample Input

150
2100



Sample input:
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0


Sample output:
150
2100

Submission status: Wrong Answer

Solution code:
for i in range(1, 101):
    count = 0
    SetCount = 0

    try:
        str1 = input()
        list1 = str1.split(" ")
        str2 = input()
        list2 = str2.split(" ")
        list2.sort(reverse=True)
        for m in range(0, int(list1[0])):
            if (m+1) % int(list1[1]) == 0:
                count = count + int(list2[m])
                SetCount = SetCount + 1
            elif (m+1) % int(list1[1]) != 0 | SetCount == int(list1[0])//int(list1[1]):
                count = count + int(list2[m])
        print(count)

    except:
        break

Submission status: Wrong Answer

Solution code:
for i in range(1, 101):
    count = 0
    temp = 0
    SetCount = 0

    try:
        str1 = input()
        list1 = str1.split(" ")
        str2 = input()
        list2 = str2.split(" ")
        list2.sort(reverse=True)
        for m in range(0, int(list1[0])):
            if (m+1) % int(list1[1]) == 0:
                SetCount = SetCount + 1
            #elif (m+1) % int(list1[1]) != 0 | SetCount == int(list1[0])//int(list1[1]):
             #   count = count + int(list2[m])
            else:
                count = count + int(list2[m])
        print(count)

    except:
        break

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
while True:
    a=map(int,raw_input().split())
    if sum(a)==0:break
    b=map(int,raw_input().split())
    b=sorted(b)
    b.reverse()
    c=[b[i] for i in range(a[1]-1,len(b),a[1])]
    ans=[]
    for i in b:
        if i not in c: ans.append(i)
    print sum(ans)

Submission status: Wrong Answer

Solution code:
while True:
	try:
		n,m=map(int, raw_input().split())
		c=sorted(map(int,raw_input().split()))[::-1]
		if m > n:
			print sum(c)
		else:
			c[m-1::m] = [0 for i in range(m-1,n,m)]
			print sum(c)
	except:
		break

Submission status: Time Limit Exceeded

Solution code:
while True:
    #n,m = list(map(int,input().split()))
    #spam = input()


    print(1)

Submission status: Accepted

Solution code:
for i in range(1, 101):
    count = 0
    temp = 0
    SetCount = 0

    try:
        str1 = input()
        list1 = str1.split(" ")
        str2 = input()
        list2 = str2.split(" ")
        list2.sort(key=int, reverse=True)
        for m in range(0, int(list1[0])):
            if (m+1) % int(list1[1]) == 0:
                SetCount = SetCount + 1
            #elif (m+1) % int(list1[1]) != 0 | SetCount == int(list1[0])//int(list1[1]):
             #   count = count + int(list2[m])
            else:
                count = count + int(list2[m])
        print(count)

    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        n,m = list(map(int,input().split()))
        if n == 0 and m == 0:
            break
        amari = n % m
        yasai = list(map(int,input().split())) 
        yasai.sort()

        s = 0
        if amari > 0:
            s = sum(yasai[0:amari])

        i = 0
        for y in yasai[amari:]:
            if i % m > 0:
                s += y
            i+=1

        print(s)
    except:
        pass

Submission status: Accepted

Solution code:
while True:
    try:
        n,m = list(map(int,input().split()))
        if n == 0 and m == 0:
            break
        amari = n % m
        yasai = list(map(int,input().split())) 
        yasai.sort()

        s = 0
        for i in range(n):
            if (i+1) % m > 0:
                s += yasai[-i-1]
        print(s)
    except:
        pass

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    n,m = map(int,input().split(" "))
    if n == 0 and m == 0:
        break
    prices = list(map(int,input().split(" ")))
    count = 0
    cost = 0
    for p in reversed(sorted(prices)):
        count += 1
        if count >= m:
            count = 0
            continue
        else:
            cost += p
    print(cost)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n, m = map(int, raw_input().split())
            if n == 0 and m == 0:
                break
            vegi = map(int, raw_input().split())
            vegi.sort(reverse=True)
            ans = 0
            for i in range(len(vegi)):
                if i % m != m - 1:
                    ans += vegi[i]
            print ans
                    
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

Solution code:
import sys
f = sys.stdin


while True:
    n, m = map(int, f.readline().split())
    if n == 0:
        break
    vegitables = sorted(map(int, f.readline().split()), reverse=True)
    discount = sum(vi for i, vi in enumerate(vegitables) if (i + 1) % m == 0)
    print(sum(vegitables) - discount)

Submission status: Accepted

Solution code:
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    price = sorted(map(int, input().split()), reverse=True)
    print(sum(price) - sum(price[m - 1::m]))

Submission status: Accepted

Solution code:
while True:
	N, M = [ int(_) for _ in raw_input().split() ]
	if N == 0: break
	p = [ int(_) for _ in raw_input().split() ]
	p.sort()
	p.reverse()
	s = 0
	for i in xrange(N):
		if i % M != M - 1:
			s += p[i]
	print s

Submission status: Accepted

Solution code:
while True:
    n, m = map(int, raw_input().split())
    if n == m == 0: break
    data = map(int, raw_input().split())
    total = [p for i,p in enumerate(sorted(data, reverse=True)) if (i+1)%m != 0]
    print sum(total)

Submission status: Accepted

Solution code:
while 1:
    _,m=map(int, input().split())
    if m==0:break
    p=sorted(map(int,input().split()),reverse=1)
    print(sum(p)-sum(p[m-1::m]))

Submission status: Accepted

Solution code:
# Aizu Problem 0227: Thanksgiving

import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")



while True:
    n, m = [int(_) for _ in input().split()]
    if n == m == 0:
        break
    prices = sorted([int(_) for _ in input().split()], reverse=True)
    for i in range(m - 1, n, m):
        prices[i] = 0
    print(sum(prices))

Submission status: Accepted

Solution code:
# AOJ 0227: Thanksgiving
# Python3 2018.6.24 bal4u

while 1:
	n, m = map(int, input().split())
	if n == 0: break
	p = list(map(int, input().split()))
	p.sort(reverse=True)
	ans = 0
	for i in range(1, n+1):
		if i % m: ans += p[i-1]
	print(ans)

Submission status: Accepted

Solution code:
while True:
  n, m = map(int, input().split())
  if n == 0:
    break
  plst = sorted(list(map(int, input().split())), reverse=True)
  s = sum(plst)
  for i in range(m - 1, n, m):
    s -= plst[i]
  print(s)

Submission status: Accepted

Solution code:
# try-except is necessary for avoiding Runtime Error 
while 1:
	try:
		n,m=map(int,raw_input().split())
		if n==0:break
		v=sorted(map(int,raw_input().split()))[::-1]
		for i in range(m-1,n,m):
			v[i]=0
		print sum(v)
	except:
		pass

Submission status: Accepted

Solution code:
while True:
	try:
		n, m = (int(x.strip()) for x in raw_input().split())
		if n == 0 and m == 0: break
		p = [int(x.strip()) for x in raw_input().split()]
		s = sum(p)
		p.sort(reverse=True)
		for x in p[m - 1::m]:
			s -= x
		print s
	except:
		pass

Submission status: Accepted

Solution code:
while 1:
    try:
        nm = map(int, raw_input().split())
        if nm == [0, 0]:
            break
        n = nm[0]
        m = nm[1]
        p = map(int, raw_input().split())
        p_sorted = sorted(p)
        sum = 0
        for i in range(n):
            if (i+1) % m != 0:
                sum += p_sorted[-1-i]
        print sum
    except:
	pass

Submission status: Accepted

Solution code:
while True :
    n, m = map(int, input().split())
    if n == 0 and m == 0 :
        break
    
    p = list(map(int, input().split()))
    p.sort(reverse=True)
    cst = 0
    for i in range(n) :
        if (i+1) % m != 0 :
            cst += p[i]
    print(cst)

Submission status: Accepted

Solution code:
# AOJ 0227: Thanksgiving
# Python3 2018.6.24 bal4u
 
while 1:
    n, m = map(int, input().split())
    if n == 0: break
    p = list(map(int, input().split()))
    p.sort(reverse=True)
    ans = 0
    for i in range(1, n+1):
        if i % m: ans += p[i-1]
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Thanksgiving
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0227

"""
import sys


def solve(n, m, prices):
    ans = 0
    for i in range(0, n, m):
        t = prices[i:i+m]
        if len(t) == m:
            t[-1] = 0
        ans += sum(t)
    return ans


def main(args):
    while True:
        n, m = map(int, input().split())
        if n == 0 and m == 0:
            break
        prices = sorted([int(p) for p in input().split()], reverse=True)
        ans = solve(n, m, prices)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:

while True:
    try:
        num, size = map(int, input().split())
        arr = list(map(int, input().split()))
        arr.sort(reverse = True)
        for i in range(size-1, num, size):
            arr[i] = 0
        print(sum(arr))
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        __, m = (lambda row: [int(row[i]) for i in range(len(row))])(input().split())
        price = sorted(list(map(int, input().split())), reverse=True)
        print(str(sum([price[i] for i in range(len(price)) if (i+1)%m != 0])))
    except:
        break

Submission status: Accepted

Solution code:
while 1:
      qua,bag = input().split()
      qua = int(qua)
      bag = int(bag)
      if qua == 0:
            break
      price = list(map(int,input().split()))
      price.sort(reverse=True)
      for i in range(qua):
            if (i+1)%bag == 0:
                  price[i]=-1
      for i in range(qua//bag):
            price.remove(-1)
      pay = sum(price)
      print(pay)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

while 1:
  try:
    n, m = map(int, input().split())
    if n == 0:
      break
    p = sorted(list(map(int, input().split())))
    p.reverse()
    for i in range(m - 1, n, m):
      p[i] = 0
    print(sum(p))
  except:
    break

Submission status: Accepted

Solution code:
while True:
    try:
        num, size = map(int, raw_input().split())
        arr = map(int, raw_input().split())
        arr.sort(reverse = True)
        for i in range(size-1, num, size):
            arr[i] = 0
        print sum(arr)
    except:
        break

Submission status: Accepted

Solution code:
while True:

    n, m = [int(i) for i in input().split()]
    if n == 0 and m == 0:
        break

    p = [int(i) for i in input().split()]
    p.sort()
    p.reverse()

    ans = 0
    for i in range(len(p)):
        if (i+1) % m > 0:
            ans = ans + p[i]

    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n, m = map(int, input().split())
    if n == 0:
        break

    veg = list(map(int, input().split()))
    veg.sort(reverse=True)

    cnt = 0
    ans = 0
    while veg != []:
        cnt += 1
        tmp = veg.pop(0)
        if cnt % m == 0:
            pass
        else:
            ans += tmp

    print(ans)

Submission status: Runtime Error

Solution code:
while True:
    n,m = list(map(int,input().split()))
    if n == 0 and m == 0:
        break

    amari = n % m
    yasai = list(map(int,input().split())) 
    yasai.sort()

    s = 0
    if amari > 0:
        s = sum(yasai[0:amari])

    i = 0
    for y in yasai[amari:]:
        if i % m > 0:
            s += y
        i+=1

    print(s)

Submission status: Runtime Error

Solution code:
while True:
    n,m = list(map(int,input().split()))
    if n == 0 and m == 0:
        break

    amari = n % m
    yasai = list(map(int,input().split())) 
    yasai.sort()

    s = 0
    if amari > 0:
        s = sum(yasai[0:amari])

    i = 0
    for y in yasai[amari:]:
        pass

    print(s)

Submission status: Runtime Error

Solution code:
while True:
    n,m = list(map(int,input().split()))
    if n == 0 and m == 0:
        break

    amari = int(n % m)
    yasai = list(map(int,input().split())) 
    yasai.sort()

    s = 0
    if amari > 0:
        s = sum(yasai[0:amari])

    i = 0
    for y in yasai[amari:]:
        pass
        if i % m > 0:
            s += y
        i+=1

    print(s)

Submission status: Runtime Error

Solution code:
while True:
    n,m = list(map(int,input().split()))
    if n == 0 and m == 0:
        break

    amari = int(n % m)
    yasai = list(map(int,input().split())) 
    print(amari)

Submission status: Runtime Error

Solution code:
while True:
    n,m = list(map(int,input().split()))
    print(amari)

Submission status: Runtime Error

Solution code:
while True:
    #n,m = list(map(int,input().split()))
    spam = input().split()
    n = int(spam[0])
    m = int(spam[1])
    if n == 0 and m == 0:
        break


    print(1)

Submission status: Runtime Error

Solution code:
while True:
    #n,m = list(map(int,input().split()))
    spam = input().split()


    print(1)

Submission status: Runtime Error

Solution code:
while True:
    #n,m = list(map(int,input().split()))
    spam = input()


    print(1)

Submission status: Runtime Error

Solution code:
while True:
    n,m = map(int,raw_input().split())
    if n == 0 and m == 0:
        break

    amari = n % m
    yasai = map(int,raw_input().split())
    yasai.sort()

    s = 0
    if amari > 0:
        s = sum(yasai[0:amari])

    i = 0
    for y in yasai[amari:]:
        if i % m > 0:
            s += y
        i+=1

    print(s)

Submission status: Runtime Error

Solution code:
while True:
    n,m = map(int,raw_input().split())

Submission status: Runtime Error

Solution code:
while True:
    n,m = map(int,raw_input().split(' '))

Submission status: Runtime Error

Solution code:
while True:
    a = raw_input()
    print 'a'

Submission status: Runtime Error

Solution code:
while True:
    a = input()
    print('a')

Submission status: Runtime Error

Solution code:

while True:
    a = input()
    print('a')

Submission status: Runtime Error

Solution code:
while True:
    n,m=map(int,raw_input().split())
    if n==m==0:break
    L=sorted(map(int,raw_input().split()),reverse=True)
    print sum(L[i] for i in range(n) if (i+1)%m<>0)

Submission status: Runtime Error

Solution code:
while True:
    try:
        n,m=map(int,raw_input().split())
    except ValueError:
        pass
    if n==m==0:break
    L=sorted(map(int,raw_input().split()),reverse=True)
    print sum(L[i] for i in range(n) if (i+1)%m<>0)

Submission status: Runtime Error

Solution code:
while True:
    A=map(int,raw_input().split())
    n,m=A[0],A[1]
    if n==m==0:break
    L=sorted(map(int,raw_input().split()),reverse=True)
    print sum(L[i] for i in range(n) if (i+1)%m<>0)

Submission status: Runtime Error

Solution code:
while True:
    n,m=input(),input()
    if n==m==0:break
    L=sorted(map(int,raw_input().split()),reverse=True)
    print sum(L[i] for i in range(n) if (i+1)%m<>0)

Submission status: Runtime Error

Solution code:
while 1:
    n,m = map(int, raw_input().split())
    if n==m==0: break
    s = 0
    p = map(int, raw_input().split())
    p.sort(reverse=True)
    s = sum([p[i] for i in range(n) if i%m!=m-1])
    print s

Submission status: Runtime Error

Solution code:
while 1:
    n,m = map(int, raw_input().split())
    if n==m==0: break
    p = map(int, raw_input().split())
    p.sort(reverse=True)
    s = 0
    for i in range(n):
        if i%m!=m-1:
            s += p[i]
    print s

Submission status: Runtime Error

Solution code:
while 1:
    n,m = map(int, raw_input().split())
    if n==m==0: break
    p = map(int, raw_input().split())
    p.sort(reverse=True)
    s = 0
    for i in range(n):
        if i%m!=m-1:
            s += p[i]
    del p[:]
    print s

Submission status: Runtime Error

Solution code:
while True:
    n, m = map(int, raw_input().split())
    if n|m == 0:
        break
    p = sorted(map(int, raw_input().split()))[::-1]
    print sum(p) - sum(p[m-1::m])

Submission status: Runtime Error

Solution code:
while True:
    n, m = map(int, raw_input().split())
    if n|m == 0:
        break
    p = sorted(map(int, raw_input().split()))[::-1]
    print sum(p) - sum(p[m-1::m]) if n >= m else 0

Submission status: Runtime Error

Solution code:
while True:
    n, m = map(int, raw_input().split())
    if n == 0:
        break
    p = sorted(map(int, raw_input().split()))[::-1]
    print sum(p) - (sum(p[m-1::m]) if n >= m else 0)

Submission status: Runtime Error

Solution code:
while True:
    n = map(int, raw_input().split())
    if n[0] == 0 and n[1] == 0:
        break
    # print(n)
    data = sorted(map(int, raw_input().split()), reverse = True)
    # print(data)   
    sum = 0

    for i in xrange(n[0]):
        if (i + 1) % n[1] != 0:
            sum += data[i]
    #     print(i)

    print(sum)

Submission status: Runtime Error

Solution code:
while True:
    n = map(int, raw_input().split())
    if n[0] == 0 and n[1] == 0:
        break
    data = sorted(map(int, raw_input().split()), reverse = True)
    sum = 0

    for i in xrange(n[0]):
        if (i + 1) % n[1] != 0:
            sum += data[i]

    print(sum)

Submission status: Runtime Error

Solution code:
while True:
    n = map(int, raw_input().split())
    if n[0] == 0 and n[1] == 0:
        break
    # print(n)
    data = sorted(map(int, raw_input().split()), reverse = True)
    # print(data)   
    sum = 0

    for i in range(n[0]):
        if (i + 1) % n[1] != 0:
            sum += data[i]
    #     print(i)

    print(sum)

Submission status: Runtime Error

Solution code:
def main():

    while True:
        n  =  map(int,  raw_input().split())
        if n[0]  ==  0 and n[1]  ==  0:
            break
        # print(n)
        data  =  sorted(map(int,  raw_input().split()),  reverse  =  True)
        # print(data)   
        sum  =  0

        for i in range(len(data)):
            if (i  +  1 )  %  n[1] !=  0:
                sum += data[i]
        #     print(i)

        print(sum)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def signal(a,e):
	s=""
	for i in range(7):
		s+="0" if a[i]==e[i] else "1"
	return s

ref=["0111111","0000110","1011011","1001111","1100110","1101101","1111101","0100111","1111111","1101111"]
while 1:
	n=int(raw_input())
	if n==-1:break
	e="0000000"
	for i in range(n):
		a=ref[int(raw_input())]
		print signal(a,e)
		e=a

Submission status: Runtime Error

Solution code:
while 1:
	n,m=map(int, raw_input().split())
	if n==0:break
	c=sorted(map(int,raw_input().split()))[::-1]
	c[m-1::m] = [0 for i in range(m-1,n,m)]
	print sum(c)

Submission status: Runtime Error

Solution code:
while 1:
	n,m=map(int, raw_input().split())
	if n==0:break
	c=sorted(map(int,raw_input().split()))[::-1]
	if m > n:
		print sum(c)
	else:
		c[m-1::m] = [0 for i in range(m-1,n,m)]
		print sum(c)

Submission status: Runtime Error

Solution code:
while 1:
	n,m=map(int, raw_input().split())
	if n==0:break
#	c=sorted(map(int,raw_input().split()))[::-1]
#	if m > n:
#		print sum(c)
#	else:
#		c[m-1::m] = [0 for i in range(m-1,n,m)]
#		print sum(c)

Submission status: Runtime Error

Solution code:
while True:
	n,m=map(int, raw_input().split())
	if n==0:break
#	c=sorted(map(int,raw_input().split()))[::-1]
#	if m > n:
#		print sum(c)
#	else:
#		c[m-1::m] = [0 for i in range(m-1,n,m)]
#		print sum(c)

Submission status: Runtime Error

Solution code:
while True:
	n,m=map(int, raw_input().split())
	if n==0:break
	c=sorted(map(int,raw_input().split()))[::-1]
#	if m > n:
#		print sum(c)
#	else:
#		c[m-1::m] = [0 for i in range(m-1,n,m)]
#		print sum(c)

Submission status: Runtime Error

Solution code:
while 1:
    n=map(int, raw_input().split())
    if n[0]==0:break
#   c=sorted(map(int,raw_input().split()))[::-1]
#   if m > n:
#       print sum(c)
#   else:
#       c[m-1::m] = [0 for i in range(m-1,n,m)]
#       print sum(c)

Submission status: Runtime Error

Solution code:
while 1:
	n,m=map(int,raw_input().split())
	if n==0:break
	v=sorted(map(int,raw_input().split()))[::-1]
	for i in range(m-1,n,m):
		v[i]=0
	print sum(v)

Submission status: Runtime Error

Solution code:
while True:
	n, m = (int(x) for x in raw_input().split(" "))
	if n == 0 and m == 0: break
	p = [int(x) for x in raw_input().split(" ")]
	s = sum(p)
	p.sort(reverse=True)
	for x in p[m - 1::m]:
		s -= x
	print s

Submission status: Runtime Error

Solution code:
while True:
	n, m = (int(x) for x in raw_input().split())
	if n == 0 and m == 0: break
	p = [int(x) for x in raw_input().split()]
	s = sum(p)
	p.sort(reverse=True)
	for x in p[m - 1::m]:
		s -= x
	print s

Submission status: Runtime Error

Solution code:
while True:
	n, m = (int(x.strip()) for x in raw_input().split())
	if n == 0 and m == 0: break
	p = [int(x.strip()) for x in raw_input().split()]
	s = sum(p)
	p.sort(reverse=True)
	for x in p[m - 1::m]:
		s -= x
	print s

Submission status: Runtime Error

Solution code:
while 1:
    nm = map(int, raw_input().split())
    if nm == [0, 0]:
	break
    n = nm[0]
    m = nm[1]
    p = map(int, raw_input().split())
    p_sorted = sorted(p)
    sum = 0
    for i in range(n):
        if (i+1) % m != 0:
	    sum += p_sorted[-1-i]
    print sum

Submission status: Runtime Error

Solution code:
while 1:
    nm = map(int, raw_input().split())
    if nm == [0, 0]:
        break
    n = nm[0]
    m = nm[1]
    p = map(int, raw_input().split())
    p_sorted = sorted(p)
    sum = 0
    for i in range(n):
        if (i+1) % m != 0:
            sum += p_sorted[-1-i]
    print sum