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.42.0) (judge verdict: Time Limit Exceeded)

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut r_points = vec![];
    let mut l_points = vec![];
    let mut d_points = vec![];
    let mut u_points = vec![];
    for i in 0..n {
        let v = read_vec::<String>();
        let x = v[0].clone().parse::<f64>().unwrap();
        let y = v[1].clone().parse::<f64>().unwrap();
        if &v[2] == "R" {
            r_points.push((x, y));
        } else if &v[2] == "L" {
            l_points.push((x, y));
        } else if &v[2] == "D" {
            d_points.push((x, y));
        } else if &v[2] == "U" {
            u_points.push((x, y));
        }
    }

    let mut lr_events = vec![0.0];
    for _ in 0..2 {
        if !l_points.is_empty() && !r_points.is_empty() {
            let most_left_r = r_points.iter().map(|&x| Total(x.0)).min().unwrap().0;
            let most_right_l = l_points.iter().map(|&x| Total(x.0)).max().unwrap().0;
            if most_left_r < most_right_l {
                lr_events.push((most_right_l - most_left_r) / 2.0f64);
            }
        }
        let mut ud_points = u_points.clone();
        ud_points.append(&mut d_points.clone());
        if !l_points.is_empty() && !ud_points.is_empty() {
            let most_right_l = l_points.iter().map(|&x| Total(x.0)).max().unwrap().0;
            let most_left_ud = ud_points.iter().map(|&x| Total(x.0)).min().unwrap().0;
            let most_right_ud = ud_points.iter().map(|&x| Total(x.0)).max().unwrap().0;
            if most_right_l > most_left_ud {
                lr_events.push(most_right_l - most_left_ud);
            }
            if most_right_l > most_right_ud {
                lr_events.push(most_right_l - most_right_ud);
            }
        }
        if !r_points.is_empty() && !ud_points.is_empty() {
            let most_left_r = r_points.iter().map(|&x| Total(x.0)).min().unwrap().0;
            let most_left_ud = ud_points.iter().map(|&x| Total(x.0)).min().unwrap().0;
            let most_right_ud = ud_points.iter().map(|&x| Total(x.0)).max().unwrap().0;
            if most_left_r < most_left_ud {
                lr_events.push(most_left_ud - most_left_r);
            }
            if most_left_r < most_right_ud {
                lr_events.push(most_right_ud - most_left_r);
            }
        }
        std::mem::swap(&mut l_points, &mut d_points);
        std::mem::swap(&mut r_points, &mut u_points);
    }
    lr_events.sort_by_key(|&x| Total(x));
    lr_events.dedup();

    let mut lr_points = l_points.clone();
    lr_points.append(&mut r_points.clone());
    let lr_most_u = lr_points.iter().map(|&x| Total(x.1)).max();
    let lr_most_d = lr_points.iter().map(|&x| Total(x.1)).min();
    let mut ud_points = u_points.clone();
    ud_points.append(&mut d_points.clone());
    let ud_most_r = ud_points.iter().map(|&x| Total(x.0)).max();
    let ud_most_l = ud_points.iter().map(|&x| Total(x.0)).min();

    let l_most_l = l_points.iter().map(|&x| Total(x.0)).min();
    let l_most_r = l_points.iter().map(|&x| Total(x.0)).max();
    let r_most_l = r_points.iter().map(|&x| Total(x.0)).min();
    let r_most_r = r_points.iter().map(|&x| Total(x.0)).max();

    let u_most_d = u_points.iter().map(|&x| Total(x.1)).min();
    let u_most_u = u_points.iter().map(|&x| Total(x.1)).max();
    let d_most_d = d_points.iter().map(|&x| Total(x.1)).min();
    let d_most_u = d_points.iter().map(|&x| Total(x.1)).max();

    let calc_area = |t: f64| -> f64 {
        let mut most_left = std::f64::MAX;
        let mut most_right = -std::f64::MAX;
        let mut most_down = std::f64::MAX;
        let mut most_up = -std::f64::MAX;
        if let Some(x) = &lr_most_u {
            most_up = x.0;
        }
        if let Some(x) = &lr_most_d {
            most_down = x.0;
        }
        if let Some(x) = &ud_most_l {
            most_left = x.0;
        }
        if let Some(x) = &ud_most_r {
            most_right = x.0;
        }
        if let Some(x) = &l_most_l {
            let x = x.0 - t;
            most_left = f64::min(x, most_left);
        }
        if let Some(x) = &l_most_r {
            let x = x.0 - t;
            most_right = f64::max(x, most_right);
        }
        if let Some(x) = &r_most_l {
            let x = x.0 + t;
            most_left = f64::min(x, most_left);
        }
        if let Some(x) = &r_most_r {
            let x = x.0 + t;
            most_right = f64::max(x, most_right);
        }

        if let Some(x) = &u_most_u {
            let x = x.0 + t;
            most_up = f64::max(x, most_up);
        }
        if let Some(x) = &u_most_d {
            let x = x.0 + t;
            most_down = f64::min(x, most_down);
        }

        if let Some(x) = &d_most_u {
            let x = x.0 - t;
            most_up = f64::max(x, most_up);
        }
        if let Some(x) = &d_most_d {
            let x = x.0 - t;
            most_down = f64::min(x, most_down);
        }

        (most_right - most_left) * (most_up - most_down)
    };

    let mut ans = std::f64::MAX;
    for &t in &lr_events {
        ans = f64::min(ans, calc_area(t));
    }
    for i in 0..lr_events.len() - 1 {
        let mid = ternary_search(lr_events[i], lr_events[i + 1], calc_area);
        ans = f64::min(ans, calc_area(mid));
    }
    println!("{}", ans);
}

fn ternary_search<F>(lb: f64, ub: f64, criterion: F) -> f64
where
    F: Fn(f64) -> f64,
{
    let offset = lb;
    let mut lb = 0.0;
    let mut ub = ub - offset;
    let mid = (lb + ub) / 2.0;
    let mut convex_upward = false;
    if criterion(mid + offset) > (criterion(lb + offset) + criterion(ub + offset)) / 2.0 {
        convex_upward = true;
    }
    while ub - lb > 0.00000002 {
        let mid1 = (ub + lb * 2.0) / 3.0;
        let mid2 = (ub * 2.0 + lb) / 3.0;
        if convex_upward {
            if criterion(mid1 + offset) < criterion(mid2 + offset) {
                lb = mid1;
            } else {
                ub = mid2;
            }
        } else {
            if criterion(mid1 + offset) > criterion(mid2 + offset) {
                lb = mid1;
            } else {
                ub = mid2;
            }
        }
    }
    (lb + ub) / 2.0 + offset
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}