sum of array elements in different ways