compute square and average