#include <list>
#include <algorithm>
#include <iostream.h>
#include <bool.h>

class Person {
private:
  static const int namelen=20;
  char name[20];
  int age;
public:
  friend bool operator<(Person,Person);
  friend ostream& operator<<(ostream&,Person);

  Person():age(0){strcpy(name,"");}; // copy constructor
  Person(istream& cin)
    { cout << "Name: "; cin >> name;
      if (cin) {cout << "Age: "; cin >> age;}}; // input constructor
};

int flag;

bool operator<(Person p1, Person p2)
{ 
  return strcmp(p1.name,p2.name) == -1 ||
    (strcmp(p1.name,p2.name) == 0 &&
     p1.age <xc p2.age);
}

ostream& operator<<(ostream& o, Person p)
{ o << p.name << ", Age: " << p.age << endl; return o; }

typedef list<Person>::iterator Pitor;

main()
{
  list<Person> l;
  Pitor i;

  while(cin)
    l.push_front(Person(cin));
  
  l.pop_front(); // remove the last item pushed on, it's empty.


  cout << endl << endl;

  for (i=l.begin(); i!=l.end(); i++)
    cout << *i;

  l.sort();

  cout << endl << endl;
  for (i=l.begin(); i!=l.end(); i++)
    cout << *i;

  return 0;
}

  
  

  

  

