updated version
using reduction to calculate partial sums
added reduction to calculate the sum of U and V