You can make a prefix sum of the array *A* and also store the sum of the series

S = a_{1} + 2 \times a_{2} + … + n \times a_{n}

If we take the first term of each term of the sum, it can be written as

*n \times a*_{1} (a_{1} + a_{2} + . . .+ a_{n}) - a_{1} (a_{2} + 2 \times a_{3} + … + (n - 1) \times a_{n})

Its first term can be calculated in O(1) using prefix sum and the second term can be calculated by subtracting sum of all the elements from S. So now S becomes

S = a_{2} + 2 \times a_{3} + … + (n - 1) \times a_{n}

Now we calculate second term of each term of the sum which is

*n \times a*_{2} (a_{2} + a_{3} + . . .+ a_{n}) - a_{2} (a_{3} + 2 \times a_{4} + … + (n - 2) \times a_{n})

which again can be calculated in O(1) using prefix sum for the first term and subtracting that sum from S. This should be done for every element in the sum. So the entire solution becomes O(n).

If you still have a doubt feel free to ask. Hope this helps.