Problem:
Score : 600 points

Problem Statement

There are N points in a two-dimensional plane. The initial coordinates of the i-th point are (x_i, y_i). Now, each point starts moving at a speed of 1 per second, in a direction parallel to the x- or y- axis. You are given a character d_i that represents the specific direction in which the i-th point moves, as follows:

If d_i = R, the i-th point moves in the positive x direction;

If d_i = L, the i-th point moves in the negative x direction;

If d_i = U, the i-th point moves in the positive y direction;

If d_i = D, the i-th point moves in the negative y direction.

You can stop all the points at some moment of your choice after they start moving (including the moment they start moving).
Then, let x_{max} and x_{min} be the maximum and minimum among the x-coordinates of the N points, respectively. Similarly, let y_{max} and y_{min} be the maximum and minimum among the y-coordinates of the N points, respectively.

Find the minimum possible value of (x_{max} - x_{min}) \times (y_{max} - y_{min}) and print it.

Constraints

1 \leq N \leq 10^5

-10^8 \leq x_i,\ y_i \leq 10^8

x_i and y_i are integers.

d_i is R, L, U, or D.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 d_1
x_2 y_2 d_2
.
.
.
x_N y_N d_N

Output

Print the minimum possible value of (x_{max} - x_{min}) \times (y_{max} - y_{min}).

The output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-9}.

Sample Input 1

2
0 3 D
3 0 L

Sample Output 1

0

After three seconds, the two points will meet at the origin. The value in question will be 0 at that moment.

Sample Input 2

5
-7 -10 U
7 -6 U
-8 7 D
-3 3 D
0 -6 R

Sample Output 2

97.5

The answer may not be an integer.

Sample Input 3

20
6 -10 R
-4 -9 U
9 6 D
-3 -2 R
0 7 D
4 5 D
10 -10 U
-1 -8 U
10 -6 D
8 -5 U
6 4 D
0 3 D
7 9 R
9 -4 R
3 10 D
1 9 U
1 -6 U
9 -8 R
6 7 D
7 -3 D

Sample Output 3

273

Solution in Common Lisp (SBCL 1.1.14) (judge verdict: Wrong Answer)

;; -*- 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 (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :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)

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (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))))))))

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

;; Body

