(defn split-space [s]
  (map #(Long/parseLong %) (.split s " ")))

(defn abs [a]
  (if (< 0 a) a (- a)))

(defn factorial [n]
  (reduce * (range 1 (inc n))))

(defn count-o [orders xi tail]
  (if (zero? (count tail))
    orders
    (recur
     (+ orders
         ;; (i - 1)!
        (* (factorial (count tail)) 
           ;; xi > xj (i < j) の個数
           (reduce (fn [acc xj]
                     (if (> xi xj)
                       (inc acc)        
                       acc))
                   0 tail)))
     (first tail)
     (rest tail))))

(defn count-order [n]
  (abs (- ((fn [xs] (count-o 1 (first xs) (rest xs))) (split-space (read-line)))
          ((fn [xs] (count-o 1 (first xs) (rest xs))) (split-space (read-line))))))

(println (count-order (Long/parseLong (read-line))))