/****************************************************************

            Example Solution for "Doctor Pickle"

	---------------------------------------------------------
		Author   :  Xiao Ma  
		            (maxiao812@msn.com)
		Edited   : Jason Daly, Arup Guha
	  Beginning  :  2004-10-13 
	 Last Update :  2004-10-13 
	  File Name  :  Pickle_Solution.cpp
	     Log     :  2004-10-13 Finish, send to other coaches.
         Edited Last :  10/16/04 during the contest, when it was      
                        discovered that there was a bug in the min
		        function. Also, a portion of the simulation
		        was rewritten to be more clear. Then, since
			  I erased the corrections Jason made, I made
			  them again on 10/17/04. 
	---------------------------------------------------------

   This program is the example solution for the 3nd problem in 
SER'97 -- 'Doctor Pickle'.

   This problem seems to be a bit comlicated, at the first glance,
there are two main difficult points which have to be sovled:
  (1) caculte the mass of drink produced each month;
  (2) make a proper schedule to package the output exactly.

  However, after deeper investigation, the second point does not 
exist actually. I will explain it following.

  For we have a barrel(s) of water, b barrel(s) of juice and 
c barrel(s) of X, including the retained material from past few 
months. Then, the total output this month is:

     Output = min {a/3, b/2, c/1} * 6 * 10 * 128 (oz)

   Obviously, the output can always be packaged as jugs, just
   
	 Output = min {a/3, b/2, c/1} * 6 * 32 (jug)

   since 10*128 is a multiple of 40 and min {a/3,b/2,c}*6
   will always be an integer, since we'll always use an integer
   number of barrels of one of the three products.


****************************************************************/

#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>

using namespace std;

// Return the minmum among a, b and c
double min ( double a, double b, double c );

int main ()
{
	int month;
	int NewJuice, OldJuice_1;
	int NewWater, OldWater;
	int NewX, OldX_1, OldX_2;
	int a,b,c;
	double one;

	cout << "Month  Ounces    4-Packs    6-Packs    8-Packs    9-Packs    Jugs" << endl;
	cout << "-----------------------------------------------------------------" << endl;

	// Initialize the variables
	month=1;
	OldJuice_1 = 0;
	OldX_1 = OldX_2 = 0;
	OldWater = 0;

	while (1) {

		cin >> NewWater >> NewJuice >> NewX;

		if (NewWater==0 && NewJuice==0 && NewX==0 )
			break;

		// a,b,c is the total amount of water, juice and X this month.
		a = NewWater + OldWater;					// Total water
        	b = NewJuice + OldJuice_1;		// Total juice
		c = NewX + OldX_1 + OldX_2;		// Total X

		// variable one is the one part of the output this month.
		// total output is one*6 (barrel)
		one = min ((double)a/3.0, (double)b/2.0, (double)c);
		
		// This is the total number of barrels of X that are
		// used (or thrown out) this month.
		int barrels_used = ceil(one);

		// Use up all of the 2 month X.
		if (barrels_used > OldX_2) {
			barrels_used -= OldX_2;
			OldX_2 = 0;

			// Use up all the 1 month old X.
			if (barrels_used > OldX_1) {
				barrels_used -= OldX_1;
				OldX_1 = 0;
				NewX -= barrels_used;
			}

			// Only used some of the 1 month old X.
			else {
				OldX_1 -= barrels_used;
			}
		}

		// Only used up some of the 2 month old X. 
		else {
			OldX_2 -= barrels_used;
		}

		// X becomes one month older.
		OldX_2 = OldX_1;
		OldX_1 = NewX;

		// This is the total number of barrels of juice that are
		// used (or thrown out) this month.
		int juice_used = ceil(2*one);
	
		// Use all the old juice first.
		if (juice_used > OldJuice_1) {
			juice_used -= OldJuice_1;
			OldJuice_1 = 0;
			NewJuice -= juice_used;
		}

		// Only used part of the old juice.
		else {
			OldJuice_1 -= juice_used;
		}

		// Juice becomes 1 month older.
		OldJuice_1 = NewJuice;

		// Water left = Total Water minus Water Used.
		OldWater = a - ceil(3*one);

		cout << setw(4) << month++;
		cout << setw(9) << ((int)(6*one+.5)*10*128);
		cout << "        0          0          0         0";
		cout << setw(11) << ((int)(6*one+.5)*32) << endl;
	}

	return 0;
}


double min ( double a, double b, double c )
{
	if ( a<=b && a<=c )
		return a;
	else if ( b<=a && b<=c )
		return b;
	else
		return c;
}
