Fixed to calculate S[i][j] ^ 2