Chain
You have N
chain pieces, where each piece i
consists of L[i]
links. You can unbend and then rebend links to connect separate pieces into a single chain.
Your task is to write a program that, given the number of chain pieces N
and the number of links in each piece L[i]
, calculates the minimum number of links that need to be unbent and rebent to connect all the pieces into one continuous chain. The chain must not have any branches, meaning each link should connect to exactly two other links, except for the two links at the ends of the chain, which should connect to only one other link.
Input
The first line of input contains an integer N
(2 ≤ N ≤ 10000
). The second line contains N
integers L[i]
(1 ≤ L[i] ≤ 1000000000
), representing the number of links in each chain piece.
Output
Output a single integer — the minimum number of links that need to be unbent and rebent to form a single chain from all the pieces.