Question description
[Split apples]
Two people, A and B, divide the apples into two piles. A hopes to divide the apples equally according to his calculation rules. His calculation rules are based on binary addition and do not calculate carry 12+5=9 (1100 + 0101 = 9). B's calculation rule is decimal addition, including normal carry. B hopes to get the most apple weight while satisfying A.
Input the number of apples and the weight of each apple, and output the total weight of apples obtained by B when A is satisfied.
If A's requirements cannot be met, -1 is output.
data range
1 <= total number of apples <= 20000
1 <= weight of each apple <= 10000
Enter description:
The first line of input is the number of apples: 3
The second input line is the weight of each apple: 3 5 6
Output description:
The first line of output is the total weight of apples obtained by B: 11
enter
3
356
output
11
Example 2 The input and output examples are for debugging only. The background judgment data generally does not contain examples.
enter
8
7258 6579 2602 6716 3050 3564 5396 1773
output
35165
Below are detailed comments and explanations of the given code:
n = int