#C4281. Counting Mystery Chapters
Counting Mystery Chapters
Counting Mystery Chapters
Aman is an avid reader who loves mystery novels. In his collection, each book consists of several chapters, and each chapter is either a Mystery
chapter denoted by M
or a Filler
chapter denoted by F
.
The task is to help Aman determine the total number of mystery chapters across all his books. You are given an integer \(T\) representing the number of books. For each book, the first number indicates the total number of chapters \(C\), and this is followed by \(C\) strings where each string is either M
(for Mystery) or F
(for Filler).
Your program should read the input from stdin and output the result to stdout as a single integer.
Note: It is guaranteed that \(0 \leq T \leq 10^5\) and the total number of chapters across all books does not exceed \(10^6\). Use efficient input methods if necessary.
For example, if the input is:
3 4 M F M F 2 F F 3 M M M
Then, the output should be:
5
inputFormat
The input is read from stdin in the following format:
- The first line contains a single integer \(T\), the number of books.
- Then, \(T\) lines follow. Each line starts with an integer \(C\) denoting the number of chapters in the book, followed by \(C\) space-separated tokens. Each token is either
M
(representing a Mystery chapter) orF
(for Filler chapter).
For example:
3 4 M F M F 2 F F 3 M M M
outputFormat
Output a single integer to stdout which is the total number of Mystery chapters across all books.
For the sample input above, the output is:
5## sample
3
4 M F M F
2 F F
3 M M M
5