Buggy python submission (verdict: Runtime Error):
while 1:
    n,m= list(map(int,input().split(' ')))
    if n ==m ==0:break
    D =[]
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    sorted(D,key = lambda x:x[0])
    while m > 0:
        temp = D.pop(0)
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
        else: 
            m -= temp[0]
            temp = (0,temp[1])
        D.append(temp)
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)


Fixed submission:
while 1:
    n,m= list(map(int,input().split(' ')))
    if n == m ==0:break
    D = []
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    D = sorted(D,key = lambda x:x[1],reverse = True)
    while m > 0:
        if len(D) ==0:break
        temp = D.pop(0)
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
            D.append(temp)
        else: 
            m -= temp[0]      
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)

Buggy python submission (verdict: Runtime Error):
while 1:
    n,m= list(map(int,input().split(' ')))
    if n ==m ==0:break
    D =[]
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    sorted(D,key = lambda x:x[0])
    while m > 0:
        temp = D.pop(0)
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
        else: 
            m -= temp[0]
            temp = (0,temp[1])
        D = D + [temp]
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)


Fixed submission:
while 1:
    n,m= list(map(int,input().split(' ')))
    if n == m ==0:break
    D = []
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    D = sorted(D,key = lambda x:x[1],reverse = True)
    while m > 0:
        if len(D) ==0:break
        temp = D.pop(0)
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
            D.append(temp)
        else: 
            m -= temp[0]      
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)

Buggy python submission (verdict: Runtime Error):
import collections 
while 1:
    n,m= list(map(int,input().split(' ')))
    if n ==m ==0:break
    D = collections.deque()
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    sorted(D,key = lambda x:x[0])
    while m > 0:
        temp = D.popleft()
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
        else: 
            m -= temp[0]
            temp = (0,temp[1])
        D.append(temp)
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)


Fixed submission:
while 1:
    n,m= list(map(int,input().split(' ')))
    if n == m ==0:break
    D = []
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    D = sorted(D,key = lambda x:x[1],reverse = True)
    while m > 0:
        if len(D) ==0:break
        temp = D.pop(0)
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
            D.append(temp)
        else: 
            m -= temp[0]      
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)

Buggy python submission (verdict: Runtime Error):
import collections 
import time 
while 1:
    n,m= list(map(int,input().split(' ')))
    if n ==m ==0:break
    D = collections.deque()
    time.sleep(20)
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    sorted(D,key = lambda x:x[0])
    while m > 0:
        temp = D.popleft()
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
        else: 
            m -= temp[0]
            temp = (0,temp[1])
        D.append(temp)
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)


Fixed submission:
while 1:
    n,m= list(map(int,input().split(' ')))
    if n == m ==0:break
    D = []
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    D = sorted(D,key = lambda x:x[1],reverse = True)
    while m > 0:
        if len(D) ==0:break
        temp = D.pop(0)
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
            D.append(temp)
        else: 
            m -= temp[0]      
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)

Buggy python submission (verdict: Runtime Error):
import collections 
while 1:
    n,m= list(map(int,input().split(' ')))
    if n == m ==0:break
    D = collections.deque()
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        if p_i !=0: 
            D.append((d_i,p_i))
    sorted(D,key = lambda x:x[0])
    while m > 0:
        temp = D.popleft()
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
            D.append(temp)
        else: 
            m -= temp[0]
            temp = (0,temp[1])
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)


Fixed submission:
while 1:
    n,m= list(map(int,input().split(' ')))
    if n == m ==0:break
    D = []
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    D = sorted(D,key = lambda x:x[1],reverse = True)
    while m > 0:
        if len(D) ==0:break
        temp = D.pop(0)
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
            D.append(temp)
        else: 
            m -= temp[0]      
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)