#P1321. Counting Pasted Words
Counting Pasted Words
Counting Pasted Words
You are given a string of length \(l\) which initially consists of \(l\) period characters (i.e. .
). Then, several paste operations are performed sequentially on the string. In each operation, either the word boy
(of length 3) or girl
(of length 4) is pasted onto the string, that is, the word is overlaid on a contiguous segment of the string. When a word is pasted, it overwrites whatever characters (periods or letters from previous pastes) were in that segment.
It is guaranteed that in the final string, each paste operation has at least one character that remains visible (i.e. not overwritten by any later operation). Based on the final string, your task is to determine how many times boy
was pasted and how many times girl
was pasted.
Note: The final string is the result after all pasting operations. Some parts of the string may still be periods if they were never covered.
inputFormat
The input consists of two lines:
- The first line contains an integer \(l\) (the length of the string).
- The second line contains a string of length \(l\) consisting of lowercase letters and periods (
.
).
You may assume that the input is always valid and corresponds to a sequence of paste operations that obey the following rules:
- Each paste operation places either
boy
(length 3) orgirl
(length 4) on some contiguous segment of the string (0-indexed). - A pasted word overwrites what was previously in that segment.
- In the final string, every pasted word has at least one character that is still visible (i.e. was not overwritten by a later paste).
outputFormat
Output two integers separated by a space. The first integer is the total number of times boy
was pasted and the second integer is the total number of times girl
was pasted.
sample
10
.bogirl...
1 1