def decode(line, dic):
    name, length, prod = line.strip().split(';')
    length = float(length)
    typ = dic[prod]
    return name, length, typ

def stands(fstands, ffood, fcraft, dic, lfood, lcraft):
    with open(fstands, 'r') as f1, open(ffood, 'w') as f2, open(fcraft, 'w') as f3:
        sfood = 0
        scraft = 0
        for line in f1:
            name, length, typ = decode(line, dic)
            if typ == 'food':
                if sfood+length <= lfood:
                    f2.write(name + '\n')
                    sfood = sfood + length
            else:
                if scraft+length <= lcraft:
                    f3.write(name + '\n')
                    scraft = scraft + length
            if sfood==lfood and scraft==lcraft:
                return

