Compass Relay
A network activates one beacon on each of consecutive nights. Beacon is located at , has direction , and contributes charge when visited.
A route is a nonempty sequence of beacon indices For every consecutive pair and , beacon must lie in the closed quadrant indicated by beacon :
- If is
NE, then and .
All inequalities are non-strict, so a beacon on a quadrant boundary can receive the signal.
Moving between consecutive beacons loses charge equal to their Manhattan distance. Therefore, the charge of a route is
Two routes are different if their index sequences are different. Determine the maximum possible charge and the number of routes attaining it, modulo .
Input
The first line contains an integer (), the number of beacons.
The next lines describe the beacons in activation order. The -th line contains integers and , a string , and an integer (, ).
Output
Print two integers and . The value is the maximum charge of any valid route, and is the number of valid routes with charge , taken modulo .
Samples
Sample 1
Input
4 0 0 NE 5 2 1 SW 4 1 0 NE 3 2 0 NW 2
Output
8 2
The maximum charge is . It is attained by the routes with index sequences and .
Sample 2
Input
2 0 0 NE 3 2 0 SW 2
Output
3 2
The one-beacon route and the route both have charge .