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 Haskell (GHC 7.10.3) (judge verdict: Runtime Error)

import Data.Array
import Control.Monad
import Data.Maybe

data Item = Item { _x :: Int, _y:: Int, _t:: String } deriving Show

data MinMax = MinMax { _min :: Int, _max:: Int } deriving Show
data MinMax2 = MinMax2 { _mmx::MinMax, _mmy::MinMax } deriving Show
data MinMaxs = MinMaxs { _r::MinMax2, _l::MinMax2, _u::MinMax2, _d::MinMax2 } deriving Show

getMinMax2 ::Int -> Int -> MinMax2 -> MinMax2
getMinMax2 x y minmax2 =   
    MinMax2 (MinMax min_x max_x) (MinMax min_y max_y)
    where 
        min_x = min x $ (_min._mmx) minmax2
        max_x = max x $ (_max._mmx) minmax2
        min_y = min y $ (_min._mmy) minmax2
        max_y = max y $ (_max._mmy) minmax2

getMinMax :: Item -> MinMaxs -> MinMaxs

getMinMax (Item { _x = _x, _y = _y, _t = "R" }) minmaxs = MinMaxs (getMinMax2 _x _y (_r minmaxs)) (_l minmaxs) (_u minmaxs) (_d minmaxs)
getMinMax (Item { _x = _x, _y = _y, _t = "L" }) minmaxs = MinMaxs (_r minmaxs) (getMinMax2 _x _y (_l minmaxs)) (_u minmaxs) (_d minmaxs)
getMinMax (Item { _x = _x, _y = _y, _t = "U" }) minmaxs = MinMaxs (_r minmaxs) (_l minmaxs) (getMinMax2 _x _y (_u minmaxs)) (_d minmaxs)
getMinMax (Item { _x = _x, _y = _y, _t = "D" }) minmaxs = MinMaxs (_r minmaxs) (_l minmaxs) (_u minmaxs) (getMinMax2 _x _y (_d minmaxs))

mergeMinMax :: MinMax -> MinMax -> MinMax
mergeMinMax mm1 mm2 =
    MinMax (min (_min mm1) (_min mm2)) (max (_max mm1) (_max mm2))

maybeMinMax :: MinMax -> Maybe MinMax
maybeMinMax mm
    | (_min mm) <= (_max mm) = Just mm
    | otherwise = Nothing

ketsugou :: Maybe a -> Maybe a -> Maybe a
ketsugou mm1 mm2 = if (isJust mm1) then mm1 else mm2

calcTime :: Maybe MinMax -> Maybe MinMax -> Maybe MinMax -> ((Maybe Int,Int,Int,Maybe Int),(Maybe Int,Int,Int,Int,Maybe Int))

-- i : increment
-- d : decrement
-- c : constant
calcTime (Just mmi) (Just mmd) (Just mmc) =    
    ((Just t12_x2, t23_x2, t34_x2, Just t45_x2),(Just h1_x2,h2_x2,h3_x2,h4_x2,Just h5_x2))
    where

        i_min = _min mmi
        i_max = _max mmi
        c_min = _min mmc
        c_max = _max mmc
        d_min = _min mmd
        d_max = _max mmd

        ic_min_x2 = 2 * (c_min - i_min)
        cd_min_x2 = 2 * (d_min - c_min)
        id_min_x2 = d_min - i_min

        cd_max_x2 = 2 * (d_max - c_max)
        ic_max_x2 = 2 * (c_max - i_max)
        id_max_x2 = d_max - i_max

        tmin1_x2 = min ic_min_x2 id_min_x2
        tmin2_x2 = max id_min_x2 cd_min_x2
        tmax1_x2 = min cd_max_x2 id_max_x2
        tmax2_x2 = max id_max_x2 ic_max_x2

        h1_x2 = 2 * ( d_max - i_min )

        h2_x2 = if tmin1_x2 < tmax1_x2
                    then 
                        if tmin1_x2 < tmin2_x2
                        then
                            2 * (d_max - c_min) 
                        else
                            (2 * d_max) - (i_min + d_min)
                    else 
                        if tmax1_x2 < tmax2_x2
                        then
                            2 * (c_max - i_min)
                        else
                            (i_max + d_max) - (2 * i_min)

        h3_x2 = if tmin2_x2 < tmax1_x2
                    then 
                        2 * (d_max - d_min) 
                    else 
                        if tmax2_x2 < tmin1_x2
                        then
                            2 * (i_max - i_min) 
                        else
                            if tmin1_x2 < tmin2_x2
                            then
                                if tmax1_x2 < tmax2_x2
                                then
                                    2 * (c_max - c_min) 
                                else
                                    ((i_max + d_max) - 2 * c_min) 
                            else
                                if tmax1_x2 < tmax2_x2
                                then
                                    (2 * c_max - (i_min + d_min)) 
                                else
                                    ((i_max + d_max) - (i_min + d_min)) 

        h4_x2 = if tmin2_x2 < tmax2_x2
                    then 
                        if tmax1_x2 < tmax2_x2
                        then
                            2 * (c_max - d_min ) 
                        else
                            (i_max + d_max) - (2 * d_min) 
                    else 
                        if tmin1_x2 < tmin2_x2
                        then
                            2 * (i_max -  c_min)
                        else
                            (2 * i_max) - (i_min + d_min)

        h5_x2 = 2 * ( i_max - d_min ) 

        t12_x2 = minimum [ic_min_x2, id_min_x2, cd_max_x2, id_max_x2]
        t23_x2 = min (max tmin1_x2 tmax1_x2) (min tmin2_x2 tmax2_x2)
        t34_x2 = max (max tmin1_x2 tmax1_x2) (min tmin2_x2 tmax2_x2)
        t45_x2 = maximum [id_min_x2, cd_min_x2, id_max_x2, ic_max_x2]

