Example

Input

2 10 6
4 4 E
6 4 W


Output

2

Source: aizu | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
(N, W, D) = map(int, input().split())

def calc(x0, y0, dx, dy):
	s = min(W - x0 if dx >= 0 else x0, D - y0 if dy >= 0 else y0)
	x = x0 + dx * s
	y = y0 + dy * s
	assert x in [0, W] or y in [0, D], (x, y)
	if y == 0:
		return x
	if x == W:
		return W + y
	if y == D:
		return 2 * W + D - x
	return 2 * W + 2 * D - y
S = []
for i in range(N):
	(x, y, f) = input().split()
	x = int(x)
	y = int(y)
	if f == 'N':
		t1 = calc(x, y, 1, 1)
		t2 = calc(x, y, -1, 1)
	elif f == 'E':
		t1 = calc(x, y, 1, -1)
		t2 = calc(x, y, 1, 1)
	elif f == 'S':
		t1 = calc(x, y, -1, -1)
		t2 = calc(x, y, 1, -1)
	else:
		t1 = calc(x, y, -1, 1)
		t2 = calc(x, y, -1, -1)
	if t1 >= t2:
		t1 -= 2 * (W + D)
	S.append((t1, t2))
S.sort(key=lambda x: x[1])
ans = N
INF = 10 ** 9
for i in range(N):
	r = 0
	cur = -INF
	base = 0
	for j in range(N):
		(a, b) = S[(i + j) % N]
		if (i + j) % N == 0:
			base += 2 * (W + D)
		if a + base <= cur:
			continue
		cur = b + base
		r += 1
	ans = min(r, ans)
print(ans)


def raySW(x, y):
	return x - y
(n, w, d) = map(int, input().split())

def toRange(xyf):
	(sx, sy, f) = xyf
	x = int(sx)
	y = int(sy)
	if f == 'S':
		s = raySW(x, y)
		t = w - raySW(w - x, y)
		return (s, t)
	if f == 'E':
		s = w - raySW(w - x, y)
		t = w + d + raySW(w - x, d - y)
		return (s, t)
	if f == 'N':
		s = w + d + raySW(w - x, d - y)
		t = w + d + w - raySW(x, d - y)
		return (s, t)
	if f == 'W':
		s = w + d + w - raySW(x, d - y)
		t = w + d + w + d + raySW(x, y)
		return (s, t) if t <= w + d + w + d else (s - w - w - d - d, t - w - w - d - d)
	exit(-1)
xyfs = [input().split() for _ in range(n)]

def swap(xy):
	(x, y) = xy
	return (y, x)
stso = list(map(swap, list(map(toRange, xyfs))))
sts = sorted(stso)

def contains(s, t, r):
	if t <= r <= s:
		return True
	if t <= r + d + d + w + w <= s:
		return True
	if t <= r - d - d - w - w <= s:
		return True
	return False

def findMin(sts):
	c = 0
	r = w + w + d + d + w + w + d + d + w + w + d + d
	for (s, t) in sts:
		if not contains(s, t, r):
			c += 1
			r = s
	return c
mins = [findMin(sts[i:] + sts[:i]) for i in range(n)]
print(min(mins))