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 Ruby (2.3.3) (judge verdict: Accepted)

class Dot
  attr_accessor :x, :y, :dir
  def initialize(x, y, direction = nil)
    @x = x.to_i
    @y = y.to_i
    @dir = direction
  end
end

class Way
  attr_accessor :x, :dx
  def initialize(x, dx)
    @x = x
    @dx = dx
  end
end

N = gets.chop.to_i
dots = []
N.times do 
  x, y, dir = gets.chop.split
  dots << Dot.new(x, y, dir)
end

rights = dots.select { |d| d.dir == "R"}
lefts = dots.select { |d| d.dir == "L"}
ups = dots.select { |d| d.dir == "U"}
downs = dots.select { |d| d.dir == "D"}

x_way = []
unless rights.empty?
  if rights.size == 1
    x_way << Way.new(rights[0].x, 1)
  else
    x_way << Way.new(rights.max_by(&:x).x, 1)
    x_way << Way.new(rights.min_by(&:x).x, 1)
  end
end
unless lefts.empty?
  if lefts.size == 1
    x_way << Way.new(lefts[0].x, -1)
  else
    x_way << Way.new(lefts.max_by(&:x).x, -1)
    x_way << Way.new(lefts.min_by(&:x).x, -1)
  end
end

x_flat = ups + downs
unless x_flat.empty?
  if x_flat.size == 1
    x_way << Way.new(x_flat[0].x, 0)
  else
    x_way << Way.new(x_flat.max_by(&:x).x, 0)
    x_way << Way.new(x_flat.min_by(&:x).x, 0)
  end
end

y_way = []
unless ups.empty?
  if ups.size == 1
    y_way << Way.new(ups[0].y, 1)
  else
    y_way << Way.new(ups.max_by(&:y).y, 1)
    y_way << Way.new(ups.min_by(&:y).y, 1)
  end
end
unless downs.empty?
  if downs.size == 1
    y_way << Way.new(downs[0].y, -1)
  else
    y_way << Way.new(downs.max_by(&:y).y, -1)
    y_way << Way.new(downs.min_by(&:y).y, -1)
  end
end

y_flat = lefts + rights
unless y_flat.empty?
  if y_flat.size == 1
    y_way << Way.new(y_flat[0].y, 0)
  else
    y_way << Way.new(y_flat.max_by(&:y).y, 0)
    y_way << Way.new(y_flat.min_by(&:y).y, 0)
  end
end

times = [0.0]
x_way.combination(2) do |a, b|
  next if a.dx == b.dx
  time = ((a.x - b.x) * -1.0) / (a.dx - b.dx)
  next if time < 0
  times << time
end

y_way.combination(2) do |a, b|
  next if a.dx == b.dx
  time = ((a.x - b.x) * -1.0) / (a.dx - b.dx)
  next if time < 0
  times << time
end

ans = 10**100
times.each do |t|
  x_max = x_way.map { |w| w.x + w.dx * t }.max * 1.0
  x_min = x_way.map { |w| w.x + w.dx * t }.min * 1.0
  y_max = y_way.map { |w| w.x + w.dx * t }.max * 1.0
  y_min = y_way.map { |w| w.x + w.dx * t }.min * 1.0
  ans = [ans, (x_max - x_min) * (y_max - y_min)].min
end

puts ans