Exact cost estimation

Validated by codeJudge on 10000 random inserts