Card Sets

Given counts of N card types and a pile of jokers, find the maximum number of decks, where each deck is either one card of every type or one card of every type but one plus a joker.

Medium7Binary searchGreedyMathImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given the number of card types NN, how many cards each type has, and how many joker cards there are. You want to build decks out of these cards. A deck is one of the following two types.

  1. One card of every type. It uses no joker.
  2. One card of every type except one, plus one joker card.

For example, with 3 card types and one joker, all of {card 1, card 2, card 3}, {joker, card 2, card 3}, {card 1, joker, card 3} and {card 1, card 2, joker} are decks. Each card belongs to at most one deck. When NN is 1, a deck of the second type consists of a single joker card.

Find the maximum number of decks you can build from the given cards.

Input

The first line contains the number of card types NN, a natural number at most 50.

The second line contains NN integers. The kk-th of them is how many cards type kk has. Each value is between 0 and 500000000.

The third line contains how many joker cards there are, between 0 and 500000000.

Output

Print one integer, the maximum number of decks you can build.