Sum over All Subarrays
Add up the sums of every contiguous subarray and print the grand total.
Input: the first line has N; the second line has N integers.
Output: the total of all subarray sums.
Constraints:
- 1 ≤ N ≤ 105
- −104 ≤ ai ≤ 104
Sample Tests
Input 1
3 1 2 3
Output 1
20
Input 2
2 -1 5
Output 2
8
Discussion (opens after you solve — no spoilers before)
No comments yet.