Under construction

Still being built. Things may change

Internet for a rainy day

Time limit1sMemory limit1024 MB

Summary
Given N crew paths on a checkerboard grid, find the coordinates of the K-th black block to get connected when a path passes alongside it.
Level

Medium7 of 10

Topics
Binary search, Geometry, Implementation
Solved
No attempts yet

Statement

The city of Shakhmatovsk has two internet providers that are carrying out a nationwide internet rollout plan. The city lies on an infinite integer grid. Straight streets run along every grid line, and each unit square is a block. A block is identified by the coordinates of its lower left corner. The blocks are colored black and white in a checkerboard pattern, and the block at (0,0)(0, 0) is black. The provider "Black Internet" connects the black blocks. Residents of the block that is connected K-th will receive a 10% discount. The rollout takes N days. On day ii, a crew starts at (xi,yi)(x_i, y_i) and moves along one of the city streets. The crew passes lil_i blocks in the given direction. While moving, it connects every black block that is not yet connected and shares a side with the crew's path (see the figure). Write a program that finds the coordinates of the block that is connected K-th. It is guaranteed that at least K blocks are connected during the rollout.

Input

The first line contains two integers N and K: 1≤N≤2 0001 \le N \le 2\,000, 1≤K≤10181 \le K \le 10^{18}. Each of the next N lines describes the crew's path on one day. The line contains xix_i and yiy_i, the starting point of the path, the character cic_i, the direction of movement, and lil_i, the distance the crew travels. It is given that −1015≤xi≤1015-10^{15} \le x_i \le 10^{15}, −1015≤yi≤1015-10^{15} \le y_i \le 10^{15}, and 1≤li≤10151 \le l_i \le 10^{15}. The character cic_i is one of 'N' (north, y increases), 'E' (east, x increases), 'S' (south, y decreases), or 'W' (west, x decreases).

Output

Print the x and y coordinates of the block that is connected K-th.

Examples2

  1. Example 1

    Input
    4 10
    2 0 N 5
    2 3 E 3
    4 3 S 2
    0 1 E 5
    
    Expected output
    4 0
    
  2. Example 2

    Input
    4 7
    -1 0 E 4
    -1 1 E 4
    -1 0 E 4
    -1 -1 E 4
    
    Expected output
    0 -2