;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))
              (return (if minus (- result) result))))))))

(defconstant +op-identity+ 0)

(declaim (inline op))
(defun op (x y)
  (+ x y))

;; Treap with explicit key
(defstruct (treap (:constructor %make-treap (key priority value &key left right (accumulator value)))
                  (:copier nil)
                  (:conc-name %treap-))
  (key 0 :type fixnum)
  (value +op-identity+ :type (unsigned-byte 32))
  (accumulator +op-identity+ :type (unsigned-byte 32))
  (priority 0 :type (integer 0 #.most-positive-fixnum))
  (left nil :type (or null treap))
  (right nil :type (or null treap)))

(declaim (inline treap-accumulator))
(defun treap-accumulator (treap)
  (declare ((or null treap) treap))
  (if (null treap)
      +op-identity+
      (%treap-accumulator treap)))

(declaim (inline update-accumulator))
(defun update-accumulator (treap)
  (declare (treap treap))
  (setf (%treap-accumulator treap)
        (if (%treap-left treap)
            (if (%treap-right treap)
                (let ((mid-res (op (%treap-accumulator (%treap-left treap))
                                   (%treap-value treap))))
                  (declare (dynamic-extent mid-res))
                  (op mid-res (%treap-accumulator (%treap-right treap))))
                (op (%treap-accumulator (%treap-left treap))
                    (%treap-value treap)))
            (if (%treap-right treap)
                (op (%treap-value treap)
                    (%treap-accumulator (%treap-right treap)))
                (%treap-value treap)))))

(declaim (inline force-self))
(defun force-self (treap)
  (declare (treap treap))
  (update-accumulator treap))

(declaim (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))
(defun treap-split (key treap &key (order #'<))
  "Destructively splits the TREAP with reference to KEY and returns two treaps,
the smaller sub-treap (< KEY) and the larger one (>= KEY)."
  (declare #.OPT
           (fixnum key)
           (ignorable order)
           ((or null treap) treap))
  (if (null treap)
      (values nil nil)
      (progn
        (if (< (%treap-key treap) key)
            (multiple-value-bind (left right)
                (treap-split key (%treap-right treap) :order order)
              (setf (%treap-right treap) left)
              (force-self treap)
              (values treap right))
            (multiple-value-bind (left right)
                (treap-split key (%treap-left treap) :order order)
              (setf (%treap-left treap) right)
              (force-self treap)
              (values left treap))))))

(declaim (inline treap-insert))
(defun treap-insert (key value treap &key (order #'<))
  "Destructively inserts KEY into TREAP and returns the resultant treap. You
cannot rely on the side effect. Use the returned value.

The behavior is undefined when duplicated keys are inserted."
  (declare ((or null treap) treap)
           (function order))
  (labels ((recur (node treap)
             (declare (treap node))
             (unless treap (return-from recur node))
             (if (> (%treap-priority node) (%treap-priority treap))
                 (progn
                   (setf (values (%treap-left node) (%treap-right node))
                         (treap-split (%treap-key node) treap :order order))
                   (force-self node)
                   node)
                 (progn
                   (if (funcall order (%treap-key node) (%treap-key treap))
                       (setf (%treap-left treap)
                             (recur node (%treap-left treap)))
                       (setf (%treap-right treap)
                             (recur node (%treap-right treap))))
                   (force-self treap)
                   treap))))
    (recur (%make-treap key (random most-positive-fixnum) value) treap)))

(declaim (inline treap-ensure-key))
(defun treap-ensure-key (key value treap &key (order #'<) if-exists)
  "IF-EXISTS := nil | function

Ensures that TREAP contains KEY and assigns VALUE to it if IF-EXISTS is
false. If IF-EXISTS is function and TREAP contains KEY, TREAP-ENSURE-KEY updates
the value by the function instead of overwriting it with VALUE."
  (declare (function order)
           ((or null treap) treap))
  (labels ((find-and-update (treap)
             ;; Updates the value slot and returns T if KEY exists
             (unless treap (return-from find-and-update nil))
             (cond ((funcall order key (%treap-key treap))
                    (when (find-and-update (%treap-left treap))
                      (force-self treap)
                      t))
                   ((funcall order (%treap-key treap) key)
                    (when (find-and-update (%treap-right treap))
                      (force-self treap)
                      t))
                   (t (setf (%treap-value treap)
                            (if if-exists
                                (funcall if-exists (%treap-value treap))
                                value))
                      (force-self treap)
                      t))))
    (if (find-and-update treap)
        treap
        (treap-insert key value treap :order order))))

(defun treap-merge (left right)
  "Destructively merges two treaps. Assumes that all keys of LEFT are smaller
 (or larger, depending on the order) than those of RIGHT."
  (declare #.OPT
           ((or null treap) left right))
  (cond ((null left) (when right (force-self right)) right)
        ((null right) (when left (force-self left)) left)
        (t (if (> (%treap-priority left) (%treap-priority right))
               (progn
                 (setf (%treap-right left)
                       (treap-merge (%treap-right left) right))
                 (force-self left)
                 left)
               (progn
                 (setf (%treap-left right)
                       (treap-merge left (%treap-left right)))
                 (force-self right)
                 right)))))

(defun treap-map (function treap)
  "Successively applies FUNCTION to TREAP[0], ..., TREAP[SIZE-1]. FUNCTION must
take two arguments: KEY and VALUE."
  (declare (function function))
  (when treap
    (treap-map function (%treap-left treap))
    (funcall function (%treap-key treap) (%treap-value treap))
    (treap-map function (%treap-right treap))
    (force-self treap)))

(defmethod print-object ((object treap) stream)
  (print-unreadable-object (object stream :type t)
    (let ((init t))
      (treap-map (lambda (key value)
                   (if init
                       (setf init nil)
                       (write-char #\  stream))
                   (format stream "<~A . ~A>" key value))
                 object))))

;; FIXME: might be problematic when two priorities collide.
(declaim (inline treap-query))
(defun treap-query (treap &key left right (order #'<))
  "Queries the sum of the half-open interval specified by the keys: [LEFT,
RIGHT). If LEFT [RIGHT] is not given, it is assumed to be -inf [+inf]."
  (if (null left)
      (if (null right)
          (treap-accumulator treap)
          (multiple-value-bind (treap-0-r treap-r-n)
              (treap-split right treap :order order)
            (prog1 (treap-accumulator treap-0-r)
              (treap-merge treap-0-r treap-r-n))))
      (if (null right)
          (multiple-value-bind (treap-0-l treap-l-n)
              (treap-split left treap :order order)
            (prog1 (treap-accumulator treap-l-n)
              (treap-merge treap-0-l treap-l-n)))
          (progn
            (assert (not (funcall order right left)))
            (multiple-value-bind (treap-0-l treap-l-n)
                (treap-split left treap :order order)
              (multiple-value-bind (treap-l-r treap-r-n)
                  (treap-split right treap-l-n :order order)
                (prog1 (treap-accumulator treap-l-r)
                  (treap-merge treap-0-l (treap-merge treap-l-r treap-r-n)))))))))

(declaim (inline bisect-left))
(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))
  "TARGET := vector | function (taking an integer argument)
ORDER := strict order

Analogue of lower_bound of C++ or bisect_left of Python: Returns the smallest
index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the
complement of ORDER. In other words, this function returns the leftmost index at
which VALUE can be inserted with keeping the order. Therefore, TARGET must be
monotonically non-decreasing with respect to ORDER.

This function returns END if VALUE exceeds TARGET[END-1]. Note that the range
[START, END) is half-open. END must be explicitly specified if TARGET is
function. KEY is applied to each element of TARGET before comparison."
  (declare (function key order)
           (integer start)
           ((or null integer) end))
  (macrolet
      ((body (accessor &optional declaration)
         `(progn
            (assert (<= start end))
            (if (= start end) end
                (labels
                    ((%bisect-left (left ok)
                       ;; TARGET[OK] >= VALUE always holds (assuming
                       ;; TARGET[END] = +infinity)
                       ,@(list declaration)
                       (let ((mid (ash (+ left ok) -1)))
                         (if (= mid left)
                             (if (funcall order (funcall key (,accessor target left)) value)
                                 ok
                                 left)
                             (if (funcall order (funcall key (,accessor target mid)) value)
                                 (%bisect-left mid ok)
                                 (%bisect-left left mid))))))
                  (%bisect-left start end))))))
    (etypecase target
      (vector
       (let ((end (or end (length target))))
         (body aref (declare ((integer 0 #.most-positive-fixnum) left ok)))))
      (function
       (assert end () "Requires END argument if TARGET is a function.")
       (body funcall (declare ((integer 0 #.most-positive-fixnum) left ok)))))))

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

Analogue of upper_bound of C++ or bisect_right of Python: Returns the smallest
index (or input) i that fulfills TARGET[i] > VALUE. In other words, this
function returns the rightmost index at which VALUE can be inserted with keeping
the order. TARGET must be monotonically non-decreasing with respect to ORDER.

This function returns END if VALUE >= TARGET[END-1]. Note that the range [START,
END) is half-open. END must be explicitly specified if TARGET is function. KEY
is applied to each element of TARGET before comparison."
  (declare (function key order)
           (integer start)
           ((or null integer) end))
  (macrolet
      ((body (accessor &optional declaration)
         `(progn
            (assert (<= start end))
            (if (= start end)
                end
                (labels
                    ((%bisect-right (left ok)
                       ;; TARGET[OK] > VALUE always holds (assuming
                       ;; TARGET[END] = +infinity)
                       ,@(list declaration)
                       (let ((mid (ash (+ left ok) -1)))
                         (if (= mid left)
                             (if (funcall order value (funcall key (,accessor target left)))
                                 left
                                 ok)
                             (if (funcall order value (funcall key (,accessor target mid)))
                                 (%bisect-right left mid)
                                 (%bisect-right mid ok))))))
                  
                  (%bisect-right start end))))))
    (etypecase target
      (vector
       (when (null end)
         (setf end (length target)))
       (body aref (declare ((integer 0 #.most-positive-fixnum) left ok))))
      (function
       (assert end () "Requires END argument if TARGET is a function.")
       (body funcall (declare ((integer 0 #.most-positive-fixnum) left ok)))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(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)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 998244353)

;; Body
;;;
;;; Arithmetic operations with static modulus
;;;

(defmacro define-mod-operations (&optional (divisor 1000000007))
  `(progn
     (defun mod* (&rest args)
       (reduce (lambda (x y) (mod (* x y) ,divisor)) args))

     (sb-c:define-source-transform mod* (&rest args)
       (if (null args)
           1
           (reduce (lambda (x y) `(mod (* ,x ,y) ,',divisor)) args)))

     (defun mod+ (&rest args)
       (reduce (lambda (x y) (mod (+ x y) ,divisor)) args))

     (sb-c:define-source-transform mod+ (&rest args)
       (if (null args)
           0
           (reduce (lambda (x y) `(mod (+ ,x ,y) ,',divisor)) args)))

     (define-modify-macro incfmod (delta divisor)
       (lambda (x y divisor) (mod (+ x y) divisor)))

     (define-modify-macro decfmod (delta divisor)
       (lambda (x y divisor) (mod (- x y) divisor)))))

(define-mod-operations 998244353)

(declaim ((simple-array uint32 (*)) *powers*))
(defparameter *powers* (make-array 500000 :element-type 'uint32))
(setf (aref *powers* 0) 1)
(loop for i from 1 below (length *powers*)
      do (setf (aref *powers* i)
               (mod* 2 (aref *powers* (- i 1)))))
(defun main ()
  (declare #.OPT
           (inline sort))
  (let* ((n (read))
         (xs (make-array n :element-type 'int32))
         (ys (make-array n :element-type 'int32))
         (ord-xs (make-array n :element-type 'uint32))
         (ord-ys (make-array n :element-type 'uint32))
         (res 0))
    (declare (uint32 n res)
             ((simple-array uint32 (*)) ord-xs ord-ys))
    (dotimes (i n)
      (setf (aref xs i) (read-fixnum)
            (aref ys i) (read-fixnum)))
    (dotimes (i n)
      (setf (aref ord-xs i) i
            (aref ord-ys i) i))
    (setf ord-xs (sort ord-xs (lambda (i j) (< (aref xs i) (aref xs j)))))
    (setf ord-ys (sort ord-ys (lambda (i j) (< (aref ys i) (aref ys j)))))
    (incfmod res (mod* (- (aref *powers* n) 1) n) +mod+)
    ;; L R U D
    (dotimes (i n)
      (let ((x (aref xs i))
            (y (aref ys i)))
        (let ((l (bisect-left (lambda (i) (aref xs (aref ord-xs i))) x :end n))
              (r (- n (bisect-right (lambda (i) (aref xs (aref ord-xs i))) x :end n)))
              (d (bisect-left (lambda (i) (aref ys (aref ord-ys i))) y :end n))
              (u (- n (bisect-right (lambda (i) (aref ys (aref ord-ys i))) y :end n))))
          (incfmod res (the uint32 (- +mod+ (aref *powers* l))) +mod+)
          (incfmod res (the uint32 (- +mod+ (aref *powers* r))) +mod+)
          (incfmod res (the uint32 (- +mod+ (aref *powers* d))) +mod+)
          (incfmod res (the uint32 (- +mod+ (aref *powers* u))) +mod+))))
    ;; LU LD
    (let (treap
          (base 0))
      (dotimes (i n)
        (let* ((ord (aref ord-xs i))
               (x (aref xs ord))
               (y (aref ys ord)))
          (when (> x (aref xs (aref ord-xs base)))
            (loop for j from base below i
                  do (setq treap (treap-ensure-key (aref ys (aref ord-xs j)) 1 treap
                                                   :if-exists #'1+)))
            (setq base i))
          (let ((ld (treap-query treap :right y))
                (lu (treap-query treap :left (+ y 1))))
            (incfmod res (aref *powers* ld) +mod+)
            (incfmod res (aref *powers* lu) +mod+)))))
    ;; RU RD
    (let (treap
          (base (- n 1)))
      (loop for i from (- n 1) downto 0
            do (let* ((ord (aref ord-xs i))
                      (x (aref xs ord))
                      (y (aref ys ord)))
                 (when (< x (aref xs (aref ord-xs base)))
                   (loop for j from base above i
                         do (setq treap (treap-ensure-key (aref ys (aref ord-xs j))
                                                          1
                                                          treap
                                                          :if-exists #'1+)))
                   (setq base i))
                 (let ((rd (treap-query treap :right y))
                       (ru (treap-query treap :left (+ y 1))))
                   (incfmod res (aref *powers* rd) +mod+)
                   (incfmod res (aref *powers* ru) +mod+)))))
    (println res)))

#-swank (main)



Measured memory_bytes: 86888