anchor.diff:           (loop for i from start1 below end1
                  for j from start2 below end2
                  always (funcall test (aref v1 i) (aref v2 j))))))
  -
  -(defsubst take (n seq)
  -  "Return the first N elements of SEQ, as a *new* sequence of the same
  -type as SEQ."
  -  (subseq seq 0 n))
  -
  -(defsubst drop (n seq)
  -  "Return all but the first N elements of SEQ.
  -The sequence returned is a new sequence of the same type as SEQ."
  -  (subseq seq n))
  -
  -(defsubst take-while (pred seq)
  -  (etypecase seq
  -    (list
  -     (ldiff seq (member-if-not pred seq)))
  -    (sequence
  -     (subseq seq 0 (position-if-not pred seq)))))
  -
  -(defsubst drop-while (pred seq)
  -  (etypecase seq
  -    (list
  -     (member-if-not pred seq))
  -    (sequence
  -     (subseq seq (position-if-not pred seq)))))
  -
  -(defsubst count-while (pred seq)
  -  (position-if-not pred seq))
   
   (defun halves (seq &optional split)
     "Return, as two values, the first and second halves of SEQ.
  
positive.code:                 (setf end mid)))
                finally (return start))))))
  
  (defun bestn (n seq pred &key (key #'identity))
    "Partial sorting.
  Equivalent to (firstn N (sort SEQ PRED)), but much faster, at least
  for small values of N.
  
  The name is from Arc."
    (declare (optimize speed) (array-length n))
    (flet ((coerce-by-example (buf seq)
             "Hack to return a sequence \"like\" SEQ."
             (etypecase seq
               (list (coerce buf 'list))
               (vector (coerce buf 'vector))
               (t (replace (subseq seq 0 (length buf)) buf)))))
      (cond ((= n 0)
             (coerce-by-example '() seq))
            ((= n 1)
             (coerce-by-example (list (extremum seq pred :key key)) seq))
            ((length<= seq n)
             (sort (copy-seq seq) pred :key key))
            (t (let ((buf (make-array n)))
                 ;; Put the first N elements of SEQ in the buffer.
                 (replace buf seq)
                 ;; Sort the buffer in advance.
                 (sortf buf pred :key key)
                 (flet ((insort (item)
                          (let ((index (bisect-left buf item pred :key key)))
                            (declare (array-length index))
                            (when (< index n)
                              (replace buf buf :start1 (1+ index) :start2 index)
                              (setf (svref buf index) item)))))
                   (declare (dynamic-extent #'insort))
                   (etypecase seq
                     (list
                      (dolist (item (nthcdr n seq))
                        (insort item)))
                     (vector
                      (loop for i from n below (length seq) do
                        (insort (aref seq i))))
                     (sequence (map nil #'insort (subseq seq n)))))
                 (coerce-by-example buf seq))))))
  
  (dotimes (i 100)
    (let ((list (map-into (make-list 1000) (lambda () (random 1000)))))
      (assert
       (equal (firstn 20 (sort (copy-list list) #'>))
              (bestn 20 list #'>)))))
  
  (defun extrema (seq pred &key (key #'identity) (start 0) end)
    "Like EXTREMUM, but returns both the minimum and the maximum (as two
  
negative.code:                    (sort (shuffle (copy-list list))
                           (ordering list))))))
  
  (defsubst take (n seq)
    "Return the first N elements of SEQ, as a *new* sequence of the same
  type as SEQ."
    (subseq seq 0 n))
  
  (defsubst drop (n seq)
    "Return all but the first N elements of SEQ.
  The sequence returned is a new sequence of the same type as SEQ."
    (subseq seq n))
  
  (defsubst take-while (pred seq)
    (etypecase seq
      (list
       (ldiff seq (member-if-not pred seq)))
      (sequence
       (subseq seq 0 (position-if-not pred seq)))))
  
  (defsubst drop-while (pred seq)
    (etypecase seq
      (list
       (member-if-not pred seq))
      (sequence
       (subseq seq (position-if-not pred seq)))))
  
  (defsubst count-while (pred seq)
    (position-if-not pred seq))
  
  ;;;# `bestn'
  (defun bisect-left (vec item pred &key key)
    "Return the index in VEC to insert ITEM and keep VEC sorted."
    (declare ((simple-array * (*)) vec))
  