Fix the triangles array to exclude the excess rows assigned when the array is preallocated.