Buggy python submission (verdict: Runtime Error):
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0 
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse() 
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    j = 0
    while M > 0:
        if M >= L[N-j-1][1]:
            S = S - L[N-j-1][0]*L[N-j-1][1]
            M = M - L[N-j-1][1]
            j = j + 1
        else:
            S = S - L[N-j-1][0]*M
            M = M - L[N-j-1][1]
    print(S)




Fixed submission:
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse()
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    for j in range(0,N):
        t = N-j-1
        if M >= L[t][1]:
            S = S - L[t][0]*L[t][1]
            M = M - L[t][1]
        elif 0 < M:
            S = S - L[t][0]*M
            M = M - L[t][1]
    print(S)

Buggy python submission (verdict: Runtime Error):
#Princess's Marriage
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2019&lang=jp
#席の位置：右中央


#Nは区間の個数
#Mは予算
#Dは区間の距離
#Pはその間を１単位距離移動したときに襲われる回数の期待値

#お姫様が予算Mを持っていて，刺客に襲われる回数の期待値が最小になるように護衛を雇ったときの，目的地までに刺客に襲われる回数の期待値

while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0 #Sが襲われる回数の期待値
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse() #ソートするとき具合がわるいので[P,D]の順に入れ替え
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    j = 0
    while M > 0:
        if M >= L[N-j-1][1]:
            S = S - L[N-j-1][0]*L[N-j-1][1]
            M = M - L[N-j-1][1]
            j = j + 1
        else:
            S = S - L[N-j-1][0]*M
            M = M - L[N-j-1][1]
    print(S)



Fixed submission:
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse()
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    for j in range(0,N):
        t = N-j-1
        if M >= L[t][1]:
            S = S - L[t][0]*L[t][1]
            M = M - L[t][1]
        elif 0 < M:
            S = S - L[t][0]*M
            M = M - L[t][1]
    print(S)

Buggy python submission (verdict: Time Limit Exceeded):
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    D = 0 #目的地までの総距離
    L = []
    for i in range(N):
        d,p = map(int,input().strip().split(" "))
        for j in range(d):
            L.append(p)
        D = D + d
    L.sort()
    S = 0 #Sが襲われる回数の期待値
    for k in range(D-M):
        S = S + L[k]
    print(S)


Fixed submission:
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse()
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    for j in range(0,N):
        t = N-j-1
        if M >= L[t][1]:
            S = S - L[t][0]*L[t][1]
            M = M - L[t][1]
        elif 0 < M:
            S = S - L[t][0]*M
            M = M - L[t][1]
    print(S)

Buggy python submission (verdict: Time Limit Exceeded):
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    D = 0 #目的地までの総距離
    L = []
    for i in range(N):
        d,p = map(int,input().strip().split(" "))
        for j in range(d):
            L.append(p)
    L.sort()
    S = 0 #Sが襲われる回数の期待値
    for k in range(len(L)-M):
        S = S + L[k]
    print(S)


Fixed submission:
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse()
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    for j in range(0,N):
        t = N-j-1
        if M >= L[t][1]:
            S = S - L[t][0]*L[t][1]
            M = M - L[t][1]
        elif 0 < M:
            S = S - L[t][0]*M
            M = M - L[t][1]
    print(S)

Buggy python submission (verdict: Time Limit Exceeded):
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    D = 0 #目的地までの総距離
    L = []
    for i in range(N):
        d,p = map(int,input().strip().split(" "))
        for j in range(d):
            L.append(p)
        D = D + d
    L.sort()
    S = 0 #Sが襲われる回数の期待値
    for k in range(D-M):
        S = S + L[k]
    print(S)


Fixed submission:
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse()
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    for j in range(0,N):
        t = N-j-1
        if M >= L[t][1]:
            S = S - L[t][0]*L[t][1]
            M = M - L[t][1]
        elif 0 < M:
            S = S - L[t][0]*M
            M = M - L[t][1]
    print(S)

Buggy python submission (verdict: Runtime Error):
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0 #Sが襲われる回数の期待値
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse() #ソートするとき具合がわるいので[P,D]の順に入れ替え
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    j = 0
    while M > 0:
        if M >= L[N-j-1][1]:
            S = S - L[N-j-1][0]*L[N-j-1][1]
            M = M - L[N-j-1][1]
            j = j + 1
        else:
            S = S - L[N-j-1][0]*M
            M = M - L[N-j-1][1]
    print(S)


Fixed submission:
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse()
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    for j in range(0,N):
        t = N-j-1
        if M >= L[t][1]:
            S = S - L[t][0]*L[t][1]
            M = M - L[t][1]
        elif 0 < M:
            S = S - L[t][0]*M
            M = M - L[t][1]
    print(S)

Buggy python submission (verdict: Runtime Error):
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0 #Sが襲われる回数の期待値
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse() #ソートするとき具合がわるいので[P,D]の順に入れ替え
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    j = N
    while M > 0:
        if M >= L[j-1][1]:
            S = S - L[j][0]*L[j][1]
            M = M - L[j][1]
            j = j - 1
        else:
            S = S - L[j][0]*M
            M = M - L[j][1]
    print(S)


Fixed submission:
while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse()
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    for j in range(0,N):
        t = N-j-1
        if M >= L[t][1]:
            S = S - L[t][0]*L[t][1]
            M = M - L[t][1]
        elif 0 < M:
            S = S - L[t][0]*M
            M = M - L[t][1]
    print(S)