(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline bisect-left))
(defun bisect-left (target value &key (start 0) end (test #'<) (key #'identity))
  "TARGET := vector | function
TEST := strict order

Returns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where
'>=' is the complement of TEST. TARGET must be monotonically non-decreasing with
respect to TEST. Returns END if VALUE exceeds TARGET[END-1]. Note that the range
[START, END) is half-open. END must be specified If TARGET is function. KEY is
applied to each element of TARGET before comparison."
  (declare (function key test)
           ((integer 0 #.most-positive-fixnum) start)
           ((or null (integer 0 #.most-positive-fixnum)) end))
  (macrolet
      ((body (accessor &optional declaration)
         `(cond ((assert (<= start end)))
                ((= start end) end)
                ((funcall test (funcall key (,accessor target (- end 1))) value)
                 end)
                (t (labels ((%bisect-left (l r)
                              ,@(list declaration)
                              (let ((mid (floor (+ l r) 2)))
                                (if (= mid l)
                                    (if (funcall test (funcall key (,accessor target l)) value)
                                        r
                                        l)
                                    (if (funcall test (funcall key (,accessor target mid)) value)
                                        (%bisect-left mid r)
                                        (%bisect-left l mid))))))
                     (%bisect-left start (- end 1)))))))
    (etypecase target
      (vector
       (let ((end (or end (length target))))
         (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))
      (function
       (assert end)
       (body funcall)))))

(declaim (inline bisect-right))
(defun bisect-right (target value &key (start 0) end (test #'<) (key #'identity))
  "TARGET := vector | function
TEST := strict order

Returns the smallest index (or input) i that fulfills TARGET[i] > VALUE. TARGET
must be monotonically non-decreasing with respect to TEST. Returns END if VALUE
exceeds TARGET[END-1]. Note that the range [START, END) is half-open. END must
be specified if TARGET is function. KEY is applied to each element of TARGET
before comparison."
  (declare (function key test)
           ((integer 0 #.most-positive-fixnum) start)
           ((or null (integer 0 #.most-positive-fixnum)) end))
  (macrolet
      ((body (accessor &optional declaration)
         `(cond ((assert (<= start end)))
                ((= start end) end)
                ((funcall test value (funcall key (,accessor target (- end 1))))
                 (labels ((%bisect-right (l r)
                            ,@(list declaration)
                            (let ((mid (floor (+ l r) 2)))
                              (if (= mid l)
                                  (if (funcall test value (funcall key (,accessor target l)))
                                      l
                                      r)
                                  (if (funcall test value (funcall key (,accessor target mid)))
                                      (%bisect-right l mid)
                                      (%bisect-right mid r))))))
                   
                   (%bisect-right start (- end 1))))
                (t end))))
    (etypecase target
      (vector
       (when (null end)
         (setf end (length target)))
       (body aref (declare ((integer 0 #.most-positive-fixnum) l r))))
      (function
       (assert end)
       (body funcall)))))

;; Test
;; (eval-when (:compile-toplevel :load-toplevel :execute)
;;   (ql:quickload :fiveam))

;; (5am:test bisect-left
;;   (5am:is (= 0 (bisect-left #(1 8) -3)))
;;   (5am:is (= 0 (bisect-left #(1 8) 1)))
;;   (5am:is (= 1 (bisect-left #(1 8) 4)))
;;   (5am:is (= 1 (bisect-left #(1 8) 8)))
;;   (5am:is (= 2 (bisect-left #(1 8) 9)))
;;   (5am:is (= 3 (bisect-left #(1 4 5 7 7 7 7 7 7 8) 7)))
;;   (5am:is (= 3 (bisect-left #(1 4 4 7 7 7 7 7 8) 6)))
;;   (5am:is (= 1 (bisect-left #(#\a #\c #\c #\d) #\b :test #'char<)))
;;   (5am:is (= 4 (bisect-left #(nil 1 4 4 7 7 nil nil) 6 :start 1 :end 4))))

;; (5am:test bisect-right
;;   (5am:is (= 0 (bisect-right #(1) 0)))
;;   (5am:is (= 1 (bisect-right #(1) 1)))
;;   (5am:is (= 1 (bisect-right #(1) 2)))
;;   (5am:is (= 0 (bisect-right #(1 8) 0)))
;;   (5am:is (= 2 (bisect-right #(1 8) 8)))
;;   (5am:is (= 1 (bisect-right #(1 8) 4)))
;;   (5am:is (= 1 (bisect-right #(1 8) 1)))
;;   (5am:is (= 2 (bisect-right #(1 8) 9)))
;;   (5am:is (= 7 (bisect-right #(1 4 5 7 7 7 7 8) 7)))
;;   (5am:is (= 3 (bisect-right #(1 4 4 7 7 7 7 7 8) 6)))
;;   (5am:is (= 3 (bisect-right #(10 9 9 7 7 7 7 7 4) 9 :test #'>)))
;;   (5am:is (= 3 (bisect-right #(#\a #\c #\c #\d) #\c :test #'char<)))
;;   (5am:is (= 4 (bisect-right #(nil 1 4 4 4 4 7 7 nil nil) 4 :start 1 :end 4))))

;; (5am:run! '(bisect-left bisect-right))

(declaim (inline read-line-into))
(defun read-line-into (buffer-string &key (in *standard-input*) (terminate-char #\Space))
  (declare (simple-base-string buffer-string))
  (loop for c of-type base-char =
           #-swank (code-char (read-byte in nil #\Newline))
           #+swank (read-char in nil #\Newline)
        for idx from 0
        until (char= c #\Newline)
        do (setf (schar buffer-string idx) c)
        finally (setf (schar buffer-string idx) terminate-char)
                (return (values buffer-string idx))))

(declaim (inline split-ints-into-vector))
(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))
  (declare (string string)
           (function key)
           ((simple-array * (*)) dest-vector)
           ((integer 0 #.most-positive-fixnum) offset))
  (loop for idx from offset below (length dest-vector)
        for pos1 = 0 then (1+ pos2)
        for pos2 = (position #\space string :start pos1 :test #'char=)
        do (setf (aref dest-vector idx)
                 (funcall key (parse-integer string :start pos1 :end pos2)))
        finally (return dest-vector)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (as (make-array n :element-type 'uint32))
         (bs (make-array n :element-type 'uint32))
         (cs (make-array n :element-type 'uint32))
         (buf (make-string 2000000 :element-type 'base-char)))
    (declare (uint32 n))
    (split-ints-into-vector (read-line-into buf) as)
    (split-ints-into-vector (read-line-into buf) bs)
    (split-ints-into-vector (read-line-into buf) cs)
    (setf as (stable-sort as #'<)
          cs (stable-sort cs #'<))
    (println
     (loop for b across bs
           sum (the fixnum (* (bisect-left as b)
                              (- n (bisect-right cs b))))
           of-type fixnum))))

#-swank(main)


Measured memory_bytes: 53732