// Arup Guha
// 7/23/02
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>

bool equal(int x[]); // Returns true iff first 4 values stored are equal.
void print(int x[]); // Prints out first four values, right justified(5).

void main() {

  ifstream fin("subtract.in");
  int i;
  int num[4];

  // Read in the data one line at a time.
  while (fin >> num[0] >> num[1] >> num[2] >> num[3]) {

    // Print out the initial data.
    print(num);

    // Continue until you have an array with the same values.
    while (!equal(num)) {

      int save = num[0]; // store the first digit.

      // Compute first three new values.
      for (i=0; i<3; i++)
        num[i] = abs(num[i] - num[i+1]);

      num[3] = abs(num[3] - save); // compute last value.

      // Print new set of values.
      print(num);
    } 
    cout << endl;
  }

}

bool equal(int x[]) {
  if (x[0] == x[1] && x[1] == x[2] && x[2] == x[3])
    return true;
  return false;
}

void print(int x[]) {
  for (int i=0; i<4; i++)
    cout << setw(5) << x[i];
  cout << endl;
}
