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: Accepted)

use std::io::prelude::*;

#[derive(Debug, Clone, Copy)]
struct Point {
    p: [i64; 2],
    d: Dir,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Dir {
    R = 0,
    L = 1,
    U = 2,
    D = 3,
}

impl std::str::FromStr for Dir {
    type Err = ();
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "R" => Ok(Dir::R),
            "L" => Ok(Dir::L),
            "U" => Ok(Dir::U),
            "D" => Ok(Dir::D),
            _ => unreachable!(),
        }
    }
}

#[derive(Debug, Clone, Copy)]
struct Range {
    min: i64,
    max: i64,
}

impl Range {
    fn from_points<'a, F: FnMut() -> T, T: Iterator<Item = &'a Point>>(
        mut pts: F,
        axis: usize,
    ) -> Option<Self> {
        let min = pts().map(|p| p.p[axis]).min();
        let max = pts().map(|p| p.p[axis]).max();

        if let (Some(min), Some(max)) = (min, max) {
            Some(Range { min: min, max: max })
        } else {
            None
        }
    }

    fn get_key_times(out: &mut Vec<i64>, ranges: &[Option<Range>; 3]) {
        // immobile - positive
        if let (Some(r1), Some(r2)) = (ranges[0], ranges[1]) {
            if r2.min < r1.min {
                out.push(r1.min - r2.min);
            }
            if r2.max < r1.max {
                out.push(r1.max - r2.max);
            }
        }
        // immobile - negative
        if let (Some(r1), Some(r2)) = (ranges[0], ranges[2]) {
            if r2.min > r1.min {
                out.push(r2.min - r1.min);
            }
            if r2.max > r1.max {
                out.push(r2.max - r1.max);
            }
        }
        // positive - negative
        if let (Some(r1), Some(r2)) = (ranges[1], ranges[2]) {
            if r1.min < r2.min {
                out.push((r2.min - r1.min) / 2);
            }
            if r1.max < r2.max {
                out.push((r2.max - r1.max) / 2);
            }
        }
    }

    fn union<F: FnMut() -> T, T: Iterator<Item = Range>>(mut ranges: F) -> Option<Self> {
        let min = ranges().map(|range| range.min).min();
        let max = ranges().map(|range| range.max).max();

        if let (Some(min), Some(max)) = (min, max) {
            Some(Range { min: min, max: max })
        } else {
            None
        }
    }

    fn translated_by(&self, x: i64) -> Self {
        Range {
            min: self.min + x,
            max: self.max + x,
        }
    }

    fn len(&self) -> i64 {
        self.max - self.min
    }
}

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_to_string(&mut input_str).unwrap();

    let input_parts = input_str.split_whitespace().collect::<Vec<_>>();
    let mut input_parts_it = input_parts.iter().cloned();

    let n: usize = input_parts_it.next().unwrap().parse().unwrap();

    let mut points: Vec<_> = (0..n)
        .map(|_| Point {
            p: [
                input_parts_it.next().unwrap().parse().unwrap(),
                input_parts_it.next().unwrap().parse().unwrap(),
            ],
            d: input_parts_it.next().unwrap().parse().unwrap(),
        })
        .collect();

    // Double the coordinates to easily handle fractional cases
    for p in points.iter_mut() {
        p.p[0] *= 2;
        p.p[1] *= 2;
    }

    let ranges = [
        // X
        [
            // Immobile
            Range::from_points(|| points.iter().filter(|p| (p.d as u8) >= 2), 0),
            // Positive
            Range::from_points(|| points.iter().filter(|p| p.d == Dir::R), 0),
            // Negative
            Range::from_points(|| points.iter().filter(|p| p.d == Dir::L), 0),
        ],
        // Y
        [
            // Immobile
            Range::from_points(|| points.iter().filter(|p| (p.d as u8) < 2), 1),
            // Positive
            Range::from_points(|| points.iter().filter(|p| p.d == Dir::U), 1),
            // Negative
            Range::from_points(|| points.iter().filter(|p| p.d == Dir::D), 1),
        ],
    ];

    let mut key_times = vec![0];

    Range::get_key_times(&mut key_times, &ranges[0]);
    Range::get_key_times(&mut key_times, &ranges[1]);

    let best = key_times
        .iter()
        .map(|&t| {
            let instant_ranges = [
                [
                    ranges[0][0],
                    ranges[0][1].map(|r| r.translated_by(t)),
                    ranges[0][2].map(|r| r.translated_by(-t)),
                ],
                [
                    ranges[1][0],
                    ranges[1][1].map(|r| r.translated_by(t)),
                    ranges[1][2].map(|r| r.translated_by(-t)),
                ],
            ];

            let aabb = [
                Range::union(|| instant_ranges[0].iter().filter_map(|r| r.clone())).unwrap(),
                Range::union(|| instant_ranges[1].iter().filter_map(|r| r.clone())).unwrap(),
            ];

            let area = aabb[0].len() * aabb[1].len();
            area
        })
        .min()
        .unwrap();

    println!("{}", best as f64 * 0.25);
}