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: Wrong Answer)

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

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

data MinMax = MinMax { _min :: Integer, _max:: Integer } 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 ::Integer -> Integer -> 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))

subMinMax :: MinMax -> Integer
subMinMax mm =
    let MinMax _min _max = mm in
    2 * (_max - _min)

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

getLeft :: Either a b -> Maybe a
getLeft = either Just (const Nothing)

getRight :: Either a b -> Maybe b
getRight = either (const Nothing) Just 

-- data Times = Pattern1 ((Integer,Integer,Integer,Integer),(Integer,Integer,Integer,Integer,Integer)) | Pattern2 ((Integer,Integer),(Integer,Integer,Integer))  | Pattern3 Integer deriving Show

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

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

        MinMax i_min i_max = mmi
        MinMax c_min c_max = mmc
        MinMax d_min d_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 =    
    (h3_x2, Just((t23_x2, t34_x2),(h2_x2, h4_x2),  Just((t12_x2, t45_x2),(h1_x2, h5_x2))))
    where

        MinMax i_min i_max = mmi
        MinMax d_min d_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) =    
    (h3_x2, Just((t23_x2, t34_x2),(h2_x2, h4_x2),Nothing))
    where

        MinMax i_min i_max = mmi
        MinMax c_min c_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) =    
    (h3_x2, Just((t23_x2, t34_x2),(h2_x2, h4_x2),Nothing))
    where

        MinMax c_min c_max = mmc
        MinMax d_min d_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

calcTime Nothing (Just mmd) Nothing =    
    (result,Nothing)
    where

        MinMax d_min d_max = mmd

        result = 2 * (d_max - d_min)

calcTime Nothing Nothing (Just mmc) =    
    (result,Nothing)
    where

        MinMax c_min c_max = mmc

        result = 2 * (c_max - c_min)

calcTime (Just mmi) Nothing Nothing =    
    (result,Nothing)
    where

        MinMax i_min i_max = mmi

        result = 2 * (i_max - i_min)

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

getFunc :: (Integer, Maybe ((Integer,Integer),(Integer,Integer),Maybe((Integer,Integer),(Integer,Integer)))) -> Integer -> Integer
getFunc neta =
    let (h3,times) = neta in if isNothing times
    then
        const h3
    else
        let Just ((t23,t34),(h2,h4),m) = times in
        let func1 = \t -> 
                if t < t23
                then
                    h2 - t
                else
                    if t34 < t
                    then
                        h4 + t
                    else
                        h3 in
        if isNothing m
        then
            func1
        else
            let Just ((t12,t45),(h1,h5)) = m in
                \t -> 
                    if t < t12
                    then
                        h1 - 2 * t
                    else
                        if t45 < t
                        then
                            h5 + 2 * t
                        else
                            func1 t

getTimes :: (Integer, Maybe ((Integer,Integer),(Integer,Integer),Maybe((Integer,Integer),(Integer,Integer)))) -> [Integer]
getTimes neta =
    let (h3,times) = neta in if isNothing times
    then
        []
    else
        let Just ((t23,t34),(h2,h4),m) = times in
        if isNothing m
        then
            [t23,t34]
        else
            let Just ((t12,t45),(h1,h5)) = m in
                [t12,t23,t34,t45]

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 -> Integer) x
        let y' = (read :: String -> Integer) y
        return $ Item x' y' d

    let initMinMax  = MinMax 200000000 (-200000000)

    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 x_neta = calcTime r_mmx l_mmx ud_mmx

    let y_neta = calcTime u_mmy d_mmy rl_mmy 

    let xFunc = getFunc x_neta
    let yFunc = getFunc y_neta
    let xTimes = getTimes x_neta
    let yTimes = getTimes y_neta

    let xResults = map (\t -> (t,(xFunc t)*(yFunc t))) xTimes
    let yResults = map (\t -> (t,(xFunc t)*(yFunc t))) yTimes

    let results = concat [xResults, yResults]

    let result_zero =   xFunc(0) * yFunc(0)

    print $ (/4) $ (realToFrac :: Integer -> Float) $ minimum $ (result_zero :) $ map snd $ filter ((0<=).fst) $  results