Problem B
Mosquito Multiplication
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 threeweek 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:

An adult mosquito lays $E$ eggs and dies. Within a day, one larva hatches from each egg.

Some of the larvae hatched from egg the last Sunday were not strong enough and died or got eaten. Only every $R$th larva will transform into a pupa on Sunday.

An adult mosquito emerges from every $S$th pupa, all other pupae dry.
For example, if there are 5 pupae and every 3rd of them survives, there will be 1 mosquito left. Out of 6 pupae, two adult mosquitoes emerge.
In the first week, there are $M$ mosquitoes, $P$ pupae and $L$ larvae. Calculate how many mosquitoes will there be after $N$ 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 $M$, $P$, $L$, $E$, $R$, $S$, $N$ separated by space. $M$, $P$ and $L$ are the numbers of mosquitoes, pupae, and larvae, respectively, in the first week. You may assume that $0 \le M, P, L \le 100\, 000$, $0\le E \le 100$, $1 \le R, S \le 10$, and $1\le N\le 1\, 000$. $E$ is the number of eggs laid by one mosquito, $R$ and $S$ specify the survival rates of larvae and pupae, and $N$ is the number of weeks.
Output
For each input instance, output a single line containing an integer number $C$, giving the count of mosquitoes after the $N$th Sunday.
You may assume that the number of mosquitoes during each of the first $N$ weeks will not exceed $1\, 000\, 000$.
Sample Input 1  Sample Output 1 

10 20 40 4 2 2 10 144 55 8 0 1 9 4 10 10 10 2 3 2 6 10 20 40 86 9 9 999 
10 0 1 10 