Calculate cost