#P11323. Minimize Moves in Card Game

    ID: 13400 Type: Default 1000ms 256MiB

Minimize Moves in Card Game

Minimize Moves in Card Game

LLL designed an interesting card game using n types of cards. The types are numbered from 1 to n, and there are vi cards of type i.

There are four ways to play a move:

  • Single: Play one card.
  • Pair: Play two cards of the same type.
  • Bomb: Play four cards of the same type.
  • Three-with-one: Play three cards of the same type together with one card of a different type.

You win the game when all cards have been played. Compute the minimum number of moves needed to win.

Note: If a formula is needed, use LaTeX notation. For example, the moves that remove 4 cards can be considered as removing $4$ cards in one move.

inputFormat

The first line of input contains a single integer n ($1 \leq n \leq 10^5$) which is the number of different card types.
The second line contains n integers v1, v2, ..., vn ($1 \leq v_i \leq 10^9$), where vi denotes the number of cards of type i.

outputFormat

Output a single integer, representing the minimum number of moves required to play all the cards.

sample

2
3 1
1