getcost_sum3 runs in O(WT) time!