calcTime (Just mmi) (Just mmd) Nothing =    
    ((Just t12_x2, t23_x2, t34_x2, Just t45_x2),(Just h1_x2,h2_x2,h3_x2,h4_x2,Just h5_x2))
    where

        i_min = _min mmi
        i_max = _max mmi
        d_min = _min mmd
        d_max = _max mmd

        id_min_x2 = d_min - i_min

        id_max_x2 = d_max - i_max

        h1_x2 = 2 * ( d_max - i_min )

        h2_x2 = if id_min_x2 < id_max_x2
                    then 
                        (2 * d_max) - (i_min + d_min)
                    else 
                        (i_max + d_max) - (2 * i_min)

        h3_x2 = if id_min_x2 < id_max_x2
                    then 
                        2 * (d_max - d_min) 
                    else 
                        if id_max_x2 < id_min_x2
                        then
                            2 * (i_max - i_min) 
                        else
                            2 * ((i_max + d_max) - (i_min + d_min)) 

        h4_x2 = if id_min_x2 < id_max_x2
                    then 
                        (i_max + d_max) - (2 * d_min) 
                    else 
                        (2 * i_max) - (i_min + d_min)

        h5_x2 = 2 * ( i_max - d_min ) 

        t12_x2 = min id_min_x2 id_max_x2
        t23_x2 = min id_min_x2 id_max_x2

        t34_x2 = max id_min_x2 id_max_x2
        t45_x2 = max id_min_x2 id_max_x2

calcTime (Just mmi) Nothing (Just mmc) =    
    ((Nothing, t23_x2, t34_x2, Nothing),(Nothing,h2_x2,h3_x2,h4_x2,Nothing))
    where

        i_min = _min mmi
        i_max = _max mmi
        c_min = _min mmc
        c_max = _max mmc

        ic_min_x2 = 2 * (c_min - i_min)
        ic_max_x2 = 2 * (c_max - i_max)

        h2_x2 = 2 * (c_max - i_min)

        h3_x2 = if ic_min_x2 < ic_max_x2
                then
                    2 * (c_max - c_min)
                else
                    2 * (i_max - i_min)

        h4_x2 =  2 * (i_max -  c_min)

        t23_x2 = min ic_min_x2 ic_max_x2

        t34_x2 = max ic_min_x2 ic_max_x2


calcTime Nothing (Just mmd) (Just mmc) =    
    ((Nothing, t23_x2, t34_x2, Nothing),(Nothing,h2_x2,h3_x2,h4_x2,Nothing))
    where

        c_min = _min mmc
        c_max = _max mmc
        d_min = _min mmd
        d_max = _max mmd

        cd_min_x2 = 2 * (d_min - c_min)
        cd_max_x2 = 2 * (d_max - c_max)

        h2_x2 = 2 * (d_max - c_min)

        h3_x2 = if cd_min_x2 < cd_max_x2
                then
                    2 * (d_max - d_min)
                else
                    2 * (c_max - c_min)

        h4_x2 =  2 * (c_max -  d_min)

        t23_x2 = min cd_max_x2 cd_min_x2

        t34_x2 = max cd_max_x2 cd_min_x2

