have a look here for some more trainings
with the reuse of the calculated sums the dictionary approach from @Yoichi is a recommendable approach for this case