Calculation of total costs