10324 - 饲料调配

农夫约翰从来只用调配得最好的饲料来为他的奶牛。饲料用三种原料调配成:大麦,燕麦和小麦。他知道自己的饲料精确的配比,在市场上是买不到这样的饲料的。他只好购买其他三种混合饲料(同样都由三种麦子组成),然后将它们混合,来调配他的完美饲料。

给出三组整数,表示 大麦:燕麦:小麦 的比例,找出用这三种饲料调配 x:y:x 的饲料的方法。

例如,给出目标饲料 3:4:5 和三种饲料的比例:

1:2:3   
3:7:1  
2:1:2

你必须编程找出使这三种饲料用量最少的方案,要是不能用这三种饲料调配目标饲料,输出“NONE”。“用量最少”意味着三种饲料的用量(整数)的和必须最小。 对于上面的例子,你可以用8份饲料1,2份饲料2,和5份饲料3,来得到7份目标饲料:

8(1:2:3) + 1(3:7:1) + 5(2:1:2) = (21:28:35) = 7(3:4:5)

表示饲料比例的整数,都是小于100(数量级)的非负整数。表示各种饲料的份数的整数,都小于100。一种混合物的比例不会由其他混合物的比例直接向加得到。

Input

Line 1: 三个用空格分开的整数,表示目标饲料
Line 2..4: 每行包括三个用空格分开的整数,表示农夫约翰买进的饲料的比例

Output

输出文件要包括一行,这一行要么有四个整数,要么是“NONE”。前三个整数表示三种饲料的份数,用这样的配比可以得到目标饲料。第四个整数表示混合前三种饲料后得到的目标饲料的份数。

Examples

Input

3 4 5 1 2 3 3 7 1 2 1 2 

Output

8 1 5 7

Hint

Feed Ratios 1998 ACM Finals, Dan Adkins Farmer John feeds his cows only the finest mixture of cow food, which has three components: Barley, Oats, and Wheat. While he knows the precise mixture of these easily mixable grains, he can not buy that mixture! He buys three other mixtures of the three grains and then combines them to form the perfect mixture.

Given a set of integer ratios barley ats:wheat, find a way to combine them IN INTEGER MULTIPLES to form a mix with some goal ratio x:y:z.

For example, given the goal 3:4:5 and the ratios of three mixtures:

    1:2:3
    3:7:1
    2:1:2

your program should find some minimum number of integer units (the mixture') of the first, second, and third mixture that should be mixed together to achieve the goal ratio or print NONE'. `Minimum number' means the sum of the three non-negative mixture integers is minimized. For this example, you can combine eight units of mixture 1, two units of mixture 2, and five units of mixture 3 to get seven units of the goal ratio:

8*(1:2:3) + 1*(3:7:1) + 5*(2:1:2) = (21:28:35) = 7*(3:4:5)

Integers in the goal ratio and mixture ratios are all non-negative and smaller than 100 in magnitude. The number of units of each type of feed in the mixture must be less than 100. The mixture ratios are not linear combinations of each other.

PROGRAM NAME: ratios INPUT FORMAT Line 1: Three space separated integers that represent the goal ratios Line 2..4: Each contain three space separated integers that represent the ratios of the three mixtures purchased.

SAMPLE INPUT (file ratios.in) 3 4 5 1 2 3 3 7 1 2 1 2

OUTPUT FORMAT The output file should contain one line containing four integers or the word `NONE'. The first three integers should represent the number of units of each mixture to use to obtain the goal ratio. The fourth number should be the multiple of the goal ratio obtained by mixing the initial feed using the first three integers as mixing ratios.

SAMPLE OUTPUT (file ratios.out) 8 1 5 7

Time Limit 1 second
Memory Limit 128 MB
Stats
上一题 下一题