import java.io.*;

public class Person {
 // max # of people in database.
 private final static int maxN = 100;

 // folks[0..n] are people in database.
 private static Person[] folks = new Person[maxN];
 private static int n = 0;

 protected String name;   // person's name.
 protected boolean male;  // person's maleness
 protected Person mom;    // person's mother
 protected Person dad;    // person's father
 protected Person kid;    // person's youngest child
 protected Person other;  // person's significant other
 protected Person sibling;// person's next older sibling
        
 // Construct person named s of maleness m.  
 public Person(String s, boolean m) {
  name = s;
  male = m;

  // check if there are too many people in the database
  if ( n >= maxN )
   System.out.println("over limit");
  else {
   folks[n] = this;
   n++;
  }
 }

 // # of people in database.   
 public static int numberOfPeople() {
  return n;
 }
        
 // i-th person in database.
 public static Person intToPerson(int i) {
  if (i < 0 || i >= n)
   return null;
  else return folks[i];
 }
        
 // string representation of a person.
 public String toString() {
  String result;
  result = "name:" + print_name();
  if (male)
   result = result + " sex:male";
  else 
   result = result + " sex:female";
  if (mom != null ) 
   result = result + " mom:" + mom.print_name();
  if (dad != null ) 
   result = result + " dad:" + dad.print_name();
  if (other != null)
   result = result + " other:" + other.print_name();
  result = result +  " kids:";
  if (kid == null)
   result = result + " none";
  else {
   Person p = kid;
   while ( p != null ){
    result = result + " " + p.print_name();
    p = p.sibling;
   }
  }
  return result; 
 }
  
 // create a child of mom and dad with name s and maleness m.
 public static void child(Person mom, Person dad, String s, boolean m)
  {
  Person child = new Person(s, m);
  child.mom = mom;
  child.dad = dad;
  child.sibling = mom.kid;
  dad.kid = child;
  mom.kid = child;
 }

 // marry persons p1 and p2.
 public static void marry(Person p1, Person p2) {
  p1.other = p2;
  p2.other = p1;
 }
        
 // field accessors.
 public String  name()         { return name; }
 public boolean male()         { return male; }
 public Person  other()        { return other; }
 public Person  dad()          { return dad; }
 public Person  mom()          { return mom; }
 public String  print_name()   { return name; }
}

