#T299. 装箱问题

装箱问题

Description

A factory manufactures products that are all cuboids in shape, with a uniform height of h and equal length and width. There are six models in total, with their length and width dimensions being 1×1, 2×2, 3×3, 4×4, 5×5, and 6×6. These products are typically packaged using a 6×6×h cuboid parcel and then shipped to customers. Since shipping costs are expensive, the factory strives to minimize the number of parcels required for each order. They urgently need a good program to help them solve this problem and reduce costs. Now, this task is assigned to you to design the program.

Input Format

The input file consists of several lines, each representing an order. Each line of an order contains six integers separated by spaces, representing the quantities of the six product models from 1×1 to 6×6. The input file ends with a line consisting of six zeros.

Output Format

Except for the last line of six zeros in the input, each line in the input file corresponds to a line in the output file. Each output line should contain a single integer representing the minimum number of parcels required for the corresponding order.

0 0 4 0 0 1
7 5 1 0 0 0
0 0 0 0 0 0


2
1