Have you ever felt you've been cheated with a "buy 3 get 1 for free" action? It's quite all right if shops advertise such an action and interpret it in such a way that if you purchase four items, you get the cheapest one for free. What bothers most customers is that some shops turn this into their advantage as soon as you buy more than four products. Cash registers might be programmed to interpret a "buy 3 get 1 for free" action such that for each $$n$$ items purchased, you get the $$\lfloor\frac{n}{4}\rfloor$$ cheaptest items for free. Here, $$\lfloor x\rfloor$$ is the largest integer not greater than $$x \in \mathbb{R}$$.

buy 3 get 1 for free
This action means that for each $$n$$ items purchased, you get the $$\lfloor\frac{n}{4}\rfloor$$ cheaptest items for free.

Only after customers have paid all their items at once, they realize that they would have made profit if they had passed the cash register several times. They could have arranged the purchased items from the most expensive one to the cheapest one, and could have passed the cash register with groups of at most four items. The first time with the four most expensive items (for which they get the cheapest for free), a second time with the next four most expensive items, and so on. If the total number of items purchased is not a multiple of four, they would have to pass the cash register one last time with less than four items, and not get an item for free this time.

Assignment

Say you have purchased a number of items in a shop that runs a "buy 3 get 1 for free" action, and whose cash register has been programmed in favor of the shop as described in the introduction of this assignment. Your task is to determine your own profit in case you would not purchase all products at once, but pass the cash register multiple times, each time getting the cheapest item for free from the group of the next four most expensive items. In order to do so, you have to write four functions that each take a sequence (list or tuple) of $$n \in \mathbb{N}_0$$ real-valued numbers (float). These numbers represent the prices of the items purchased.

Example

>>> prices = [3.23, 5.32, 8.23, 2.23, 9.98, 7.43, 6.43, 8.23, 4.23]
>>> together(prices)
49.85
>>> group(prices)
[(9.98, 8.23, 8.23, 7.43), (6.43, 5.32, 4.23, 3.23), (2.23,)]
>>> grouped(prices)
44.65
>>> profit(prices)
5.2