Wall Clocks

Each member sees a section of the office walls inside a 90 degree cone, and the task asks for the fewest clock points so every member sees at least one.

Medium6GreedyIntervalsGeometryNo attempts yetTime limit1sMemory limit256 MB

Problem

You manage a chocolate sales team. The team takes a tea break every two hours and tastes the new chocolate products of the company at each break. Everyone looks forward to the break, so they glance at a wall clock often.

The team moved to a new office recently, and you have just finished arranging the desks. One member asked you to hang a clock on the wall in front of her desk so that she is not late for a break, and everyone else agreed with her.

You decided to hang enough clocks that every member has one in view. A member is satisfied if at least one clock is within 45 degrees to the left and 45 degrees to the right (both ends included) of the direction the seat faces. The orientation of the clock itself does not matter. You want to buy as few clocks as possible, so compute the minimum number of clocks that satisfies everyone.

The office is a rectangle whose sides run east to west and north to south. The walls are tall enough that you can hang a clock above the door, and neither other members nor furniture block anyone's line of sight. A clock is a point of size zero, so you can hang one even at a corner of the room.

Arrangements of seats and clocks

Figure 1. Arrangements of seats and clocks. The gray area is the field of view.

For example, suppose the team has two members. If they sit facing each other as in Figure 1(A), the wall sections they see are disjoint, so you need two clocks. In the arrangement of Figure 1(B) their fields of view meet at a single point on the wall, so one clock hung at that point is enough. In Figure 1(C) the two fields of view share a section of the wall, and one clock anywhere in that section is enough. Arrangements (A), (B), and (C) in Figure 1 correspond to the first, the second, and the third example.

Input

The input consists of a single test case in the following format.

n w d
x1 y1 f1
...
xn yn fn

Every value in the input is an integer. The first line contains the number of team members nn (1n10001 \le n \le 1000) and the size of the office ww and dd (2w,d1000002 \le w, d \le 100000). The office has width ww east to west and depth dd north to south. Each of the following nn lines gives the position and the orientation of one member's seat. The seat of member ii is at position (xi,yi)(x_i, y_i) and faces direction fif_i, where 1xiw11 \le x_i \le w - 1 and 1yid11 \le y_i \le d - 1. Each fif_i is one of N, E, W, and S, meaning north, east, west, and south. The position (x,y)(x, y) is the point at distance xx from the west wall and distance yy from the south wall. All seat positions are distinct.

Output

Print the minimum number of clocks needed.