Accumulate function to combine sum and product