#include <stdio.h> 
/* Define the trade apparatus */
struct stock_trade {double price; int number; int pe_ratio;};
struct bond_trade {double price; int number; double yield;};
union trade {
  struct stock_trade stock; 
  struct bond_trade bond;
};
struct tagged_trade {
  int code;
  union trade trade;
};
/* Define type codes */
enum {stock, bond};
/* Define trade array */
struct tagged_trade *trade_pointers[100];
main ( ) {
  /* Declare various variables */
  int limit, counter, trade_type, stock_count = 0, bond_count = 0;
  int pe_sum = 0;
  double yield_sum = 0.0;
  /* Read type code */
  for (limit = 0; 1 == scanf ("%i", &trade_type); ++limit) {
    /* Allocate space for structure */
    trade_pointers[limit] = (struct tagged_trade*)
                            malloc (sizeof (struct tagged_trade));
    trade_pointers[limit] -> code = trade_type;
    /* Read remaining information according to type */
    switch (trade_type) {
      case stock: scanf ("%lf%i%i", 
                    &trade_pointers[limit] -> trade.stock.price,
                    &trade_pointers[limit] -> trade.stock.number,
                    &trade_pointers[limit] -> trade.stock.pe_ratio);
                  break;
      case bond:  scanf ("%lf%i%lf",
                    &trade_pointers[limit] -> trade.bond.price,
                    &trade_pointers[limit] -> trade.bond.number,
                    &trade_pointers[limit] -> trade.bond.yield);
                  break; 
    }
  }
  /* Analyze array elements */
  for (counter = 0; counter < limit; ++counter)
    switch ((trade_pointers[counter] -> code)) {
      case stock: 
        ++stock_count;
        pe_sum += trade_pointers[counter] -> trade.stock.pe_ratio;
        break;
      case bond:
        ++bond_count;
        yield_sum += trade_pointers[counter] -> trade.bond.yield;
        break;
    }
  /* Display report */
  printf ("The average stock price/earnings ratio is %i.\n",
          pe_sum / stock_count);
  printf ("The average bond yield is %f.\n", 
          yield_sum / bond_count);
}
