!752

answer {
  if "how many elements are in the list *" {
    L list = cast safeUnstructure(m.unq(0));
    ret str(l(list));
  }
  
  if "what is the * element in the list *" {
    S x = m.unq(0).toLowerCase();
    L list = cast safeUnstructure(m.unq(1));
    if (eq(x, "first"))
      ret structure(first(list));
    if (eq(x, "last"))
      ret structure(last(list));
    
    // "1st", "2nd" etc  
    int i = 0;
    while (i < l(x) && isDigit(x.charAt(i)))
      ++i;
    if (i > 0)
      ret structure(get(list, parseInt(x.substring(0, i))-1));
  }
  
  // It should match if you write: "what is the 1st element..."
  // cause the tokenizer works like that...
  if (match("what is the * st element in the list *", s, m)
    || match("what is the * nd element in the list *", s, m)
    || match("what is the * rd element in the list *", s, m)
    || match("what is the * th element in the list *", s, m)) {
    L list = cast safeUnstructure(m.unq(1));
    ret structure(get(list, parseInt(m.unq(0))-1));
  }
}