#K49817. Cumulative Sum
Cumulative Sum
Cumulative Sum
Given an array of integers, compute the cumulative sum of the elements. For each index \(i\), the output is the sum of all elements from the beginning up to index \(i\). Formally, the cumulative sum is defined as \(s_i = \sum_{j=1}^{i} a_j\). If the input array is empty, the output should also be empty.
Examples:
- Input: [1, 2, 3, 4] → Output: [1, 3, 6, 10]
- Input: [0, 1, 0, 1] → Output: [0, 1, 1, 2]
inputFormat
The first line contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers. If \(n = 0\), there will be no second line.
outputFormat
Output a single line containing the cumulative sums of the array elements, separated by spaces. If the array is empty, output nothing.
## sample4
1 2 3 4
1 3 6 10