# Age of Empires

问题描述 :

P. T. Tigris has been an avid computer game lover since he was a little boy fifteen years ago. “Age of Empires” was one of the most famous real-time strategy games in that past years. Resource is one of the most important consideration when playing this game. In this game, there are four different types of resources: food, wood, stone and gold.

Food is the most important resource in the game, which is used for producing many military units and researching important technologies. Wood is most often required for buildings or training ranged units. Stone is mainly used to build static defenses like Towers and Walls, but it is also used for some units and technologies as well as Wonders. Finally, gold is used for creating most units and upgrades and is a precious resource which becomes more important as the game progresses.

The Villager is a common civilian unit for almost every game. They are the backbone of all civilizations. The Villagers are arguably the most important units in the game because they are able to collect all the resources.

P. T. Tigris is very interesting in the optimal strategy of game playing. He wants to discover the fastest way to gather enough resources. We may assume that P. T. Tigris has N villagers at the beginning of the game with initially no food, wood, stone or gold at all. P. T. Tigris knows that every second, each villager could gather A

can not gather A

Different villagers could gather different types of resources at a time. P. T. Tigris should decide which type of resources he should gather for each villager at every second, so that he could have A

P. T. Tigris could also training more villagers to speed up his process of gathering. To training a villager, P. T. Tigris should spend X units of food at the beginning of a second, and a new villager will able to work after T seconds. Please note that at he beginning of the second you start training a villager, you must have not less than X units of food. All villagers are trained at the Town Center but unfortunately there is only one Town Center for P. T. Tigris. So he can only train one villager at a time.

It is really difficult to find the optimal answer. P. T. Tigris decides to ask you to write a program to help him calculate the minimum time to get the required amount of resources.

Food is the most important resource in the game, which is used for producing many military units and researching important technologies. Wood is most often required for buildings or training ranged units. Stone is mainly used to build static defenses like Towers and Walls, but it is also used for some units and technologies as well as Wonders. Finally, gold is used for creating most units and upgrades and is a precious resource which becomes more important as the game progresses.

The Villager is a common civilian unit for almost every game. They are the backbone of all civilizations. The Villagers are arguably the most important units in the game because they are able to collect all the resources.

P. T. Tigris is very interesting in the optimal strategy of game playing. He wants to discover the fastest way to gather enough resources. We may assume that P. T. Tigris has N villagers at the beginning of the game with initially no food, wood, stone or gold at all. P. T. Tigris knows that every second, each villager could gather A

_{1}units of food, or B_{1}units of wood, or C_{1}units of stone, or D_{1}units of gold. Note that the villager can not split one second into smaller pieces to gather different types of resource. For example, a single villagercan not gather A

_{1}/2 units of food and B_{1}/2 units of wood for a single second. Moreover, all kinds of recourse are gathered exactly the end of that second.Different villagers could gather different types of resources at a time. P. T. Tigris should decide which type of resources he should gather for each villager at every second, so that he could have A

_{2}units of food and B_{2}units of wood and C_{2}units of stone and D_{2}units of gold as soon as possible.P. T. Tigris could also training more villagers to speed up his process of gathering. To training a villager, P. T. Tigris should spend X units of food at the beginning of a second, and a new villager will able to work after T seconds. Please note that at he beginning of the second you start training a villager, you must have not less than X units of food. All villagers are trained at the Town Center but unfortunately there is only one Town Center for P. T. Tigris. So he can only train one villager at a time.

It is really difficult to find the optimal answer. P. T. Tigris decides to ask you to write a program to help him calculate the minimum time to get the required amount of resources.

输入:

There are several test cases.

For each test case, the first line contains four integers A

The second line also contains four integers A

The third line contains three integers N, X and T (1 ≤ N,X,T ≤ 10

Input is terminated by EOF.

For each test case, the first line contains four integers A

_{1}, B_{1}, C_{1}and D_{1}(1 ≤ A_{1}, B_{1}, C_{1}, D_{1}≤ 10^{18}),indicating the amount of resource a villager can gather for each type in a second.The second line also contains four integers A

_{2}, B_{2}, C_{2}and D_{2}(0 ≤ A_{2}, B_{2}, C_{2}, D_{2}≤ 10^{18}), denoting the amount of resource P. T. Tigris want to have.The third line contains three integers N, X and T (1 ≤ N,X,T ≤ 10

^{5}), denoting that P. T. Tigris has N villager at the beginning of the game, and it will spend X units of food and T seconds to train each new villager.Input is terminated by EOF.

输出:

There are several test cases.

For each test case, the first line contains four integers A

The second line also contains four integers A

The third line contains three integers N, X and T (1 ≤ N,X,T ≤ 10

Input is terminated by EOF.

For each test case, the first line contains four integers A

_{1}, B_{1}, C_{1}and D_{1}(1 ≤ A_{1}, B_{1}, C_{1}, D_{1}≤ 10^{18}),indicating the amount of resource a villager can gather for each type in a second.The second line also contains four integers A

_{2}, B_{2}, C_{2}and D_{2}(0 ≤ A_{2}, B_{2}, C_{2}, D_{2}≤ 10^{18}), denoting the amount of resource P. T. Tigris want to have.The third line contains three integers N, X and T (1 ≤ N,X,T ≤ 10

^{5}), denoting that P. T. Tigris has N villager at the beginning of the game, and it will spend X units of food and T seconds to train each new villager.Input is terminated by EOF.

样例输入:

1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 2 2 2 2 1 1 1 1 1 1 1 10 10 10 10 1 1 25

样例输出:

Case 1: 1 Case 2: 5 Case 3: 34