よく見ると、最初の部分にあたる計算は実は毎回重複しており、すでに計算済みの合計を再利用すれば、無駄を削減できるのがわかります。そこで、プレフィックスサム(prefix sum)を格納する配列 p を用意し、次のように計算します。p[i] には、元の配列 a の要素を先頭から i 番目まで足し合わせた値を保存しておきます。すると、任意のクエリ の答えは p[] を参照するだけで瞬時に求まります。
This can be calculated with a single for loop in linear time instead of having multiple loops that do the same computation over and over. After computing the prefix sum array p, we will be able to answer all the queries instantly - as p[i] holds the information about the sum a[0] + a[1] + a[2] + ... + a[i]. So, for each query , the response will just be p[].
Can you calculate the prefix sum array now?
Input
The first line of the input contains a single integer n (1 ≤ n ≤ ). The second line of the input contains n space-separated integers representing the array a.
Output
The program should output the prefix sum array of a.