Buggy python submission (verdict: Time Limit Exceeded):
class charge:
    def __init__(self,x,y,z,v):
        self.coins = {10:x,50:y,100:z,500:v}
    def get_sum(self):
        return self.coins[10]*10 + self.coins[50]*50+self.coins[100]*100 + self.coins[500]*500
    def how_sheet(self):
        return self.coins[10] + self.coins[50] +self.coins[100] + self.coins[500]


def cal_charge(price,payment):
    a =[0,0,0,0]
    temp = payment - price
    if temp //500 !=0:
        a[3] = temp // 500
        temp = temp % 500
    if temp //100 !=0:
        a[2] = temp // 100
        temp = temp % 100
    if price //50 !=0:
        a[1] = temp // 50
        temp = temp % 50
    a[0] = temp //10
    return charge(*a)

if __name__ == "__main__":
    c =0
    while 1:
        price = int(input())
        if price ==0:break
        if c !=0:print("")
        max10,max50,max100,max500 = list(map(int,input().split(" ")))
        ans  = charge(max10,max50,max100,max500)
        minsh =  max10+max50+max100+max500
        i =0
        while i <= max500:
            j =0
            while  j <= max100:
                k =0
                while k <= max50:
                    l =0
                    while l <= max10:
                        payment = 500*i + 100*j +50*k + 10*l
                        if payment >= price:
                            temp = cal_charge(price,payment)
                            if minsh > temp.how_sheet():
                                minsh = temp.how_sheet()
                                ans = charge(l,k,j,i)
                        l +=1
                    k +=1
                j +=1
            i +=1
        for i in [10,50,100,500]:
            if ans.coins[i] !=0 :print("{} {}".format(i,ans.coins[i]))
        c +=1
    



Fixed submission:
count = 0
coins =[10,50,100,500]
while 1:
    price = int(input())
    if price ==0:break
    if count !=0:print('')
    wallet= list(map(int,input().split(' ')))
    cash = wallet[0]* 10 + wallet[1] * 50 + wallet[2] * 100 + wallet[3] * 500
    charge = cash - price
    chargecoins = ((charge % 50) // 10,(charge % 100)//50,(charge % 500)//100,charge // 500)
    for  i in range(4):
        if wallet[i] > chargecoins[i]:print('{} {}'.format(coins[i],wallet[i]-chargecoins[i]))
    count +=1

Buggy python submission (verdict: Time Limit Exceeded):
import itertools as it
def charge(price,payment):
    val =[0,0,0,0]
    coins = [500,100,50,10]
    rem = payment - price
    for i in range(4):
        val[i] =rem //coins[i]
        rem = rem%coins[i]
    return sum(val)
count =0
while 1:
    price = int(input())
    if price ==0:break
    if count !=0:print(' ')
    max10,max50,max100,max500 = list(map(int,input().split(' ')))
    ans = (max10,max50,max100,max500)
    mincharge = max10+max50+max100+max500
    temp10 = [i for i in range(max10+1)]
    temp50 = [i for i in range(max50+1)]
    temp100 = [i for i in range(max100+1)]
    temp500 = [i for i in range(max500+1)]
    combinations = list(it.product(temp10,temp50,temp100,temp500))
    for com in combinations:
        pay= com[0]*10+com[1]*50+com[2]*100+com[3]*500
        if price> pay:continue
        temp = charge(price,pay)
        if mincharge > temp:
            mincharge = temp
            ans = com
    p = [10,50,100,500]
    for i in range(4):
        if ans[i] !=0:print("{} {}".format(p[i],ans[i]))
    count+=1


Fixed submission:
count = 0
coins =[10,50,100,500]
while 1:
    price = int(input())
    if price ==0:break
    if count !=0:print('')
    wallet= list(map(int,input().split(' ')))
    cash = wallet[0]* 10 + wallet[1] * 50 + wallet[2] * 100 + wallet[3] * 500
    charge = cash - price
    chargecoins = ((charge % 50) // 10,(charge % 100)//50,(charge % 500)//100,charge // 500)
    for  i in range(4):
        if wallet[i] > chargecoins[i]:print('{} {}'.format(coins[i],wallet[i]-chargecoins[i]))
    count +=1