Under construction

Still being built. Things may change

Virus Experiment

Time limit2sMemory limit512 MB

Summary
Given wind directions for each time period and a resistance value per grid cell, find the minimum infected count after a huge horizon and how many starting cells reach it.
Level

Hard9 of 10

Topics
Simulation, Matrix, Implementation
Solved
No attempts yet

Statement

Do you know Just Odd Inventions Co., Ltd.? Its business is making 'just odd inventions,' and here we call it JOI Company.

JOI Company developed a new virus, the JOI Virus. The company wants to run an experiment by infecting the inhabitants of IOI Island with it.

IOI Island is rectangular. There are R−1R-1 parallel roads running east to west and C−1C-1 parallel roads running north to south. They divide the island into RCRC sections, and each section has exactly one inhabitant. We call the inhabitant in the section that is the ii-th from the north and the jj-th from the west inhabitant (i,j)(i, j), where 1≤i≤R1 \le i \le R and 1≤j≤C1 \le j \le C.

A day has MM time periods. We call the kk-th time period time period kk. Wind always blows from one of four directions: north, south, east, or west. The direction can change between time periods, but within the same time period, the wind blows from the same direction on every day.

Each inhabitant has a resistance value, a non-negative integer Ui,jU_{i,j}.

  • If Ui,j=0U_{i,j}=0, inhabitant (i,j)(i,j) has high resistance and never gets infected.
  • If Ui,jU_{i,j} is positive, inhabitant (i,j)(i,j) may get infected. If the neighbor in the direction the wind blows from stays infected for Ui,jU_{i,j} consecutive time periods, inhabitant (i,j)(i,j) becomes infected starting from the next time period.

The last time period of a day and the first time period of the next day are consecutive.

The experiment must infect at least one inhabitant, but the goal is to infect as few as possible. At the start, we choose one inhabitant as the first infected person and infect them. We cannot choose an inhabitant with resistance 0 as the first infected person.

Given the wind direction for each time period and the resistance of each inhabitant, compute the minimum number of infected inhabitants after 1010010^{100} days. Also compute how many choices of first infected inhabitant achieve that minimum.

Input

The first line contains MM, RR, and CC. The second line contains a string DD of length MM. The kk-th character of DD is the direction the wind blows from during time period kk. Note that this is the direction the wind comes from, not the direction it blows toward. N means north, S means south, W means west, and E means east.

The next RR lines each contain CC integers. The jj-th integer on the ii-th line is Ui,jU_{i,j}.

Output

Print two lines. The first line contains the minimum number of infected inhabitants after 1010010^{100} days. The second line contains the number of inhabitants who reach that minimum when chosen as the first infected person.

Constraints

  • 1≤M≤100 0001 \le M \le 100\,000
  • 1≤R≤8001 \le R \le 800
  • 1≤C≤8001 \le C \le 800
  • DD has length MM and contains only N, S, W, and E.
  • 0≤Ui,j≤100 0000 \le U_{i,j} \le 100\,000 for 1≤i≤R1 \le i \le R and 1≤j≤C1 \le j \le C.
  • At least one pair (i,j)(i, j) satisfies 1≤Ui,j1 \le U_{i,j}.

Examples2

  1. Example 1

    Input
    6 3 4
    SWNEES
    2 1 1 2
    1 0 1 3
    1 1 2 2
    
    Expected output
    8
    8
    
  2. Example 2

    Input
    4 4 4
    EWWE
    1 2 1 2
    1 1 1 1
    0 0 0 0
    2 2 2 4
    
    Expected output
    3
    3