Treasure Map
InterviewTime limit1sMemory limit1024 MB
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 coordinate increases to the right and the 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 clues about the treasure's position. Each clue consists of two integers and a character . The character is one of
L,R,U, orD, meaning the treasure is buried to the left, right, above, or below the point , 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 .
Each of the next lines contains , , and , separated by spaces. This means the treasure is buried in the direction from the coordinate . 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.