Company: Myntra_7may
Difficulty: medium
Sum of Magical Numbers Problem Description You are given an array of size N. A magical number 'M' is computed on a subarray [L, R] using a special formula. The magical number for a subarray is calculated as the difference between the sum of its prefix sums and the sum of its suffix sums. Mathematically, for a subarray arr[L...R] : M = (Σ i=L R Σ j=i R arr[j]) - (Σ i=L R Σ j=L i arr[j]) Basically, the magical number for some subarray [a,b,c] would be ((a) + (a+b) + (a+b+c)) - ((a+b+c) + (b+c) + c) . You need to find the sum of magical numbers of the following subarrays: [i, N-1] for i ∈ {0, 1, 2, 3, ..., N-1} Input Format Input: The first line of input takes N. The second line takes input of N integer values of array. Output Format Output: Print the sum of all magical numbers. Constraints 1 1 Examples Example 1: Input: 5 4 8 2 3 12 Output: -64 Explanation: For subarray [0,4] -> M = ((4) + (4+8) + (4+8+2) + (4+8+2+3) + (4+8+2+3+12)) - ((4+8+2+3+12) + (8+2+3+12) + (2+3+12) + (3+12) + (12)