computing cost for one variable