(defun main ()
  (let* ((n (read))
         (xs- (make-array 0 :fill-pointer 0 :element-type 'int32))
         (xs0 (make-array 0 :fill-pointer 0 :element-type 'int32))
         (xs+ (make-array 0 :fill-pointer 0 :element-type 'int32))
         (ys- (make-array 0 :fill-pointer 0 :element-type 'int32))
         (ys0 (make-array 0 :fill-pointer 0 :element-type 'int32))
         (ys+ (make-array 0 :fill-pointer 0 :element-type 'int32)))
    (dotimes (i n)
      (let ((x (read-fixnum))
            (y (read-fixnum))
            (d (read-char)))
        (case d
          (#\R
           (vector-push-extend x xs+)
           (vector-push-extend y ys0))
          (#\L
           (vector-push-extend x xs-)
           (vector-push-extend y ys0))
          (#\U
           (vector-push-extend x xs0)
           (vector-push-extend y ys+))
          (#\D
           (vector-push-extend x xs0)
           (vector-push-extend y ys-)))))
    (let ((xmax+ (reduce #'max xs+ :initial-value most-negative-fixnum))
          (xmax- (reduce #'max xs- :initial-value most-negative-fixnum))
          (ymax+ (reduce #'max ys+ :initial-value most-negative-fixnum))
          (ymax- (reduce #'max ys- :initial-value most-negative-fixnum))
          (xmax0 (reduce #'max xs0 :initial-value most-negative-fixnum))
          (ymax0 (reduce #'max ys0 :initial-value most-negative-fixnum))
          (xmin+ (reduce #'min xs+ :initial-value most-positive-fixnum))
          (xmin- (reduce #'min xs- :initial-value most-positive-fixnum))
          (ymin+ (reduce #'min ys+ :initial-value most-positive-fixnum))
          (ymin- (reduce #'min ys- :initial-value most-positive-fixnum))
          (xmin0 (reduce #'min xs0 :initial-value most-positive-fixnum))
          (ymin0 (reduce #'min ys0 :initial-value most-positive-fixnum)))
      (let ((t1 (* 0.5d0 (- xmax- xmax+)))
            (t2 (* 0.5d0 (- xmin- xmin+)))
            (t3 (* 0.5d0 (- ymax- ymax+)))
            (t4 (* 0.5d0 (- ymin- ymin+)))
            (t5 xmax0)
            (t6 xmin0)
            (t7 ymax0)
            (t8 ymin0))
        (println
         (min (* (- (max (- xmax- t1) (+ xmax+ t1) xmax0)
                    (min (- xmin- t1) (+ xmin+ t1) xmin0))
                 (- (max (- ymax- t1) (+ ymax+ t1) ymax0)
                    (min (- ymin- t1) (+ ymin+ t1) ymin0)))
              (* (- (max (- xmax- t2) (+ xmax+ t2) xmax0)
                    (min (- xmin- t2) (+ xmin+ t2) xmin0))
                 (- (max (- ymax- t2) (+ ymax+ t2) ymax0)
                    (min (- ymin- t2) (+ ymin+ t2) ymin0)))
              (* (- (max (- xmax- t3) (+ xmax+ t3) xmax0)
                    (min (- xmin- t3) (+ xmin+ t3) xmin0))
                 (- (max (- ymax- t3) (+ ymax+ t3) ymax0)
                    (min (- ymin- t3) (+ ymin+ t3) ymin0)))
              (* (- (max (- xmax- t4) (+ xmax+ t4) xmax0)
                    (min (- xmin- t4) (+ xmin+ t4) xmin0))
                 (- (max (- ymax- t4) (+ ymax+ t4) ymax0)
                    (min (- ymin- t4) (+ ymin+ t4) ymin0)))
               (* (- (max (- xmax- t5) (+ xmax+ t5) xmax0)
                    (min (- xmin- t5) (+ xmin+ t5) xmin0))
                 (- (max (- ymax- t5) (+ ymax+ t5) ymax0)
                    (min (- ymin- t5) (+ ymin+ t5) ymin0)))
              (* (- (max (- xmax- t6) (+ xmax+ t6) xmax0)
                    (min (- xmin- t6) (+ xmin+ t6) xmin0))
                 (- (max (- ymax- t6) (+ ymax+ t6) ymax0)
                    (min (- ymin- t6) (+ ymin+ t6) ymin0)))
              (* (- (max (- xmax- t7) (+ xmax+ t7) xmax0)
                    (min (- xmin- t7) (+ xmin+ t7) xmin0))
                 (- (max (- ymax- t7) (+ ymax+ t7) ymax0)
                    (min (- ymin- t7) (+ ymin+ t7) ymin0)))
              (* (- (max (- xmax- t8) (+ xmax+ t8) xmax0)
                    (min (- xmin- t8) (+ xmin+ t8) xmin0))
                 (- (max (- ymax- t8) (+ ymax+ t8) ymax0)
                    (min (- ymin- t8) (+ ymin+ t8) ymin0)))))))))

#-swank(main)


;; For Test
#+swank
(defun io-equal (in-string out-string &optional (func #'main))
  "Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and checks the string
output to *STANDARD-OUTPUT* is equal to OUT-STRING."
  (labels ((ensure-last-lf (s)
             (if (and (> (length s) 0)
                      (eql (char s (- (length s) 1)) #\Linefeed))
                 s
                 (uiop:strcat s uiop:+lf+))))
    (equal (ensure-last-lf out-string)
           (with-output-to-string (out)
             (let ((*standard-output* out))
               (with-input-from-string (*standard-input* (ensure-last-lf in-string))
                 (funcall func)))))))

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))

#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))
#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *this-pathname*))

#+swank
(defun run (&optional thing (out *standard-output*))
  (let ((*standard-output* out))
    (etypecase thing
      (null ; Runs #'MAIN with the string on clipboard
       (with-input-from-string (*standard-input* (delete #\Return (get-clipbrd)))
         (main)))
      (string
       (with-input-from-string (*standard-input* (delete #\Return thing))
         (main)))
      (symbol (5am:run! thing))
      (pathname ; Runs #'MAIN with the string in a text file
       (with-open-file (*standard-input* thing)
         (main))))))

#+swank
(defun gen-dat ()
  (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)
    (format out "")))

#+swank
(defun bench (&optional (out (make-broadcast-stream)))
  (time (run *dat-pathname* out)))

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "2
0 3 D
3 0 L
"
    "0
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "5
-7 -10 U
7 -6 U
-8 7 D
-3 3 D
0 -6 R
"
    "97.5
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "20
6 -10 R
-4 -9 U
9 6 D
-3 -2 R
0 7 D
4 5 D
10 -10 U
-1 -8 U
10 -6 D
8 -5 U
6 4 D
0 3 D
7 9 R
9 -4 R
3 10 D
1 9 U
1 -6 U
9 -8 R
6 7 D
7 -3 D
"
    "273
")))