#P1456. Aggressive Monkeys Duel

    ID: 14742 Type: Default 1000ms 256MiB

Aggressive Monkeys Duel

Aggressive Monkeys Duel

In a mysterious forest, there are N aggressive monkeys. Initially, each monkey is isolated and only knows itself. However, quarrels break out between any two monkeys (or groups of monkeys) that do not know each other. When a quarrel occurs between two monkeys (or groups), both sides call upon the strongest monkey in their respective groups to duel. (Note that every monkey knows himself.) After the duel, the two duelists have their strongness value reduced to only half of their current value (in \(\LaTeX\), this operation is written as \(\lfloor v/2 \rfloor\); for instance, 10 becomes 5 and 5 becomes 2). In addition, all monkeys involved in the duel (i.e. in the two groups) then know each other, and no future quarrel will occur among monkeys that already know each other.

The duels continue until all monkeys have become friends, that is, until there is exactly one group. Because a quarrel always forces a duel between the strongest monkeys of two different groups, the order in which duels are arranged influences the final outcome. Your task is to determine, if the duel order is chosen optimally to maximize the final maximum strongness value among all monkeys, what will that value be.

Observation: There will be exactly \(N-1\) duels if \(N \ge 2\). If \(N = 1\), no duel will occur and the final strongness will be the initial value of the single monkey.

inputFormat

The input consists of two lines:

  • The first line contains a single integer \(N\) (\(1 \le N \le 10^5\)), representing the number of monkeys.
  • The second line contains \(N\) space-separated positive integers, each representing the initial strongness value of a monkey.

outputFormat

Output a single integer representing the final maximum strongness value among all monkeys after all duels have been conducted in an order that maximizes this value.

sample

1
5
5