All problems

Problem 24

Running Sum

Easy · 10 pts · Array, Prefix Sum

Problem

You are given an array A of N integers. Print its running sum (also called the prefix sum): a new array where the i-th value is the total of all elements from the start up to and including position i, that is A[0] + A[1] + ... + A[i]. Each running sum is the previous running sum plus the current element, so the whole array can be computed in a single pass.

Input

First line: integer N. Second line: N space-separated integers.

Output

Print N space-separated running sums.

Constraints

1 <= N <= 100000; -1000000 <= A[i] <= 1000000

Example input

4
1 2 3 4

Example output

1 3 6 10

Explanation

For 1 2 3 4, the running sums are 1, 1 + 2 = 3, 3 + 3 = 6 and 6 + 4 = 10, so the output is 1 3 6 10.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Rotate Array Right Next: Missing Number