#B3833. Minimizing the Sum with Halving and Doubling Operations

    ID: 11490 Type: Default 1000ms 256MiB

Minimizing the Sum with Halving and Doubling Operations

Minimizing the Sum with Halving and Doubling Operations

Alice has a sequence of n positive integers \(a_1, a_2, \dots, a_n\). She is allowed to perform the following operation any number of times (possibly zero):

  • Choose two different indices \(i, j\) (\(1 \le i,j \le n,\ i \neq j\)). Then update \[ a_i \leftarrow \lfloor a_i/2 \rfloor \quad \text{and} \quad a_j \leftarrow 2\,a_j, \] with the condition that after the operation \(a_i\) must remain a positive integer.

The goal is to minimize the total sum of the sequence after performing some sequence of operations. Output the minimum possible sum.

Note: In the formula above, \(\lfloor x\rfloor\) denotes the floor function (i.e. the greatest integer less than or equal to \(x\)).

inputFormat

The first line contains a single integer \(n\) (the number of elements in the sequence).
The second line contains \(n\) space-separated positive integers \(a_1, a_2, \dots, a_n\).

outputFormat

Output a single integer: the minimum possible sum of the sequence after performing the allowed operations.

sample

2
4 1
4