Time limit: 1 second Memory limit: 6 MB Karim is a 5-year-old child who is interested in…
- User
Time limit: 1 second Memory limit: 6 MB Karim is a 5-year-old child who is interested in painting, and his love for painting has made most of his paintings to be very long.
Karim draws his paintings on checkered paper and they can be described as follows:
Each checkered house is either completely black or completely white There is a black path from every black house to all black houses. A black path means a sequence of black houses where both houses in a row share a corner. There are no white holes in the figure; It means that there is a white path from every white house to the outside of the painting. A white path means a sequence of white houses where both houses in a row share a common side. Today, Karim started painting according to his weekly habit, but for unknown reasons, he got tired and decided to describe only the distance of his painting.
A black house in the drawing is called a corner house if there is at least one white house in the houses adjacent to its vertex (8 houses). The distance described by Karim is a sequence of movement commands that correspond to English letters. This description starts with the letter P and ends with the letter K. The rest of the sequence consists of the letters E, N, W, and S, which are the commands to move west, north, east, and south, respectively. Karim starts from a desired corner house and goes through all the corner houses of his desired painting and returns to the starting house. On the way of movement, all the houses seen will be painted black corner houses. We know that Karim does his distance in a counter-clockwise order.
Karim's mother always shows great enthusiasm for his paintings; So, after seeing his distance, he decides to get the number of black houses in this painting. Help him with a little memory!
input The input contains the delimitation sequence given by Karim, with each letter on a separate line. The sequence consists of a maximum of 4000000 characters. The input sequence is guaranteed to be a correct offset.
output On the only output line you should output the number of black houses in the described drawing.
Example Sample entry 1 P S S S E N E E S E E N N N N S S S W W N N W W W N S K Plain text Sample output 1 23
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.