Asymptotically analyze the running time of the following algorithm.
Algorithm Intervals(A, n):
Input: array A of n positive integers, indexed from 1, and its size n.
Y = 0
for i from 1 to n
for j from i to n
X = 0
for k from 1 to j
X = X + A[k]
for h from k to i
X = X + A[h]
Y = Y + X
return Y