get total cost function