Under construction

Still being built. Things may change

Treasure Map

Interview

Time limit1sMemory limit1024 MB

Summary
Each clue bounds the treasure with a strict inequality, so count the lattice points inside the resulting rectangle, or print Infinity if some side is open.
Level

Easy2 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

You live on an infinite coordinate plane, where the xx coordinate increases to the right and the yy coordinate increases upward. One day you find a treasure map. Unfortunately, the map is split into several pieces, so you cannot tell exactly where the treasure is buried. Still, after analyzing the pieces, you learn the following about the treasure's position.

  • The treasure is buried at an integer lattice point.
  • There are NN clues about the treasure's position. Each clue consists of two integers xi,yix_i, y_i and a character did_i. The character did_i is one of L, R, U, or D, meaning the treasure is buried to the left, right, above, or below the point (xi,yi)(x_i, y_i), respectively.
  • All the information is consistent. That is, there is no pair of clues whose combination leaves no possible position for the treasure.

Using the collected clues, you want to search every possible position for the treasure. Find the number of lattice points you need to search. If the clues are so incomplete that there are infinitely many positions to search, print Infinity instead.

Input

The first line contains the number of clues NN. (1≤N≤100 000)(1 \le N \le 100\ 000)

Each of the next NN lines contains xix_i, yiy_i, and did_i, separated by spaces. This means the treasure is buried in the did_i direction from the coordinate (xi,yi)(x_i, y_i). (−109≤xi,yi≤109;(-10^9 \le x_i, y_i \le 10^9; did_i is one of L, R, U, D)

All numbers in the input are integers.

Output

Print the number of integer lattice points where the treasure may be buried. If there are infinitely many such lattice points, print Infinity instead.

Hint

A lattice point is a point with integer coordinates.

Examples2

  1. Example 1

    Input
    4
    2 1 L
    -2 -1 R
    0 -2 U
    0 2 D
    
    Expected output
    9
    
  2. Example 2

    Input
    1
    1000000000 -1000000000 U
    
    Expected output
    Infinity