how to calculate sum of 2d array