#P2415. Sum of All Subset Elements
Sum of All Subset Elements
Sum of All Subset Elements
Given a set \( s \) of at most 30 elements, compute the sum of the elements for every possible subset of \( s \). In other words, for each subset \( T \subseteq s \), calculate \( \text{sum}(T) \), and then output the total sum over all subsets.
Note: The empty subset is considered, and its sum is \(0\). It can be shown that if \( s = \{a_1, a_2, \dots, a_n\} \), the answer is \( (a_1+a_2+\dots+a_n) \times 2^{n-1} \) when \( n > 0 \), and \(0\) when \( n = 0 \).
inputFormat
The input consists of two lines:
- The first line contains a single integer \( n \) (\(0 \le n \le 30\)) representing the number of elements in the set.
- The second line contains \( n \) space-separated integers, which are the elements of the set \( s \).
outputFormat
Output a single integer, the sum of elements for all subsets of the given set.
sample
3
1 2 3
24