CBOJ 2023 Welcome Contest Problem 3 - Finding "Amis"


Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

While sitting in his French class, NK was feeling a bit bored. To liven things up, his teacher challenged him to count the number of times the word "amis" appeared as a subsequence in a very lengthy string, which she provided to him.

A string \(x\) is a subsequence of a string \(y\) if \(x\) can be obtained from \(y\) by deletion of several (possibly, zero or all) elements. Two subsequences are different if the sequences of their indices are not the same.

NK was struggling with the task and feeling quite overwhelmed. He had spent the entire previous night working on CBOJ problems and hadn't slept a wink. Feeling exhausted and unable to focus, he turned to his closest friend for help - you. As one of his most trusted companions, he knew he could rely on you to assist him in conquering this challenge. You must not let him down!

Constraints

\(2 \le N \le 50\)

\(S\) is made entirely of lowercase English letters.

Input Specification

The first line will contain \(N\), the length of the string.

The next line will contain a string \(S\), consisting of \(N\) lowercase english letters.

Output Specification

Output the number of times "amis" is a subsequence of \(S\).

Sample Input 1

17
somethingwasamiss

Sample Output 1

4

Explanation

There are 4 occurences of "amis" as a subsequence in "somethingwasamiss":

  1. somethingwasamiss

  2. somethingwasamiss

  3. somethingwasamiss

  4. somethingwasamiss

Sample Input 2

4
amis

Sample Output 2

1

Comments

There are no comments at the moment.