Under construction

Still being built. Things may change

Vector Field

Interview

Time limit5sMemory limit512 MB

Summary
Given n points that each redirect a proton along an axis, find the most points a proton can pass through when its start position and direction are chosen freely.
Level

Medium4 of 10

Topics
Graph, Simulation
Solved
No attempts yet

Problem

In 20015, JAG (Jagan Acceleration Group) built a new accelerator called "Force Point" for proton collision experiments on the two-dimensional xyxy-plane. When a proton touches a Force Point, its speed doubles and its direction changes. The new direction is one of four: the positive or negative direction of the xx-axis or the yy-axis. The type of the Force Point determines the direction. A Force Point accelerates a proton only once, then it disappears. A set of Force Points on the plane is called a 2D Force Point Field. Passing a proton through the Force Points in sequence can accelerate it up to a target speed.

JAG has these technical limitations:

  • JAG cannot generate a Force Point at a specified position with a specified type.
  • JAG cannot generate a Force Point after a proton is put into the field.
  • JAG cannot move Force Points.
  • JAG cannot change a proton's direction except through Force Points.
  • JAG can use only one proton for each 2D Force Point Field.
  • JAG can place a proton moving in any direction with speed 1 at any position in the field.

To reach the maximum speed, the engineers must observe the generated field, then pick the initial position and initial direction of the proton so that it is accelerated by as many Force Points as possible.

The field has nn Force Points. The position (xi,yi)(x_i, y_i) and the direction type did_i of each point are known. Write a program that computes the maximum speed a proton can reach when JAG places the proton optimally.

Input

The input is a single test case in this format:

$n$

$x_1$ $y_1$ $d_1$

...

$x_n$ $y_n$ $d_n$

The first line contains one integer nn (1≤n≤3,0001\le n\le 3{,}000). Each of the next nn lines contains two integers xix_i and yiy_i (∣xi∣,∣yi∣≤109|x_i|, |y_i| \le 10^9) and one character did_i, which is one of '>', 'v', '<', or '^'. The type '>' sends the proton in the positive xx direction, 'v' in the positive yy direction, '<' in the negative xx direction, and '^' in the negative yy direction. No two Force Points share the same coordinates.

Output

Print one line with the integer log⁡2vmax\log_2 v_{\mathrm{max}}, where vmaxv_{\mathrm{max}} is the fastest speed the proton can reach.

Examples2

  1. Example 1

    Input
    9
    0 0 v
    1 0 >
    2 0 <
    0 1 >
    1 1 v
    2 1 v
    0 2 ^
    1 2 ^
    2 2 <
    
    Expected output
    9
    
  2. Example 2

    Input
    9
    0 0 ^
    1 0 ^
    2 0 ^
    0 1 <
    1 1 ^
    2 1 >
    0 2 v
    1 2 v
    2 2 v
    
    Expected output
    2