Mosquito Multiplication#4157

Mosquito Multiplication

1 second
64 megabytes
Easy

Have you ever wondered why there are so many mosquitos in wet environments? One of the reasons is that adult female mosquitos can lay as many as hundreds of eggs. Even if most of them do not (fortunately!) survive, it is said that a single pair of mosquitos can generate a population of thousands in just a couple of weeks. Let us have a closer look at these numbers.

The mosquito life cycle includes four stages: egg, larva, pupa, and adult. For simplicity, we will make several assumptions that are not quite true in the nature: The egg stage lasts less than one day, and all the other stages are one week long. Each mosquito lives as a larva for the first week, the second week "hibernates" in the form of a pupa, and finally, the third week lives as an adult mosquito. At the end of its three-week life, each mosquito lays eggs and dies.

To simplify things even further, we will assume that the transformation from one life stage into another always happens on Sunday. Each Sunday, the following things happen:

For example, if there are pupae and every -rd of them survives, there will be mosquito left. Out of pupae, two adult mosquitos emerge.

In the first week, there are mosquitos, pupae and larvae. Calculate how many mosquitos will there be after Sunday transformations. Of course, we are counting only living adult mosquitos, not the dry dead bodies.

Input

The input consists of several instances, each instance per one line. Each line contains seven integers , , , , , , separated by space. , and are the numbers of mosquitos, pupae, and larvae, respectively, in the first week. You may assume that 0 \le M, P, L \le 100000, 0 \le E \le 100, 1 \le R, S \le 10, and 1 \le N \le 1000. is the number of eggs laid by one mosquito, and specify the survival rates of larvae and pupae, and is the number of weeks.

Output

For each input instance, output a single line containing an integer number , giving the count of mosquitos after the -th Sunday. You may assume that the number of mosquitos during each of the first weeks will not exceed .

Examples

Example 1

Loading
Loading