/* Problem 2--Packing Bricks
   Since there are only six ways to orient the bricks in the box, all we
   need do is try every combination looking for the best. */

#include <stdio.h>
#include <stdlib.h>

FILE *in, *out;

int main (int argc, char **argv);
int max (int a, int b);
int fit (int A, int B, int C, int a, int b, int c);

int main (int argc, char **argv) {

  int A,B,C,a,b,c,bct,cs=0;

 in = fopen ("prob2.in","r");
 out = fopen ("prob2.out","w");
 while (fscanf(in,"%d %d %d",&A,&B,&C),A > 0) {
  fscanf (in,"%d %d %d",&a,&b,&c);
  bct = 0;
  bct = max(bct,fit(A,B,C,a,b,c)); /* Try all possibilities */
  bct = max(bct,fit(A,B,C,a,c,b));
  bct = max(bct,fit(A,B,C,b,a,c));
  bct = max(bct,fit(A,B,C,b,c,a));
  bct = max(bct,fit(A,B,C,c,a,b));
  bct = max(bct,fit(A,B,C,c,b,a));
  fprintf (out,"Case %d:  Jar Jar can fit %d bricks in the box.\n\n",
           ++cs,bct);
 }
 fclose (in);
 fclose (out);
 return EXIT_SUCCESS;
}

/* max returns the maximum of a and b. */
int max (int a, int b) {

 return a>b?a:b;
}

/* fit computes how many bricks will fit into the box with A and a,
   B and b, C and c parallel. */
int fit (int A, int B, int C, int a, int b, int c) {

 return (A/a)*(B/b)*(C/c);
}
