hmm cost calculation