You are given the number of card types N, 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.
- One card of every type. It uses no joker.
- 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 N 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.