answer
as 0.arr
using index i
.arr[i]
:
odd_left = (i / 2) + 1
odd_right = ((n - i - 1) / 2) + 1
even_left = (i + 1) / 2
even_right = (n - i) / 2
arr[i]
in odd-length subarrays as odd_left * odd_right + even_left * even_right
.arr[i]
and add it to answer
.answer
after the loop.