main :: IO()
main = do

    n <- (read :: String -> Int)  <$> getLine

    arr <- map words <$> replicateM n getLine

    let arr2 = do 
        [x, y, d] <- arr
        let x' = (read :: String -> Int) x
        let y' = (read :: String -> Int) y
        return $ Item x' y' d

    let initMinMax  = MinMax maxBound minBound

    let initMinMax2 = MinMax2 initMinMax initMinMax

    let seed = MinMaxs initMinMax2 initMinMax2 initMinMax2 initMinMax2

    let MinMaxs { _r = _r, _l = _l, _u = _u, _d = _d } = foldr getMinMax seed arr2

    let r_mmx = maybeMinMax $ _mmx _r

    let l_mmx = maybeMinMax $ _mmx _l

    let rl_mmy = maybeMinMax $ mergeMinMax (_mmy _r) (_mmy _l)

    let u_mmy = maybeMinMax $ _mmy _u

    let d_mmy = maybeMinMax $ _mmy _d

    let ud_mmx = maybeMinMax $ mergeMinMax (_mmx _u) (_mmx _d)

    let ((tx1,tx2,tx3,tx4),(hx1,hx2,hx3,hx4,hx5)) = calcTime r_mmx l_mmx ud_mmx

    let ((ty1,ty2,ty3,ty4),(hy1,hy2,hy3,hy4,hy5)) = calcTime u_mmy d_mmy rl_mmy 

    let result25 = do
        _hy5 <- hy5
        return [(tx2, hx3 * (_hy5 + (2 * tx2)))]  

    let result24 = if maybe True ( tx2 < ) ty4
        then
            Just [(tx2, hx3 * (hy4 + tx2))] 
        else
            do
                _ty4 <- ty4
                _result25 <- result25
                return $ (_ty4, (hx2 - _ty4) * (hy4 + _ty4)) : _result25 

    let result15 = do
        _tx1 <- tx1
        _hy5 <- hy5
        _result25 <- result25
        return $ (_tx1,(hx2 - _tx1) * (_hy5 + 2 * _tx1)) : _result25 

    let result14 = do
        _tx1 <- tx1
        _result24 <- result24
        _result15 <- result15
        if maybe True ( _tx1 < ) ty4
        then
            return $ (_tx1,(hx2 - _tx1) * (hy4 - _tx1)) : _result24
        else
            do 
                _hx1 <- hx1
                _ty4 <- ty4
                return $ (_ty4,(_hx1 - 2 * _ty4) * (hy4 + _ty4)) : _result15 

    -- 9個全部計算してまえ！
    let result0 = if ty3 < tx2 
        then 

            if maybe True ( < ty3) tx1
            then
                do  
                    _result24 <- result24
                    return $ (ty3, (hx2 - ty3) * hy3) : _result24 
            else
                do
                    _hx1 <- hx1
                    _result14 <- result14
                    return $ (ty3,(_hx1 - 2 * ty3) * hy3) : _result14 

        else 
            Nothing 

    let result52 = do
        _hx5 <- hx5
        return [(ty2, hy3 * (_hx5 + 2 * ty2))]

    let result51 = do
        _hx5 <- hx5
        _ty1 <- ty1
        _result52 <- result52
        return $ (_ty1, hy3 * (_hx5 + 2 * _ty1)) : _result52

    let result42 = do
        _hx5 <- hx5
        _ty1 <- ty1
        _result52 <- result52
        if maybe True ( ty2 < ) tx4
        then
            return $ [(ty2, (hx4 + ty2) * hy3)]
        else
            do
                _tx4 <- tx4
                return $ (_ty1, (hx4 + _tx4) * (hy2 - _tx4) ) : _result52

    let result41 = do
        _result42 <- result42
        _result51 <- result51
        _ty1 <- ty1
        if maybe True ( _ty1 < ) tx4
        then
            return $ (_ty1, (hx4 + _ty1) * (hy2 - _ty1)) :_result42
        else
            do
                _tx4 <- tx4
                _hy1 <- hy1
                return $ (_tx4, (hx4 + _tx4) * (_hy1 - 2 * _tx4) ) : _result51

    let result10 = if tx3 < ty2 
        then 
            if maybe True ( < tx3 ) ty1
            then
                do
                    _result42 <- result42
                    return $ (tx3, hx3 * (hy2 - tx3)) : _result42
            else
                do
                    _hy1 <- hy1
                    _result41 <- result41
                    return $ (tx3,hx3 * (_hy1 - 2 * tx3)) :_result41
        else 
            Nothing

    let result_center = if (max tx2 ty2 ) <= (min tx3 ty3)
        then 
            Just [((min tx3 ty3),(hx3 * hy3))]
        else
            Nothing

    let array_result = catMaybes [result_center, result10, result0]

    let result_zero =   let x1 = minimum $ map _min $ catMaybes [r_mmx, l_mmx, ud_mmx] in
                        let x2 = maximum $ map _max $ catMaybes [r_mmx, l_mmx, ud_mmx] in
                        let y1 = minimum $ map _min $ catMaybes [u_mmy, d_mmy, rl_mmy] in
                        let y2 = maximum $ map _max $ catMaybes [u_mmy, d_mmy, rl_mmy] in
                        4 * (x2 - x1) * (y2 - y1)

    let isOneKind = (1 == ) $ length $ catMaybes [r_mmx, l_mmx, u_mmy, d_mmy]

    print $ (/4) $ (realToFrac :: Int -> Float) $ minimum $ (result_zero :) $ if isOneKind then [] else map snd $ filter ((0<=).fst) $  concat array_result