Codeforces Round 455 (Div. 2)
C
Python Indentation
Codeforces
1800
原题
← BD →
翻译中…

In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.

翻译中…

We will consider an extremely simplified subset of Python with only two types of statements.

翻译中…

Simple statements are written in a single line, one per line. An example of a simple statement is assignment.

翻译中…

For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.

翻译中…

You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.

翻译中…

Input

翻译中…

The first line contains a single integer $*N*$ ($1 ≤ *N* ≤ 5000$) — the number of commands in the program. $*N*$ lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.

翻译中…

Output

翻译中…

Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo $10^{9} + 7$.

翻译中…

Note

翻译中…

In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.

翻译中…

simple statement
for statement
    for statement
        simple statement

翻译中…

In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.

翻译中…

for statement
    simple statement
    for statement
        simple statement

翻译中…

or

翻译中…

for statement
    simple statement
for statement
    simple statement

翻译中…

样例

Input #1
4
s
f
f
s
Output #1
1
InputCopy OutputCopy
Input #2
4
f
s
f
s
Output #2
2
InputCopy OutputCopy
题目信息
题号
909C
时间限制
2 s
内存限制
256 MB
标签
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。