#C13603. Sum Except Self

    ID: 43160 Type: Default 1000ms 256MiB

Sum Except Self

Sum Except Self

Given an array of integers, compute a new array such that the i-th element is the sum of all the numbers from the original array except the element at index i. More formally, if the array is \(a = [a_1,a_2,\dots,a_n]\), you need to output an array \(b\) where:

[ b_i = \sum_{j=1}^{n} a_j - a_i, \quad \text{for } i=1,2,\dots,n. ]

Example:

Input:  4
        1 2 3 4
Output: 9 8 7 6

Please note that the input is provided via standard input and the output should be printed to standard output.

inputFormat

The input consists of two lines. The first line contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers.

For example:

4
1 2 3 4

outputFormat

Output a single line containing \(n\) space-separated integers, where the \(i\)-th integer is the sum of all the numbers in the array except the \(i\)-th element.

For the above example, the output would be:

9 8 7 6
## sample
4
1 2 3 4
9 8 7 6