Matrix Multiplication and Total Expenditure Calculation