#C9493. Maximizing Gold Coin Collection Days

    ID: 53592 Type: Default 1000ms 256MiB

Maximizing Gold Coin Collection Days

Maximizing Gold Coin Collection Days

You are given a collection of treasure chests, where each chest contains a certain number of gold coins. In one day, you can choose any two different chests and remove one coin from each. Your task is to determine the maximum number of days you can continue this activity without running out of coins in any two chosen chests.

Note: On any day, you must remove one coin from two distinct chests. If one chest does not have any coins, you cannot select it even if another chest has coins remaining.

Mathematically, if the total number of coins is \(T\) and the maximum coins in any single chest is \(M\), then the maximum number of days is given by \(\min\left(\lfloor\frac{T}{2}\rfloor, T - M\right)\).

inputFormat

The first line of input contains a single integer \(n\) representing the number of treasure chests.

The second line contains \(n\) space-separated integers, where each integer represents the number of gold coins in a chest.

If \(n = 0\), then there are no chests.

outputFormat

Output a single integer which is the maximum number of days you can remove one coin from any two chests.

## sample
3
3 3 3
4