(defvar *cache*)

(defun fact (n)
  (loop with result = 1
        for i from 1 to n
        do (setf result
                 (* result i))
        finally (return result)))

(defun solve (n xs)
  (labels ((solve% (n xs)
             (or (gethash xs *cache*)
                 (setf (gethash xs *cache*)
                       (if (= n 1)
                           0
                           (loop with past = ()
                                 for (x y . rest) on xs
                                 while y
                                 summing (/ (+ (- y x)
                                               (solve% (1- n)
                                                       (nconc (reverse past) (cons y rest))))
                                            (1- n))
                                 do (setf past
                                          (cons x past))))))))
    (let ((*cache* (make-hash-table :test 'equal)))
      (rem (* (solve% n xs) (fact (1- n)))
           (+ (expt 10 9) 7)))))

#-swank
(let* ((n (read))
       (xs (loop repeat n collect (read))))
  (format t "~A~%" (solve n xs)))
