Mr. Willy Wonka, the eccentric owner of the world's greatest chocolate factory, has decided to open the doors of his factory to five lucky children and their parents. In order to choose who will enter the factory, Mr. Wonka hides five golden tickets in the wrappers of his chocolate bars. As a bonus, the five winners can for the rest of their lives return three wrappers of Wonka-chocolate to get one chocolate for free. The search for the five golden tickets is fast and furious. Four kids have already found the golden tickets — Augustus Gloop, Veruca Salt, Violet Beauregarde and Mike Teavee.
A poor boy Charlie Stevens lives in a tiny house with his parents and four of his grandparents. His grandparents share the only bed in the house, located in the only bedroom. Charlie and his parents sleep on mattresses on the floor. Charlie desperately wants to win the fifth golden ticket, but a bar of Wonka-chocolate costs 3 euro and his parents are simply too poor to spend their money on chocolate. One day, Charlie finds a purse containing 45 euro that was buried in the snow. Instead of turning the money to his parents, he decides to spend all of it to buy Wonka-chocolates. After unwrapping the last bar, Charlie finds the fifth golden ticket that he can use to start exchanging wrappers for new chocolates. The next day is the date that Mr. Wonka has set for his guests to enter the factory. How many chocolates can Charlie buy in total with his initial budget of 45 euro?
A bar of Wonka-chocolate costs 3 euro and Charlie has 45 euro to spend, which initially gives him 15 bars of chocolate. But because he has the golden ticket, he can return the wrappers of the 15 chocolates to get another 5 bars of Wonka-chocolate for free. These 5 bars again give him 5 wrapper, from which he can return 3 to get one free chocolate bar. Finally he can use the wrapper of that one chocolate bar with the two remaining wrappers to get one more chocolate bar. In total, Charlie can buy $$15 + 5 + 1 + 1 = 22$$ bars of Wonka-chocolate.
In a generalized version of the above problem, Charlie has an initial budget of $$b$$ euro and a bar of Wonka-chocolate costs $$p$$ euro. Using the golden ticket, Charlie has the eternal right to return $$w$$ wrappers of Wonka-chocolate to get $$n$$ new bars of Wonka-chocolate for free (with $$n < w$$). The integers numbers $$b$$, $$p$$, $$w$$ and $$n$$ are given as the input of this assignment, each on a separate line.
The total number of chocolate bars that Charlie can buy, given the data from the input.
Input:
45
3
3
1
Output:
22
In Willy Wonka & the Chocolate Factory (1971), just after Charlie buys a chocolate bar, he discovers a commotion at a newsstand: the finder of the fifth ticket — a “gambler from Paraguay” — has been declared a fraud.
“Can you imagine the nerve of that guy, trying to fool the whole world?” says one man.
“Boy, he really was a crook,” says another.
The man pictured in the newspaper is Martin Bormann1, Adolf Hitler's private secretary.