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 Rust (1.15.1) (judge verdict: Runtime Error)

#![allow(unused_imports)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}



#[derive(Debug, PartialEq, Eq)]
enum MinMax {
    Min,
    Max,
}


#[derive(Debug, PartialEq)]
struct Edge {
    increase: Option<i64>,
    decrease: Option<i64>,
    constant: Option<i64>,
    f: MinMax,
}

impl Edge {
    fn new_min() -> Edge {
        Edge {
            increase: None,
            decrease: None,
            constant: None,
            f: MinMax::Min,
        }
    }

    fn new_max() -> Edge {
        Edge {
            increase: None,
            decrease: None,
            constant: None,
            f: MinMax::Max,
        }
    }

    fn min_max(self: &Edge, a: i64, b: i64) -> i64 {
        match self.f {
            MinMax::Min => min(a, b),
            MinMax::Max => max(a, b),
        }
    }

    fn put_increase(self: &mut Edge, a: i64) {
        if let Some(b) = self.increase {
            self.increase = Some(self.min_max(a, b));
        } else {
            self.increase = Some(a);
        }
    }

    fn put_decrease(self: &mut Edge, a: i64) {
        if let Some(b) = self.decrease {
            self.decrease = Some(self.min_max(a, b));
        } else {
            self.decrease = Some(a);
        }
    }

    fn put_constant(self: &mut Edge, a: i64) {
        if let Some(b) = self.constant {
            self.constant = Some(self.min_max(a, b));
        } else {
            self.constant = Some(a);
        }
    }

    fn solve_maybe_crossing_ts(self: &Edge) -> Vec<i64> {
        let mut ts = vec![];

        if let Some(a) = self.constant {
            if let Some(b) = self.increase {
                ts.push((a-b).abs());
            }

            if let Some(b) = self.decrease {
                ts.push((a-b).abs());
            }
        }

        if let Some(a) = self.increase {
            if let Some(b) = self.decrease {
                // Notice that scaled by 2.
                ts.push((a-b).abs() / 2);
            }
        }

        ts
    }

    fn position(self: &Edge, t: i64) -> i64 {
        let mut ts = vec![];

        if let Some(a) = self.increase {
            ts.push(a + t);
        }
        if let Some(a) = self.decrease {
            ts.push(a - t);
        }
        if let Some(a) = self.constant {
            ts.push(a);
        }

        ts.iter().fold(ts[0], |a, z| self.min_max(a, *z))
    }
}

#[derive(Debug)]
struct BoundingBox {
    x_min: Edge,
    x_max: Edge,
    y_min: Edge,
    y_max: Edge,
}

impl BoundingBox {
    fn area(self: &Self, t: i64) -> i64 {
        (self.x_max.position(t) - self.x_min.position(t)) * (self.y_max.position(t) - self.y_min.position(t))
    }
}

fn main() {
    input! {
        n: usize,
        ps: [(i64, i64, chars); n],
    }

    // Dangerous trick.  Scale by 2 to make all calculation to be in integers.  Area should be scaled by 1/4.
    let ps = ps.into_iter().map(|p| (2 * p.0, 2 * p.1, p.2)).vec();

    let mut x_min = Edge::new_min();
    let mut x_max = Edge::new_max();
    let mut y_min = Edge::new_min();
    let mut y_max = Edge::new_max();

    for p in ps {
        match p.2[0] {
            'U' => {
                x_min.put_constant(p.0);
                x_max.put_constant(p.0);
                y_min.put_increase(p.1);
                y_max.put_increase(p.1);
            },
            'D' => {
                x_min.put_constant(p.0);
                x_max.put_constant(p.0);
                y_min.put_decrease(p.1);
                y_max.put_decrease(p.1);
            },
            'R' => {
                x_min.put_increase(p.0);
                x_max.put_increase(p.0);
                y_min.put_constant(p.1);
                y_max.put_constant(p.1);
            },
            'L' => {
                x_min.put_decrease(p.0);
                x_max.put_decrease(p.0);
                y_min.put_constant(p.1);
                y_max.put_constant(p.1);
            },
            _ => panic!(),
        }
    }

    let mut ts = vec![];
    ts.append(&mut x_min.solve_maybe_crossing_ts());
    ts.append(&mut x_max.solve_maybe_crossing_ts());
    ts.append(&mut y_min.solve_maybe_crossing_ts());
    ts.append(&mut y_max.solve_maybe_crossing_ts());

    let bbox = BoundingBox {
        x_min: x_min,
        x_max: x_max,
        y_min: y_min,
        y_max: y_max,
    };
    let area = ts.into_iter().map(move |t| { bbox.area(t) }).min().unwrap();
    let area = (area as f64) / 4.0;

    println!("{}", area);
}